我希望将自定义数据保存到购物车项目中,并在产品添加到磁力车中的购物车时添加新的购物车项目而不是更新数量。
我在 Observer.php 文件
中添加了以下代码public function saveProductTabData(Varien_Event_Observer $observer)
{
$product = $observer->getProduct();
try {
$product = $this->getProduct();
$productId = $product->getId();
$data = $this->_getRequest()->getPost();
$customize_price = $data['customize_price'];
$customize_data = $data['customize_data'];
$customize_status = $data['customize_status'];
$customize_description = $data['customize_description'];
$checkProduct = Mage::getModel('productcustomizer/productsetting')->loadByProductId($productId);
if($checkProduct->getProductId() == ''){
$productModel = Mage::getModel('productcustomizer/productsetting');
$productModel->setProductId($productId);
$productModel->setCustomizePrice($customize_price);
$productModel->setCustomizeData($customize_data);
$productModel->setCustomizeStatus($customize_status);
$productModel->setCustomizeDescription($customize_description);
$productModel->save();
} else {
$checkProduct = Mage::getModel('productcustomizer/productsetting')->loadByProductId($productId);
$checkProduct->setCustomizePrice($customize_price);
$checkProduct->setCustomizeData($customize_data);
$checkProduct->setCustomizeStatus($customize_status);
$checkProduct->setCustomizeDescription($customize_description);
$checkProduct->save();
}
}
catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
它将自定义数据保存到购物车项目中,但是当我将相同的产品添加到购物车时,它正在更新数量。我想添加新项目而不是更新数量。
我想单独添加,因为每次将商品添加到购物车时,产品的“自定义数据”和“价格”都不同。