当前位置: 首页>>代码示例>>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;未经允许,请勿转载。