/** * Serializes the virtual category configuration before it will be saved. * * @param Mage_Catalog_Model_Category $object Category saved. * * @return Smile_VirtualCategories_Model_Category_Attributes_Backend_Virtual */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getName(); $savedValue = $this->_defaultValue; $savedValue['is_virtual'] = (bool) $object->getIsVirtual(); if ($object->getVirtualCategoryRule()) { $savedValue['rule_serialized'] = $object->getVirtualCategoryRule()->getConditions()->asArray(); } $object->setData($attributeCode, serialize($savedValue)); return $this; }
/** * Format url_key value * * @param Mage_Catalog_Model_Category $object * @return Mage_Catalog_Model_Category_Attribute_Backend_Urlkey */ public function beforeSave($object) { $attributeName = $this->getAttribute()->getName(); $urlKey = $object->getData($attributeName); if ($urlKey === false) { return $this; } if ($urlKey == '') { $urlKey = $object->getName(); } if (empty($urlKey)) { $urlKey = Mage::helper('core')->uniqHash(); } $object->setData($attributeName, $object->formatUrlKey($urlKey)); $this->_validateEntityUrl($object); return $this; }
/** * @param Mage_Catalog_Model_Category $object * @return $this|Convenient_CategoryCode_Model_Attribute_Backend_Code * * @author Luke Rodgers <*****@*****.**> */ public function beforeSave($object) { $attributeName = $this->getAttribute()->getName(); $code = $object->getData($attributeName); if ($code === false) { return $this; } if ($code == '') { $code = array(); $parents = $object->getParentCategories(); foreach ($parents as $parent) { if ($parent->getLevel() > 1 && $parent->getId() != $object->getId()) { $code[] = $parent->getName(); } } $code[] = $object->getName(); $code = implode('-', $code); } $object->setData($attributeName, $object->formatUrlKey($code)); return $this; }
/** * Retrieve Url for specified category * * @param Mage_Catalog_Model_Category $category * @return string */ public function getCategoryUrl(Mage_Catalog_Model_Category $category) { $url = $category->getData('url'); if (null !== $url) { return $url; } Varien_Profiler::start('REWRITE: ' . __METHOD__); if ($category->hasData('request_path') && $category->getData('request_path') != '') { $category->setData('url', $this->_getDirectUrl($category)); Varien_Profiler::stop('REWRITE: ' . __METHOD__); return $category->getData('url'); } $requestPath = $this->_getRequestPath($category); if ($requestPath) { $category->setRequestPath($requestPath); $category->setData('url', $this->_getDirectUrl($category)); Varien_Profiler::stop('REWRITE: ' . __METHOD__); return $category->getData('url'); } Varien_Profiler::stop('REWRITE: ' . __METHOD__); $category->setData('url', $category->getCategoryIdUrl()); return $category->getData('url'); }
/** * Adds url_path property for non-root category - to ensure that url path is not empty. * * Sometimes attribute 'url_path' can be empty, because url_path hasn't been generated yet, * in this case category is loaded with empty url_path and we should generate it manually. * * @param Varien_Object $category * @return void */ protected function _addCategoryUrlPath($category) { if (!$category instanceof Varien_Object || $category->getUrlPath()) { return; } // This routine is not intended to be used with root categories, // but handle 'em gracefully - ensure them to have empty path. if ($category->getLevel() <= 1) { $category->setUrlPath(''); return; } if (self::$_categoryForUrlPath === null) { self::$_categoryForUrlPath = Mage::getModel('catalog/category'); } // Generate url_path $urlPath = self::$_categoryForUrlPath->setData($category->getData())->getUrlPath(); $category->setUrlPath($urlPath); }
public function testGetLevel() { $this->assertEquals(0, $this->_model->getLevel()); $this->_model->setData('level', 1); $this->assertEquals(1, $this->_model->getLevel()); }
/** * Set store specific data to category * * @param Mage_Catalog_Model_Category $category * @param Mage_Core_Model_Store $store * @return Mage_Catalog_Model_Category */ protected function _setStoreSpecificData(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store) { $category->setStoreId($store->getId()); $storeCategoryData = $this->_urlResource->getCategory($category->getId(), $store->getId()); if ($storeCategoryData) { foreach ($storeCategoryData->toArray() as $key => $data) { $category->setData($key, $data); } } $rewrites = $this->_categoryRelation->loadByCategory($category); $category->setRequestPath($rewrites->getRequestPath()); return $category; }
public function testGetAvailableSortBy() { $this->assertEquals(array(), $this->_model->getAvailableSortBy()); $this->_model->setData('available_sort_by', 'test,and,test'); $this->assertEquals(array('test', 'and', 'test'), $this->_model->getAvailableSortBy()); }
/** * @param Mage_Catalog_Model_Category $category * @param int $cmsBlockId */ protected function setCategoryCmsBlock($category, $cmsBlockId) { $category->setData('landing_page', $cmsBlockId); $mode = $category->getData('display_mode'); if ($mode == Mage_Catalog_Model_Category::DM_PRODUCT) { $category->setData('display_mode', Mage_Catalog_Model_Category::DM_MIXED); } }
protected function changeCategoryData(Mage_Catalog_Model_Category $category) { /** @var Amasty_Shopby_Helper_Attributes $helper */ $helper = Mage::helper('amshopby/attributes'); $brand = $helper->getRequestedBrandOption(); $isBrandPage = $brand && $category->getId() == Mage::app()->getStore()->getRootCategoryId(); if ($isBrandPage) { $category->setData('name', $brand->getTitle()); $category->setData('description', $brand->getDescr()); $category->setData('image', $brand->getImgBig() ? '../../amshopby/' . $brand->getImgBig() : null); $category->setData('landing_page', $brand->getCmsBlockId()); } $titles = array(); $descriptions = array(); $imageUrl = null; $cmsBlockId = null; foreach ($this->options as $opt) { /** @var Amasty_Shopby_Model_Value $opt */ if ($isBrandPage && $brand->getId() == $opt->getId()) { // Already applied continue; } if (!$opt->getShowOnList()) { continue; } if ($opt->getTitle()) { $titles[] = $opt->getTitle(); } if ($opt->getDescr()) { $descriptions[] = $opt->getDescr(); } if ($opt->getCmsBlockId()) { $cmsBlockId = $opt->getCmsBlockId(); } if ($opt->getImgBig()) { $imageUrl = '../../amshopby/' . $opt->getImgBig(); } } $position = Mage::getStoreConfig('amshopby/heading/add_title'); if ($titles && $position != Amasty_Shopby_Model_Source_Description_Position::DO_NOT_ADD) { switch ($position) { case Amasty_Shopby_Model_Source_Description_Position::AFTER: array_unshift($titles, $category->getName()); break; case Amasty_Shopby_Model_Source_Description_Position::BEFORE: array_push($titles, $category->getName()); break; } $title = join(Mage::getStoreConfig('amshopby/heading/h1_separator'), $titles); $category->setData('name', $title); } $position = Mage::getStoreConfig('amshopby/heading/add_description'); if ($descriptions && $position != Amasty_Shopby_Model_Source_Description_Position::DO_NOT_ADD) { $oldDescription = $category->getData('description'); $description = '<span class="amshopby-descr">' . join('<br>', $descriptions) . '</span>'; switch ($position) { case Amasty_Shopby_Model_Source_Description_Position::AFTER: $description = $oldDescription ? $oldDescription . '<br>' . $description : $description; break; case Amasty_Shopby_Model_Source_Description_Position::BEFORE: $description = $oldDescription ? $description . '<br>' . $oldDescription : $description; break; case Amasty_Shopby_Model_Source_Description_Position::REPLACE: break; } $category->setData('description', $description); } if (isset($imageUrl) && Mage::getStoreConfig('amshopby/heading/add_image')) { $category->setData('image', $imageUrl); } if (isset($cmsBlockId) && Mage::getStoreConfig('amshopby/heading/add_cms_block')) { $category->setData('landing_page', $cmsBlockId); $mode = $category->getData('display_mode'); if ($mode == Mage_Catalog_Model_Category::DM_PRODUCT) { $category->setData('display_mode', Mage_Catalog_Model_Category::DM_MIXED); } } }