public function getDateStrFormat() { $str_format = Varien_Date::convertZendToStrftime($this->getDateFormat(), true, true); return $str_format; }
/** * Gather and save information about product entities. * * @return Mage_ImportExport_Model_Import_Entity_Product */ protected function _saveProducts() { /** @var $resource Mage_ImportExport_Model_Import_Proxy_Product_Resource */ $resource = Mage::getModel('Mage_ImportExport_Model_Import_Proxy_Product_Resource'); $priceIsGlobal = Mage::helper('Mage_Catalog_Helper_Data')->isPriceGlobal(); $strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $productLimit = null; $productsQty = null; while ($bunch = $this->_dataSourceModel->getNextBunch()) { $entityRowsIn = array(); $entityRowsUp = array(); $attributes = array(); $websites = array(); $categories = array(); $tierPrices = array(); $groupPrices = array(); $mediaGallery = array(); $uploadedGalleryFiles = array(); $previousType = null; $previousAttributeSet = null; foreach ($bunch as $rowNum => $rowData) { if (!$this->validateRow($rowData, $rowNum)) { continue; } $rowScope = $this->getRowScope($rowData); if (self::SCOPE_DEFAULT == $rowScope) { $rowSku = $rowData[self::COL_SKU]; // 1. Entity phase if (isset($this->_oldSku[$rowSku])) { // existing row $entityRowsUp[] = array('updated_at' => now(), 'entity_id' => $this->_oldSku[$rowSku]['entity_id']); } else { // new row if (!$productLimit || $productsQty < $productLimit) { $entityRowsIn[$rowSku] = array('entity_type_id' => $this->_entityTypeId, 'attribute_set_id' => $this->_newSku[$rowSku]['attr_set_id'], 'type_id' => $this->_newSku[$rowSku]['type_id'], 'sku' => $rowSku, 'created_at' => now(), 'updated_at' => now()); $productsQty++; } else { $rowSku = null; // sign for child rows to be skipped $this->_rowsToSkip[$rowNum] = true; continue; } } } elseif (null === $rowSku) { $this->_rowsToSkip[$rowNum] = true; continue; // skip rows when SKU is NULL } elseif (self::SCOPE_STORE == $rowScope) { // set necessary data from SCOPE_DEFAULT row $rowData[self::COL_TYPE] = $this->_newSku[$rowSku]['type_id']; $rowData['attribute_set_id'] = $this->_newSku[$rowSku]['attr_set_id']; $rowData[self::COL_ATTR_SET] = $this->_newSku[$rowSku]['attr_set_code']; } // 2. Product-to-Website phase if (!empty($rowData['_product_websites'])) { $websites[$rowSku][$this->_websiteCodeToId[$rowData['_product_websites']]] = true; } // 3. Categories phase $categoryPath = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY]; if (!empty($rowData[self::COL_ROOT_CATEGORY])) { $categoryId = $this->_categoriesWithRoots[$rowData[self::COL_ROOT_CATEGORY]][$categoryPath]; $categories[$rowSku][$categoryId] = true; } elseif (!empty($categoryPath)) { $categories[$rowSku][$this->_categories[$categoryPath]] = true; } // 4.1. Tier prices phase if (!empty($rowData['_tier_price_website'])) { $tierPrices[$rowSku][] = array('all_groups' => $rowData['_tier_price_customer_group'] == self::VALUE_ALL, 'customer_group_id' => $rowData['_tier_price_customer_group'] == self::VALUE_ALL ? 0 : $rowData['_tier_price_customer_group'], 'qty' => $rowData['_tier_price_qty'], 'value' => $rowData['_tier_price_price'], 'website_id' => self::VALUE_ALL == $rowData['_tier_price_website'] || $priceIsGlobal ? 0 : $this->_websiteCodeToId[$rowData['_tier_price_website']]); } // 4.2. Group prices phase if (!empty($rowData['_group_price_website'])) { $groupPrices[$rowSku][] = array('all_groups' => $rowData['_group_price_customer_group'] == self::VALUE_ALL, 'customer_group_id' => $rowData['_group_price_customer_group'] == self::VALUE_ALL ? 0 : $rowData['_group_price_customer_group'], 'value' => $rowData['_group_price_price'], 'website_id' => self::VALUE_ALL == $rowData['_group_price_website'] || $priceIsGlobal ? 0 : $this->_websiteCodeToId[$rowData['_group_price_website']]); } // 5. Media gallery phase foreach ($this->_imagesArrayKeys as $imageCol) { if (!empty($rowData[$imageCol])) { if (!array_key_exists($rowData[$imageCol], $uploadedGalleryFiles)) { $uploadedGalleryFiles[$rowData[$imageCol]] = $this->_uploadMediaFiles($rowData[$imageCol]); } $rowData[$imageCol] = $uploadedGalleryFiles[$rowData[$imageCol]]; } } if (!empty($rowData['_media_image'])) { $mediaGallery[$rowSku][] = array('attribute_id' => $rowData['_media_attribute_id'], 'label' => $rowData['_media_lable'], 'position' => $rowData['_media_position'], 'disabled' => $rowData['_media_is_disabled'], 'value' => $rowData['_media_image']); } // 6. Attributes phase $rowStore = self::SCOPE_STORE == $rowScope ? $this->_storeCodeToId[$rowData[self::COL_STORE]] : 0; $productType = $rowData[self::COL_TYPE]; if (!is_null($rowData[self::COL_TYPE])) { $previousType = $rowData[self::COL_TYPE]; } if (!is_null($rowData[self::COL_ATTR_SET])) { $previousAttributeSet = $rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_ATTR_SET]; } if (self::SCOPE_NULL == $rowScope) { // for multiselect attributes only if (!is_null($previousAttributeSet)) { $rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_ATTR_SET] = $previousAttributeSet; } if (is_null($productType) && !is_null($previousType)) { $productType = $previousType; } if (is_null($productType)) { continue; } } $rowData = $this->_productTypeModels[$productType]->prepareAttributesWithDefaultValueForSave($rowData, !isset($this->_oldSku[$rowSku])); $product = Mage::getModel('Mage_ImportExport_Model_Import_Proxy_Product', $rowData); foreach ($rowData as $attrCode => $attrValue) { $attribute = $resource->getAttribute($attrCode); if ('multiselect' != $attribute->getFrontendInput() && self::SCOPE_NULL == $rowScope) { continue; // skip attribute processing for SCOPE_NULL rows } $attrId = $attribute->getId(); $backModel = $attribute->getBackendModel(); $attrTable = $attribute->getBackend()->getTable(); $storeIds = array(0); if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) { $attrValue = gmstrftime($strftimeFormat, strtotime($attrValue)); } elseif ($backModel) { $attribute->getBackend()->beforeSave($product); $attrValue = $product->getData($attribute->getAttributeCode()); } if (self::SCOPE_STORE == $rowScope) { if (self::SCOPE_WEBSITE == $attribute->getIsGlobal()) { // check website defaults already set if (!isset($attributes[$attrTable][$rowSku][$attrId][$rowStore])) { $storeIds = $this->_storeIdToWebsiteStoreIds[$rowStore]; } } elseif (self::SCOPE_STORE == $attribute->getIsGlobal()) { $storeIds = array($rowStore); } } foreach ($storeIds as $storeId) { if ('multiselect' == $attribute->getFrontendInput()) { if (!isset($attributes[$attrTable][$rowSku][$attrId][$storeId])) { $attributes[$attrTable][$rowSku][$attrId][$storeId] = ''; } else { $attributes[$attrTable][$rowSku][$attrId][$storeId] .= ','; } $attributes[$attrTable][$rowSku][$attrId][$storeId] .= $attrValue; } else { $attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue; } } // restore 'backend_model' to avoid 'default' setting $attribute->setBackendModel($backModel); } } $this->_saveProductEntity($entityRowsIn, $entityRowsUp)->_saveProductWebsites($websites)->_saveProductCategories($categories)->_saveProductTierPrices($tierPrices)->_saveProductGroupPrices($groupPrices)->_saveMediaGallery($mediaGallery)->_saveProductAttributes($attributes); } return $this; }
/** * Retrieve time format by strftime function * * @param string $type * @return string */ public function getTimeStrFormat($type) { return Varien_Date::convertZendToStrftime($this->getTimeFormat($type), false, true); }
/** * Gather and save information about customer entities. * * @return Mage_ImportExport_Model_Import_Entity_Customer */ protected function _saveCustomers() { /** @var $resource Mage_Customer_Model_Customer */ $resource = Mage::getModel('customer/customer'); $strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $table = $resource->getResource()->getEntityTable(); $nextEntityId = Mage::getResourceHelper('importexport')->getNextAutoincrement($table); $passId = $resource->getAttribute('password_hash')->getId(); $passTable = $resource->getAttribute('password_hash')->getBackend()->getTable(); while ($bunch = $this->_dataSourceModel->getNextBunch()) { $entityRowsIn = array(); $entityRowsUp = array(); $attributes = array(); foreach ($bunch as $rowNum => $rowData) { if (!$this->validateRow($rowData, $rowNum)) { continue; } if (self::SCOPE_DEFAULT == $this->getRowScope($rowData)) { // entity table data $entityRow = array('group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'], 'store_id' => empty($rowData[self::COL_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]], 'created_at' => empty($rowData['created_at']) ? now() : gmstrftime($strftimeFormat, strtotime($rowData['created_at'])), 'updated_at' => now()); if (isset($this->_oldCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]])) { // edit $entityId = $this->_oldCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]]; $entityRow['entity_id'] = $entityId; $entityRowsUp[] = $entityRow; } else { // create $entityId = $nextEntityId++; $entityRow['entity_id'] = $entityId; $entityRow['entity_type_id'] = $this->_entityTypeId; $entityRow['attribute_set_id'] = 0; $entityRow['website_id'] = $this->_websiteCodeToId[$rowData[self::COL_WEBSITE]]; $entityRow['email'] = $rowData[self::COL_EMAIL]; $entityRow['is_active'] = 1; $entityRowsIn[] = $entityRow; $this->_newCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]] = $entityId; } // attribute values foreach (array_intersect_key($rowData, $this->_attributes) as $attrCode => $value) { if (!$this->_attributes[$attrCode]['is_static'] && strlen($value)) { /** @var $attribute Mage_Customer_Model_Attribute */ $attribute = $resource->getAttribute($attrCode); $backModel = $attribute->getBackendModel(); $attrParams = $this->_attributes[$attrCode]; if ('select' == $attrParams['type']) { $value = $attrParams['options'][strtolower($value)]; } elseif ('datetime' == $attrParams['type']) { $value = gmstrftime($strftimeFormat, strtotime($value)); } elseif ($backModel) { $attribute->getBackend()->beforeSave($resource->setData($attrCode, $value)); $value = $resource->getData($attrCode); } $attributes[$attribute->getBackend()->getTable()][$entityId][$attrParams['id']] = $value; // restore 'backend_model' to avoid default setting $attribute->setBackendModel($backModel); } } // password change/set if (isset($rowData['password']) && strlen($rowData['password'])) { $attributes[$passTable][$entityId][$passId] = $resource->hashPassword($rowData['password']); } } } $this->_saveCustomerEntity($entityRowsIn, $entityRowsUp)->_saveCustomerAttributes($attributes); } return $this; }
/** * Retrieve pattern for time formatting * * @return string */ protected function _getStrftimeFormat() { return Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); }
/** * Import data rows. * * @return boolean */ protected function _importData() { /** @var $customer Mage_Customer_Model_Customer */ $customer = Mage::getModel('customer/customer'); /** @var $resource Mage_Customer_Model_Address */ $resource = Mage::getModel('customer/address'); $strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $table = $resource->getResource()->getEntityTable(); $nextEntityId = Mage::getResourceHelper('importexport')->getNextAutoincrement($table); $customerId = null; $regionColName = self::getColNameForAttrCode('region'); $countryColName = self::getColNameForAttrCode('country_id'); /** @var $regionIdAttr Mage_Customer_Model_Attribute */ $regionIdAttr = Mage::getSingleton('eav/config')->getAttribute($this->getEntityTypeCode(), 'region_id'); $regionIdTable = $regionIdAttr->getBackend()->getTable(); $regionIdAttrId = $regionIdAttr->getId(); $isAppendMode = Mage_ImportExport_Model_Import::BEHAVIOR_APPEND == $this->_customer->getBehavior(); while ($bunch = $this->_dataSourceModel->getNextBunch()) { $entityRows = array(); $attributes = array(); $defaults = array(); // customer default addresses (billing/shipping) data foreach ($bunch as $rowNum => $rowData) { if (!empty($rowData[Mage_ImportExport_Model_Import_Entity_Customer::COL_EMAIL]) && !empty($rowData[Mage_ImportExport_Model_Import_Entity_Customer::COL_WEBSITE])) { $customerId = $this->_customer->getCustomerId($rowData[Mage_ImportExport_Model_Import_Entity_Customer::COL_EMAIL], $rowData[Mage_ImportExport_Model_Import_Entity_Customer::COL_WEBSITE]); } if (!$customerId || !$this->_isRowWithAddress($rowData) || !$this->validateRow($rowData, $rowNum)) { continue; } /** @var $addressCollection Mage_Customer_Model_Resource_Address_Collection */ $addressCollection = Mage::getResourceModel('customer/address_collection'); $addressCollection->addAttributeToFilter('parent_id', $customerId); $addressAttributes = array(); foreach ($this->_attributes as $attrAlias => $attrParams) { if (isset($rowData[$attrAlias]) && strlen($rowData[$attrAlias])) { if ('select' == $attrParams['type']) { $value = $attrParams['options'][strtolower($rowData[$attrAlias])]; } elseif ('datetime' == $attrParams['type']) { $value = gmstrftime($strftimeFormat, strtotime($rowData[$attrAlias])); } else { $value = $rowData[$attrAlias]; } $addressAttributes[$attrParams['id']] = $value; $addressCollection->addAttributeToFilter($attrParams['code'], $value); } } // skip duplicate address if ($isAppendMode && $addressCollection->getSize()) { continue; } $entityId = $nextEntityId++; // entity table data $entityRows[] = array('entity_id' => $entityId, 'entity_type_id' => $this->_entityTypeId, 'parent_id' => $customerId, 'created_at' => now(), 'updated_at' => now()); // attribute values foreach ($this->_attributes as $attrAlias => $attrParams) { if (isset($addressAttributes[$attrParams['id']])) { $attributes[$attrParams['table']][$entityId][$attrParams['id']] = $addressAttributes[$attrParams['id']]; } } // customer default addresses foreach (self::getDefaultAddressAttrMapping() as $colName => $customerAttrCode) { if (!empty($rowData[$colName])) { $attribute = $customer->getAttribute($customerAttrCode); $defaults[$attribute->getBackend()->getTable()][$customerId][$attribute->getId()] = $entityId; } } // let's try to find region ID if (!empty($rowData[$regionColName])) { $countryNormalized = strtolower($rowData[$countryColName]); $regionNormalized = strtolower($rowData[$regionColName]); if (isset($this->_countryRegions[$countryNormalized][$regionNormalized])) { $regionId = $this->_countryRegions[$countryNormalized][$regionNormalized]; $attributes[$regionIdTable][$entityId][$regionIdAttrId] = $regionId; // set 'region' attribute value as default name $tbl = $this->_attributes[$regionColName]['table']; $regionColNameId = $this->_attributes[$regionColName]['id']; $attributes[$tbl][$entityId][$regionColNameId] = $this->_regions[$regionId]; } } } $this->_saveAddressEntity($entityRows)->_saveAddressAttributes($attributes)->_saveCustomerDefaults($defaults); } return true; }
/** * Gather and save information about product entities. * * @return Mage_ImportExport_Model_Import_Entity_Product */ protected function _saveProducts() { /** @var $resource Mage_ImportExport_Model_Import_Proxy_Product_Resource */ $resource = Mage::getModel('importexport/import_proxy_product_resource'); $priceIsGlobal = Mage::helper('catalog')->isPriceGlobal(); $strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $productLimit = null; $productsQty = null; while ($bunch = $this->_dataSourceModel->getNextBunch()) { $entityRowsIn = array(); $entityRowsUp = array(); $attributes = array(); $websites = array(); $categories = array(); $tierPrices = array(); foreach ($bunch as $rowNum => $rowData) { if (!$this->validateRow($rowData, $rowNum)) { continue; } $rowScope = $this->getRowScope($rowData); if (self::SCOPE_DEFAULT == $rowScope) { $rowSku = $rowData[self::COL_SKU]; // 1. Entity phase if (isset($this->_oldSku[$rowSku])) { // existing row $entityRowsUp[] = array('updated_at' => now(), 'entity_id' => $this->_oldSku[$rowSku]['entity_id']); } else { // new row if (!$productLimit || $productsQty < $productLimit) { $entityRowsIn[$rowSku] = array('entity_type_id' => $this->_entityTypeId, 'attribute_set_id' => $this->_newSku[$rowSku]['attr_set_id'], 'type_id' => $this->_newSku[$rowSku]['type_id'], 'sku' => $rowSku, 'created_at' => now(), 'updated_at' => now()); $productsQty++; } else { $rowSku = null; // sign for child rows to be skipped $this->_rowsToSkip[$rowNum] = true; continue; } } } elseif (null === $rowSku) { $this->_rowsToSkip[$rowNum] = true; continue; // skip rows when SKU is NULL } elseif (self::SCOPE_STORE == $rowScope) { // set necessary data from SCOPE_DEFAULT row $rowData[self::COL_TYPE] = $this->_newSku[$rowSku]['type_id']; $rowData['attribute_set_id'] = $this->_newSku[$rowSku]['attr_set_id']; $rowData[self::COL_ATTR_SET] = $this->_newSku[$rowSku]['attr_set_code']; } if (!empty($rowData['_product_websites'])) { // 2. Product-to-Website phase $websites[$rowSku][$this->_websiteCodeToId[$rowData['_product_websites']]] = true; } if (!empty($rowData[self::COL_CATEGORY])) { // 3. Categories phase $categories[$rowSku][$this->_categories[$rowData[self::COL_CATEGORY]]] = true; } if (!empty($rowData['_tier_price_website'])) { // 4. Tier prices phase $tierPrices[$rowSku][] = array('all_groups' => $rowData['_tier_price_customer_group'] == self::VALUE_ALL, 'customer_group_id' => $rowData['_tier_price_customer_group'] == self::VALUE_ALL ? 0 : $rowData['_tier_price_customer_group'], 'qty' => $rowData['_tier_price_qty'], 'value' => $rowData['_tier_price_price'], 'website_id' => self::VALUE_ALL == $rowData['_tier_price_website'] || $priceIsGlobal ? 0 : $this->_websiteCodeToId[$rowData['_tier_price_website']]); } // 5. Attributes phase if (self::SCOPE_NULL == $rowScope) { continue; // skip attribute processing for SCOPE_NULL rows } $rowStore = self::SCOPE_STORE == $rowScope ? $this->_storeCodeToId[$rowData[self::COL_STORE]] : 0; $rowData = $this->_productTypeModels[$rowData[self::COL_TYPE]]->prepareAttributesForSave($rowData); $product = Mage::getModel('importexport/import_proxy_product', $rowData); foreach ($rowData as $attrCode => $attrValue) { $attribute = $resource->getAttribute($attrCode); $attrId = $attribute->getId(); $backModel = $attribute->getBackendModel(); $attrTable = $attribute->getBackend()->getTable(); $storeIds = array(0); if ('datetime' == $attribute->getBackendType()) { $attrValue = gmstrftime($strftimeFormat, strtotime($attrValue)); } elseif ($backModel) { $attribute->getBackend()->beforeSave($product); $attrValue = $product->getData($attribute->getAttributeCode()); } if (self::SCOPE_STORE == $rowScope) { if (self::SCOPE_WEBSITE == $attribute->getIsGlobal()) { // check website defaults already set if (!isset($attributes[$attrTable][$rowSku][$attrId][$rowStore])) { $storeIds = $this->_storeIdToWebsiteStoreIds[$rowStore]; } } elseif (self::SCOPE_STORE == $attribute->getIsGlobal()) { $storeIds = array($rowStore); } } foreach ($storeIds as $storeId) { $attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue; } $attribute->setBackendModel($backModel); // restore 'backend_model' to avoid 'default' setting } } $this->_saveProductEntity($entityRowsIn, $entityRowsUp)->_saveProductWebsites($websites)->_saveProductCategories($categories)->_saveProductTierPrices($tierPrices)->_saveProductAttributes($attributes); } return $this; }
/** * Gather and save information about category entities. * * @return AvS_FastSimpleImport_Model_Import_Entity_Category */ protected function _saveCategories() { $strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $nextEntityId = Mage::getResourceHelper('importexport')->getNextAutoincrement($this->_entityTable); static $entityId; while ($bunch = $this->_dataSourceModel->getNextBunch()) { $entityRowsIn = array(); $entityRowsUp = array(); $attributes = array(); $uploadedGalleryFiles = array(); foreach ($bunch as $rowNum => $rowData) { if (!$this->validateRow($rowData, $rowNum)) { continue; } $rowScope = $this->getRowScope($rowData); $rowData = $this->_prepareRowForDb($rowData); $this->_filterRowData($rowData); if (self::SCOPE_DEFAULT == $rowScope) { $rowCategory = $rowData[self::COL_CATEGORY]; $parentCategory = $this->_getParentCategory($rowData); // entity table data $entityRow = array('parent_id' => $parentCategory['entity_id'], 'level' => $parentCategory['level'] + 1, 'created_at' => empty($rowData['created_at']) ? now() : gmstrftime($strftimeFormat, strtotime($rowData['created_at'])), 'updated_at' => now(), 'position' => $rowData['position']); if (isset($this->_categoriesWithRoots[$rowData[self::COL_ROOT]][$rowData[self::COL_CATEGORY]])) { //edit $entityId = $this->_categoriesWithRoots[$rowData[self::COL_ROOT]][$rowData[self::COL_CATEGORY]]['entity_id']; $entityRow['entity_id'] = $entityId; $entityRow['path'] = $parentCategory['path'] . '/' . $entityId; $entityRowsUp[] = $entityRow; $rowData['entity_id'] = $entityId; } else { // create $entityId = $nextEntityId++; $entityRow['entity_id'] = $entityId; $entityRow['path'] = $parentCategory['path'] . '/' . $entityId; $entityRow['entity_type_id'] = $this->_entityTypeId; $entityRow['attribute_set_id'] = $this->_defaultAttributeSetId; $entityRowsIn[] = $entityRow; $this->_newCategory[$rowData[self::COL_ROOT]][$rowData[self::COL_CATEGORY]] = array('entity_id' => $entityId, 'path' => $entityRow['path'], 'level' => $entityRow['level']); } } foreach ($this->_imagesArrayKeys as $imageCol) { if (!empty($rowData[$imageCol])) { // 5. Media gallery phase if (!array_key_exists($rowData[$imageCol], $uploadedGalleryFiles)) { $uploadedGalleryFiles[$rowData[$imageCol]] = $this->_uploadMediaFiles($rowData[$imageCol]); } $rowData[$imageCol] = $uploadedGalleryFiles[$rowData[$imageCol]]; } } // Attributes phase $rowStore = self::SCOPE_STORE == $rowScope ? $this->_storeCodeToId[$rowData[self::COL_STORE]] : 0; /* @var $category Mage_Catalog_Model_Category */ $category = Mage::getModel('catalog/category', $rowData); foreach (array_intersect_key($rowData, $this->_attributes) as $attrCode => $attrValue) { if (!$this->_attributes[$attrCode]['is_static']) { /** @var $attribute Mage_Eav_Model_Entity_Attribute */ $attribute = $this->_attributes[$attrCode]['attribute']; if ('multiselect' != $attribute->getFrontendInput() && self::SCOPE_NULL == $rowScope) { continue; // skip attribute processing for SCOPE_NULL rows } $attrId = $attribute->getAttributeId(); $backModel = $attribute->getBackendModel(); $attrTable = $attribute->getBackend()->getTable(); $attrParams = $this->_attributes[$attrCode]; $storeIds = array(0); if ('select' == $attrParams['type']) { if (isset($attrParams['options'][strtolower($attrValue)])) { $attrValue = $attrParams['options'][strtolower($attrValue)]; } } elseif ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) { $attrValue = gmstrftime($strftimeFormat, strtotime($attrValue)); } elseif ($backModel && 'available_sort_by' != $attrCode) { $attribute->getBackend()->beforeSave($category); $attrValue = $category->getData($attribute->getAttributeCode()); } if (self::SCOPE_STORE == $rowScope) { if (self::SCOPE_WEBSITE == $attribute->getIsGlobal()) { // check website defaults already set if (!isset($attributes[$attrTable][$entityId][$attrId][$rowStore])) { $storeIds = $this->_storeIdToWebsiteStoreIds[$rowStore]; } } elseif (self::SCOPE_STORE == $attribute->getIsGlobal()) { $storeIds = array($rowStore); } } foreach ($storeIds as $storeId) { if ('multiselect' == $attribute->getFrontendInput()) { if (!isset($attributes[$attrTable][$entityId][$attrId][$storeId])) { $attributes[$attrTable][$entityId][$attrId][$storeId] = ''; } else { $attributes[$attrTable][$entityId][$attrId][$storeId] .= ','; } $attributes[$attrTable][$entityId][$attrId][$storeId] .= $attrValue; } else { $attributes[$attrTable][$entityId][$attrId][$storeId] = $attrValue; } } $attribute->setBackendModel($backModel); // restore 'backend_model' to avoid 'default' setting } } } $this->_saveCategoryEntity($entityRowsIn, $entityRowsUp); $this->_saveCategoryAttributes($attributes); } return $this; }
protected function _saveSublogins() { $_7db6df59a882fa9b6c2a6e49a36b0f579969198b = Mage::getModel('sublogin/sublogin'); $_72d6e7b8a81bce45d9a6a08c264a4a8c7fba3b67 = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $_619f2f7036ba5fbdda57b17825965ca9dcf53f2d = $_7db6df59a882fa9b6c2a6e49a36b0f579969198b->getResource()->getTable('sublogin/sublogin'); $_826ac81b600de90edf50807750cadbf5e3472cd0 = Mage::getResourceHelper('importexport')->getNextAutoincrement($_619f2f7036ba5fbdda57b17825965ca9dcf53f2d); while ($_fc619f04005aa176dc83b766703e47a1fe3766df = $this->_dataSourceModel->getNextBunch()) { $_ec3c8c69350539b4b891cdadf9ca1402bb079b2b = array(); $_3dd5bfd6452e735ee202bd6a62310c3a943a942d = array(); $_23e4e5c6f6a86c11c52dcedab299b01a2b2f2f1b = array_change_key_case($this->_oldSublogins, CASE_LOWER); foreach ($_fc619f04005aa176dc83b766703e47a1fe3766df as $_aff33f624f1937ce04460117b27455912e1855af => $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9) { if (!$this->validateRow($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9, $_aff33f624f1937ce04460117b27455912e1855af)) { continue; } $_c6044a04428a38b473f1cf8ee777cafff97f3b0c = gmstrftime($_72d6e7b8a81bce45d9a6a08c264a4a8c7fba3b67, strtotime("+ " . self::DEFAULT_EXPIRY_DAYS . " days")); $_d19f29254a19bec723c54975fdca138389407a19 = empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_ENTITY_ID]) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_ENTITY_ID]; $_e79f42cd6fb01fb1483aa880b524a8d65c7b6081 = empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_STORE_ID]) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_STORE_ID]; $_ff0a3525eb1a63ce44e7951a0b522829a4d2f607 = empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_EMAIL]) ? '' : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_EMAIL]; $_2899572bbfe45ff9c6681ad22fd211aa42c9b569 = strtolower($_ff0a3525eb1a63ce44e7951a0b522829a4d2f607); $_48b69966511a1516081c24326c362b7099172474 = array('entity_id' => $_d19f29254a19bec723c54975fdca138389407a19, 'customer_id' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['customer_id']) ? '' : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['customer_id'], 'email' => $_2899572bbfe45ff9c6681ad22fd211aa42c9b569, 'password' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['password']) ? Mage::helper('core')->getHash('123456', 2) : Mage::helper('core')->getHash($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['password'], 2), 'rp_token' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['rp_token']) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['rp_token'], 'rp_token_created_at' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['rp_token_created_at']) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['rp_token_created_at'], 'firstname' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_FIRSTNAME]) ? 'firstname' : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_FIRSTNAME], 'lastname' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_LASTNAME]) ? 'lastname' : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9[self::COL_LASTNAME], 'expire_date' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['expire_date']) ? $_c6044a04428a38b473f1cf8ee777cafff97f3b0c : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['expire_date'], 'active' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['active']) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['active'], 'send_backendmails' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['send_backendmails']) ? 1 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['send_backendmails'], 'store_id' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['store_id']) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['store_id'], 'address_ids' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['address_ids']) ? '' : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['address_ids'], 'create_sublogins' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['create_sublogins']) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['create_sublogins'], 'is_subscribed' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['is_subscribed']) ? 0 : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['is_subscribed'], 'prefix' => empty($_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['prefix']) ? '' : $_e02fbefe8dd8ff9651f964f9f9798a32fdaf63a9['prefix']); if (isset($_23e4e5c6f6a86c11c52dcedab299b01a2b2f2f1b[$_e79f42cd6fb01fb1483aa880b524a8d65c7b6081][$_d19f29254a19bec723c54975fdca138389407a19][$_2899572bbfe45ff9c6681ad22fd211aa42c9b569])) { $_48b69966511a1516081c24326c362b7099172474['id'] = $_23e4e5c6f6a86c11c52dcedab299b01a2b2f2f1b[$_e79f42cd6fb01fb1483aa880b524a8d65c7b6081][$_d19f29254a19bec723c54975fdca138389407a19][$_2899572bbfe45ff9c6681ad22fd211aa42c9b569]; $_3dd5bfd6452e735ee202bd6a62310c3a943a942d[] = $_48b69966511a1516081c24326c362b7099172474; } else { $_76e2873fa893a2a0fb1fdf179ed951f32e603054 = $_826ac81b600de90edf50807750cadbf5e3472cd0++; $_48b69966511a1516081c24326c362b7099172474['id'] = $_76e2873fa893a2a0fb1fdf179ed951f32e603054; $_ec3c8c69350539b4b891cdadf9ca1402bb079b2b[] = $_48b69966511a1516081c24326c362b7099172474; $this->_newSublogins[$_e79f42cd6fb01fb1483aa880b524a8d65c7b6081][$_d19f29254a19bec723c54975fdca138389407a19][$_2899572bbfe45ff9c6681ad22fd211aa42c9b569] = $_76e2873fa893a2a0fb1fdf179ed951f32e603054; } } $this->_saveSubloginEntity($_ec3c8c69350539b4b891cdadf9ca1402bb079b2b, $_3dd5bfd6452e735ee202bd6a62310c3a943a942d); } return $this; }
/** * Get date/time format string * * @return string */ protected function _getDateTimeFormat() { if (!$this->_dateTimeFormat) { $this->_dateTimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); } return $this->_dateTimeFormat; }
/** * Prepare customer data for update * * @param array $rowData * @return array */ protected function _prepareDataForUpdate(array $rowData) { /** @var $passwordAttribute Mage_Customer_Model_Attribute */ $passwordAttribute = $this->_customerModel->getAttribute('password_hash'); $passwordAttributeId = $passwordAttribute->getId(); $passwordStorageTable = $passwordAttribute->getBackend()->getTable(); $dateTimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true); $entitiesToCreate = array(); $entitiesToUpdate = array(); $attributesToSave = array(); // entity table data $entityRow = array('group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'], 'store_id' => empty($rowData[self::COLUMN_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COLUMN_STORE]], 'created_at' => empty($rowData['created_at']) ? now() : gmstrftime($dateTimeFormat, strtotime($rowData['created_at'])), 'updated_at' => now()); $emailInLowercase = strtolower($rowData[self::COLUMN_EMAIL]); if ($entityId = $this->_getCustomerId($emailInLowercase, $rowData[self::COLUMN_WEBSITE])) { // edit $entityRow['entity_id'] = $entityId; $entitiesToUpdate[] = $entityRow; } else { // create $entityId = $this->_getNextEntityId(); $entityRow['entity_id'] = $entityId; $entityRow['entity_type_id'] = $this->getEntityTypeId(); $entityRow['attribute_set_id'] = 0; $entityRow['website_id'] = $this->_websiteCodeToId[$rowData[self::COLUMN_WEBSITE]]; $entityRow['email'] = $emailInLowercase; $entityRow['is_active'] = 1; $entitiesToCreate[] = $entityRow; $this->_newCustomers[$emailInLowercase][$rowData[self::COLUMN_WEBSITE]] = $entityId; } // attribute values foreach (array_intersect_key($rowData, $this->_attributes) as $attributeCode => $value) { if (!$this->_attributes[$attributeCode]['is_static'] && strlen($value)) { /** @var $attribute Mage_Customer_Model_Attribute */ $attribute = $this->_customerModel->getAttribute($attributeCode); $backendModel = $attribute->getBackendModel(); $attributeParameters = $this->_attributes[$attributeCode]; if ('select' == $attributeParameters['type']) { $value = $attributeParameters['options'][strtolower($value)]; } elseif ('datetime' == $attributeParameters['type']) { $value = gmstrftime($dateTimeFormat, strtotime($value)); } elseif ($backendModel) { $attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value)); $value = $this->_customerModel->getData($attributeCode); } $attributesToSave[$attribute->getBackend()->getTable()][$entityId][$attributeParameters['id']] = $value; // restore 'backend_model' to avoid default setting $attribute->setBackendModel($backendModel); } } // password change/set if (isset($rowData['password']) && strlen($rowData['password'])) { $attributesToSave[$passwordStorageTable][$entityId][$passwordAttributeId] = $this->_customerModel->hashPassword($rowData['password']); } return array(self::ENTITIES_TO_CREATE_KEY => $entitiesToCreate, self::ENTITIES_TO_UPDATE_KEY => $entitiesToUpdate, self::ATTRIBUTES_TO_SAVE_KEY => $attributesToSave); }