我正在尝试以编程方式将一个项目添加到访问者的购物车中。在此过程中,项目将获得自定义价格。在添加项目后最初显示的页面上,“我的购物车”摘要(在右栏中)表示购物车包含具有正确价格的商品。但是,当我转到查看购物车页面时,该项目将以其默认价格(而非自定义价格)列出。
如何制作自定义价格棒?
谢谢你,
本
以下是代码:
$product = Mage::getModel('catalog/product');
$product->load(169);
$product->setSpecialPrice(10);
$cart = Mage::getSingleton('checkout/cart');
$cart->addProduct($product, array('qty' => 1, 'options' => array(5 => 'spec goes here' . time())));
$cart->save();
我尝试在$ product-> setSpecialPrice()之后调用$ product-> save(),但结果是:
Warning: Invalid argument supplied for foreach() in app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 1068
#0 app\code\core\Mage\Eav\Model\Entity\Abstract.php(1068): mageCoreErrorHandler(2, 'Invalid argumen...', 'C:\Program File...', 1068, Array)
#1 app\code\core\Mage\Eav\Model\Entity\Abstract.php(1012): Mage_Eav_Model_Entity_Abstract->_collectSaveData(Object(Mage_Catalog_Model_Product))
#2 app\code\core\Mage\Core\Model\Abstract.php(318): Mage_Eav_Model_Entity_Abstract->save(Object(Mage_Catalog_Model_Product))
#3 app\code\local\BenGribaudo\RazaOrderGrid\controllers\IndexController.php(13): Mage_Core_Model_Abstract->save()
#4 app\code\core\Mage\Core\Controller\Varien\Action.php(418): BenGribaudo_RazaOrderGrid_IndexController->addAction()
#5 app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('add')
#6 app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#7 app\code\core\Mage\Core\Model\App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#8 app\Mage.php(627): Mage_Core_Model_App->run(Array)
#9 index.php(80): Mage::run('', 'store')
#10 {main}