I have a Custom product which when added to cart, I intend to validate the cart and ensure the custom product meets certain criterias before checkout.
Please see Shopware Documentation: Add Cart Validator.
class CustomCartValidator implements CartValidatorInterface
{
public function validate(Cart $cart, ErrorCollection $errorCollection, SalesChannelContext $salesChannelContext): void
{
foreach ($cart->getLineItems()->getFlat() as $lineItem) {
if($lineItem->getQuantityInformation() === null){
continue;
}
//use the quantity information here
}
}
}
The $lineItem->getQuantityInformation()
always returns NULL. But if I var_dump($lineItem->getQuantityInformation())
, it outputs the correct information.
How do I solve this problem?