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

Function for sorting array

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-12-2007, 10:26 AM
 
toomnyhats toomnyhats is offline
 

Advanced Member
  
Join Date: Sep 2006
Posts: 41
 

Default Function for sorting array

Hello,

I am trying to implement a table to show product variants so a customer doesn't have to click the dropdown to see the price. I have the table functioning, however, I would like it to be sorted by price (lowest first). This is how it is appearing now:

http://mermaids-natural-skin-care.com/images/Sizes.gif

Does anybody know how I can put a sort (lowest price 1st) into the following code:

{***BEGIN Mod to add Variant Table***}
{if $variants ne ""}
<tr id="product_weight_box">
<td width="30%">&nbsp;</td>
<td nowrap="nowrap">&nbsp;</td>
</tr>
<table width="100%" cellpadding="0" cellspacing="0"><tr><td colspan="4"><b><font class="ProductDetailsTitle">{$lng.lbl_AvailableSiz es}</font></b></td></tr>
<tr><td class="Line" height="1" colspan="4"><img src="{$ImagesDir}/spacer.gif" class="Spc" alt="" /><br></td></tr>
<tr><td colspan="4">&nbsp;</td></tr>
<tr>
{foreach name=variants from=$variants item=tempVar}
<td colspan="4">
{foreach from=$tempVar.options item=tempOpt}
<tr>
<td width="45%">
{$tempOpt.option_name}
</td>
<td align="left" width="5%">
{include file="currency.tpl"}
</td>
<td align="right" width="10%">
{$tempVar.price}
</td>
<td align="right" >
&nbsp;</td>
</tr>
{/foreach}
</td>
{if $smarty.foreach.variants.iteration is div by 3}
</tr>
<tr>
{elseif not $smarty.foreach.variants.last}
<td width="30%"></td>
{/if}
{/foreach}
</tr>
</table>
{/if}
{***END Mod to Add Variant Table***}


Thanks so much!
__________________
toomnyhats
X-Cart Gold 4.1.9 (Unix)
X-SpecialOffers
DSEFU (disabled)
Reply With Quote
  #2  
Old 09-12-2007, 11:53 AM
 
inebriate inebriate is offline
 

eXpert
  
Join Date: May 2006
Posts: 301
 

Default Re: Function for sorting array

have a look at http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1079

or you can sort it in php using something like 'usort' and pass that array to smarty
__________________
x-cart pro 4.0.18
linux
www.fabric8d.com (currently undergoing construction)
Reply With Quote
  #3  
Old 09-12-2007, 12:16 PM
 
toomnyhats toomnyhats is offline
 

Advanced Member
  
Join Date: Sep 2006
Posts: 41
 

Default Re: Function for sorting array

Thanks! I actually saw the thread on the other forum but didn't read far enough. I'm going to give it a try (I'm really new to php) so I may be back with more questions!
__________________
toomnyhats
X-Cart Gold 4.1.9 (Unix)
X-SpecialOffers
DSEFU (disabled)
Reply With Quote
  #4  
Old 09-13-2007, 12:34 PM
 
toomnyhats toomnyhats is offline
 

Advanced Member
  
Join Date: Sep 2006
Posts: 41
 

Default Re: Function for sorting array

I'm having a bit of trouble with this. Can anybody tell me which php file I would put the sort function in? Also, what would be the smarty syntax to call the function in which an array is being passed to the function, sorted, and returned? Thanks so much!
__________________
toomnyhats
X-Cart Gold 4.1.9 (Unix)
X-SpecialOffers
DSEFU (disabled)
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 09:03 AM.

   

 
X-Cart forums © 2001-2020