当前位置: 首页>>代码示例>>PHP>>正文


PHP Mage_Catalog_Model_Category::getId方法代码示例

本文整理汇总了PHP中Mage_Catalog_Model_Category::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category::getId方法的具体用法?PHP Mage_Catalog_Model_Category::getId怎么用?PHP Mage_Catalog_Model_Category::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mage_Catalog_Model_Category的用法示例。


在下文中一共展示了Mage_Catalog_Model_Category::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: apply

 /**
  * Apply category filter to layer
  *
  * @param   Zend_Controller_Request_Abstract $request
  * @param   Mage_Core_Block_Abstract $filterBlock
  * @return  Mage_Catalog_Model_Layer_Filter_Category
  */
 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
 {
     $filter = (int) $request->getParam($this->getRequestVar());
     if (!$filter) {
         return $this;
     }
     // load data for applied category
     $this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($filter);
     if ($this->_appliedCategory->getId()) {
         // create join and conditions for additional category filter
         $tableAlias = 'category_layered_' . $this->_rootCategory->getId();
         $conditions = array();
         $conditions['category_id'] = $filter;
         $conditions['store_id'] = Mage::app()->getStore()->getId();
         if (!$this->_appliedCategory->getIsAnchor()) {
             $conditions['is_parent'] = 1;
         }
         $this->getLayer()->getProductCollection()->joinTable(array($tableAlias => 'catalog/category_product_index'), "product_id=entity_id", array($tableAlias . '_cat_id' => 'category_id', $tableAlias . '_store_id' => 'store_id'), $conditions, 'inner');
         // add filter to layer state
         $this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter));
         // if current applied category has no children reset items array (for hiding filter block)
         if (!$this->_appliedCategory->getChildrenCategories()) {
             $this->_items = array();
         }
     }
     return $this;
 }
开发者ID:bitbull-team,项目名称:magento-module-category-layered,代码行数:34,代码来源:CategoryLayered.php

示例2: getCategory

 /**
  * Search category by the name from root category or specified one.
  * Create category when it doesn't exist if $createIfNotExists
  * parameter is set.
  * Search category by store-specific name if $store parameter is set.
  *
  * @param string $name
  * @param bool $createIfNotExists
  * @param Mage_Catalog_Model_Category $parent
  * @param null|Mage_Core_Model_Store $store
  *
  * @return Mage_Catalog_Model_Category|null
  */
 public function getCategory($name, $createIfNotExists = false, $parent = null, $store = null)
 {
     $store = $store instanceof Mage_Core_Model_Store ? $store : Mage::app()->getStore();
     $collection = $parent && ($parentId = $parent->getId()) ? $parent->setStoreId($store->getId())->getCollection()->addFieldToFilter('parent_id', $parentId) : Mage::getModel('catalog/category')->setStoreId($store->getId())->load($store->getRootCategoryId())->getCollection();
     $collection->addAttributeToFilter('name', $name);
     if ($collection->count()) {
         return $collection->getFirstItem();
     }
     if (!$createIfNotExists) {
         return;
     }
     if ($parent && $parent->getId()) {
         $rootCategory = $parent;
     } else {
         $collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('parent_id', 1);
         if (count($collection) != 1) {
             return null;
         }
         $rootCategory = $collection->getFirstItem();
         if (!$rootCategory->getId()) {
             return null;
         }
     }
     $model = Mage::getModel('catalog/category');
     $model->setStoreId($rootCategory->getStoreId())->setData(array('name' => $name, 'is_active' => 1, 'include_in_menu' => 1))->setPath($rootCategory->getPath())->setAttributeSetId($model->getDefaultAttributeSetId());
     try {
         $model->save();
     } catch (Exception $e) {
         return null;
     }
     return $model;
 }
开发者ID:james-hickman-arc,项目名称:magento-w2p,代码行数:45,代码来源:Category.php

示例3: drawOpenCategoryItem

 /**
  * @param Mage_Catalog_Model_Category $category
  * @param int $level
  * @return string
  */
 public function drawOpenCategoryItem($category, $level = 0)
 {
     if ($this->_isExcluded($category->getId()) || !$category->getIsActive() || !$category->getIncludeInMenu()) {
         return '';
     }
     $cssClass = array('amshopby-cat', 'level' . $level);
     $currentCategory = $this->getDataHelper()->getCurrentCategory();
     if ($currentCategory->getId() == $category->getId()) {
         $cssClass[] = 'active';
     }
     if ($this->isCategoryActive($category)) {
         $cssClass[] = 'parent';
     }
     if ($category->hasChildren()) {
         $cssClass[] = 'has-child';
     }
     $productCount = '';
     if ($this->showProductCount()) {
         $productCount = $category->getProductCount();
         if ($productCount > 0) {
             $productCount = '&nbsp;<span class="count">(' . $productCount . ')</span>';
         } else {
             $productCount = '';
         }
     }
     $html = array();
     $html[1] = '<a href="' . $this->getCategoryUrl($category) . '">' . $this->htmlEscape($category->getName()) . $productCount . '</a>';
     $showAll = Mage::getStoreConfig('amshopby/advanced_categories/show_all_categories');
     $showDepth = Mage::getStoreConfig('amshopby/advanced_categories/show_all_categories_depth');
     $hasChild = false;
     $inPath = in_array($category->getId(), $currentCategory->getPathIds());
     $showAsAll = $showAll && ($showDepth == 0 || $showDepth > $level + 1);
     if ($inPath || $showAsAll) {
         $children = $this->_getCategoryCollection()->addIdFilter($category->getChildren());
         $this->_addCounts($children);
         $children = $this->asArray($children);
         if ($children && count($children) > 0) {
             $hasChild = true;
             $htmlChildren = '';
             foreach ($children as $child) {
                 $htmlChildren .= $this->drawOpenCategoryItem($child, $level + 1);
             }
             if ($htmlChildren != '') {
                 $cssClass[] = 'expanded';
                 $html[2] = '<ol>' . $htmlChildren . '</ol>';
             }
         }
     }
     $html[0] = sprintf('<li class="%s">', implode(" ", $cssClass));
     $html[3] = '</li>';
     ksort($html);
     if ($category->getProductCount() || $hasChild && $htmlChildren) {
         $result = implode('', $html);
     } else {
         $result = '';
     }
     return $result;
 }
开发者ID:xiaoguizhidao,项目名称:tyler-live,代码行数:63,代码来源:Advanced.php

示例4: saveCategoryRelation

 /**
  * Save  category - post relations
  *
  * @access public
  * @param Mage_Catalog_Model_Category $category
  * @param array $data
  * @return Tech_Blog_Model_Resource_Post_Category
  * @author Ultimate Module Creator
  */
 public function saveCategoryRelation($category, $data)
 {
     if (!is_array($data)) {
         $data = array();
     }
     $deleteCondition = $this->_getWriteAdapter()->quoteInto('category_id=?', $category->getId());
     $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition);
     foreach ($data as $postId => $info) {
         $this->_getWriteAdapter()->insert($this->getMainTable(), array('post_id' => $postId, 'category_id' => $category->getId(), 'position' => @$info['position']));
     }
     return $this;
 }
开发者ID:k0bix,项目名称:Tech_Blog,代码行数:21,代码来源:Category.php

示例5: exportData

 protected function exportData(Mage_Catalog_Model_Category $category, $file, $depth = 0)
 {
     $data = array('id' => $category->getId(), 'parent_id' => $category->getParentId(), 'attribute_set_id' => $category->getAttributeSetId(), 'urlPath' => $category->getUrlPath(), 'urlKey' => $category->getUrlKey(), 'path' => $category->getPath(), 'position' => $category->getPosition(), 'page_layout' => $category->getPageLayout(), 'description' => $category->getDescription(), 'display_mode' => $category->getDisplayMode(), 'is_active' => $category->getIsActive(), 'is_anchor' => $category->getIsAnchor(), 'include_in_menu' => $category->getIncludeInMenu(), 'custom_design' => $category->getCustomDesign(), 'level' => $category->getLevel(), 'name' => $category->getName(), 'metaTitle' => $category->getMetaTitle(), 'metaKeywords' => $category->getMetaKeywords(), 'metaDescription' => $category->getMetaDescription());
     echo str_repeat('  ', $depth);
     echo '* ' . $category->getName() . sprintf(' (%s products)', $category->getProductCount()) . PHP_EOL;
     fputcsv($file, $data);
     if ($category->hasChildren()) {
         $children = Mage::getModel('catalog/category')->getCategories($category->getId());
         foreach ($children as $child) {
             $child = Mage::getModel('catalog/category')->load($child->getId());
             $this->exportData($child, $file, $depth + 1);
         }
     }
 }
开发者ID:sonaht,项目名称:magento-category-migration,代码行数:14,代码来源:exportCategories.php

示例6: _isProductInCategory

 /**
  * Check if product is inside of the category
  * 
  * @param  Mage_Catalog_Model_Product   $product  
  * @param  Mage_Catalog_Model_Category  $category 
  * @return boolean
  */
 private function _isProductInCategory($product, $category)
 {
     $categoryIds = $product->getCategoryIds();
     $categoryId = $category->getId();
     if (in_array($categoryId, $categoryIds)) {
         return true;
     }
     return false;
 }
开发者ID:danielozano,项目名称:magento_prevnext,代码行数:16,代码来源:Product.php

示例7: _isPageHandled

 /**
  * @param Mage_Catalog_Model_Category $category Will be updated according matched Page
  * @return bool
  */
 protected function _isPageHandled($category)
 {
     /** @var Amasty_Shopby_Model_Mysql4_Page $pageResource */
     $pageResource = Mage::getResourceModel('amshopby/page');
     $page = $pageResource->getCurrentMatchedPage($category->getId());
     $this->_handleCanonical($page);
     if (is_null($page)) {
         return false;
     }
     /** @var Mage_Page_Block_Html_Head $head */
     $head = $this->getLayout()->getBlock('head');
     // metas
     $title = $head->getTitle();
     // trim prefix if any
     $prefix = Mage::getStoreConfig('design/head/title_prefix');
     $prefix = htmlspecialchars(html_entity_decode(trim($prefix), ENT_QUOTES, 'UTF-8'));
     if ($prefix) {
         $title = substr($title, strlen($prefix));
     }
     $suffix = Mage::getStoreConfig('design/head/title_suffix');
     $suffix = htmlspecialchars(html_entity_decode(trim($suffix), ENT_QUOTES, 'UTF-8'));
     if ($suffix) {
         $title = substr($title, 0, -1 - strlen($suffix));
     }
     $descr = $head->getDescription();
     $kw = $head->getKeywords();
     $titleSeparator = Mage::getStoreConfig('amshopby/general/title_separator');
     $descrSeparator = Mage::getStoreConfig('amshopby/general/descr_separator');
     $kwSeparator = ',';
     if ($page->getUseCat()) {
         $title = $title . $titleSeparator . $page->getMetaTitle();
         $descr = $descr . $descrSeparator . $page->getMetaDescr();
         $kw = $page->getMetaKw() . $kwSeparator . $kw;
     } else {
         $title = $page->getMetaTitle();
         $descr = $page->getMetaDescr();
         $kw = $page->getMetaKw();
     }
     $head->setTitle($this->trim($title));
     $head->setDescription($this->trim($descr));
     $head->setKeywords($this->trim($kw));
     // in-page description
     if ($page->getCmsBlockId()) {
         $this->setCategoryCmsBlock($category, $page->getCmsBlockId());
     }
     if ($page->getBottomCmsBlockId()) {
         $this->addBottomCmsBlock($page->getBottomCmsBlockId());
     }
     if ($page->getTitle()) {
         $category->setData('name', $page->getTitle());
     }
     if ($page->getDescription()) {
         $category->setData('description', $page->getDescription());
     }
     return true;
 }
开发者ID:rcclaudrey,项目名称:dev,代码行数:60,代码来源:Top.php

示例8: _validateEntityUrl

 /**
  * Check unique url_key value in catalog_category_entity_url_key table.
  *
  * @param Mage_Catalog_Model_Category $object
  * @return Mage_Catalog_Model_Category_Attribute_Backend_Urlkey
  * @throws Mage_Core_Exception
  */
 protected function _validateEntityUrl($object)
 {
     $connection = $object->getResource()->getReadConnection();
     $select = $connection->select()->from($this->getAttribute()->getBackendTable(), array('count' => new Zend_Db_Expr('COUNT(\'value_id\')')))->where($connection->quoteInto('entity_id <> ?', $object->getId()))->where($connection->quoteInto('value = ?', $object->getUrlKey()));
     $result = $connection->fetchOne($select);
     if ((int) $result) {
         throw new Mage_Core_Exception(Mage::helper('catalog')->__("Category with the '%s' url_key attribute already exists.", $object->getUrlKey()));
     }
     return $this;
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:17,代码来源:Urlkey.php

示例9: _collectTags

 /**
  * Should return list of tags to clean
  *
  * @param Mage_Catalog_Model_Category $object
  * @return string[]|string
  */
 protected function _collectTags($object)
 {
     $tags = array(self::TAG_PREFIX . $object->getId());
     if ($this->_isForUpdate) {
         foreach ($object->getParentIds() as $categoryId) {
             $tags[] = self::TAG_PREFIX . $categoryId;
         }
     }
     return $tags;
 }
开发者ID:jonesio,项目名称:EcomDev_Varnish,代码行数:16,代码来源:Category.php

示例10: purge

 /**
  * Purge Category
  *
  * @param Mage_Catalog_Model_Category $category
  * @return Phoenix_VarnishCache_Model_Control_Catalog_Category
  */
 public function purge(Mage_Catalog_Model_Category $category)
 {
     if ($this->_canPurge()) {
         $this->_purgeById($category->getId());
         if ($categoryName = $category->getName()) {
             $this->_getSession()->addSuccess(Mage::helper('varnishcache')->__('Varnish cache for "%s" has been purged.', $categoryName));
         }
     }
     return $this;
 }
开发者ID:rob3000,项目名称:Magento-PageCache-powered-by-Varnish,代码行数:16,代码来源:Category.php

示例11: getSubcategories

 /**
  * Returns list of subcategories recursively.
  *
  * @param Mage_Catalog_Model_Category $category
  * @return mixed
  */
 protected function getSubcategories(Mage_Catalog_Model_Category $category)
 {
     if (!isset($this->subcategories[$category->getId()])) {
         $list = array();
         $categories = $category->getChildrenCategories();
         $this->getAllChildCategories($categories, $list);
         $this->subcategories[$category->getId()] = $list;
     }
     return $this->subcategories[$category->getId()];
 }
开发者ID:xiaoguizhidao,项目名称:magento,代码行数:16,代码来源:Category.php

示例12: getProductCountExcludeOutStock

 /**
  * Get products count in category
  *
  * @param Mage_Catalog_Model_Category $category
  * @return integer
  */
 public function getProductCountExcludeOutStock($category)
 {
     $read = $this->_getReadAdapter();
     $store_data = Mage::getModel('core/store')->load($category->getStoreId());
     //load store object
     $website_id = $store_data->getWebsiteId();
     //get website id from the store
     $select = $read->select()->from(array('main_table' => $this->getTable('catalog/category_product')), "COUNT(main_table.product_id)")->joinLeft(array('stock' => $this->getTable('cataloginventory/stock_status')), 'main_table.product_id=stock.product_id AND ' . $read->quoteInto('stock.website_id=? ', $website_id), array())->where("main_table.category_id = ?", $category->getId())->where("round(stock.qty) > 0 ")->where("stock.stock_status = ? ", 1)->group("main_table.category_id");
     //echo $select->__toString(); exit;
     return (int) $read->fetchOne($select);
 }
开发者ID:sagmahajan,项目名称:aswan_release,代码行数:17,代码来源:Hidecategories.php

示例13: getFirstLevelCategory

 /**
  * @param Mage_Catalog_Model_Category $category
  * @return Mage_Catalog_Model_Category
  */
 public function getFirstLevelCategory($category)
 {
     if (!isset($this->_firstLevelCategories[$category->getId()])) {
         $rootId = Mage::app()->getStore()->getRootCategoryId();
         $id = $rootId;
         $rootFound = false;
         foreach ($category->getPathIds() as $pathId) {
             if ($rootFound) {
                 $id = $pathId;
                 break;
             } else {
                 if ($pathId == $rootId) {
                     $rootFound = true;
                 }
             }
         }
         if ($id == $category->getId()) {
             $this->_firstLevelCategories[$category->getId()] = $category;
         } elseif ($id == $rootId) {
             $this->_firstLevelCategories[$category->getId()] = $this->getRootCategory();
         } else {
             $this->_firstLevelCategories[$category->getId()] = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($id);
         }
     }
     return $this->_firstLevelCategories[$category->getId()];
 }
开发者ID:xiaoguizhidao,项目名称:cupboardglasspipes.ecomitize.com,代码行数:30,代码来源:Data.php

示例14: loadByCategory

 /**
  * Load url rewrite based on specified category
  *
  * @param Mage_Core_Model_Abstract $object
  * @param Mage_Catalog_Model_Category $category
  * @return Enterprise_Catalog_Model_Resource_Category
  */
 public function loadByCategory(Mage_Core_Model_Abstract $object, Mage_Catalog_Model_Category $category)
 {
     $idField = $this->_getReadAdapter()->getIfNullSql('url_rewrite_cat.id', 'default_urc.id');
     $requestPath = $this->_getReadAdapter()->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path');
     $select = $this->_getReadAdapter()->select()->from(array('main_table' => $this->getTable('catalog/category')), array($this->getIdFieldName() => $idField))->where('main_table.entity_id = ?', (int) $category->getId())->joinLeft(array('url_rewrite_cat' => $this->getTable('enterprise_catalog/category')), 'url_rewrite_cat.category_id = main_table.entity_id AND url_rewrite_cat.store_id = ' . (int) $category->getStoreId(), array(''))->joinLeft(array('url_rewrite' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'url_rewrite.url_rewrite_id = url_rewrite_cat.url_rewrite_id', array(''))->joinLeft(array('default_urc' => $this->getTable('enterprise_catalog/category')), 'default_urc.category_id = main_table.entity_id AND default_urc.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->getTable('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urc.url_rewrite_id', array('request_path' => $requestPath));
     $result = $this->_getReadAdapter()->fetchRow($select);
     if ($result) {
         $object->setData($result);
     }
     $this->unserializeFields($object);
     $this->_afterLoad($object);
     return $this;
 }
开发者ID:hientruong90,项目名称:ee_14_installer,代码行数:20,代码来源:Category.php

示例15: categoryAttribute

 /**
  * Prepare category attribute html output
  *
  * @param   Mage_Catalog_Model_Category $category
  * @param   string $attributeHtml
  * @param   string $attributeName
  * @return  string
  */
 public function categoryAttribute($category, $attributeHtml, $attributeName)
 {
     $isDefaultCategory = $category->getId() == Mage::app()->getStore()->getRootCategoryId();
     if ($attributeName == 'name' && $isDefaultCategory) {
         /** @var Amasty_Shopby_Helper_Attributes $helper */
         $helper = Mage::helper('amshopby/attributes');
         $setting = $helper->getRequestedBrandOption();
         if (is_array($setting)) {
             return $this->escapeHtml($setting['title']);
         }
     }
     return parent::categoryAttribute($category, $attributeHtml, $attributeName);
 }
开发者ID:xiaoguizhidao,项目名称:tyler-live,代码行数:21,代码来源:Output.php


注:本文中的Mage_Catalog_Model_Category::getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。