我正在自定义一个POS扩展,以准备在场外活动中自动售货。
以前,我们只是手动收取销售费用,并在事后返回手动添加订单。此POS扩展程序将使我们能够使用我们的实时网站来销售商品,然后正确记录销售情况(并且现有的付款方式将起作用)。
现在,我正在尝试在将商品添加到购物车时对商品应用特价。扩展的代码这样做是为了将商品添加到购物车:
$product_model = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId());
$session = Mage::getSingleton('checkout/session');
$cart = Mage::getSingleton('checkout/cart');
$product_model = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($pr_id);
if(!$product_model)
throw new Exception("Product id {$pr_id} not found");
$cart->addProduct($product_model, array('qty' => $qty));
$cart->save();
$session->setLastAddedProductId($last_pr_id);
$this->getPos()->getQuote()->collectTotals()->save();
我发现的关于应用定价的所有内容都是针对$item
而不是在购物车级别完成的。在其他代码中,我已经尝试了$product_model->setCustomPrice($price);
和setPrice()
和setOriginalPrice()
但这些都不起作用。我觉得我非常接近解决方案。
在这里有经验的人会帮助我在上下文中获取该项目或找到在上述代码段中应用折扣的方法吗?
谢谢!
您需要挂钩到事件中,请查看我在此处提供的答案,如果您有任何问题或遇到问题,请告诉我:
在将产品添加到购物车时更改报价:magento