Skip to content

Commit

Permalink
Merge pull request PrestaShop#31752 from lea-BMS/productcore-getdefau…
Browse files Browse the repository at this point in the history
…ltcategory-patch

Fix ProductCore::getDefaultCategory to return an int consistently
  • Loading branch information
lartist authored Mar 30, 2023
2 parents 643b82c + 45d1d1e commit 080b986
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7865,24 +7865,20 @@ public function setAdvancedStockManagement($value)
}

/**
* Get the default category according to the shop.
* Get the default category id according to the shop.
*
* @return array{id_category_default: int}|int
* @return int
*/
public function getDefaultCategory()
public function getDefaultCategory(): int
{
$default_category = Db::getInstance()->getValue(
$defaultCategory = Db::getInstance()->getValue(
'SELECT product_shop.`id_category_default`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`id_product` = ' . (int) $this->id
);

if (!$default_category) {
return ['id_category_default' => Context::getContext()->shop->id_category];
} else {
return (int) $default_category;
}
return (int) ($defaultCategory ?? Context::getContext()->shop->id_category);
}

/**
Expand Down

0 comments on commit 080b986

Please sign in to comment.