本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
}
示例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;
}