本文整理汇总了PHP中Magento\Catalog\Model\Category::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getChildren方法的具体用法?PHP Category::getChildren怎么用?PHP Category::getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Category
的用法示例。
在下文中一共展示了Category::getChildren方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductCollection
/**
* @param \Magento\Catalog\Model\Category $category
* @param int $storeId
* @return $this
*/
public function getProductCollection(\Magento\Catalog\Model\Category $category, $storeId)
{
/** @var $layer \Magento\Catalog\Model\Layer */
$layer = $this->catalogLayer->setStore($storeId);
$collection = $category->getResourceCollection();
$collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->load();
/** @var $productCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */
$productCollection = $this->collectionFactory->create();
$currentCategory = $layer->setCurrentCategory($category);
$layer->prepareProductCollection($productCollection);
$productCollection->addCountToCategories($collection);
$category->getProductCollection()->setStoreId($storeId);
$products = $currentCategory->getProductCollection()->addAttributeToSort('updated_at', 'desc')->setVisibility($this->visibility->getVisibleInCatalogIds())->setCurPage(1)->setPageSize(50);
return $products;
}
示例2: getChildrenCategories
/**
* Return child categories
*
* @param \Magento\Catalog\Model\Category $category
* @return \Magento\Catalog\Model\Resource\Category\Collection
*/
public function getChildrenCategories($category)
{
$collection = $category->getCollection();
/* @var $collection \Magento\Catalog\Model\Resource\Category\Collection */
$collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('all_children')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->setOrder('position', \Magento\Framework\DB\Select::SQL_ASC)->joinUrlRewrite()->load();
return $collection;
}
示例3: _renderCategoryMenuItemHtml
/**
* Render category to html
*
* @param Category $category
* @param int $level Nesting level number
* @param boolean $isLast Whether ot not this item is last, affects list item class
* @param boolean $isFirst Whether ot not this item is first, affects list item class
* @param boolean $isOutermost Whether ot not this item is outermost, affects list item class
* @param string $outermostItemClass Extra class of outermost list items
* @param string $childrenWrapClass If specified wraps children list in div with this class
* @param boolean $noEventAttributes Whether ot not to add on* attributes to list item
* @return string
*/
protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false, $isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
{
if (!$category->getIsActive()) {
return '';
}
// get all children
if ($this->flatState->isAvailable()) {
$children = (array) $category->getChildrenNodes();
} else {
$children = $category->getChildren();
}
// select active children
$activeChildren = array();
foreach ($children as $child) {
if ($child->getIsActive()) {
$activeChildren[] = $child;
}
}
$activeChildrenCount = count($activeChildren);
$hasActiveChildren = $activeChildrenCount > 0;
// prepare list item html classes
$classes = array();
$classes[] = 'level' . $level;
$classes[] = 'nav-' . $this->_getItemPosition($level);
if ($this->isCategoryActive($category)) {
$classes[] = 'active';
}
$linkClass = '';
if ($isOutermost && $outermostItemClass) {
$classes[] = $outermostItemClass;
$linkClass = ' class="' . $outermostItemClass . '"';
}
if ($isFirst) {
$classes[] = 'first';
}
if ($isLast) {
$classes[] = 'last';
}
if ($hasActiveChildren) {
$classes[] = 'parent';
}
// prepare list item attributes
$attributes = array();
if (count($classes) > 0) {
$attributes['class'] = implode(' ', $classes);
}
if ($hasActiveChildren && !$noEventAttributes) {
$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';
}
// assemble list item with attributes
$htmlLi = '<li';
foreach ($attributes as $attrName => $attrValue) {
$htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\\"', $attrValue) . '"';
}
$htmlLi .= '>';
$html = array();
$html[] = $htmlLi;
$html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
// render children
$htmlChildren = '';
$j = 0;
foreach ($activeChildren as $child) {
$htmlChildren .= $this->_renderCategoryMenuItemHtml($child, $level + 1, $j == $activeChildrenCount - 1, $j == 0, false, $outermostItemClass, $childrenWrapClass, $noEventAttributes);
$j++;
}
if (!empty($htmlChildren)) {
if ($childrenWrapClass) {
$html[] = '<div class="' . $childrenWrapClass . '">';
}
$html[] = '<ul class="level' . $level . '">';
$html[] = $htmlChildren;
$html[] = '</ul>';
if ($childrenWrapClass) {
$html[] = '</div>';
}
}
$html[] = '</li>';
$html = implode("\n", $html);
return $html;
}
示例4: testGetChildren
public function testGetChildren()
{
$this->_model->load(3);
$this->assertEquals('4', $this->_model->getChildren());
}
示例5: getChildren
/**
* {@inheritdoc}
*/
public function getChildren()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getChildren');
if (!$pluginInfo) {
return parent::getChildren();
} else {
return $this->___callPlugins('getChildren', func_get_args(), $pluginInfo);
}
}