本文整理汇总了PHP中Mage_Catalog_Model_Category::getParentCategories方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Category::getParentCategories方法的具体用法?PHP Mage_Catalog_Model_Category::getParentCategories怎么用?PHP Mage_Catalog_Model_Category::getParentCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Category
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Category::getParentCategories方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildCategoryString
/**
* Builds a tagging string of the given category including all its parent
* categories.
* The categories are sorted by their position in the category tree path.
*
* @param Mage_Catalog_Model_Category $category the category model.
*
* @return string
*/
public function buildCategoryString($category)
{
$data = array();
if ($category instanceof Mage_Catalog_Model_Category) {
/** @var $categories Mage_Catalog_Model_Category[] */
$categories = $category->getParentCategories();
$path = $category->getPathInStore();
$ids = array_reverse(explode(',', $path));
foreach ($ids as $id) {
if (isset($categories[$id]) && $categories[$id]->getName()) {
$data[] = $categories[$id]->getName();
}
}
}
if (!empty($data)) {
return DS . implode(DS, $data);
} else {
return '';
}
}
示例2: beforeSave
/**
* @param Mage_Catalog_Model_Category $object
* @return $this|Convenient_CategoryCode_Model_Attribute_Backend_Code
*
* @author Luke Rodgers <lukerodgers90@gmail.com>
*/
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;
}
示例3: testGetParentCategoriesEmpty
public function testGetParentCategoriesEmpty()
{
$this->_model->load(1);
$parents = $this->_model->getParentCategories();
$this->assertEquals(0, count($parents));
}