當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Category::getPath方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\Category::getPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP Category::getPath方法的具體用法?PHP Category::getPath怎麽用?PHP Category::getPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\Category的用法示例。


在下文中一共展示了Category::getPath方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: ajaxRequestResponse

 /**
  * Build response for ajax request
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param \Magento\Backend\Model\View\Result\Page $resultPage
  *
  * @return \Magento\Framework\Controller\Result\Json
  *
  * @deprecated
  */
 protected function ajaxRequestResponse($category, $resultPage)
 {
     // prepare breadcrumbs of selected category, if any
     $breadcrumbsPath = $category->getPath();
     if (empty($breadcrumbsPath)) {
         // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
         $breadcrumbsPath = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session')->getDeletedPath(true);
         if (!empty($breadcrumbsPath)) {
             $breadcrumbsPath = explode('/', $breadcrumbsPath);
             // no need to get parent breadcrumbs if deleting category level 1
             if (count($breadcrumbsPath) <= 1) {
                 $breadcrumbsPath = '';
             } else {
                 array_pop($breadcrumbsPath);
                 $breadcrumbsPath = implode('/', $breadcrumbsPath);
             }
         }
     }
     $eventResponse = new \Magento\Framework\DataObject(['content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml() . $resultPage->getLayout()->getBlock('category.tree')->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(), 'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()]);
     $this->_eventManager->dispatch('category_prepare_ajax_response', ['response' => $eventResponse, 'controller' => $this]);
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->_objectManager->get('Magento\\Framework\\Controller\\Result\\Json');
     $resultJson->setHeader('Content-type', 'application/json', true);
     $resultJson->setData($eventResponse->getData());
     return $resultJson;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:36,代碼來源:Category.php

示例2: createCategory

 /**
  * Creates a new child category for $parentCategory
  *
  * @param \Magento\Catalog\Model\Category $parentCategory
  * @return \Magento\Catalog\Model\Category
  */
 protected function createCategory($parentCategory)
 {
     /** @var \Magento\Catalog\Model\Category $category */
     $category = $this->objectManager->create('Magento\\Catalog\\Model\\Category');
     $category->setStoreId(self::DEFAULT_STORE_ID)->setParentId($parentCategory->getId())->setName(self::NAMES_PREFIX . $this->titlesGenerator->generateCategoryTitle())->setAttributeSetId($category->getDefaultAttributeSetId())->setLevel($parentCategory->getLevel() + 1)->setPath($parentCategory->getPath())->setIsActive(1)->save();
     return $category;
 }
開發者ID:rogyar,項目名稱:m2-sampledata-generator,代碼行數:13,代碼來源:CategoriesCreator.php

示例3: buildPath

 /**
  * @param Category $category
  * @return string
  */
 protected function buildPath(Category $category)
 {
     $data = [];
     $path = $category->getPath();
     foreach (explode('/', $path) as $categoryId) {
         $category = $this->_categoryRepository->get($categoryId);
         if ($category && $category->getLevel() > 1) {
             $data[] = $category->getName();
         }
     }
     return count($data) ? '/' . implode('/', $data) : '';
 }
開發者ID:Nosto,項目名稱:nosto-magento2,代碼行數:16,代碼來源:Builder.php

示例4: getChildrenIds

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return int[]
  */
 public function getChildrenIds(Category $category, $recursive = false)
 {
     $cacheKey = $category->getId() . '_' . (int) $recursive;
     if (!isset($this->childrenIds[$cacheKey])) {
         $connection = $category->getResource()->getReadConnection();
         $select = $connection->select()->from($category->getResource()->getEntityTable(), 'entity_id')->where($connection->quoteIdentifier('path') . ' LIKE :c_path');
         $bind = ['c_path' => $category->getPath() . '/%'];
         if (!$recursive) {
             $select->where($connection->quoteIdentifier('level') . ' <= :c_level');
             $bind['c_level'] = $category->getLevel() + 1;
         }
         $this->childrenIds[$cacheKey] = $connection->fetchCol($select, $bind);
     }
     return $this->childrenIds[$cacheKey];
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:20,代碼來源:ChildrenCategoriesProvider.php

示例5: getChildren

 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return array
  */
 public function getChildren($category, $recursive = true)
 {
     $attributeId = (int) $this->_getIsActiveAttributeId();
     $backendTable = $this->getTable(array($this->getEntityTablePrefix(), 'int'));
     $adapter = $this->_getReadAdapter();
     $checkSql = $adapter->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
     $bind = array('attribute_id' => $attributeId, 'store_id' => $category->getStoreId(), 'scope' => 1, 'c_path' => $category->getPath() . '/%');
     $select = $this->_getReadAdapter()->select()->from(array('m' => $this->getEntityTable()), 'entity_id')->joinLeft(array('d' => $backendTable), 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = m.entity_id', array())->joinLeft(array('c' => $backendTable), 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id', array())->where($checkSql . ' = :scope')->where($adapter->quoteIdentifier('path') . ' LIKE :c_path');
     if (!$recursive) {
         $select->where($adapter->quoteIdentifier('level') . ' <= :c_level');
         $bind['c_level'] = $category->getLevel() + 1;
     }
     return $adapter->fetchCol($select, $bind);
 }
開發者ID:pavelnovitsky,項目名稱:magento2,代碼行數:21,代碼來源:Category.php

示例6: getChildren

 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param boolean $recursive
  * @return array
  */
 public function getChildren($category, $recursive = true)
 {
     $linkField = $this->getLinkField();
     $attributeId = $this->getIsActiveAttributeId();
     $backendTable = $this->getTable([$this->getEntityTablePrefix(), 'int']);
     $connection = $this->getConnection();
     $checkSql = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value');
     $linkField = $this->getLinkField();
     $bind = ['attribute_id' => $attributeId, 'store_id' => $category->getStoreId(), 'scope' => 1, 'c_path' => $category->getPath() . '/%'];
     $select = $this->getConnection()->select()->from(['m' => $this->getEntityTable()], 'entity_id')->joinLeft(['d' => $backendTable], "d.attribute_id = :attribute_id AND d.store_id = 0 AND d.{$linkField} = m.{$linkField}", [])->joinLeft(['c' => $backendTable], "c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.{$linkField} = m.{$linkField}", [])->where($checkSql . ' = :scope')->where($connection->quoteIdentifier('path') . ' LIKE :c_path');
     if (!$recursive) {
         $select->where($connection->quoteIdentifier('level') . ' <= :c_level');
         $bind['c_level'] = $category->getLevel() + 1;
     }
     return $connection->fetchCol($select, $bind);
 }
開發者ID:rafaelstz,項目名稱:magento2,代碼行數:23,代碼來源:Category.php

示例7: getChildren

 /**
  * Return children ids of category
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param bool $recursive
  * @param bool $isActive
  * @return array
  */
 public function getChildren($category, $recursive = true, $isActive = true)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getMainStoreTable($category->getStoreId()), 'entity_id')->where('path LIKE ?', "{$category->getPath()}/%");
     if (!$recursive) {
         $select->where('level <= ?', $category->getLevel() + 1);
     }
     if ($isActive) {
         $select->where('is_active = ?', '1');
     }
     $_categories = $this->_getReadAdapter()->fetchAll($select);
     $categoriesIds = [];
     foreach ($_categories as $_category) {
         $categoriesIds[] = $_category['entity_id'];
     }
     return $categoriesIds;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:24,代碼來源:Flat.php

示例8: getCategoryBreadcrumb

 /**
  * Return a mini-breadcrumb for a category
  *
  * @param \Magento\Catalog\Model\Category $category The category
  *
  * @return array
  */
 private function getCategoryBreadcrumb(\Magento\Catalog\Model\Category $category)
 {
     $path = $category->getPath();
     $rawPath = explode('/', $path);
     // First occurence is root category (1), second is root category of store.
     $rawPath = array_slice($rawPath, 2);
     // Last occurence is the category displayed.
     array_pop($rawPath);
     $breadcrumb = [];
     foreach ($rawPath as $categoryId) {
         $breadcrumb[] = html_entity_decode($this->getCategoryNameById($categoryId, $category->getStoreId()));
     }
     return $breadcrumb;
 }
開發者ID:smile-sa,項目名稱:elasticsuite,代碼行數:21,代碼來源:ItemFactory.php

示例9: addCategoryTreeChildren

 /**
  * @param Category $parentCategory
  * @param array $children
  */
 public function addCategoryTreeChildren(Category $parentCategory, array $children)
 {
     foreach ($children as $index => $categoryData) {
         // Prepare Data
         $category = $this->categoryFactory->create();
         /** @var \Magento\Catalog\Model\Category\ $category */
         // Set Data
         $category->addData($this->categorySkeleton)->setName($categoryData['name'])->setPath($parentCategory->getPath())->setIsAnchor(isset($categoryData['children']))->setPosition($index + 1)->save();
         // Recursive
         if (isset($categoryData['children']) && is_array($categoryData['children'])) {
             $this->addCategoryTreeChildren($category, $categoryData['children']);
         }
         // Store Names
         if (isset($categoryData['store_name']) && is_array($categoryData['store_name'])) {
             foreach ($categoryData['store_name'] as $code => $name) {
                 $store = $this->getStore($code);
                 if (!$store->getId()) {
                     $this->logger->warning(__('There is no Store with code: %1', $code));
                     continue;
                 }
                 $category->setStoreId($store->getId())->setName($name)->save();
             }
         }
     }
 }
開發者ID:MauroNigrele,項目名稱:magento2-module-setup_tools,代碼行數:29,代碼來源:CatalogInstaller.php

示例10: getPath

 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPath');
     if (!$pluginInfo) {
         return parent::getPath();
     } else {
         return $this->___callPlugins('getPath', func_get_args(), $pluginInfo);
     }
 }
開發者ID:HaonanXu,項目名稱:der-snack-backup,代碼行數:12,代碼來源:Interceptor.php

示例11: getCategoryAsArray

 /**
  * Convert category to array
  *
  * @param \Magento\Catalog\Model\Category $category
  * @param \Magento\Catalog\Model\Category $currentCategory
  * @return array
  */
 private function getCategoryAsArray($category, $currentCategory)
 {
     return ['name' => $category->getName(), 'id' => 'category-node-' . $category->getId(), 'url' => $this->catalogCategory->getCategoryUrl($category), 'has_active' => in_array((string) $category->getId(), explode('/', $currentCategory->getPath()), true), 'is_active' => $category->getId() == $currentCategory->getId()];
 }
開發者ID:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:11,代碼來源:AddCatalogToTopmenuItemsObserver.php


注:本文中的Magento\Catalog\Model\Category::getPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。