Вопрос

I want to get category ids of specific store.

$product->getCategoryIds()

This will get all categories of product

Array ( [0] => 63 [1] => 178 )

63 is category of store 1 and 178 is category of store 2 but I want only category 63.

Это было полезно?

Решение

use \Magento\Store\Model\StoreManagerInterface for current store and apply it in your query

Try this

protected $storeManager;

public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    $data = []
) {
    $this->storeManager = $storeManager;
    parent::__construct($data);
}

$categoryFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categories = $categoryFactory->create()                              
    ->addAttributeToSelect('*')
    ->setStore($this->storeManager->getStore());

foreach ($categories as $category){
    $category->getId();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top