當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。