How to get the discount amount code of voucher app

2019-09-20 05:08发布

I am attaching the below snapshots of prestashop shopping cart So how I will get the code of discount amount from the voucher redeemed.

http://imgur.com/a/bvx7J

http://imgur.com/a/XgT9p

1条回答
甜甜的少女心
2楼-- · 2019-09-20 05:38

You can use the getCartRules() function to fetch all the cart rules applied on any cart. This function is defined in the Cart.php class file.

You can use the following code to fetch all the coupon details on current cart:

$this->context->cart->getCartRules();

and you can use below code to know if the customer is using the voucher for the first time.

if ($context->cart->id_customer) {
        $quantityUsed = Db::getInstance()->getValue('
        SELECT count(*)
        FROM '._DB_PREFIX_.'orders o
        LEFT JOIN '._DB_PREFIX_.'order_cart_rule od ON o.id_order = od.id_order
        WHERE o.id_customer = '.$context->cart->id_customer.'
        AND od.id_cart_rule = '.(int)$this->id.'
        AND '.(int)Configuration::get('PS_OS_ERROR').' != o.current_state
        ');
        if ($quantityUsed == 0) {
          // Customer is using the coupon for first time.
        }
    }
查看更多
登录 后发表回答