![]() |
Last Item Added in mini-cart
Hi,
Is there any way of showing only the last product added in the mini-cart, rather than all items added? Like a lot of x-cart users, I've got my minicart in the header, to the right of my logo. Obviously, there's not much vertical space, so I need a small box displaying the last added item, along with whatever the minicart normally displays; total, items etc. Any help with this would be much appreciated! n00bert |
Re: Last Item Added in mini-cart
in minicart.php add the code below before "?>"
Code:
if (!empty($cart["products"]) and is_array($cart["products"])) ...however when you add a similar product it will not get updated, it requires a bit more code |
Re: Last Item Added in mini-cart
Hi inebriate,
Thanks for your quick reply. I need to know one more thing though. ;) In minicart.tpl, there is a {foreach} which I'm guessing gets the results of an array. Is there any way of reversing those results ? I'd like to display all products added to the minicart in <td>s, but in reverse order, so that the last added item's details would appear in the top most <td>, i.e. first in the HTML source. Again, any help or ideas are much appreciated! n00bert |
Re: Last Item Added in mini-cart
To update, I googled the php function array_flip(), which apparently does what I need. However, I have no idea how to use this...
|
Re: Last Item Added in mini-cart
i take it that you are using the minicart mod in the completed mod section...what you want is array_reverse instead of array_flip
in minicart.php, replace Code:
$smarty->assign("minicart_contents", $cart["products"]); Code:
$smarty->assign("minicart_contents", array_reverse($cart["products"])); |
Re: Last Item Added in mini-cart
Perfect! Thank you so much inebriate. Works like a charm!
|
Re: Last Item Added in mini-cart
OH NO!!
It worked for about 5 minutes, now I get the following smarty error: Warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/username/public_html/minicart.php on line 65 any ideas how to get round this? |
Re: Last Item Added in mini-cart
I was checking out the smarty manual for array_reverse. I applied the sample code to the {foreach} in minicart.tpl.
I changed this line: Code:
{foreach from=$minicart_contents item=item} to this: Code:
{foreach from=$minicart_contents|@array_reverse:true item=item} Seems to be working fine. Is there any disadvantage to using smarty rather than PHP? Is it more server-intensive? thanks, n00bert |
All times are GMT -8. The time now is 07:24 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.