我现在需要在magento 1.x中使用sql查询来更新目录/库存数量,现在使用模型如下所示,但是要花一些时间来执行,所以需要一个查询来检查产品是否存在然后更新数量< / p>
foreach ($value as $item)
{
$sku = $item['internalskucode'];
$availQty = $item['availableQuantity'];
if (is_numeric($sku) || $sku === '')
{
Mage::log($sku, null, 'numericsku.log');
}
else
{
if (Mage::getSingleton('catalog/product')->getIdBySku($sku)) {
// Product exists
$product_id = Mage::getModel("catalog/product")->getIdBySku($sku);
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product_id);
$stockItem->setQty($availQty);
$stockItem->save();
Mage::log($sku, null, 'save.log');
}
else
{
// Product does not exist
Mage::log($sku, null, 'unavailable.log');
}
}
}
foreach ($value as $item)
{
$sku = $item['internalskucode'];
$availQty = $item['availableQuantity'];
if (is_numeric($sku) || $sku === '')
{
Mage::log($sku, null, 'numericsku.log');
}
else
{
if (Mage::getSingleton('catalog/product')->getIdBySku($sku)) {
// Product exists
$product_id = Mage::getModel("catalog/product")->getIdBySku($sku);
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product_id);
$stockItem->setQty($availQty);
$stockItem->save();
Mage::log($sku, null, 'save.log');
}
else
{
// Product does not exist
Mage::log($sku, null, 'unavailable.log');
}
}
}
应通过所有产品的SQL查询更新数量。