有一個鉤子actionAfterDeleteProductInCart
它從購物車中刪除產品後,你可以做你的支票運行。所以用這個代碼創建一個模塊。
class CartExtraProductsCleaner extends Module {
public function __construct() {
$this->name = 'cartextraproductscleaner';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'whatever';
parent::__construct();
$this->displayName = $this->l('Cart extra products cleaner.');
$this->description = $this->l('Module deletes additional products from cart when there are no standalone products in cart.');
}
public function install() {
return parent::install() && $this->registerHook('actionAfterDeleteProductInCart');
}
public function hookActionAfterDeleteProductInCart($params) {
if ($this->context->cart->nbProducts()) {
$only_additional_products = true;
foreach ($this->context->cart->getProducts() as $product) {
if ($product['id_category_default'] != 10) {
$only_additional_products = false;
break;
}
}
if ($only_additional_products) {
$this->context->cart->delete();
}
}
}
}
基本上從購物車中的每個產品刪除後,我們檢查,如果仍有產品在購物車,遍歷每個產品並檢查它們的默認類別ID。如果僅存在類別ID爲10的產品,則只需刪除整個購物車。
任何人的想法?也許我修改了CartController.php? – redpillcoders
你在使用模塊嗎? – TheDrot
哪個版本使用prestashop? –