I want to add item(one fix) to cart automatically when another product is present but quantity changes when main product quantity changed. Ex. if I add Product A with qty 1 in cart then product B with qty 1 will be add to cart same if I add Product A with qty 2 in cart then product B with qty 2. Please don't recommend any extension. Thanks
1条回答 默认 最新
- duancao2082 2016-09-29 08:41关注
You need to override cart controller. Register your module, then in your modules config.xml
<?xml version="1.0"?> <config> <modules> <Kreativ_Buynow> <version>1.0.0</version> </Kreativ_Buynow> </modules> <frontend> <routers> <checkout> <args> <modules> <Kreativ_Buynow before="Mage_Checkout">Kreativ_Buynow</Kreativ_Buynow> </modules> </args> </checkout> </routers> </frontend> </config>
Then create CartController.php in controllers folder
require_once 'Mage/Checkout/controllers/CartController.php'; class Kreativ_Buynow_CartController extends Mage_Checkout_CartController{ public function addAction(){ foreach ($this->_getCart()->getQuote()->getAllItems() as $items) { if($items->getProductId() == 933){ $value = $items->getQty(); $prd = Mage::getModel('catalog/product')->load(943); $this->_getCart()->addProduct($prd,$value)->save(); $this->_getSession()->setCartWasUpdated(true); } } return parent::addAction(); }
Where I assumed if product with id 933 is present, then you are going to add product with id 943 in the cart.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog