/** * @magentoConfigFixture current_store catalog/frontend/flat_catalog_category 1 * @magentoDbIsolation enabled */ public function testSaveWithFlatIndexer() { $categoryName = 'Indexer Category Name ' . uniqid(); /** @var $parentCategory Mage_Catalog_Model_Category */ $parentCategory = self::$_objectManager->create('Mage_Catalog_Model_Category'); $parentCategory->load($this->_store->getRootCategoryId()); // init category model with EAV entity resource model $resourceModel = self::$_objectManager->create('Mage_Catalog_Model_Resource_Category'); $this->_model = self::$_objectManager->create('Mage_Catalog_Model_Category', array('resource' => $resourceModel)); $this->_model->setName($categoryName)->setParentId($parentCategory->getId())->setPath($parentCategory->getPath())->setLevel(2)->setPosition(1)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->save(); // check if category record exists in flat table /** @var $collection Mage_Catalog_Model_Resource_Category_Flat_Collection */ $collection = self::$_objectManager->create('Mage_Catalog_Model_Resource_Category_Flat_Collection'); $collection->addFieldToFilter('name', $categoryName); $this->assertCount(1, $collection->getItems()); }
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(); }
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(); }
<?php ini_set("memory_limit", "1000M"); require_once "/home/www/demo/app/Mage.php"; umask(0); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); /* supply parent id */ $parentId = '258'; //$name = 'Mont Blank'; $names = array('Burberry', 'Swarovski', 'Bvlgari', 'Tom Ford', 'Carrera', 'Oakley', 'Chanel', 'Oliver Peoples', 'Dior', 'Paul Smith', 'D&G', 'Polo Ralf Lauren', 'Dsquared', 'Prada', 'Diesel', 'Gucci', 'Ray Ban', 'Tiffany', 'Hugo Boss'); foreach ($names as $name) { $category = new Mage_Catalog_Model_Category(); $category->setName($name); $category->setIsActive(1); $category->setDisplayMode('PAGE'); $category->setIsAnchor(1); $category->setIncludeInMenu(0); $parentCategory = Mage::getModel('catalog/category')->load($parentId); $category->setPath($parentCategory->getPath()); try { $category->save(); echo $category->getName() . ' - ' . $category->getId() . "\n"; } catch (Exception $e) { echo $e->getMessage(); } unset($category); }
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(); }
/** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Mage_Catalog * @subpackage integration_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * After installation system has two categories: root one with ID:1 and Default category with ID:2 */ $category = new Mage_Catalog_Model_Category(); $category->setName('Category Without Image 1')->setParentId(2)->setLevel(2)->setAvailableSortBy('name')->setDefaultSortBy('name')->setIsActive(true)->save(); Mage::register('_fixture/Mage_Catalog_Model_Category', $category);