我正在建立一个Ajax Cart系统,作为我自己主题的一部分。当我尝试添加简单或可配置的产品时,我收到错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'website_ids' in 'where clause'
这是我的代码:
function add_to_cartAction($product = false)
{
$data = json_decode(base64_decode($_POST['data']) , true);
if(!$product)
{
$product = Mage::getModel('catalog/product')->load($data['entity_id']);
}
try{
if($product->getTypeId() == 'simple'){
$params = array(
'qty' => $data['quantity'] ,
'product' => $product->getId()
);
$this->addProduct($product , $params);
die(base64_encode(json_encode(array('success' => 'Successfully added product to cart'))));
}else{
$options = $data['attrs'];
$_matchedItem = null;
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
foreach($childProducts as $item)
{
$matchAmount = count($options);
$matched = 0;
foreach($options as $attr => $option)
{
if($item->getData($attr) == $option)
{
$matched++;
}
}
if($matched == $matchAmount)
{
$_matchedItem = $item;
break;
}
}
if($_matchedItem == null)
{
throw new Exception("Matched Item is null");
}
$params = array(
'qty' => $data['quantity'] ,
'product' => $_matchedItem->getId()
);
$this->addProduct($_matchedItem , $params);
die(base64_encode(json_encode(array('success' => 'Successfully added product to cart'))));
}
}catch(Exception $e)
{
die($e->getMessage());
}
}
function addProduct($product , $params)
{
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->setWebsiteId(Mage::app()->getWebsite()->getId());
$cart->setStoreId(Mage::app()->getStore()->getId());
$cart->getQuote()->addProduct($product , $params['qty']);
$cart->getQuote()->save();
$cart->save();
}
每当我尝试将产品添加到购物车时,我都会遇到salesrule
表格的问题,说明网站site_ids并不存在,虽然在Magento的工作版本上,它并没有这样做。存在,但仍有效。这让我很困惑,任何人都有解决方案吗?
编辑* 添加了salesrule表的屏幕截图。