简体   繁体   English

Prestashop:如何在购物车中获取虚拟产品以在Address.php中使用?

[英]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. 在Prestashop CMS中,仅当购物车中有虚拟产品时才需要address1

How can this be achieved? 如何做到这一点? Does anybody have the solution for this? 有人对此有解决方案吗?

$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;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM