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


PHP Model\Category類代碼示例

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


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

示例1: setUp

 protected function setUp()
 {
     $this->_category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category');
     $this->_category->load(5);
     $layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Category', ['data' => ['current_category' => $this->_category]]);
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Filter\\Category', ['layer' => $layer]);
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:7,代碼來源:CategoryTest.php

示例2: 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:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:36,代碼來源:Category.php

示例3: 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

示例4: aroundGetUrlInstance

 public function aroundGetUrlInstance(Category $category, \Closure $proceed)
 {
     if ($category->getStoreId() == 0) {
         return $proceed();
     } else {
         return $this->objectManager->create(self::FRONTEND_URL)->setStoreId($category->getStoreId());
     }
 }
開發者ID:algolia,項目名稱:algoliasearch-magento-2,代碼行數:8,代碼來源:CategoryUrlPlugin.php

示例5: aroundReindex

 /**
  * Reindex category's products after reindexing the category
  *
  * @param \Magento\Catalog\Model\Category $subject The cateogry being reindexed
  * @param callable                        $proceed The parent function we are plugged on
  *                                                 : Magento\Catalog\Model\Category::reindex()
  *
  * @return \Magento\Catalog\Model\Category
  */
 public function aroundReindex(\Magento\Catalog\Model\Category $subject, callable $proceed)
 {
     $proceed();
     if (!empty($subject->getAffectedProductIds())) {
         $this->processFullTextIndex($subject->getAffectedProductIds());
     }
     return;
 }
開發者ID:smile-sa,項目名稱:elasticsuite,代碼行數:17,代碼來源:ReindexProductsAfterSave.php

示例6: testAddCatalogToTopMenuItemsWithFlat

 public function testAddCatalogToTopMenuItemsWithFlat()
 {
     $observer = $this->_preparationData();
     $this->_category->expects($this->once())->method('getChildrenNodes')->will($this->returnValue([$this->_childrenCategory]));
     $this->_category->expects($this->once())->method('getUseFlatResource')->will($this->returnValue(true));
     $this->_categoryFlatState->expects($this->once())->method('isFlatEnabled')->will($this->returnValue(true));
     $this->_observer->execute($observer);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:8,代碼來源:AddCatalogToTopmenuItemsObserverTest.php

示例7: generateForCustom

 /**
  * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url
  * @param int $storeId
  * @return array
  */
 protected function generateForCustom($url, $storeId)
 {
     $urls = [];
     $targetPath = !$url->getRedirectType() ? $url->getTargetPath() : $this->categoryUrlPathGenerator->getUrlPathWithSuffix($this->category, $storeId);
     if ($url->getRequestPath() !== $targetPath) {
         $urls[$url->getRequestPath() . '_' . $storeId] = $this->urlRewriteFactory->create()->setEntityType(CategoryUrlRewriteGenerator::ENTITY_TYPE)->setEntityId($this->category->getId())->setRequestPath($url->getRequestPath())->setTargetPath($targetPath)->setRedirectType($url->getRedirectType())->setStoreId($storeId)->setDescription($url->getDescription())->setIsAutogenerated(0)->setMetadata($url->getMetadata());
     }
     return $urls;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:CurrentUrlRewritesRegenerator.php

示例8: getNode

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @return Node
  */
 protected function getNode(\Magento\Catalog\Model\Category $category)
 {
     $nodeId = $category->getId();
     $node = $this->categoryTree->loadNode($nodeId);
     $node->loadChildren();
     $this->prepareCollection();
     $this->categoryTree->addCollectionData($this->categoryCollection);
     return $node;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:13,代碼來源:Tree.php

示例9: afterSave

 /**
  * @param \Magento\Catalog\Model\Category $subject
  * @param \Magento\Catalog\Model\Category $result
  * @return \Magento\Catalog\Model\Category
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterSave(\Magento\Catalog\Model\Category $subject, \Magento\Catalog\Model\Category $result)
 {
     /** @var \Magento\Catalog\Model\Category $result */
     $productIds = $result->getAffectedProductIds();
     if ($productIds) {
         $this->productRuleProcessor->reindexList($productIds);
     }
     return $result;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:16,代碼來源:Category.php

示例10: getSelectedAuthors

 /**
  * @access public
  * @param \Magento\Catalog\Model\Category $category
  * @return mixed
  */
 public function getSelectedAuthors(CategoryModel $category)
 {
     if (!$category->hasSelectedAuthors()) {
         $authors = [];
         foreach ($this->getSelectedAuthorsCollection($category) as $author) {
             $authors[] = $author;
         }
         $category->setSelectedAuthors($authors);
     }
     return $category->getData('selected_authors');
 }
開發者ID:avra911,項目名稱:Magento2SampleModule,代碼行數:16,代碼來源:Category.php

示例11: getSelectedArticles

 /**
  * @access public
  * @param \Magento\Catalog\Model\Category $category
  * @return mixed
  */
 public function getSelectedArticles(CategoryModel $category)
 {
     if (!$category->hasSelectedArticles()) {
         $articles = [];
         foreach ($this->getSelectedArticlesCollection($category) as $article) {
             $articles[] = $article;
         }
         $category->setSelectedArticles($articles);
     }
     return $category->getData('selected_articles');
 }
開發者ID:pleminh,項目名稱:Gemtoo,代碼行數:16,代碼來源:Category.php

示例12: generateForGlobalScope

 /**
  * Generate list of urls for global scope
  *
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 protected function generateForGlobalScope()
 {
     $urls = [];
     $categoryId = $this->category->getId();
     foreach ($this->category->getStoreIds() as $id) {
         if (!$this->isGlobalScope($id) && !$this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($id, $categoryId, Category::ENTITY)) {
             $urls = array_merge($urls, $this->generateForSpecificStoreView($id));
         }
     }
     return $urls;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:16,代碼來源:CategoryUrlRewriteGenerator.php

示例13: aroundReindex

 /**
  * Reindex category's data after into search engine after reindexing the category
  *
  * @param \Magento\Catalog\Model\Category $subject The category being reindexed
  * @param callable                        $proceed The parent function we are plugged on
  *                                                 : Magento\Catalog\Model\Category::reindex()
  *
  * @return \Magento\Catalog\Model\Category
  */
 public function aroundReindex(\Magento\Catalog\Model\Category $subject, callable $proceed)
 {
     $proceed();
     if ($subject->getLevel() > 1) {
         $categoryIndexer = $this->indexerRegistry->get(\Smile\ElasticsuiteCatalog\Model\Category\Indexer\Fulltext::INDEXER_ID);
         if (!$categoryIndexer->isScheduled()) {
             $categoryIndexer->reindexRow($subject->getId());
         }
     }
     return;
 }
開發者ID:smile-sa,項目名稱:elasticsuite,代碼行數:20,代碼來源:ReindexCategoryAfterSave.php

示例14: 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

示例15: _getCategory

 /**
  * Get Category from request
  *
  * @return Category
  */
 protected function _getCategory()
 {
     if (!$this->_category) {
         $this->_category = $this->_objectManager->create('Magento\\Catalog\\Model\\Category');
         $categoryId = (int) $this->getRequest()->getParam('category', 0);
         if (!$categoryId && $this->_getUrlRewrite()->getId()) {
             $categoryId = $this->_getUrlRewrite()->getCategoryId();
         }
         if ($categoryId) {
             $this->_category->load($categoryId);
         }
     }
     return $this->_category;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:19,代碼來源:Urlrewrite.php


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