Jump to content

[SOLVED] How do I get the category of lastProductAdded?


Recommended Posts

Hello, I'm not very experienced with Prestashop/Smarty.

How do I get the category of lastProductAdded?

I am trying to make the "continue shopping" button redirect to the category of the last product added.

 

<a href="{$link->getCategoryLink($lastProductAdded.category->id)|escape:'htmlall':'UTF-8'}" class="button_large" title="{l s='Continue shopping'}">« {l s='Continue shopping'}</a>

 

The following code doesn't seem to work, giving category id of 0 for some reason.

Any help would be much appreciated. Thank you!

Edited by daquity36 (see edit history)
Link to comment
Share on other sites

SOLVED IT with the help of someone on stackoverflow.

 

The following is correct:

<a href="{$link->getCategoryLink($lastProductAdded.id_category_default)|escape:'htm‌​lall':'UTF-8'}" class="button_large" title="{l s='Continue shopping'}">« {l s='Continue shopping'}</a>

 

For Prestashop 1.4, however, you have to go to classes/cart.php and modify the function getLastProduct as following:

public function getLastProduct()
{
$sql = '
	SELECT cp.`id_product`, cp.`id_product_attribute`, p.`id_category_default`
	FROM `'._DB_PREFIX_.'cart_product` cp
	JOIN `'._DB_PREFIX_.'product` p ON (cp.`id_product` = p.`id_product`)
	WHERE `id_cart` = '.(int)($this->id).'
	ORDER BY cp.`date_add` DESC';
$result = Db::getInstance()->getRow($sql);
if ($result AND isset($result['id_product']) AND $result['id_product'])
	return $result;
return false;
}

Link to comment
Share on other sites

  • 2 years later...
×
×
  • Create New...