Prestashop:如何清空购物车? [英] Prestashop : How to Empty cart?
本文介绍了Prestashop:如何清空购物车?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将新产品添加到购物车后,我想使购物车订单列表为空。
实际上,每次只能在产品上进行购物。
Tanx
I want to make Cart order list empty after a new product has been added to the cart. In fact only on product every time can be in cart. Tanx
推荐答案
添加自定义逻辑的2种方法:
2 ways to add your custom logic :
- 创建您自己的模块并将其挂接到 actionCartSave上
-
覆盖 Cart类中的 add和 update方法( /override/classes/Cartp.php)
- create your own module and hook it on "actionCartSave"
override "add" and "update" methods in "Cart" class (/override/classes/Cartp.php)
编辑:第二种方法出错是因为无限的更新循环。
Edit : The 2nd way os wrong because infinite update loop.
以下是执行此操作的模块:
Here is a module that do it :
class OneProductCart extends Module {
public function __construct() {
$this->name = 'oneproductcart';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'SJousse';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('One Product Cart');
$this->description = $this->l('Keep only last product in cart.');
}
public function install() {
return (parent::install() && $this->registerHook('actionCartSave'));
}
public function hookActionCartSave($params) {
$cart = $params['cart'];
$last = $cart->getLastProduct();
$prods = $cart->getProducts();
foreach ($prods as $prod)
if ($prod['id_product'] != $last['id_product'])
$cart->deleteProduct($prod['id_product']);
}
}
这篇关于Prestashop:如何清空购物车?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文