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


PHP CategoryFactory::create方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\CategoryFactory::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryFactory::create方法的具体用法?PHP CategoryFactory::create怎么用?PHP CategoryFactory::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\CategoryFactory的用法示例。


在下文中一共展示了CategoryFactory::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _getCategory

 /**
  * Get or create new instance of category
  *
  * @return \Magento\Catalog\Model\Product
  */
 private function _getCategory()
 {
     if (!$this->hasData('category')) {
         $this->setCategory($this->_categoryFactory->create());
     }
     return $this->getCategory();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:Edit.php

示例2: _getParentCategoryOptions

 /**
  * Get parent category options
  *
  * @return array
  */
 protected function _getParentCategoryOptions()
 {
     $items = $this->_categoryFactory->create()->getCollection()->addAttributeToSelect('name')->addAttributeToSort('entity_id', 'ASC')->setPageSize(3)->load()->getItems();
     $result = array();
     if (count($items) === 2) {
         $item = array_pop($items);
         $result = array($item->getEntityId() => $item->getName());
     }
     return $result;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:15,代码来源:NewCategory.php

示例3: getCategory

 /**
  * @param int $id
  * @return CategoryModel
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 private function getCategory($id)
 {
     /** @var CategoryModel $category */
     $category = $this->categoryFactory->create();
     $category->load($id);
     if (!$category->getId()) {
         throw NoSuchEntityException::singleField(Category::ID, $id);
     }
     return $category;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:15,代码来源:ReadService.php

示例4: load

 /**
  * @param int $categoryId
  * @return Category
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function load($categoryId)
 {
     /** @var Category $category */
     $category = $this->categoryFactory->create();
     $category->load($categoryId);
     if (!$category->getId()) {
         throw new NoSuchEntityException('There is no category with provided ID');
     }
     return $category;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:15,代码来源:CategoryLoader.php

示例5: tree

 /**
  * {@inheritdoc}
  */
 public function tree($rootCategoryId = null, $depth = null)
 {
     $category = null;
     if (!is_null($rootCategoryId)) {
         /** @var \Magento\Catalog\Model\Category $category */
         $category = $this->categoryFactory->create()->load($rootCategoryId);
         if (!$category->getId()) {
             throw new \Magento\Framework\Exception\NoSuchEntityException('Root Category does not exist');
         }
     }
     $result = $this->categoryTree->getTree($this->categoryTree->getRootNode($category), $depth);
     return $result;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:16,代码来源:ReadService.php

示例6: getCategories

 /**
  * Get all categories
  *
  * @param bool $sorted
  * @param bool $asCollection
  * @param bool $toLoad
  *
  * @return array|\Magento\Catalog\Model\ResourceModel\Category\Collection|\Magento\Framework\Data\Tree\Node\Collection
  */
 public function getCategories($sorted = false, $asCollection = false, $toLoad = true)
 {
     $cacheKey = sprintf('%d-%d-%d-%d', $this->getSelectedRootCategory(), $sorted, $asCollection, $toLoad);
     if (isset($this->_storeCategories[$cacheKey])) {
         return $this->_storeCategories[$cacheKey];
     }
     /**
      * Check if parent node of the store still exists
      */
     $category = $this->_categoryFactory->create();
     $storeCategories = $category->getCategories($this->getSelectedRootCategory(), $recursionLevel = 1, $sorted, $asCollection, $toLoad);
     $this->_storeCategories[$cacheKey] = $storeCategories;
     return $storeCategories;
 }
开发者ID:Sebwite,项目名称:magento2-category-sidebar,代码行数:23,代码来源:Sidebar.php

示例7: createCategory

 /**
  * Creates a category.
  *
  * @param string $name
  * @param int $parentId
  *
  * @return int
  */
 protected function createCategory($name, $parentId)
 {
     /** @var \Magento\Catalog\Model\Category $category */
     $category = $this->categoryFactory->create();
     $parentCategory = $this->categoryFactory->create()->load($parentId);
     $category->setPath($parentCategory->getPath());
     $category->setParentId($parentId);
     $category->setName($name);
     $category->setIsActive(true);
     $category->setIncludeInMenu(true);
     $category->setAttributeSetId($category->getDefaultAttributeSetId());
     $category->save();
     return $category->getId();
 }
开发者ID:kid17,项目名称:magento2,代码行数:22,代码来源:CategoryProcessor.php

示例8: convertAttribute

 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $productCategories = $product->getCategoryIds();
     // TODO: set Default value for product_type attribute if product isn't assigned for any category
     $value = 'Shop';
     if (!empty($productCategories)) {
         $category = $this->_categoryFactory->create()->load(array_shift($productCategories));
         $breadcrumbs = array();
         foreach ($category->getParentCategories() as $cat) {
             $breadcrumbs[] = $cat->getName();
         }
         $value = implode(' > ', $breadcrumbs);
     }
     $this->_setAttribute($entry, 'product_type', self::ATTRIBUTE_TYPE_TEXT, $value);
     return $entry;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:23,代码来源:ProductType.php

示例9: _getProductCollection

 /**
  * Retrieve loaded category collection
  *
  * @return AbstractCollection
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
         /* @var $layer \Magento\Catalog\Model\Layer */
         if ($this->getShowRootCategory()) {
             $this->setCategoryId($this->_storeManager->getStore()->getRootCategoryId());
         }
         // if this is a product view page
         if ($this->_coreRegistry->registry('product')) {
             // get collection of categories this product is associated with
             $categories = $this->_coreRegistry->registry('product')->getCategoryCollection()->setPage(1, 1)->load();
             // if the product is associated with any category
             if ($categories->count()) {
                 // show products from this category
                 $this->setCategoryId(current($categories->getIterator()));
             }
         }
         $origCategory = null;
         if ($this->getCategoryId()) {
             /** @var \Magento\Catalog\Model\Category $category */
             $category = $this->_categoryFactory->create()->load($this->getCategoryId());
             if ($category->getId()) {
                 $origCategory = $layer->getCurrentCategory();
                 $layer->setCurrentCategory($category);
             }
         }
         $this->_productCollection = $layer->getProductCollection();
         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
         if ($origCategory) {
             $layer->setCurrentCategory($origCategory);
         }
     }
     return $this->_productCollection;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:40,代码来源:ListProduct.php

示例10: getCategoryUrl

 /**
  * Retrieve category url
  *
  * @param ModelCategory $category
  * @return string
  */
 public function getCategoryUrl($category)
 {
     if ($category instanceof ModelCategory) {
         return $category->getUrl();
     }
     return $this->_categoryFactory->create()->setData($category->getData())->getUrl();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Category.php

示例11: getTreeRootCategory

 /**
  * @return \Magento\Catalog\Model\Category
  */
 protected function getTreeRootCategory()
 {
     if (!$this->treeRootCategory) {
         $this->treeRootCategory = $this->categoryFactory->create()->load(Category::TREE_ROOT_ID);
     }
     return $this->treeRootCategory;
 }
开发者ID:MauroNigrele,项目名称:magento2-module-setup_tools,代码行数:10,代码来源:StoreInstaller.php

示例12: loadCategory

 /**
  * Load current category using the request params.
  *
  * @return CategoryInterface
  */
 private function loadCategory()
 {
     $category = $this->categoryFactory->create();
     $storeId = $this->getRequest()->getParam('store');
     $categoryId = $this->getRequest()->getParam('entity_id');
     $category->setStoreId($storeId)->load($categoryId);
     return $category;
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:13,代码来源:Preview.php

示例13: getCategoryCollection

 /**
  * Get categories collection
  *
  * @return \Magento\Catalog\Model\ResourceModel\Category\Collection
  */
 public function getCategoryCollection()
 {
     $collection = $this->_getData('category_collection');
     if ($collection === null) {
         $collection = $this->_categoryFactory->create()->getCollection()->addAttributeToSelect(['name', 'is_active'])->setLoadProductCount(true);
         $this->setData('category_collection', $collection);
     }
     return $collection;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Tree.php

示例14: loadCategory

 /**
  * Load category
  *
  * @param int $id
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @return \Magento\Catalog\Model\Category
  */
 protected function loadCategory($id)
 {
     $model = $this->categoryFactory->create();
     $model->load($id);
     if (!$model->getId()) {
         throw NoSuchEntityException::singleField(CategoryDataObject::ID, $id);
     }
     return $model;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:16,代码来源:WriteService.php

示例15: getLastCategoryPur

 /**
  * Get last purchased category.
  *
  * @return string
  */
 public function getLastCategoryPur()
 {
     $categoryId = $this->customer->getLastCategoryId();
     //customer last category id
     if ($categoryId) {
         return $this->categoryFactory->create()->setStoreId($this->customer->getStoreId())->load($categoryId)->getName();
     }
     return '';
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:14,代码来源:Customer.php


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