Jump to content

Display "Add to cart" on Christmas items only in December


Recommended Posts

I need something like...

I have some products that are only available during December.

But outside of December, I do not want to manually change all of the product quantities to zero, ie product not available.

I would like the product to be still available but for it to say that the product is available next December or even an image "This is a preorder for next December".

Something like

If Month equals 'December' and product description equals 'Christmas Tree' then display qty and buy button

and

If month does not equal 'December' and product description equals 'Christmas Tree' then display qty, buy button and 'Item will be shipped next December'.

Any ideas on the coding please.

Link to comment
Share on other sites

Topic split

You could try changing lines 255-283 of product.tpl in your theme's directory to something like the following:

{if $product->description == 'Christmas Tree' AND $smarty.now|date_format:'%m' != 12}

{l s='This is a preorder for next December'}
{else}
   <!-- quantity wanted -->

quantity == 0) || $virtual} style="display:none;"{/if}>
{l s='Quantity :'}
       <input type="text" name="qty" id="quantity_wanted" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" />


   <!-- availability -->

quantity == 0 && !$product->available_later) || (!$product->available_now && $display_qties != 1) } style="display:none;"{/if}>
{l s='Availability:'}
quantity == 0} class="warning-inline"{/if}>
           {if $product->quantity == 0}{if $allow_oosp}{$product->available_later}{else}{l s='This product is no longer in stock'}{/if}{else}{$product->available_now}{/if}



   <!-- number of item in stock -->

quantity == 0)} style="display:none;"{/if}>
{$product->quantity|intval}
quantity > 1} style="display:none;"{/if} id="quantityAvailableTxt">{l s='item in stock'}
quantity < 2} style="display:none;"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'}


   <!-- Out of stock hook -->

quantity > 0} style="display:none;"{/if}>
       {$HOOK_PRODUCT_OOS}



quantity > $last_qties || $product->quantity == 0) || $allow_oosp} style="display:none;"{/if} >{l s='Warning: Last items in stock!'}


quantity == 0} style="display:none;"{/if} id="add_to_cart" class="buttons_bottom_block"><input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /></p>
{/if}

Link to comment
Share on other sites

The ref to '$product->description' should be '$product->name'

{if $product->description == 'Christmas Tree' AND $smarty.now|date_format:'%m' != 12}


to

{if $product->name == 'Christmas Tree'}


It displays the text, but no other buttons. However as soon as I add the date format it does not display the text, but it does show the buttons. As its April now I have tried 04 and just 4 as the smarty month.

I also think using the id number is better and a lot shorter than typing the name.

{if $product->id == '16' AND $smarty.now|date_format:'%m' != 04}


It just does not like the month format.

Any ideas plz.
Link to comment
Share on other sites

Ok all I needed to do was delete the Else command

{if $product->description == 'Christmas Tree' AND $smarty.now|date_format:'%m' != 12}

{l s='This is a preorder for next December'}
{else}
   <!-- quantity wanted -->



changed to

{if $product->id == '16' AND $smarty.now|date_format:'%m' != 'April'}

{l s='This is a preorder for next December'}

   <!-- quantity wanted -->



Any ideas how I can incorporate a range of months, like November to March ??

Link to comment
Share on other sites

Any body any clues as to why this code does not work. Its bound to be something simple.

{$data = array("10","11","12","01","02","03");}
{foreach ($data as &$value) 
{if (stristr($product->name, 'Bare Rooted') == TRUE AND $smarty.now|date_format:'%m' == $value)}



Please NoteThis item is only available during November to March. Orders placed from end of March will be regarded as a pre order for the following year. If in doubt please ask.
{/if}
}

Link to comment
Share on other sites

You're trying to use Smarty in the same way as you would PHP, which won't work. If you want to use PHP code, you should use the {php} tag. For example:

{php}$data = array("10","11","12","01","02","03");{/php}
{foreach from=$data item=value}
  {if $product->name|stristr:'Bare Rooted' == TRUE AND $smarty.now|date_format:'%m' == $value}



Please NoteThis item is only available during November to March. Orders placed from end of March will be regarded as a pre order for the following year. If in doubt please ask.
  {/if}
{/foreach}



I haven't tested this. I'm not sure whether stristr works in Smarty. If it doesn't, you may need to make the entire block PHP instead just the first line.

Link to comment
Share on other sites

At the least the template product.tpl is displayed on the screen, but the contents of the code does not. Even changing 03 to 04 of the array to make it display for this current month.

I moved the {/php} to the end of the code, but I now get a totally blank template on the screen.

Any other advice plz.

Link to comment
Share on other sites

Turns out that variables declared in a {php} tag are not accessible to Smarty tags and there is no syntax to declare arrays in Smarty. The only way I could declare an array was to use the explode function to create one for me. Try the following code:

{assign var='data' value=','|explode:'10,11,12,01,02,03'}
{foreach from=$data item=value}
  {if $product->name|stristr:'Bare Rooted' == TRUE AND $smarty.now|date_format:'%m' == $value}



Please NoteThis item is only available during November to March. Orders placed from end of March will be regarded as a pre order for the following year. If in doubt please ask.
  {/if}
{/foreach}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...