Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...