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)
-   -   "look ahead" in a section loop (https://forum.x-cart.com/showthread.php?t=10028)

jds580s 10-26-2004 11:07 AM

"look ahead" in a section loop
 
Not sure if this is possible with smarty but thought I would ask

I am displaying products in 3 columns sorted by manufacture.
I would like to place the product manufacture name at the beginning of each "section" of manufactures ASCII excample below

manufacture1---------
prod1 prod2 prod3
prod4 prod5
manufacture2---------
prod6 prod7 prod8
prod9
manufacture3---------
prod10

With lots of help from pmstudios the manufacture info for each product is displaying and the products are sorted in the correct order

My thought was to do something like
if product manufactureID is not equal to product_next manufactureID
output manufacture name

My question is in
{section name=product loop=$products}
can I "look ahead" to the next product in the loop to compare to the current product's manufacturer id?

Thanks!

B00MER 10-26-2004 01:04 PM

Your best bet would be to build an associative array to loop over as it would make it alot easier to maintain and edit. You'll need to group your data into a per manufacturer basis and order by manufacturer.

Basic example of an associative array:

Code:

[root array]
 |
 [mfrid1 array]
  |->[product1 array]
  |->[product2 array]
 [mfrid2 array]
  |->[product1 array]
  |->[product2 array]
  |->[product3 array]


pmstudios 10-26-2004 03:13 PM

Hey jds580s,

To do what you're describing now changes the previous stuff (actually a bit simpler).

Just replace the previous code in products.php with
Code:

#
# Create manufacturers array
#
$query = func_query("SELECT manufacturerid, manufacturer FROM $sql_tbl[manufacturers]");
$smarty->assign("manufacturers", $manufacturers);


Then in your template you'll do something like this
Code:

{section name=id loop=$manufacturers}


{$manufacturers[id].manufacturer}

{section name=product loop=$products}
{if $products[product].manufacturerid eq $manufacturers[id].manufacturerid}
{$products[product].product}
{/if}
{/section}
{/section}


Hope this helps....

jds580s 10-26-2004 03:20 PM

Thanks Boomer and pmstudios.

pmstudios, I actually use what you helped me with earlier in another section of the cart. I was able to solve this issue in the template (well almost, I've still got a few things to work out) but it's 90% of the way there.

Code:

{*** ########## Manufacture Heading for products ########## ***}
{assign var="manid" value=$products[product].manufacturerid}
{if $manufacturers[$manid].manufacturerid ne $last_manufacturerid}
{if $manufacturers[$manid].manufacturerid ne "0"}
{if $first_product eq"false"}
</td></tr><tr><td colspan="3">
<hr>
{else}
<td colspan="3">
{/if}
{$manufacturers[$manid].manufacturer}

{if $manufacturers[$manid].descr ne ""}
<span class="maintext">{$manufacturers[$manid].descr}
</span>
{if $manufacturers[$manid].image ne ""}
Manufacture Logo<hr>
{/if}{/if}</td></tr><tr valign="top">{/if}{/if}
{assign var="last_manufacturerid" value=$products[product].manufacturerid}
{assign var="first_product" value="false"}
{*** ########## End Manufacture Heading for products ########## ***}


My original approach of looking ahead seemed way to hard, but I thought, why look ahead when I can look back?!
I just set a variable towards the end of the loop that remembers what the manufacture was of the last product and if it is the same, it just skips the code.


All times are GMT -8. The time now is 02:50 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.