category load by collection or by id


\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $CollectionFactory,
\Magento\Catalog\Model\Category $Category,

$storeadminid = $this->storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId();
$collection = $this->collectionFactory->create();
$collection->addAttributeToSelect('*')
->setStoreId($storeadminid)
->addAttributeToFilter('url_key', self::URL_KEY_THE_LAB)
->load();

if ($collection->getSize()) {
$categoryIdLab = $collection->getFirstItem()->getId();
$categories = $product->getCategoryIds();
foreach ($categories as $category) {
$cat = $this->category->load($category);
...

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *