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.
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…