Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing invalid null-return in Google Analytics #3438

Merged
merged 11 commits into from
Aug 21, 2023
24 changes: 15 additions & 9 deletions app/code/core/Mage/GoogleAnalytics/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,23 @@ public function isUserIdEnabled($store = null)
* Returns last category name
*
* @param Mage_Catalog_Model_Product $product
* @return string
* @return ?string
*/
public function getLastCategoryName($product): string
public function getLastCategoryName($product): ?string
alexh-swdev marked this conversation as resolved.
Show resolved Hide resolved
{
$_categoryIds = $product->getCategoryIds();
if ($_categoryIds) {
$_lastCat = array_pop($_categoryIds);
$_cat = Mage::getModel('catalog/category')->load($_lastCat);
return $_cat->getName();
}
return '';
// force root category to current store
$rootCategory = Mage::getModel('catalog/category')
->load(Mage::app()->getStore()->getRootCategoryId());

$_lastCat = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('name')
->addIdFilter($product->getCategoryIds())
->addIsActiveFilter()
->addFieldToFilter('path', array('like' => $rootCategory->getPath() . '/%'))
->addOrder('level')
->getFirstItem();

return $_lastCat->getName() ?: false;
alexh-swdev marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down