isAvailableTimeToImport()) { return $this; } $this->removeFlagImportByDuration(); if (!file_exists(self::ORANGE_35_PRODUCT_IMPORT_FLAG)) { ini_set('memory_limit', '4096M'); file_put_contents(self::ORANGE_35_PRODUCT_IMPORT_FLAG, '1'); register_shutdown_function(array('Orange35_ProductImport_Model_Observer', 'deleteFlagFile'), getcwd()); set_time_limit(self::MAX_EXECUTION_TIME); /** @var Orange35_ProductImport_Helper_Data $helper */ $helper = Mage::helper('orange35_productImport'); Mage::helper('orange35_productImport/timer')->startTimer(); $importStart = explode(' ', microtime()); $message = "==================================== Start Import ===================================="; $helper->log($message, true); $message = round($helper::MAX_FILE_SIZE / 1024); $helper->log("\nOptions:"); $helper->log("\nMAX_FILE_SIZE = " . $message . 'Kb'); $helper->log( 'PRODUCT_PROCESS_GROUP_COUNT = ' . Product_Import_Adapter_Abstract::PRODUCT_PROCESS_GROUP_COUNT . ' simple products' ); $helper->startImport(); $importEnd = explode(' ', microtime()); $message = "==================================== End Import ======================================"; $helper->log($message, true); $time = $importEnd[0] - $importStart[0] + $importEnd[1] - $importStart[1]; $helper->log('Total import time: ' . sprintf("%.3f s", $time) . "(" . sprintf("%.3f min", $time/60) .")\n"); Mage::helper('orange35_productImport/timer')->layoutTimers(); $this->updateConfigurableProducts(); } else { //$helper->log("Import is already running ", true); } chdir($oldDir); return $this; } /** * @return bool */ protected function isAvailableTimeToImport() { $access = false; if (file_exists(Orange35_ProductImport_Helper_Data::DAY_FLAG_FILE)) { $access = true; } else { list($hour, $minute) = explode(':', date('H:i')); if ($hour == 4 && $minute > 0 && $minute < 10) { $access = true; $this->removeDayFlagFileDaily(); } } return $access; } protected function removeFlagImportByDuration() { if (file_exists(self::ORANGE_35_PRODUCT_IMPORT_FLAG)) { if (time() - self::MAX_EXECUTION_TIME > filectime(self::ORANGE_35_PRODUCT_IMPORT_FLAG)) { unlink(self::ORANGE_35_PRODUCT_IMPORT_FLAG); unlink(Orange35_ProductImport_Helper_Data::DAY_FLAG_FILE); } } } protected function removeDayFlagFileDaily() { if (!file_exists(self::ORANGE_35_PRODUCT_IMPORT_FLAG) && file_exists( Orange35_ProductImport_Helper_Data::DAY_FLAG_FILE ) ) { unlink(Orange35_ProductImport_Helper_Data::DAY_FLAG_FILE); } } public function updateConfigurableProducts() { $productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect('*') ->addAttributeToFilter('type_id', 'configurable') ->addAttributeToFilter('sku', array('like' => '%configurable_FL%')); /** * @var $product Mage_Catalog_Model_Product */ $storeIds = array(0,1,7,6); foreach ($productCollection as $product) { $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product); if (sizeof($childProducts) > 0) { /** * @var $childProduct Mage_Catalog_Model_Product */ foreach ($childProducts as $childProduct) { if (strpos($childProduct->getName(), 'фн') ) { /** * @var $product Mage_Catalog_Model_Product */ foreach($storeIds as $storeId) { $product->setName(Mage::getResourceModel('catalog/product') ->getAttributeRawValue($childProduct->getId(), 'name', $storeId)); $product->setPrice($childProduct->getPrice()); $product->setStoreId($storeId); $product->save(); } break; } } } } return $this; } }