我想在将新产品添加到购物车后将购物车订单列表清空。 事实上,每次只能在产品上购物。 Tanx
答案 0 :(得分:4)
添加自定义逻辑的两种方法:
编辑:第二种方式错误,因为无限更新循环。
这是一个模块:
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']);
}
}
答案 1 :(得分:2)
对于使用Prestashop v 1.4.9并创建了模块的人:
致电global $smarty, $cart;
然后运行函数$cart->delete();
function hookHome($params)
{
global $smarty, $cart;
/** some code here **/
$cart->delete();
}