protected function _addPathSuffix($path) { if (is_null($this->_pathSuffix)) { $this->_pathSuffix = Mage::getstoreconfig("catalog/seo/category_url_suffix", $this->_storeId); } return trim($path, "/") . $this->_pathSuffix; }
protected function _importCreateCategory($name) { $profile = $this->_profile; $storeId = $this->_storeId; $attr = "category.name"; if (!$profile->getData("options/import/dryrun")) { if (is_null($this->_autoCategory)) { $row = $this->_read->fetchRow('' . 'select entity_type_id, default_attribute_set_id from ' . $this->_t('eav/entity_type') . ' where entity_type_code=\'catalog_category\''); $eav = Mage::getsingleton("eav/config"); $this->_autoCategory = array("type_id" => $row['entity_type_id'], "attribute_set_id" => $row['default_attribute_set_id'], "suffix" => Mage::getstoreconfig("catalog/seo/category_url_suffix", $storeId), "default" => array("is_active" => $profile->getData("options/import/create_categories_active"), "is_anchor" => $profile->getData("options/import/create_categories_anchor"), "display_mode" => $profile->getData("options/import/create_categories_display"), "name" => null, "url_key" => null, "url_path" => null)); if (Mage::helper("urapidflow")->hasMageFeature("category.include_in_menu")) { $this->_autoCategory['default']['include_in_menu'] = $profile->getData("options/import/create_categories_menu"); } foreach ($this->_autoCategory['default'] as $a => $v) { $a1 = $eav->getAttribute("catalog_category", $a); $this->_autoCategory['attr'][$a] = array("type" => $a1->getBackendType(), "id" => $a1->getId()); } } $delimiter = !empty($this->_fields[$attr]['delimiter']) ? $this->_fields[$attr]['delimiter'] : " > "; $path = "1/" . $this->_getRootCatId(); $parentId = $this->_getRootCatId(); $namePathArr = array(); $urlPathArr = array(); $level = 1; $table = $this->_t("catalog/category"); $createdInPaths = array(); $catNameArr = explode(trim($delimiter), $name); foreach ($catNameArr as $i => $catName) { $catName = trim($catName); ++$level; $namePathArr[] = $catName; $namePath = join($delimiter, $namePathArr); $namePathKey = strtolower(join(">", $namePathArr)); if (empty($this->_attributesByCode[$attr]['options_bytext'][$namePathKey])) { if (!isset($this->_attributesByCode['category.ids']['children_max_pos'][$parentId])) { $this->_attributesByCode['category.ids']['children_max_pos'][$parentId] = 0; } $this->_write->insert($table, array("entity_type_id" => $this->_autoCategory['type_id'], "attribute_set_id" => $this->_autoCategory['attribute_set_id'], "parent_id" => $parentId, "created_at" => now(), "updated_at" => now(), "path" => $path, "position" => ++$this->_attributesByCode['category.ids']['children_max_pos'][$parentId], "level" => $level, "children_count" => 0)); $cId = $this->_write->lastInsertId(); $parentId = $cId; $createdInPaths[] = $path; $path .= "/" . $cId; $this->_write->update($table, array("path" => $path), "entity_id='{$cId}'"); $attrValues = $this->_autoCategory['default']; $attrValues['name'] = $catName; $attrValues['url_key'] = Mage::helper("urapidflow")->formatUrlKey($catName); $urlPathArr[] = $attrValues['url_key']; $urlPath = join("/", $urlPathArr) . $this->_autoCategory['suffix']; $attrValues['url_path'] = $urlPath; foreach ($attrValues as $a => $v) { $a1 = $this->_autoCategory['attr'][$a]; $this->_write->insert($table . "_" . $a1['type'], array("entity_type_id" => $this->_autoCategory['type_id'], "entity_id" => $cId, "attribute_id" => $a1['id'], "value" => $v)); } $this->_attributesByCode[$attr]['options'][$cId] = $namePath; $this->_attributesByCode[$attr]['options_bytext'][$namePathKey] = $cId; $this->_attributesByCode['category.path']['options'][$cId] = $urlPath; $this->_attributesByCode['category.path']['options_bytext'][$urlPath] = $cId; } else { $parentId = $this->_attributesByCode[$attr]['options_bytext'][$namePathKey]; $urlPathArr[] = $this->_write->fetchOne("select `value` from {$table}_varchar where entity_id='{$parentId}' and attribute_id='{$this->_autoCategory['attr']['url_key']['id']}' order by store_id"); $this->_attributesByCode['category.path']['options'][$parentId]; $path .= "/" . $parentId; $cId = $parentId; } } if (!empty($createdInPaths)) { $updateCountIds = array(); foreach ($createdInPaths as $cInPath) { foreach (explode("/", $cInPath) as $cCountId) { if (empty($updateCountIds[$cCountId])) { $updateCountIds[$cCountId] = 0; } ++$updateCountIds[$cCountId]; } } foreach ($updateCountIds as $uCountId => $cAddCount) { $this->_write->query("update {$table} set children_count=children_count+" . intval($cAddCount) . " where entity_id=" . intval($uCountId)); } } } else { if (!empty($this->_attributesByCode[$attr]['options'])) { $cId = 0; foreach ($this->_attributesByCode[$attr]['options'] as $k => $v) { $oId = max($oId, $k); } ++$cId; } else { $cId = 1; } $this->_attributesByCode[$attr]['options'][$cId] = $name; $this->_attributesByCode[$attr]['options_bytext'][strtolower($name)] = $cId; } return $cId; }
protected function _fetchCategoryRow($urlPath) { $t = $this->_t("catalog/category"); if (!$this->_urlPaths) { $storeId = $this->_profile->getStoreId(); if (is_null($this->_categoryUrlSuffix)) { $this->_categoryUrlSuffix = Mage::getstoreconfig("catalog/seo/category_url_suffix", $storeId); $this->_categoryUrlSuffixLen = strlen($this->_categoryUrlSuffix); $this->_categoryUrlPathAttrId = $this->_getAttributeId("url_path", "catalog_category"); } $select = $this->_write->select()->from(array("e" => $t), array("entity_id", "path"))->join(array("v" => $t . "_varchar"), "v.entity_id=e.entity_id", array("url_path" => "value"))->where("v.attribute_id=?", $this->_categoryUrlPathAttrId)->where("v.store_id in (?)", array(0, $storeId))->order("v.store_id desc"); $rows = $this->_write->fetchAll($select); foreach ($rows as $r) { if (!empty($this->_urlPaths[$r['url_path']])) { continue; } $adjUrlPath = substr($r['url_path'], 0 - $this->_categoryUrlSuffixLen) == $this->_categoryUrlSuffix ? substr($r['url_path'], 0, strlen($r['url_path']) - $this->_categoryUrlSuffixLen) : $r['url_path'] . $this->_categoryUrlSuffix; $data = array("entity_id" => $r['entity_id'], "path" => $r['path']); $this->_urlPaths[$r['url_path']] = $data; $this->_urlPaths[$adjUrlPath] = $data; $this->_catIds[(int) $r['entity_id']] = $data; } } if (is_numeric($urlPath)) { if (empty($this->_catIds[(int) $urlPath])) { return false; } return $this->_catIds[(int) $urlPath]; } return !empty($this->_urlPaths[$urlPath]) ? $this->_urlPaths[$urlPath] : false; }