如何使用与数据库的直接连接在Magento中导入产品 [英] How do I have to import products in Magento using a direct connection to the database
问题描述
我在Magento商店中有大约50,000条记录要导入。我已经测试过:
文件约为50 MB。
I have about 50.000 of records to import in a Magento store. What I have already tested: The file is about 50 MB.
- 拆分文件
- API
- Magento Classes
拆分文件并不会提高速度进口产品。
Api非常慢。
Magento类很慢。
Splitting the file doesn't improve the speed of the importing of the products. Api are very slow. Magento Classes are slow.
这是使用Magento类的一段代码:
This is a snipped of code using the Magento Classes:
// Build the product
$product->setIsMassupdate(true)
->setExcludeUrlRewrite(true)
->setManufacturer($this->addManufacturers(utf8_encode($record[4])))
->setSku($record[3])
->setAttributeSetId($this->attribute_set)# 9 is for default
->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
->setName(utf8_encode($record[5]))
->setCategoryIds($this->getCategories(array($record[0], $record[1], $record[2]))) # some cat id's,
->setWebsiteIDs(array(1)) # Website id, 1 is default
->setDescription(utf8_encode($record[6]))
->setShortDescription($this->shortText(utf8_encode($record[6]), 150))
->setPrice($price) # Set some price
->setSpecialPrice($special_price)
->setWeight($record[12])
->setStatus( Mage_Catalog_Model_Product_Status::STATUS_ENABLED )
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->setTaxClassId(2) // default tax class
->setPixmaniaimg($record[10])
->setStockData(array('is_in_stock' => $inStock, 'qty' => $qty))
->setCreatedAt(strtotime('now'));
$product->save();
$ID = is_numeric($productID) ? $productID : $product->getId();
所以上面的方法是正确的但是花了大约5个小时才能插入只有2300记录!!
为了添加新产品,我必须在Magento DB中执行哪些简单的SQL插入?
Which are the simple SQL inserts that I have to execute in the Magento DB in order to add a new product?
推荐答案
如果在加载运行时禁用索引器,然后重新启用并在之后运行,则应该会缩短加载时间。
If you disable the indexer while your load runs and then re-enable and run afterwards, it should improve your load time.
$indexer = Mage::getSingleton('index/indexer');
$indexer->lockIndexer();
// ... run your processing ...
$indexer->unlockIndexer();
// Reindex everything
$processes = $indexer->getProcessesCollection();
foreach ($processes as $process)
{
// echo 'Processing: ' . $process->getIndexerCode() . "n";
$process->reindexEverything();
}
这篇关于如何使用与数据库的直接连接在Magento中导入产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!