Search code examples
phpprestashopvirtualrequired

Prestashop: How to get virtual product in the cart for use in Address.php?


In Prestashop CMS, address1 is only required if there is a virtual product in the cart.

How can this be achieved? Does anybody have the solution for this?


Solution

  • $context = Context::getContext();
    $cart = $context->cart;
    $is_virtual = $cart->isVirtualCart();
    

    Works perfectly. Example:

            if (in_array('address1', $arr) && $is_virtual) {
                $this->def['fields']['address1']['required'] = 0;
            } else if (in_array('address1', $arr)) {
                $this->def['fields']['address1']['required'] = 1;
                $this->fieldsRequired[] = 'address1';
            } else {
                $this->def['fields']['address1']['required'] = 0;
            }