Jump to content

Group products in their own panels based on {if} name in products.tpl.


-M-

Recommended Posts

Though I am starting to get the hang of things, I still cannot achieve 'new' stuff I haven't done before.

 

I am now trying to edit products.tpl (from the standard_cart orderform) so it will shows the products in groups. Reason for this is purely cosmetic and will make it look nicer for the customer.

 

Thanks to Brian, I know how to apply {if} rules a little. However in this situation I have a small problem.

 

Below is partial (tried my best to keep it short) example of my products.tpl (standard_cart):

 

           <div class="products" id="products">
               <div class="row row-eq-height">
                   {foreach $products as $product}
                       <div class="col-md-12">

                       {if $product.name eq {'Basic (1 jaar)'} || $product.name eq {'Basic (2 jaar)'} || $product.name eq {'Basic (3 jaar)'}}

                           <div class="product clearfix" id="product{$product@iteration}">
                               <header>
                                   <span id="product{$product@iteration}-name">{$product.name}</span>
                                   {if $product.qty}
                                       <span class="qty">
                                           {$product.qty} {$LANG.orderavailable}
                                       </span>
                                   {/if}
                               </header>
                               <div class="product-desc">
                                   {if $product.featuresdesc}
                                       <p id="product{$product@iteration}-description">
                                           {$product.featuresdesc}
                                       </p>
                                   {/if}
                                   <ul>
                                       {foreach $product.features as $feature => $value}
                                           <li id="product{$product@iteration}-feature{$value@iteration}">
                                               <span class="feature-value">{$value}</span>
                                               {$feature}
                                           </li>
                                       {/foreach}
                                   </ul>
                               </div>
                               <footer>
                                   <div class="product-pricing" id="product{$product@iteration}-price">
                                       {if $product.bid}
                                           {$LANG.bundledeal}<br />
                                           {if $product.displayprice}
                                               <span class="price">{$product.displayprice}</span>
                                           {/if}
                                       {else}
                                           {if $product.pricing.hasconfigoptions}
                                               {$LANG.startingfrom}
                                               <br />
                                           {/if}
                                           <span class="price">{$product.pricing.minprice.price}</span>
                                           <br />
                                           {if $product.pricing.minprice.cycle eq "monthly"}
                                               {$LANG.orderpaymenttermmonthly}
                                           {elseif $product.pricing.minprice.cycle eq "quarterly"}
                                               {$LANG.orderpaymenttermquarterly}
                                           {elseif $product.pricing.minprice.cycle eq "semiannually"}
                                               {$LANG.orderpaymenttermsemiannually}
                                           {elseif $product.pricing.minprice.cycle eq "annually"}
                                               {$LANG.orderpaymenttermannually}
                                           {elseif $product.pricing.minprice.cycle eq "biennially"}
                                               {$LANG.orderpaymenttermbiennially}
                                           {elseif $product.pricing.minprice.cycle eq "triennially"}
                                               {$LANG.orderpaymenttermtriennially}
                                           {/if}
                                       {/if}
                                   </div>
                                   <a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-success btn-sm" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {$LANG.ordernowbutton}
                                   </a>
                               </footer>
                           </div>



                       {/if}

                       </div>
                       {if $product@iteration % 2 == 0}
                           </div>
                           <div class="row row-eq-height">
                       {/if}
                   {/foreach}
               </div>
           </div>

 

If the above code is run all products will be displayed when the {if} statement is true.

However all products are displayed in their own "panels". This is what I don't want, otherwise I could have left it as it is.

 

I want only 3 panels (Basic, Advanced and Professional; see below) each with their corresponding products.

 

{if $product.name eq {'Basic (1 jaar)'} || $product.name eq {'Basic (2 jaar)'} || $product.name eq {'Basic (3 jaar)'}}

{if $product.name eq {'Advanced (1 jaar)'} || $product.name eq {'Advanced (2 jaar)'} || $product.name eq {'Advanced (3 jaar)'}}

{if $product.name eq {'Professional (1 jaar)'} || $product.name eq {'Professional (2 jaar)'} || $product.name eq {'Professional (3 jaar)'}}

 

 

So instead of:

 

<panel>

Basic (1 jaar)

</panel>

 

<panel>

Basic (2 jaar)

</panel>

 

<panel>

Basic (3 jaar)

</panel>

 

<panel>

Advanced (1 jaar)

</panel>

 

<panel>

Advanced (2 jaar)

</panel>

 

etc...

 

 

I want it to look like this:

 

<panel>

Basic (1 jaar)

Basic (2 jaar)

Basic (3 jaar)

</panel>

 

<panel>

Advanced (1 jaar)

Advanced (2 jaar)

Advanced (3 jaar)

</panel>

 

<panel>

etc...

</panel>

 

I tried placing the {if} codes above <div class="products" id="products">, but that didn't work. Probably because of {foreach $products as $product}. Then, I tried changing my {if} statements from {if $product.name eq .....} to {if $products.name eq .....}, but that didn't work either (no output / blank contents).

 

I think the issue lies with {foreach $products as $product}?

How should I interpret that any ways? Is it something like; treat all products as a product?

 

Any ideas on how to get the items grouped in their own "panel"...?

 

I think, not sure (or how for that matter) it should create the panel first and then run the {if} statement (as described above) close and then repeat it for the next {if} statements. But no idea on how to do that in the current coding.

 

Thank you.

Link to comment
Share on other sites

Though I am starting to get the hang of things, I still cannot achieve 'new' stuff I haven't done before.

 

I am now trying to edit products.tpl (from the standard_cart orderform) so it will shows the products in groups. Reason for this is purely cosmetic and will make it look nicer for the customer.

this is not *exactly* what you want to do, but is probably worth mentioning...

 

if you choose the Slider template as the default order-form template, or the first product group uses Slider, then the Product Groups will be shown as their own panels - i'm assuming here that you have Basic, Advanced and Professional product groups.

 

I want only 3 panels (Basic, Advanced and Professional; see below) each with their corresponding products.

 

I think the issue lies with {foreach $products as $product}?

How should I interpret that any ways? Is it something like; treat all products as a product?

 

Any ideas on how to get the items grouped in their own "panel"...?

 

I think, not sure (or how for that matter) it should create the panel first and then run the {if} statement (as described above) close and then repeat it for the next {if} statements. But no idea on how to do that in the current coding.

I think you need two foreach loops - the existing one for $products, and an outer one for headings.

 

$prodheadings is going to be a Smarty array that you define in the template...

 

{$prodheadings = ['Basic','Advanced','Professional']}

you then add another {foreach} loop...

 

{foreach $prodheadings as $prodheading}

you then add your code above and before the final </div> of that block, add a closing {/foreach}

 

then instead of your lengthy {if} statement...

 

{if $product.name eq {'Basic (1 jaar)'} || $product.name eq {'Basic (2 jaar)'} || $product.name eq {'Basic (3 jaar)'}} 

use this...

 

{if $product.name|strstr:$prodheading}

this way, you'll loop through the first array and display all basic products, then advanced, then professional.

 

that's the easy bit done - the part I can leave in your capable hands is to reorganise the <divs> to change the output to how you want it... :)

 

for example, if you wanted to do something very simple and just add Group Headings to the output, you could leave the code alone just add the $prodheading variable to the output...

 

    {$prodheadings = ['Basic','Advanced','Professional']}            

           {foreach $prodheadings as $prodheading}
                       <div class="products" id="products"><h3>{$prodheading}</h3><br />
               <div class="row row-eq-height">

                   {foreach $products as $product}
                       <div class="col-md-6">

                       {if $product.name|strstr:$prodheading}

                           <div class="product clearfix" id="product{$product@iteration}">
                               <header>
                                   <span id="product{$product@iteration}-name">{$product.name}</span>
                                   {if $product.qty}
                                       <span class="qty">
                                           {$product.qty} {$LANG.orderavailable}
                                       </span>
                                   {/if}
                               </header>
                               <div class="product-desc">
                                   {if $product.featuresdesc}
                                       <p id="product{$product@iteration}-description">
                                           {$product.featuresdesc}
                                       </p>
                                   {/if}
                                   <ul>
                                       {foreach $product.features as $feature => $value}
                                           <li id="product{$product@iteration}-feature{$value@iteration}">
                                               <span class="feature-value">{$value}</span>
                                               {$feature}
                                           </li>
                                       {/foreach}
                                   </ul>
                               </div>
                               <footer>
                                   <div class="product-pricing" id="product{$product@iteration}-price">
                                       {if $product.bid}
                                           {$LANG.bundledeal}<br />
                                           {if $product.displayprice}
                                               <span class="price">{$product.displayprice}</span>
                                           {/if}
                                       {else}
                                           {if $product.pricing.hasconfigoptions}
                                               {$LANG.startingfrom}
                                               <br />
                                           {/if}
                                           <span class="price">{$product.pricing.minprice.price}</span>
                                           <br />
                                           {if $product.pricing.minprice.cycle eq "monthly"}
                                               {$LANG.orderpaymenttermmonthly}
                                           {elseif $product.pricing.minprice.cycle eq "quarterly"}
                                               {$LANG.orderpaymenttermquarterly}
                                           {elseif $product.pricing.minprice.cycle eq "semiannually"}
                                               {$LANG.orderpaymenttermsemiannually}
                                           {elseif $product.pricing.minprice.cycle eq "annually"}
                                               {$LANG.orderpaymenttermannually}
                                           {elseif $product.pricing.minprice.cycle eq "biennially"}
                                               {$LANG.orderpaymenttermbiennially}
                                           {elseif $product.pricing.minprice.cycle eq "triennially"}
                                               {$LANG.orderpaymenttermtriennially}
                                           {/if}
                                       {/if}
                                   </div>
                                   <a href="cart.php?a=add&{if $product.bid}bid={$product.bid}{else}pid={$product.pid}{/if}" class="btn btn-success btn-sm" id="product{$product@iteration}-order-button">
                                       <i class="fa fa-shopping-cart"></i>
                                       {$LANG.ordernowbutton}
                                   </a>
                               </footer>
                           </div>
                       {/if}
                       </div>
                       {if $product@iteration % 2 == 0}
                           </div>
                           <div class="row row-eq-height">
                       {/if}
                   {/foreach}
               </div>{/foreach}
           </div>  

you may want to replace the <h3> with a css class, but you get the idea... :idea:

Link to comment
Share on other sites

Sorry Brian, but I am not using the Cloud Slider template for this product?

The main template I am using is standard_cart, depending on the productgroup it uses a different template.

 

However this is not the case for this one. For this product group I am using (a seperate / custom version) standard_cart. The changes I am making to this is in products.tpl.

 

And also, I don't have product groups for this. That's why I said I had:

 

Basic (1 jaar)

Basic (2 jaar)

Basic (3 jaar)

Advanced (1 jaar)

Advanced (2 jaar)

Advanced (3 jaar)

 

These are all individual products not product groups.

They are all seperate products in a product group called SSL.

 

Maybe I misunderstood you, but what you described, doesn't work for this, because SSL is the product group and the Basic (1 jaar), Basic (2 jaar), etc. etc. are the products within the SSL produt group.

 

Regards.

Edited by MvdL1979
Explained a bit more in detail.
Link to comment
Share on other sites

Hi,

 

Maybe I misunderstood you, but what you described, doesn't work for this, because SSL is the product group and the Basic (1 jaar), Basic (2 jaar), etc. etc. are the products within the SSL produt group.

it absolutely will work - as the above code is for standard cart/products.tpl and tested before posting! :idea:

 

the above code is virtually the code you posted with a few minor adjustments - it just creates three headings (Basic, Advanced & Pro) and then displays the products in the group (in your case SSL) under the appropriate heading.

 

it will do what you want - except it doesn't put the Basic products in one panel, they're still in three separate ones - but that's fixed by playing with the <divs> and changing the output... e.g perhaps moving the heading to the header of the panel and then looping the products.

 

it's a good starting point and just needs the output tweaking.

Link to comment
Share on other sites

I just tested the code example you have given me and it indeed works.

 

Sorry once again Brian. Really thought you misunderstood me.

Should try it first, before posting a reply. :twisted:

 

I only need to do the HTML-stuff, as you mentioned, but that isn't a problem. That's something (for a change) I do understand. :)

 

Thanks again Brian!

Link to comment
Share on other sites

Well HTML / CSS is starting to look good.

Was kinda hard to remove the correct parts and or replace them, so they were put into panels. But I managed that.

 

Thanks to your code it indeed places them into groups, but I have one tiny issue.

 

I have the following groups now:

 

{$prodheadings = ['Basic',Basic Wildcard','Pro']}

 

This results in:

 

Regular Basic

Basic (1 year)

Basic (2 year)

Basic (3 year)

Basic Wildcard (1 year) = shouldn't be here

Basic Wildcard (2 year) = shouldn't be here

Basic Wildcard (3 year) = shouldn't be here

 

Regular Basic Wildcard

Basic Wildcard (1 year)

Basic Wildcard (2 year)

Basic Wildcard (3 year)

 

Regular Pro

Pro (1 year)

Pro (2 year)

Pro (3 year)

 

Though groups 2 and 3 are 100% correct, it also adds the 'Wildcard' ones to the first group. Which shouldn't be in there.

 

Is there a simple way to filter them out from the first group?

 

I know the easiest way is to rename them actually, but that's not an option unfortunately. You got an idea to work around this?

 

Thanks!

 

PS: I have more products like this (with sorta similar names), the above is an example I currently ran into. :|

Edited by MvdL1979
Added PS.
Link to comment
Share on other sites

Is there a simple way to filter them out from the first group?

 

I know the easiest way is to rename them actually, but that's not an option unfortunately. You got an idea to work around this?

that was my first thought - rename them! :)

 

but if you say that's not an option, you could try the following...

 

{$prodheadings = ['Basic (',Basic Wildcard','Pro']}

if you're still using this array for panel headings, you might then need to use the following to avoid the '(' being in the heading...

 

<h3>{$prodheading|replace:'Basic (':'Basic'}</h3> 

Link to comment
Share on other sites

Thanks Brian!

 

One question; how do you filter more than 1 product with:

 

{$prodheading|replace:'Basic (':'Basic'}

 

For example the above one + 'Regular Pro ('

 

I tried using || and 'AND' but no luck. I also tried the following:

 

{$prodheading|replace:'Basic (':'Basic'}{$prodheading|replace:'Regular Pro (':'Regular Pro'}

 

But that also didn't work apparently.

 

Thank you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated