public function run($name) { $fileName = MAGENTO . '/var/split/old/' . $name; echo "Reading {$fileName}.\n"; $file = fopen($fileName, "r"); while (!feof($file)) { $csv[] = fgetcsv($file, 0, ','); } $keys = array_shift($csv); foreach ($csv as $i => $row) { $csv[$i] = array_combine($keys, $row); $csv[$i] = $csv[$i]; //array_filter($csv[$i],'self::checkEmpty'); } $i = 0; $currentSet = null; foreach ($csv as $row) { $row['sku_type'] = 1; $row['price_type'] = 1; $row['weight_type'] = 1; $row = $this->removeInvalidData($row); $row = $this->convertBool($row); if (trim($row['sku']) != '') { $currentSet = $row['sku']; $this->_groups[$currentSet][] = $row; $i++; } else { $processedChild = array_filter($row, 'self::checkEmpty'); if (!empty($processedChild)) { $newExtRow = array_merge($this->_groups[$currentSet][0], $processedChild); if (array_equal($this->_groups[$currentSet][0], $newExtRow)) { continue; } $newExtRow['bundle_skus'] = ''; $newExtRow['bundle_options'] = ''; $this->_groups[$currentSet][] = $newExtRow; } unset($processedChild, $newExtRow); } } echo "MEMORY USED : " . convert(memory_get_usage(true)) . "\n"; fclose($file); unset($csv, $keys, $file, $row); $finalArray = array(); foreach ($this->_groups as $sku => $_product) { foreach ($_product as $__product) { $finalArray[] = $__product; } } unset($this->_groups); prepareCsv($finalArray, 'split/new/' . $name, ','); echo "MEMORY USED : " . convert(memory_get_usage(true)) . "\n"; }
function prepareCollection($ent_type_id, $exportAttributes) { $resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_read'); // Increase maximium length for group_concat $connection->query("SET SESSION group_concat_max_len = 1000000;"); $select_attribs = $connection->select()->from(array('ea' => $resource->getTableName('eav/attribute')), array('ea.*', 'c_ea.*', "(SELECT GROUP_CONCAT(CONCAT_WS('|',l_ea.value,l_ea.store_id) SEPARATOR ':') FROM " . $resource->getTableName('eav/attribute_label') . " as l_ea WHERE ea.attribute_id = l_ea.attribute_id GROUP BY l_ea.attribute_id) as arrtibute_frontname")); $select_attribs->join(array('c_ea' => $resource->getTableName('catalog/eav_attribute')), 'ea.attribute_id = c_ea.attribute_id'); if (!empty($exportAttributes)) { $select_attribs = $select_attribs->where('ea.attribute_code in ( ' . implode(',', $exportAttributes) . ' )'); } $select_prod_attribs = $select_attribs->where('ea.entity_type_id = ' . $ent_type_id)->order('ea.attribute_id ASC'); $product_attributes = $connection->fetchAll($select_prod_attribs); $select_attrib_option = $select_attribs->join(array('e_ao' => $resource->getTableName('eav/attribute_option'), array('option_id')), 'c_ea.attribute_id = e_ao.attribute_id')->columns("(SELECT GROUP_CONCAT(CONCAT_WS('|',e_aov.value,e_aov.store_id) SEPARATOR ':') FROM " . $resource->getTableName('eav/attribute_option_value') . " as e_aov WHERE e_ao.option_id = e_aov.option_id GROUP BY e_aov.option_id) as value")->join(array('e_aov' => $resource->getTableName('eav/attribute_option_value'), array('value')), 'e_ao.option_id = e_aov.option_id ', array())->order('e_ao.attribute_id ASC'); $product_attribute_options = $connection->fetchAll($select_attrib_option); $attributesCollection = mergeCollections($product_attributes, $product_attribute_options); unset($product_attributes, $product_attribute_options); echo "preparing csv.... \n"; prepareCsv($attributesCollection, 'importAttribute.csv', ','); unset($attributesCollection); }