Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. From
  2. // Check if the product belongs to category flash deal
  3. $allCategoryIds = $product->getCategoryIds();
  4. /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */
  5. $categoryCollection = $this->_categoryCollection->create();
  6. $categoryCollection->addFieldToFilter('entity_id', ['in' => $allCategoryIds]);
  7. /** @var \Magento\Catalog\Model\Category[] $categories */
  8. $categories = $categoryCollection->getItems();
  9. foreach ($categories as $category) {
  10. $categoryIds = $category->getParentIds();
  11. $allCategoryIds = array_merge($allCategoryIds, $categoryIds);
  12. }
  13. $allCategoryIds = array_unique($allCategoryIds);
  14. if (in_array($value, $allCategoryIds)) {
  15. $canShow = true;
  16. }
  17.  
  18. To
  19. // Check if the product belongs to category flash deal
  20. $categories = $product->getCategoryCollection();
  21. $allCategoryIds = [];
  22. foreach ($categories as $category) {
  23. $allCategoryIds = array_merge($allCategoryIds, explode('/', $category->getPath()));
  24. }
  25. if (in_array($value, $allCategoryIds)) {
  26. $canShow = true;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement