Skip to content

Commit 1df432b

Browse files
author
Andy
committed
Performance Fix for Large Catalogs
Refer to this thread for the full issue. magento/magento2#278 We confirmed this issue Exists in Magento EE 1.13 Where for large catalogs we were experiencing out of memory issues due to this function _loadSkuSuperAttributeValues() This patch will help those stores with large amounts of configurable products process large imports with hundreds of thousands of rows without hitting this issue as a bottleneck
1 parent 1bbefc7 commit 1df432b

File tree

1 file changed

+44
-1
lines changed
  • src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type

1 file changed

+44
-1
lines changed

src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ protected function _isSkuNew($sku)
125125
return !isset($oldSkus[$sku]);
126126
}
127127

128+
/**
129+
* Array of SKU to array of super attribute values for all products.
130+
*
131+
* @return Mage_ImportExport_Model_Import_Entity_Product_Type_Configurable
132+
*/
133+
protected function _loadSkuSuperAttributeValues($bunch, $newSku, $oldSku)
134+
{
135+
if ($this->_superAttributes) {
136+
$attrSetIdToName = $this->_entityModel->getAttrSetIdToName();
137+
$allowProductTypes = array();
138+
139+
foreach ($bunch as $rowData){
140+
if (!empty($rowData['_super_products_sku'])) {
141+
if (isset($newSku[$rowData['_super_products_sku']])) {
142+
$productIdArray[] = $newSku[$rowData['_super_products_sku']];
143+
} elseif (isset($oldSku[$rowData['_super_products_sku']])) {
144+
$productIdArray[] = $oldSku[$rowData['_super_products_sku']];
145+
}
146+
}
147+
}
148+
foreach (Mage::getConfig()
149+
->getNode('global/catalog/product/type/configurable/allow_product_types')->children() as $type) {
150+
$allowProductTypes[] = $type->getName();
151+
}
152+
foreach (Mage::getResourceModel('catalog/product_collection')
153+
->addFieldToFilter('type_id', $allowProductTypes)
154+
->addFieldToFilter ('entity_id', array('in' => $productIdArray))
155+
->addAttributeToSelect(array_keys($this->_superAttributes)) as $product) {
156+
$attrSetName = $attrSetIdToName[$product->getAttributeSetId()];
157+
$data = array_intersect_key(
158+
$product->getData(),
159+
$this->_superAttributes
160+
);
161+
foreach ($data as $attrCode => $value) {
162+
$attrId = $this->_superAttributes[$attrCode]['id'];
163+
$this->_skuSuperAttributeValues[$attrSetName][$product->getId()][$attrId] = $value;
164+
}
165+
}
166+
}
167+
return $this;
168+
}
128169

129170
/**
130171
* Save product type specific data.
@@ -149,7 +190,6 @@ public function saveData()
149190
if ($this->_entityModel->getBehavior() == Mage_ImportExport_Model_Import::BEHAVIOR_APPEND) {
150191
$this->_loadSkuSuperData();
151192
}
152-
$this->_loadSkuSuperAttributeValues();
153193

154194
while ($bunch = $this->_entityModel->getNextBunch()) {
155195
$superAttributes = array(
@@ -159,6 +199,9 @@ public function saveData()
159199
'super_link' => array(),
160200
'relation' => array()
161201
);
202+
203+
$this->_loadSkuSuperAttributeValues($bunch, $newSku, $oldSku);
204+
162205
foreach ($bunch as $rowNum => $rowData) {
163206
if (!$this->_entityModel->isRowAllowedToImport($rowData, $rowNum)) {
164207
continue;

0 commit comments

Comments
 (0)