Exemple #1
0
 public function createCategory()
 {
     $catId = $this->getCategoryIdByName($this->categoryName);
     if ($catId) {
         return $catId;
     }
     $parentId = Mage::app()->getStore($this->storeId)->getRootCategoryId();
     $category = new Mage_Catalog_Model_Category();
     $category->setName($this->categoryName);
     $category->setUrlKey('contact-lenses');
     $category->setIsActive(1);
     $category->setDisplayMode('PRODUCTS');
     $category->setIsAnchor(0);
     $parentCategory = Mage::getModel('catalog/category')->load($parentId);
     $category->setPath($parentCategory->getPath());
     $category->save();
     //unset($category);
     return $category->getId();
 }
 /**
  * Format url key of category into valid form
  *
  * @param Mage_Catalog_Model_Category $category
  * @return Mage_Catalog_Model_Category
  */
 protected function _formatUrlKey(Mage_Catalog_Model_Category $category)
 {
     if ($category->getUrlKey() == '') {
         $category->setUrlKey($category->formatUrlKey($category->getName()));
     } else {
         $category->setUrlKey($category->formatUrlKey($category->getUrlKey()));
     }
     return $category;
 }
Exemple #3
0
 public function testGetCategoryIdUrl()
 {
     $this->assertStringEndsWith('catalog/category/view/', $this->_model->getCategoryIdUrl());
     $this->_model->setUrlKey('test_key');
     $this->assertStringEndsWith('catalog/category/view/s/test_key/', $this->_model->getCategoryIdUrl());
 }
 function create_category($parentId, $name, $url)
 {
     $category = new Mage_Catalog_Model_Category();
     $category->setName($name);
     $category->setUrlKey($url);
     $category->setIsActive(1);
     $category->setDisplayMode('PRODUCTS');
     $category->setIsAnchor(0);
     $parentCategory = Mage::getModel('catalog/category')->load($parentId);
     $category->setPath($parentCategory->getPath());
     $category->save();
     return $category->getId();
 }
Exemple #5
0
 public function createCategory($object)
 {
     $collection = Mage::getModel('catalog/category')->getCollection()->clear();
     $category = new Mage_Catalog_Model_Category();
     $category->setEntityTypeId($this->entityTypeId);
     $category->setAttributeSetId($this->attributeSetId);
     if (!empty($object['custom_apply_to_products'])) {
         $category->setCustomApplyToProducts($object['custom_apply_to_products']);
     }
     if (!empty($object['custom_design'])) {
         $category->setCustomDesign($object['custom_design']);
     }
     if (!empty($object['custom_design_from'])) {
         $category->setCustomDesignFrom($object['custom_design_from']);
     }
     if (!empty($object['custom_design_to'])) {
         $category->setCustomDesignTo($object['custom_design_to']);
     }
     if (!empty($object['custom_layout_update'])) {
         $category->setCustomLayoutUpdate($object['custom_layout_update']);
     }
     if (!empty($object['custom_use_parent_settings'])) {
         $category->setCustomUseParentSettings($object['custom_use_parent_settings']);
     }
     $category->setAvailablesortBy($object['available_sort_by']);
     $category->setParentId(0);
     $category->setCreatedAt($object['created_at']);
     $category->setUpdatedAt($object['updated_at']);
     $category->setPosition((int) $object['position']);
     $category->setChildrenCount($object['children_count']);
     $category->setDescription($object['description']);
     $category->setDisplayMode($object['display_mode']);
     $category->setDefaultSortBy($object['default_sort_by']);
     $category->setFilterPriceRange($object['filter_price_range']);
     $category->setImage($object['image']);
     $category->setIncludeInMenu($object['include_in_menu']);
     $category->setIsActive($object['is_active']);
     $category->setIsAnchor($object['is_anchor']);
     $category->setLandingPage($object['landing_page']);
     $category->setLevel($object['level']);
     $category->setMetaTitle($object['meta_title']);
     $category->setMetaKeywords($object['meta_keywords']);
     $category->setMetaDescription($object['meta_description']);
     $category->setName($object['name']);
     $category->setPageLayout($object['page_layout']);
     if (!empty($object['path'])) {
         $category->setPath($object['path']);
     }
     if (!empty($object['path_in_store'])) {
         $category->setPathInStore($object['path_in_store']);
     }
     $category->setPosition((int) $object['position']);
     $category->setThumbnail((int) $object['thumbnail']);
     $category->setUrlKey($object['url_key']);
     $category->setUrlPath($object['url_path']);
     try {
         $category->save();
         $category->load();
         // must do it, because of position set wrong for first saving. magento bug?
         $category->setPosition((int) $object['position']);
         $category->save();
     } catch (Exception $e) {
         zend_debug::dump($e);
         return;
     }
     return $category->getId();
 }
Exemple #6
0
 /**
  * Update category url key
  *
  * @param Mage_Catalog_Model_Category $category
  * @param string $newUrlKey
  * @param int $storeId
  */
 function processCategory($category, $newUrlKey, $storeId)
 {
     $store = Mage::app()->getStore();
     Mage::app()->setCurrentStore(Mage::app()->getStore(0));
     if (!$this->isEntityProcessed(self::ENTITY_TYPE_CATEGORY, $category->getId() . '-' . $storeId) && !preg_match('~-[a-f0-9]{32}$~i', $newUrlKey)) {
         $category->setStoreId($storeId);
         $category->setUrlKey($newUrlKey . '-' . md5($category->getStoreId() . $category->getId()));
         $category->save();
         $this->_reindexCategory($category->getId());
         $category->unsetData('request_path');
         $category->unsetData('url');
         $this->markEntityProcessed(self::ENTITY_TYPE_CATEGORY, $category->getId() . '-' . $category->getStoreId());
     }
     Mage::app()->setCurrentStore($store);
 }