How to get the discount amount code of voucher applied in prestashop

ぃ、小莉子 提交于 2020-01-17 18:38: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:


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.
        }
    }


来源:https://stackoverflow.com/questions/39763488/how-to-get-the-discount-amount-code-of-voucher-applied-in-prestashop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!