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


PHP Product::getCategoryCollection方法代码示例

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


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

示例1: generate

 /**
  * Generate product url rewrites
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 public function generate(Product $product)
 {
     $this->product = $product;
     $storeId = $this->product->getStoreId();
     $productCategories = $product->getCategoryCollection()->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
     $urls = $this->isGlobalScope($storeId) ? $this->generateForGlobalScope($productCategories) : $this->generateForSpecificStoreView($storeId, $productCategories);
     $this->product = null;
     return $urls;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:ProductUrlRewriteGenerator.php

示例2: getCategories

 /**
  * Get categories assigned to product
  *
  * @return \Magento\Catalog\Model\Resource\Category\Collection
  */
 protected function getCategories()
 {
     if (!$this->categories) {
         $this->categories = $this->product->getCategoryCollection();
         $this->categories->addAttributeToSelect('url_key');
         $this->categories->addAttributeToSelect('url_path');
     }
     return $this->categories;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:ProductUrlGenerator.php

示例3: testGetCategoryCollection

 public function testGetCategoryCollection()
 {
     // empty
     $collection = $this->_model->getCategoryCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', $collection);
     // fixture
     $this->_model->setId($this->productRepository->get('simple')->getId());
     $fixtureCollection = $this->_model->getCategoryCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', $fixtureCollection);
     $this->assertNotSame($fixtureCollection, $collection);
     $ids = [];
     foreach ($fixtureCollection as $category) {
         $ids[] = $category->getId();
     }
     $this->assertEquals([2, 3, 4, 13], $ids);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:16,代码来源:ProductExternalTest.php

示例4: testGetCategoryCollection

 public function testGetCategoryCollection()
 {
     // empty
     $collection = $this->_model->getCategoryCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Resource\\Category\\Collection', $collection);
     // fixture
     $this->_model->setId(1);
     $fixtureCollection = $this->_model->getCategoryCollection();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Resource\\Category\\Collection', $fixtureCollection);
     $this->assertNotSame($fixtureCollection, $collection);
     $ids = array();
     foreach ($fixtureCollection as $category) {
         $ids[] = $category->getId();
     }
     $this->assertEquals(array(2, 3, 4), $ids);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:16,代码来源:ProductExternalTest.php

示例5: testSetCategoryCollection

 public function testSetCategoryCollection()
 {
     $collection = $this->getMockBuilder('\\Magento\\Framework\\Data\\Collection')->disableOriginalConstructor()->getMock();
     $this->resource->expects($this->once())->method('getCategoryCollection')->will($this->returnValue($collection));
     $this->assertSame($this->model->getCategoryCollection(), $this->model->getCategoryCollection());
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:6,代码来源:ProductTest.php

示例6: generate

 /**
  * Generate product url rewrites
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[]
  */
 public function generate(Product $product)
 {
     if ($product->getVisibility() == Visibility::VISIBILITY_NOT_VISIBLE) {
         return [];
     }
     $this->product = $product;
     $storeId = $this->product->getStoreId();
     $productCategories = $product->getCategoryCollection()->addAttributeToSelect('url_key')->addAttributeToSelect('url_path');
     $urls = $this->isGlobalScope($storeId) ? $this->generateForGlobalScope($productCategories) : $this->generateForSpecificStoreView($storeId, $productCategories);
     $this->product = null;
     return $urls;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:18,代码来源:ProductUrlRewriteGenerator.php

示例7: getCategoryCollection

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

示例8: buildCategories

 /**
  * @param Product $product
  * @return array
  */
 protected function buildCategories(Product $product)
 {
     $categories = [];
     foreach ($product->getCategoryCollection() as $category) {
         $categories[] = $this->_categoryBuilder->build($category);
     }
     return $categories;
 }
开发者ID:Nosto,项目名称:nosto-magento2,代码行数:12,代码来源:Builder.php


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