From 1df432bf81845bde543e39875f8b336a194739f7 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 12 Nov 2014 22:26:15 +0000 Subject: [PATCH 1/2] 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 --- .../Entity/Product/Type/Configurable.php | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php index 933c9bf2..118d8bc9 100644 --- a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php +++ b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php @@ -125,6 +125,47 @@ protected function _isSkuNew($sku) return !isset($oldSkus[$sku]); } + /** + * Array of SKU to array of super attribute values for all products. + * + * @return Mage_ImportExport_Model_Import_Entity_Product_Type_Configurable + */ + protected function _loadSkuSuperAttributeValues($bunch, $newSku, $oldSku) + { + if ($this->_superAttributes) { + $attrSetIdToName = $this->_entityModel->getAttrSetIdToName(); + $allowProductTypes = array(); + + foreach ($bunch as $rowData){ + if (!empty($rowData['_super_products_sku'])) { + if (isset($newSku[$rowData['_super_products_sku']])) { + $productIdArray[] = $newSku[$rowData['_super_products_sku']]; + } elseif (isset($oldSku[$rowData['_super_products_sku']])) { + $productIdArray[] = $oldSku[$rowData['_super_products_sku']]; + } + } + } + foreach (Mage::getConfig() + ->getNode('global/catalog/product/type/configurable/allow_product_types')->children() as $type) { + $allowProductTypes[] = $type->getName(); + } + foreach (Mage::getResourceModel('catalog/product_collection') + ->addFieldToFilter('type_id', $allowProductTypes) + ->addFieldToFilter ('entity_id', array('in' => $productIdArray)) + ->addAttributeToSelect(array_keys($this->_superAttributes)) as $product) { + $attrSetName = $attrSetIdToName[$product->getAttributeSetId()]; + $data = array_intersect_key( + $product->getData(), + $this->_superAttributes + ); + foreach ($data as $attrCode => $value) { + $attrId = $this->_superAttributes[$attrCode]['id']; + $this->_skuSuperAttributeValues[$attrSetName][$product->getId()][$attrId] = $value; + } + } + } + return $this; + } /** * Save product type specific data. @@ -149,7 +190,6 @@ public function saveData() if ($this->_entityModel->getBehavior() == Mage_ImportExport_Model_Import::BEHAVIOR_APPEND) { $this->_loadSkuSuperData(); } - $this->_loadSkuSuperAttributeValues(); while ($bunch = $this->_entityModel->getNextBunch()) { $superAttributes = array( @@ -159,6 +199,9 @@ public function saveData() 'super_link' => array(), 'relation' => array() ); + + $this->_loadSkuSuperAttributeValues($bunch, $newSku, $oldSku); + foreach ($bunch as $rowNum => $rowData) { if (!$this->_entityModel->isRowAllowedToImport($rowData, $rowNum)) { continue; From 9d8dc7a37dd38a342e4ee1f9e64495e66897495a Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 6 Jan 2015 21:41:08 +0000 Subject: [PATCH 2/2] Initiate $productIdArray Variable --- .../Model/Import/Entity/Product/Type/Configurable.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php index 118d8bc9..44bb0c90 100644 --- a/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php +++ b/src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product/Type/Configurable.php @@ -135,6 +135,7 @@ protected function _loadSkuSuperAttributeValues($bunch, $newSku, $oldSku) if ($this->_superAttributes) { $attrSetIdToName = $this->_entityModel->getAttrSetIdToName(); $allowProductTypes = array(); + $productIdArray = array(); foreach ($bunch as $rowData){ if (!empty($rowData['_super_products_sku'])) {