有一个钩子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? –