Reputation: 35
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
Upvotes: 0
Views: 8361
Reputation: 21
For people using Prestashop v 1.4.9 and have created a module:
call global $smarty, $cart;
then run the function $cart->delete();
function hookHome($params)
{
global $smarty, $cart;
/** some code here **/
$cart->delete();
}
Upvotes: 2
Reputation: 711
2 ways to add your custom logic :
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']);
}
}
Upvotes: 4