예제 #1
0
 /**
  * Return parent categories of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @return \Magento\Framework\Object[]
  */
 public function getParentCategories($category)
 {
     $pathIds = array_reverse(explode(',', $category->getPathInStore()));
     /** @var \Magento\Catalog\Model\Resource\Category\Collection $categories */
     $categories = $this->_categoryCollectionFactory->create();
     return $categories->setStore($this->_storeManager->getStore())->addAttributeToSelect('name')->addAttributeToSelect('url_key')->addFieldToFilter('entity_id', array('in' => $pathIds))->addFieldToFilter('is_active', 1)->load()->getItems();
 }
예제 #2
0
 public function testGetPathInStore()
 {
     $this->_model->load(5);
     $this->assertEquals('5,4,3', $this->_model->getPathInStore());
 }
예제 #3
0
파일: Flat.php 프로젝트: aiesh/magento2
 /**
  * Return parent categories of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param bool $isActive
  * @return \Magento\Catalog\Model\Category[]
  */
 public function getParentCategories($category, $isActive = true)
 {
     $categories = array();
     $read = $this->_getReadAdapter();
     $select = $read->select()->from(array('main_table' => $this->getMainStoreTable($category->getStoreId())), array('main_table.entity_id', 'main_table.name'))->joinLeft(array('url_rewrite' => $this->getTable('core_url_rewrite')), 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND ' . $read->quoteInto('url_rewrite.product_id IS NULL AND url_rewrite.store_id=? AND ', $category->getStoreId()) . $read->prepareSqlCondition('url_rewrite.id_path', array('like' => 'category/%')), array('request_path' => 'url_rewrite.request_path'))->where('main_table.entity_id IN (?)', array_reverse(explode(',', $category->getPathInStore())));
     if ($isActive) {
         $select->where('main_table.is_active = ?', '1');
     }
     $select->order('main_table.path ASC');
     $result = $this->_getReadAdapter()->fetchAll($select);
     foreach ($result as $row) {
         $row['id'] = $row['entity_id'];
         $categories[$row['entity_id']] = $this->_categoryFactory->create()->setData($row);
     }
     return $categories;
 }
예제 #4
0
 /**
  * Return parent categories of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param bool $isActive
  * @return \Magento\Catalog\Model\Category[]
  */
 public function getParentCategories($category, $isActive = true)
 {
     $categories = [];
     $read = $this->_getReadAdapter();
     $select = $read->select()->from(['main_table' => $this->getMainStoreTable($category->getStoreId())], ['main_table.entity_id', 'main_table.name'])->joinLeft(['url_rewrite' => $this->getTable('url_rewrite')], 'url_rewrite.entity_id = main_table.entity_id AND url_rewrite.is_autogenerated = 1' . $read->quoteInto(' AND url_rewrite.store_id = ?', $category->getStoreId()) . $read->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE), ['request_path' => 'url_rewrite.request_path'])->where('main_table.entity_id IN (?)', array_reverse(explode(',', $category->getPathInStore())));
     if ($isActive) {
         $select->where('main_table.is_active = ?', '1');
     }
     $select->order('main_table.path ASC');
     $result = $this->_getReadAdapter()->fetchAll($select);
     foreach ($result as $row) {
         $row['id'] = $row['entity_id'];
         $categories[$row['entity_id']] = $this->_categoryFactory->create()->setData($row);
     }
     return $categories;
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function getPathInStore()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPathInStore');
     if (!$pluginInfo) {
         return parent::getPathInStore();
     } else {
         return $this->___callPlugins('getPathInStore', func_get_args(), $pluginInfo);
     }
 }