Skip to content

Commit

Permalink
Removed load of root category, fixed phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Aug 18, 2023
1 parent 5f174bf commit ad9d881
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/code/core/Mage/GoogleAnalytics/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,19 @@ public function isUserIdEnabled($store = null)
* Returns last category name
*
* @param Mage_Catalog_Model_Product $product
* @return ?string
* @return string
*/
public function getLastCategoryName($product): string
{
// force root category to current store
$rootCategory = Mage::getModel('catalog/category')
->load(Mage::app()->getStore()->getRootCategoryId());

$_lastCat = Mage::getResourceModel('catalog/category_collection')
$storeRootCategory = Mage::app()->getStore()->getRootCategoryId();
$lastCategory = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('name')
->addIdFilter($product->getCategoryIds())
->addIsActiveFilter()
->addFieldToFilter('path', array('like' => $rootCategory->getPath() . '/%'))
->addFieldToFilter('path', ['like' => "{$storeRootCategory}/%"])
->addOrder('level')
->getFirstItem();

return $_lastCat->getName() ?: false;
return $lastCategory->getName() ?: '';
}

/**
Expand Down

0 comments on commit ad9d881

Please sign in to comment.