ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Help with Switchee

September 18, 2012 10:36pm

Subscribe [3]
  • #1 / Sep 18, 2012 10:36pm

    xenowebdev

    34 posts

    Hey guys,

    I’m currently updating an EE1.7x ecommerce site using CartThrob to EEV2.x.
    I needed a way of showing discounted pricing on the front end. The client didn’t want to go through 3000+ products and change the sale price on each, so I am allocating a ‘status’ of Discount5, Discount10 etc to each product and then using a math plugin to display the discounted price.

    I’m trying to use the ‘status’ parameter in a switchee statement as follows to reduce overhead - before I was just using ‘if statements’:

    {exp:channel:entries channel="products" url_title="{last_segment}" dynamic="no" disable="category_fields|pagination|member_data" status="open|Discount5|Discount10|Discount15|Discount20|Discount25"}
    
    {exp:switchee variable='status' parse='inward'}
    
     {case value='Discount5'}
         <div class='OldPrice'>NZ${exp:number_format number='{product_price}' decimals='2'}</div>
         <div class='ProductPrice'>NZ${exp:math:percentMe num1='{product_price}' num2='5'}</div>
     {/case}
     {case value='Discount10'}
         <div class='OldPrice'>NZ${exp:number_format number='{product_price}' decimals='2'}</div>
         <div class='ProductPrice'>NZ${exp:math:percentMe num1='{product_price}' num2='10'}</div>
     {/case}
     {case value='Discount15'}
         <div class='OldPrice'>NZ${exp:number_format number='{product_price}' decimals='2'}</div>
         <div class='ProductPrice'>NZ${exp:math:percentMe num1='{product_price}' num2='15'}</div>
     {/case}
     {case value='Discount20'}
         <div class='OldPrice'>NZ${exp:number_format number='{product_price}' decimals='2'}</div>
         <div class='ProductPrice'>NZ${exp:math:percentMe num1='{product_price}' num2='20'}</div>
     {/case}
     {case value='Discount25'}
         <div class='OldPrice'>NZ${exp:number_format number='{product_price}' decimals='2'}</div>
         <div class='ProductPrice'>NZ${exp:math:percentMe num1='{product_price}' num2='25'}</div>
     {/case}
     {case default="yes"}
         <div class='ProductPrice'>NZ${exp:number_format number='{product_price}' decimals='2'}</div>
     {/case}
    
    {/exp:switchee}
    
    {/exp:channel:entries}

    This breaks the page layout at the price.
    I’ve tried it without using the other plugins but same result. Have also tried it without the “default=‘yes’” and just a ‘value=“open”’ instead.

    Can anyone see what’s going wrong?

    Cheers
    Steve

  • #2 / Sep 18, 2012 10:53pm

    John St-Amand

    865 posts

    Got it:

    {exp:switchee variable='status' parse='inward'}

    Should be

    {exp:switchee variable="{status}" parse="inward"}
  • #3 / Sep 18, 2012 10:58pm

    John St-Amand

    865 posts

    If that doesn’t work, what result do you get with something like this:

    {exp:channel:entries channel="products" url_title="{last_segment}" dynamic="no" disable="category_fields|pagination|member_data" status="open|Discount5|Discount10|Discount15|Discount20|Discount25"}
    
    {exp:switchee variable="{status}" parse="inward"}
    
    {case value="Discount5"}
     Discount5 is my status
    {/case}
     {case value="Discount10"}
    Discount10 is my status
     {/case}
     {case value='Discount15'}
         Discount15 is my status
     {/case}
    
    and you could repeat this if needed…
    
    {/exp:switchee}
    
    {/exp:channel:entries}
  • #4 / Sep 18, 2012 11:09pm

    xenowebdev

    34 posts

    Just in case anyone else is following:
    The issue was that I had nested 2 Switchee blocks, therefore one was closing out the other before running.
    Ended up using Marks other plugin, “IfElse” inside the first Switchee block to run my check against the statuses.
    Many thanks to John for his help 😊

  • #5 / Sep 24, 2012 10:44am

    Vertexer

    1 posts

    The issue was that I had nested 2 Switchee blocks, therefore one was closing out the other before running.

    You can also nest switchee by leaving off the ‘exp:’ in nested tags.


    Outer switchee block:

    {exp:switchee ...}

    Nested switchee block:

    {switchee ...}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases