public function getFotoliaCategoryParams(Mage_Catalog_Model_Category $category) { $this->_fotoliaCategory1Id = $category->getFotoliaCategory1Id(); $this->_fotoliaCategory2Id = $category->getFotoliaCategory2Id(); $this->_fotoliaSearchQuery = $category->getFotoliaSearchQuery(); $this->_fotoliaContentType = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'fotolia_content_type')->getSource()->getOptionText($category->getData('fotolia_content_type')); $this->_fotoliaWithPeople = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'fotolia_with_people')->getSource()->getOptionText($category->getData('fotolia_with_people')); $this->_fotoliaOrientation = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'fotolia_orientation')->getSource()->getOptionText($category->getData('fotolia_orientation')); $this->_fotoliaIsolated = Mage::getSingleton('eav/config')->getAttribute('catalog_category', 'fotolia_isolated')->getSource()->getOptionText($category->getData('fotolia_isolated')); $this->_fotoliaColors = $category->getFotoliaColors(); $this->_fotoliaGalleryId = false; //todo $this->_fotoliaIdsList = $category->getFotoliaIdsList(); }
/** * @magentoDataFixture Mage/Core/_files/store.php * @magentoDbIsolation enabled * @dataProvider saveActionDataProvider * @param array $inputData * @param array $defaultAttributes * @param array $attributesSaved */ public function testSaveAction($inputData, $defaultAttributes, $attributesSaved = array()) { $store = new Mage_Core_Model_Store(); $store->load('fixturestore', 'code'); $storeId = $store->getId(); $this->getRequest()->setPost($inputData); $this->getRequest()->setParam('store', $storeId); $this->getRequest()->setParam('id', 2); $this->dispatch('backend/admin/catalog_category/save'); $messages = Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS); $this->assertNotEmpty($messages, "Could not save category"); $this->assertEquals('The category has been saved.', current($messages)->getCode()); $category = new Mage_Catalog_Model_Category(); $category->setStoreId($storeId); $category->load(2); $errors = array(); foreach ($attributesSaved as $attribute => $value) { $actualValue = $category->getData($attribute); if ($value !== $actualValue) { $errors[] = "value for '{$attribute}' attribute must be '{$value}', but '{$actualValue}' is found instead"; } } foreach ($defaultAttributes as $attribute => $exists) { if ($exists !== $category->getExistsStoreValueFlag($attribute)) { if ($exists) { $errors[] = "custom value for '{$attribute}' attribute is not found"; } else { $errors[] = "custom value for '{$attribute}' attribute is found, but default one must be used"; } } } $this->assertEmpty($errors, "\n" . join("\n", $errors)); }
/** * Retrieve category url * * @param Mage_Catalog_Model_Category $category * @return string */ public function getCategoryUrl($category) { if ($category instanceof Mage_Catalog_Model_Category) { return $category->getUrl(); } return Mage::getModel('catalog/category')->setData($category->getData())->getUrl(); }
protected function _hasCustomUpdate(Mage_Catalog_Model_Category $category) { if ($category->getData('custom_layout_update') && in_array($category->getCustomDesignApply(), array(Mage_Catalog_Model_Design::CATEGORY_APPLY_CATEGORY_AND_PRODUCT_RECURSIVE, Mage_Catalog_Model_Design::CATEGORY_APPLY_CATEGORY_RECURSIVE))) { return true; } return false; }
/** * Get url for category data * * @param Mage_Catalog_Model_Category $category * @return string */ public function getCategoryUrl($category) { if ($category instanceof Mage_Catalog_Model_Category) { $url = $category->getUrl(); } else { $url = $this->_getCategoryInstance()->setData($category->getData())->getUrl(); } return $url; }
/** * Check if click able enabled for category. * * @param Varien_Data_Tree_Node|Mage_Catalog_Model_Category $category * @return bool */ protected function _isCategoryClickAble($category) { $isCategoryClickAbleStatus = true; $isCategoryClickAble = $category->getData(Monsoon_Test_Helper_Data::IS_CLICK_ABLE_LINK_CODE); if ($isCategoryClickAble !== null && (bool) $isCategoryClickAble === false) { $isCategoryClickAbleStatus = false; } return $isCategoryClickAbleStatus; }
/** * 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'); }
/** * 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; }
/** * Unserializes the virtual category configuration after it has been loaded. * * @param Mage_Catalog_Model_Category $object Category saved. * * @return Smile_VirtualCategories_Model_Category_Attributes_Backend_Virtual */ public function afterLoad($object) { $attributeCode = $this->getAttribute()->getName(); $data = $object->getData($attributeCode); if ($data && is_string($data) && strlen($data)) { $data = unserialize($data); } else { $data = $this->_defaultValue; } $virtualCategoryRule = Mage::getModel('smile_virtualcategories/rule'); if (isset($data['rule_serialized'])) { $virtualCategoryRule->getConditions()->setConditions(array())->loadArray($data['rule_serialized']); } $virtualCategoryRule->setCategory($object); $object->setData('is_virtual', $data['is_virtual']); $object->setData('virtual_rule', $virtualCategoryRule); 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; }
/** * Get url for category data * * @param Mage_Catalog_Model_Category $category * @return string */ public function getCategoryUrl($category) { if ($category instanceof Mage_Catalog_Model_Category) { $url = $category->getUrl(); } else { $url = $this->_getCategoryInstance()->setData($category->getData())->getUrl(); } return Mage::getModel('core/url')->sessionUrlVar($url); }
/** * Prepare array of category data to insert or update. * * array( * 'field_name' => 'value' * ) * * @param Mage_Catalog_Model_Category $category * @param array $replaceFields * @return array */ protected function _prepareDataForAllFields($category, $replaceFields = array()) { $table = $this->_getReadAdapter()->describeTable($this->getMainStoreTable($category->getStoreId())); $data = array(); foreach ($table as $column => $columnData) { if (null !== $category->getData($column)) { if (key_exists($column, $replaceFields)) { $value = $category->getData($replaceFields[$column]); } else { $value = $category->getData($column); } if (is_array($value)) { $value = implode(',', $value); } $data[$column] = $value; } } return $data; }
public function getObject(Mage_Catalog_Model_Category $category) { /** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */ $productCollection = $category->getProductCollection(); $category->setProductCount($productCollection->addMinimalPrice()->count()); $transport = new Varien_Object(); Mage::dispatchEvent('algolia_category_index_before', array('category' => $category, 'custom_data' => $transport)); $customData = $transport->getData(); $storeId = $category->getStoreId(); $category->getUrlInstance()->setStore($storeId); $path = ''; foreach ($category->getPathIds() as $categoryId) { if ($path != '') { $path .= ' / '; } $path .= $this->getCategoryName($categoryId, $storeId); } $image_url = NULL; try { $image_url = $category->getImageUrl(); } catch (Exception $e) { /* no image, no default: not fatal */ } $data = array('objectID' => $category->getId(), 'name' => $category->getName(), 'path' => $path, 'level' => $category->getLevel(), 'url' => $category->getUrl(), '_tags' => array('category'), 'popularity' => 1, 'product_count' => $category->getProductCount()); if (!empty($image_url)) { $data['image_url'] = $image_url; } foreach ($this->config->getCategoryAdditionalAttributes($storeId) as $attribute) { $value = $category->getData($attribute['attribute']); $attribute_ressource = $category->getResource()->getAttribute($attribute['attribute']); if ($attribute_ressource) { $value = $attribute_ressource->getFrontend()->getValue($category); } if (isset($data[$attribute['attribute']])) { $value = $data[$attribute['attribute']]; } if ($value) { $data[$attribute['attribute']] = $value; } } $data = array_merge($data, $customData); foreach ($data as &$data0) { $data0 = $this->try_cast($data0); } return $data; }
/** * @param Mage_Catalog_Model_Category $category * @return array */ public function getAllCategoryIdsFromCategory(Mage_Catalog_Model_Category $category = null) { if (empty($category)) { return array(); } $_pathIds = $category->getData("path"); return explode("/", $_pathIds); }
/** * Retrieve category url * * @param Mage_Catalog_Model_Category $category * @return string */ public function getCategoryUrl($category) { return Mage::getModel('catalog/category')->setData($category->getData())->getCategoryUrl(); }
/** * Return the number of products assigned to the category * * @param Mage_Catalog_Model_Category|Varien_Data_Tree_Node $category * @return int */ protected function _getProductCount($category) { if (null === ($count = $category->getData('product_count'))) { $count = 0; if ($category instanceof Mage_Catalog_Model_Category) { $count = $category->getProductCount(); } elseif ($category instanceof Varien_Data_Tree_Node) { $count = $this->_getProductCountFromTreeNode($category); } } return $count; }
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); } } }
/** * @param Mage_Catalog_Model_Category $category * @param Mage_Catalog_Model_Resource_Category_Collection $categoryCollection * @return array */ protected function _prepareData($category, $categoryCollection = null) { return array("id" => $category->getId(), "path" => $category->getData("path"), self::PATH_NAMES => $this->_getNames($category->getPathIds(), $categoryCollection)); }
/** * @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); } }