Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Last Item Added in mini-cart

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-19-2007, 05:37 PM
  n00bert's Avatar 
n00bert n00bert is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 46
 

Default 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
__________________
Version 4.1.6 Gold

urban-kings.com
urbanwear and street fashion specialist
Reply With Quote
  #2  
Old 03-19-2007, 11:58 PM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default 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
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote
  #3  
Old 03-20-2007, 06:07 AM
  n00bert's Avatar 
n00bert n00bert is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 46
 

Default 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
__________________
Version 4.1.6 Gold

urban-kings.com
urbanwear and street fashion specialist
Reply With Quote
  #4  
Old 03-20-2007, 06:10 AM
  n00bert's Avatar 
n00bert n00bert is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 46
 

Default 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...
__________________
Version 4.1.6 Gold

urban-kings.com
urbanwear and street fashion specialist
Reply With Quote
  #5  
Old 03-20-2007, 12:49 PM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default 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"]));
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote
  #6  
Old 03-20-2007, 01:31 PM
  n00bert's Avatar 
n00bert n00bert is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 46
 

Default Re: Last Item Added in mini-cart

Perfect! Thank you so much inebriate. Works like a charm!
__________________
Version 4.1.6 Gold

urban-kings.com
urbanwear and street fashion specialist
Reply With Quote
  #7  
Old 03-20-2007, 01:50 PM
  n00bert's Avatar 
n00bert n00bert is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 46
 

Default 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?
__________________
Version 4.1.6 Gold

urban-kings.com
urbanwear and street fashion specialist
Reply With Quote
  #8  
Old 03-20-2007, 02:28 PM
  n00bert's Avatar 
n00bert n00bert is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 46
 

Default 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
__________________
Version 4.1.6 Gold

urban-kings.com
urbanwear and street fashion specialist
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:33 AM.

   

 
X-Cart forums © 2001-2020