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


PHP Category::getChildren方法代码示例

本文整理汇总了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;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:Category.php

示例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;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:13,代码来源:Category.php

示例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;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:96,代码来源:Navigation.php

示例4: testGetChildren

 public function testGetChildren()
 {
     $this->_model->load(3);
     $this->assertEquals('4', $this->_model->getChildren());
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:5,代码来源:CategoryTreeTest.php

示例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);
     }
 }
开发者ID:HaonanXu,项目名称:der-snack-backup,代码行数:12,代码来源:Interceptor.php


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