新しい商品がカートに追加された後、カートの注文リストを空にしたいです。実際には、毎回カートに入れることができるのは製品のみです。タンクス
質問する
7437 次
2 に答える
4
カスタム ロジックを追加する 2 つの方法:
- 独自のモジュールを作成し、「actionCartSave」にフックします
「カート」クラスの「追加」および「更新」メソッドをオーバーライドします (/override/classes/Cartp.php)
編集:無限の更新ループのため、2番目の方法は間違っています。
これを行うモジュールは次のとおりです。
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']);
}
}
于 2013-01-24T09:25:22.300 に答える
2
Prestashop v 1.4.9 を使用していて、モジュールを作成した場合:
電話global $smarty, $cart;
次に、関数を実行します$cart->delete();
function hookHome($params)
{
global $smarty, $cart;
/** some code here **/
$cart->delete();
}
于 2013-12-11T19:20:23.040 に答える