我正在使用Opencart 2.0.3.1。我有两个制造商。每个都有两个产品。我应该能够将第一个制造商的两个产品添加到购物车中,当我尝试从第二个制造商添加产品时,它不应该允许添加。
它应告诉客户单独订购。
我能够使用clear功能将单个项目添加到购物车。但是,如果我们能够为每个订单实现单个制造商产品,那将更有意义。
答案 0 :(得分:1)
您必须修改 ControllerCheckoutCart 中的add方法。 所以打开文件 /catalog/controller/checkout/cart.php 并找到以下行
public function add()
在此函数中,约336行用
重复这两行 $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
这些行
//BEGIN OF THE PATCH
/*
OTRIGINAL CODE
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
*/
//control if the cart isn't empty
$can_add_product=true;
if ($this->cart->hasProducts()>0){
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_just_in_cart = $this->model_catalog_product->getProduct($product['product_id']);
$manufacturer_id_in_cart=$product_just_in_cart['manufacturer_id'];
$manufacturer_name_in_cart=$product_just_in_cart['manufacturer'];
//we just analyze only the first product
break;
}
if ($product_info['manufacturer_id']!=$manufacturer_id_in_cart) {
$can_add_product=false;
}
}
if ($can_add_product) {
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
}
else {
$json['success'] =sprintf('For this order you can add only products of '.$manufacturer_name_in_cart, $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
}
//END OF THE PATCH
您可以测试此修补程序here