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


PHP Product::getCategoryIds方法代码示例

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


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

示例1: afterLoad

 /**
  * Set category ids to product data
  *
  * @param \Magento\Catalog\Model\Product $object
  * @return $this
  */
 public function afterLoad($object)
 {
     $object->setData($this->getAttribute()->getAttributeCode(), $object->getCategoryIds());
     return parent::afterLoad($object);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Category.php

示例2: testGetCategoryIds

 public function testGetCategoryIds()
 {
     // none
     /** @var $model \Magento\Catalog\Model\Product */
     $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->assertEquals([], $model->getCategoryIds());
     // fixture
     $this->_model->setId(1);
     $this->assertEquals([2, 3, 4], $this->_model->getCategoryIds());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:ProductExternalTest.php

示例3: copy

 /**
  * Create product duplicate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function copy(\Magento\Catalog\Model\Product $product)
 {
     $product->getWebsiteIds();
     $product->getCategoryIds();
     /** @var \Magento\Catalog\Model\Product $duplicate */
     $duplicate = $this->productFactory->create();
     $duplicate->setData($product->getData());
     $duplicate->setOptions([]);
     $duplicate->setIsDuplicate(true);
     $duplicate->setOriginalId($product->getEntityId());
     $duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
     $duplicate->setCreatedAt(null);
     $duplicate->setUpdatedAt(null);
     $duplicate->setId(null);
     $duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->copyConstructor->build($product, $duplicate);
     $isDuplicateSaved = false;
     do {
         $urlKey = $duplicate->getUrlKey();
         $urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
         $duplicate->setUrlKey($urlKey);
         try {
             $duplicate->save();
             $isDuplicateSaved = true;
         } catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
         }
     } while (!$isDuplicateSaved);
     $this->getOptionRepository()->duplicate($product, $duplicate);
     $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
     $product->getResource()->duplicate($product->getData($metadata->getLinkField()), $duplicate->getData($metadata->getLinkField()));
     return $duplicate;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:38,代码来源:Copier.php

示例4: copy

 /**
  * Create product duplicate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function copy(\Magento\Catalog\Model\Product $product)
 {
     $product->getWebsiteIds();
     $product->getCategoryIds();
     $duplicate = $this->productFactory->create();
     $duplicate->setData($product->getData());
     $duplicate->setIsDuplicate(true);
     $duplicate->setOriginalId($product->getId());
     $duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
     $duplicate->setCreatedAt(null);
     $duplicate->setUpdatedAt(null);
     $duplicate->setId(null);
     $duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->copyConstructor->build($product, $duplicate);
     $isDuplicateSaved = false;
     do {
         $urlKey = $duplicate->getUrlKey();
         $urlKey = preg_match('/(.*)-(\\d+)$/', $urlKey, $matches) ? $matches[1] . '-' . ($matches[2] + 1) : $urlKey . '-1';
         $duplicate->setUrlKey($urlKey);
         try {
             $duplicate->save();
             $isDuplicateSaved = true;
         } catch (DuplicateEntryException $e) {
         }
     } while (!$isDuplicateSaved);
     $product->getOptionInstance()->duplicate($product->getId(), $duplicate->getId());
     $product->getResource()->duplicate($product->getId(), $duplicate->getId());
     return $duplicate;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:35,代码来源:Copier.php

示例5: testGetCategoryIds

 public function testGetCategoryIds()
 {
     // none
     /** @var $model \Magento\Catalog\Model\Product */
     $model = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $this->assertEquals([], $model->getCategoryIds());
     // fixture
     $this->_model->setId($this->productRepository->get('simple')->getId());
     $this->assertEquals([2, 3, 4, 13], $this->_model->getCategoryIds());
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:ProductExternalTest.php

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

示例7: processCategoriesActions

 private function processCategoriesActions(\Magento\Catalog\Model\Product $product)
 {
     $productCategories = $product->getCategoryIds();
     $categoriesByWebsite = array(0 => $productCategories);
     foreach ($product->getWebsiteIds() as $websiteId) {
         $categoriesByWebsite[$websiteId] = $productCategories;
     }
     /** @var \Ess\M2ePro\Model\Listing\Auto\Actions\Mode\Category $autoActionsCategory */
     $autoActionsCategory = $this->modelFactory->getObject('Listing\\Auto\\Actions\\Mode\\Category');
     $autoActionsCategory->setProduct($product);
     foreach ($categoriesByWebsite as $websiteId => $categoryIds) {
         foreach ($categoryIds as $categoryId) {
             $autoActionsCategory->synchWithAddedCategoryId($categoryId, $websiteId);
         }
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:AddedProducts.php

示例8: copy

 /**
  * Create product duplicate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  */
 public function copy(\Magento\Catalog\Model\Product $product)
 {
     $product->getWebsiteIds();
     $product->getCategoryIds();
     $duplicate = $this->productFactory->create();
     $duplicate->setData($product->getData());
     $duplicate->setIsDuplicate(true);
     $duplicate->setOriginalId($product->getId());
     $duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
     $duplicate->setCreatedAt(null);
     $duplicate->setUpdatedAt(null);
     $duplicate->setId(null);
     $duplicate->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->copyConstructor->build($product, $duplicate);
     $duplicate->save();
     $product->getOptionInstance()->duplicate($product->getId(), $duplicate->getId());
     $product->getResource()->duplicate($product->getId(), $duplicate->getId());
     return $duplicate;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:25,代码来源:Copier.php

示例9: testGetCategoryIds

 public function testGetCategoryIds()
 {
     $this->model->lockAttribute('category_ids');
     $this->assertEquals([], $this->model->getCategoryIds());
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:5,代码来源:ProductTest.php

示例10: getCategoryIds

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return array
  */
 public function getCategoryIds(\Magento\Catalog\Model\Product $product)
 {
     if (!$this->_config->getItem(Config::SIMILARITY_USE_CATEGORY_FILTER)) {
         return [];
     }
     return $product->getCategoryIds();
 }
开发者ID:richdynamix,项目名称:personalised-products,代码行数:11,代码来源:Upsell.php

示例11: getCategoryIds

 /**
  * {@inheritdoc}
  */
 public function getCategoryIds()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCategoryIds');
     if (!$pluginInfo) {
         return parent::getCategoryIds();
     } else {
         return $this->___callPlugins('getCategoryIds', func_get_args(), $pluginInfo);
     }
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:12,代码来源:Interceptor.php

示例12: getObject

 public function getObject(Product $product)
 {
     $type = $product->getTypeId();
     $this->logger->start('CREATE RECORD ' . $product->getId() . ' ' . $this->logger->getStoreName($product->getStoreId()));
     $defaultData = [];
     $transport = new DataObject($defaultData);
     $this->eventManager->dispatch('algolia_product_index_before', ['product' => $product, 'custom_data' => $transport]);
     $defaultData = $transport->getData();
     $visibility = (int) $product->getVisibility();
     $visibleInCatalog = $this->visibility->getVisibleInCatalogIds();
     $visibleInSearch = $this->visibility->getVisibleInSearchIds();
     $customData = ['objectID' => $product->getId(), 'name' => $product->getName(), 'url' => $product->getProductUrl(false), 'visibility_search' => (int) in_array($visibility, $visibleInSearch), 'visibility_catalog' => (int) in_array($visibility, $visibleInCatalog)];
     $additionalAttributes = $this->getAdditionalAttributes($product->getStoreId());
     $groups = null;
     if ($this->isAttributeEnabled($additionalAttributes, 'description')) {
         $customData['description'] = $product->getDescription();
     }
     $categories = [];
     $categories_with_path = [];
     $_categoryIds = $product->getCategoryIds();
     if (is_array($_categoryIds) && count($_categoryIds) > 0) {
         $categoryCollection = $this->getAllCategories($_categoryIds);
         $rootCat = $this->storeManager->getStore($product->getStoreId())->getRootCategoryId();
         foreach ($categoryCollection as $category) {
             // Check and skip all categories that is not
             // in the path of the current store.
             $path = $category->getPath();
             $path_parts = explode('/', $path);
             if (isset($path_parts[1]) && $path_parts[1] != $rootCat) {
                 continue;
             }
             $categoryName = $category->getName();
             if ($categoryName) {
                 $categories[] = $categoryName;
             }
             $category->getUrlInstance()->setStore($product->getStoreId());
             $path = [];
             foreach ($category->getPathIds() as $treeCategoryId) {
                 $name = $this->getCategoryName($treeCategoryId, $product->getStoreId());
                 if ($name) {
                     $path[] = $name;
                 }
             }
             $categories_with_path[] = $path;
         }
     }
     foreach ($categories_with_path as $result) {
         for ($i = count($result) - 1; $i > 0; $i--) {
             $categories_with_path[] = array_slice($result, 0, $i);
         }
     }
     $categories_with_path = array_intersect_key($categories_with_path, array_unique(array_map('serialize', $categories_with_path)));
     $categories_hierarchical = [];
     $level_name = 'level';
     foreach ($categories_with_path as $category) {
         for ($i = 0; $i < count($category); $i++) {
             if (isset($categories_hierarchical[$level_name . $i]) === false) {
                 $categories_hierarchical[$level_name . $i] = [];
             }
             $categories_hierarchical[$level_name . $i][] = implode(' /// ', array_slice($category, 0, $i + 1));
         }
     }
     foreach ($categories_hierarchical as &$level) {
         $level = array_values(array_unique($level));
     }
     foreach ($categories_with_path as &$category) {
         $category = implode(' /// ', $category);
     }
     $customData['categories'] = $categories_hierarchical;
     $customData['categories_without_path'] = $categories;
     /** @var Image $imageHelper */
     $imageHelper = $this->objectManager->create('Algolia\\AlgoliaSearch\\Helper\\Image');
     if (false === isset($defaultData['thumbnail_url'])) {
         $thumb = $imageHelper->init($product, 'thumbnail')->resize(75, 75);
         $customData['thumbnail_url'] = $thumb->getUrl();
     }
     if (false === isset($defaultData['image_url'])) {
         $image = $imageHelper->init($product, $this->config->getImageType())->resize($this->config->getImageWidth(), $this->config->getImageHeight());
         $customData['image_url'] = $image->getUrl();
         if ($this->isAttributeEnabled($additionalAttributes, 'media_gallery')) {
             $product->load('media_gallery');
             $customData['media_gallery'] = [];
             $images = $product->getMediaGalleryImages();
             if ($images) {
                 foreach ($images as $image) {
                     $customData['media_gallery'][] = str_replace(['https://', 'http://'], '//', $image->getUrl());
                 }
             }
         }
     }
     $sub_products = [];
     $ids = null;
     if ($type == 'configurable' || $type == 'grouped' || $type == 'bundle') {
         if ($type == 'bundle') {
             $ids = [];
             $selection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);
             foreach ($selection as $option) {
                 $ids[] = $option->getProductId();
             }
         }
//.........这里部分代码省略.........
开发者ID:algolia,项目名称:algoliasearch-magento-2,代码行数:101,代码来源:ProductHelper.php


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