本文整理汇总了PHP中Mage_Catalog_Model_Category类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category类的具体用法?PHP Mage_Catalog_Model_Category怎么用?PHP Mage_Catalog_Model_Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Catalog_Model_Category类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _hasCustomUpdate
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;
}
示例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;
}
示例3: _applyCustomDesignSettings
/**
* Recursively apply custom design settings to product if it's container
* category custom_use_for_products option is setted to 1.
* If not or product shows not in category - applyes product's internal settings
*
* @deprecated after 1.4.2.0-beta1, functionality moved to Mage_Catalog_Model_Design
* @param Mage_Catalog_Model_Category|Mage_Catalog_Model_Product $object
* @param Mage_Core_Model_Layout_Update $update
*/
protected function _applyCustomDesignSettings($object, $update)
{
if ($object instanceof Mage_Catalog_Model_Category) {
// lookup the proper category recursively
if ($object->getCustomUseParentSettings()) {
$parentCategory = $object->getParentCategory();
if ($parentCategory && $parentCategory->getId() && $parentCategory->getLevel() > 1) {
$this->_applyCustomDesignSettings($parentCategory, $update);
}
return;
}
// don't apply to the product
if (!$object->getCustomApplyToProducts()) {
return;
}
}
if ($this->_designProductSettingsApplied) {
return;
}
$date = $object->getCustomDesignDate();
if (array_key_exists('from', $date) && array_key_exists('to', $date) && Mage::app()->getLocale()->isStoreDateInInterval(null, $date['from'], $date['to'])) {
if ($object->getPageLayout()) {
$this->_designProductSettingsApplied['layout'] = $object->getPageLayout();
}
$this->_designProductSettingsApplied['update'] = $object->getCustomLayoutUpdate();
}
}
示例4: _getProductCollection
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$categoryID = $this->getCategoryId();
if ($categoryID) {
$category = new Mage_Catalog_Model_Category();
$category->load($categoryID);
// this is category id
$collection = $category->getProductCollection();
} else {
$collection = Mage::getResourceModel('catalog/product_collection');
}
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d') + 1, date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
//$collection->getSelect()->order('rand()');
$collection->addAttributeToSort('created_at', 'desc');
$collection->addStoreFilter();
$collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left');
$numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
$collection->setPage(1, $numProducts)->load();
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
示例5: _reindexCategoryUrlKey
protected function _reindexCategoryUrlKey(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store)
{
$requestPath = trim($category->getParentUrl(), '/');
if (Mage::getStoreConfig('catalog/seo/category_use_parent_category')) {
$requestPath = (!empty($requestPath) ? $requestPath . '/' : '') . $category->getUrlKey();
} else {
$requestPath = $category->getUrlKey();
}
$requestPath = $this->_cutRequestPath($requestPath);
$urlKeyValue = $this->_getUrlKeyAttributeValueId($category, $store);
if (empty($urlKeyValue) && empty($urlKeyValue['value_id'])) {
$category = $this->_setUrlKeyForDefaultStore($category, $store);
$urlKeyValue = $this->_getUrlKeyAttributeValueId($category, $store);
}
$valueId = $urlKeyValue['value_id'];
$rewriteRow = $this->_getRewrite($requestPath, $store->getId());
if (!$rewriteRow || $rewriteRow['value_id'] != $valueId) {
$rewriteForValueId = $this->_getRewriteForValueId($store->getId(), $valueId);
$suffix = trim(str_replace($requestPath, '', $category->getRequestPath()), '-');
$requestPathIncrement = (int) $this->_getRewriteRequestIncrement($requestPath, $store);
if (!$rewriteForValueId || !preg_match('#^(\\d)+$#', $suffix) || $suffix > $requestPathIncrement) {
if ($rewriteRow && $rewriteRow['value_id'] != $valueId) {
$requestPath .= '-' . ++$requestPathIncrement;
}
$category = $this->_saveRewrite($category, $store, $requestPath, $valueId);
}
}
$this->_indexedCategoryIds[$store->getId()][$category->getId()] = 1;
return $category;
}
开发者ID:vinayshuklasourcefuse,项目名称:sareez,代码行数:30,代码来源:Mnm_ExcParentCatPathFromSubCatUrls_Model_Catalog_Index_Action_Url_Rewrite_Category_Refresh.php
示例6: isCategoryAcceptable
/**
* Checks if a category matches criteria: active && url_key not null && included in menu if it has to
*/
protected static function isCategoryAcceptable(Mage_Catalog_Model_Category $category = null, $mustBeIncludedInNavigation = true)
{
if (!$category->getIsActive() || is_null($category->getUrlKey()) || $mustBeIncludedInNavigation && !$category->getIncludeInMenu()) {
return false;
}
return true;
}
示例7: setUp
protected function setUp()
{
$this->_category = Mage::getModel('Mage_Catalog_Model_Category');
$this->_category->load(5);
$this->_model = Mage::getModel('Mage_Catalog_Model_Layer_Filter_Category');
$this->_model->setData(array('layer' => Mage::getModel('Mage_Catalog_Model_Layer', array('data' => array('current_category' => $this->_category)))));
}
示例8: _getProductCollection
/**
* Retrieve loaded category collection.
* Variables collected from CMS markup: category_id, product_count, is_random
*/
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$categoryID = $this->getCategoryId();
if ($categoryID) {
$category = new Mage_Catalog_Model_Category();
$category->load($categoryID);
$collection = $category->getProductCollection();
//Sort order parameters
$sortBy = $this->getSortBy();
//param: sort_by
if ($sortBy === NULL) {
$sortBy = 'position';
}
$sortDirection = $this->getSortDirection();
//param: sort_direction
if ($sortDirection === NULL) {
$sortDirection = 'ASC';
}
$collection->addAttributeToSort($sortBy, $sortDirection);
} else {
$collection = Mage::getResourceModel('catalog/product_collection');
}
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
if ($this->getIsRandom()) {
$collection->getSelect()->order('rand()');
}
$collection->addStoreFilter();
$productCount = $this->getProductCount() ? $this->getProductCount() : 8;
$collection->setPage(1, $productCount)->load();
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
示例9: setUp
protected function setUp()
{
$category = new Mage_Catalog_Model_Category();
$category->load(4);
$this->_model = new Mage_Catalog_Model_Layer_Filter_Price();
$this->_model->setData(array('layer' => new Mage_Catalog_Model_Layer(array('current_category' => $category))));
}
示例10: testSaveAction
/**
* @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));
}
示例11: getCategoryUrl
/**
* 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();
}
示例12: reindex
/**
* Reindex a single virtual category.
*
* @param Mage_Catalog_Model_Category $category The category.
*
* @return void
*/
public function reindex($category)
{
/** Reindex all data from virtual categories products positions index */
$engine = Mage::helper('catalogsearch')->getEngine();
$mapping = $engine->getCurrentIndex()->getMapping('product');
$dataprovider = $mapping->getDataProvider('virtual_categories_products_position');
$dataprovider->updateAllData($category->getStoreId(), $category->getVirtualProductIds());
}
示例13: _buildCategoryTree
/**
* Take a Mage_Catalog_Model_Category object and build a category tree from
* the child leaf to the root of the category (root > inner child > inner most child)
* @param Mage_Catalog_Model_Category $category the inner most child
* @return string
*/
protected function _buildCategoryTree(Mage_Catalog_Model_Category $category)
{
$collecton = $this->_getCategoriesByIds(explode('/', $category->getPath()));
$categories = array();
foreach ($collecton as $cat) {
$categories[] = $cat->getName();
}
return implode(' > ', array_filter($categories));
}
示例14: _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;
}
示例15: getCmsIdentifier
/**
* Get static block identifier
*
* @param Mage_Catalog_Model_Category $category
*
* @return string
*/
protected function getCmsIdentifier(Mage_Catalog_Model_Category $category)
{
$cmsBlockId = intval($category->getLandingPage());
if (is_integer($cmsBlockId) && $cmsBlockId > 0) {
$cmsBlock = Mage::getModel('cms/block')->load($cmsBlockId);
return $cmsBlock->getIdentifier();
}
return NULL;
}