我正在以编程方式将产品从 XML 提要导入 Magento 1.7.0.2。
该脚本在一周的大部分时间里运行良好,但现在我在保存产品时收到如下所示的错误。
这个错误有多严重,是什么原因造成的?
我尝试重新索引所有内容并截断一堆表,错误似乎仍然存在。
错误:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '51-1' for key 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'
导入php(示例):
$sProduct = $this->_productModel;
$sProduct->setTypeId($this->_productTypeSimple)
->setWebsiteIds(array(1))
->setStatus($this->_productStatusDisabled)
->setVisibility($this->_productVisibilityNotVisible)
->setTaxClassId(2) //Taxable Good
->setAttributeSetId(XML_FEED_PRODUCT_ATTRIBUTE_SET)
->setSku($arrayProductData['ProductSKU'])
->setName($arrayProductData['ProductName'])
->setShortDescription($arrayProductData['ProductShortDescription'])
->setDescription($arrayProductData['ProductLongDescription'])
->setPrice(sprintf("%0.2f", $arrayProductData['ProductPrice']))
->setRRP(sprintf("%0.2f", $arrayProductData['ProductPrice']))
->setWeight(0)
->setCategoryIds($arrayProductData['ProductCategories'])
->setUrlKey(str_replace(array(" ","'","&"),"-",$arrayProductData['ProductName']) . "-" . $arrayProductData['ProductSKU']);
$sProduct->setStockData(
array(
'use_config_manage_stock' => 1,
'is_in_stock' =>1,
'qty' => $arrayProductData['ProductStockQty']
)
);
$sProduct->setMetaTitle($arrayProductData['ProductName'])
->setMetaDescription(str_replace("<<THE_PRODUCT>>",$arrayProductData['ProductName'], DEFAULT_META_DESC));
if(isset($arrayProductData['ProductSize'])) {
$sProduct->setData("sizes", $arrayProductData['ProductSize']);
}
if(isset($arrayProductData['ProductColour'])) {
$sProduct->setData("color", $arrayProductData['ProductColour']);
}
try {
$sProduct->save();
}
catch (Mage_Core_Exception $e) {
echo $e->getMessage();
}
感谢您的关注。