X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Last Item Added in mini-cart (https://forum.x-cart.com/showthread.php?t=29810)

n00bert 03-19-2007 05:37 PM

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

inebriate 03-19-2007 11:58 PM

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"]))
{
        $smarty->assign("last_item_added", end($cart["products"]));
}

and in minicart.tpl use $last_item_added and its associated values, ie: $last_item_added.productid


...however when you add a similar product it will not get updated, it requires a bit more code

n00bert 03-20-2007 06:07 AM

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

n00bert 03-20-2007 06:10 AM

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...

inebriate 03-20-2007 12:49 PM

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"]);
with
Code:

$smarty->assign("minicart_contents", array_reverse($cart["products"]));

n00bert 03-20-2007 01:31 PM

Re: Last Item Added in mini-cart
 
Perfect! Thank you so much inebriate. Works like a charm!

n00bert 03-20-2007 01:50 PM

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?

n00bert 03-20-2007 02:28 PM

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.