Skip to content

Commit

Permalink
MC-33086: [Improvement] Apply Event To Category observer
Browse files Browse the repository at this point in the history
  • Loading branch information
mslabko committed Apr 9, 2020
1 parent 15dc874 commit baebe46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/code/Magento/Catalog/Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ public function getLayer()
*/
public function getLoadedProductCollection()
{
return $this->_getProductCollection();
$collection = $this->_getProductCollection();

$categoryId = $this->getLayer()->getCurrentCategory()->getId();
foreach ($collection as $product) {
$product->setData('category_id', $categoryId);
}

return $collection;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,14 @@ public function getIdBySku($sku)
*/
public function getCategoryId()
{
if ($this->hasData('category_id')) {
return $this->getData('category_id');
}
$category = $this->_registry->registry('current_category');
if ($category && in_array($category->getId(), $this->getCategoryIds())) {
return $category->getId();
$categoryId = $category ? $category->getId() : null;
if ($categoryId && in_array($categoryId, $this->getCategoryIds())) {
$this->setData('category_id', $categoryId);
return $categoryId;
}
return false;
}
Expand Down

0 comments on commit baebe46

Please sign in to comment.