how can I add/print tracking number on invoice?..
I used the code below
{l s='Tracking Number:' pdf='true'}
{$order->shipping_number}
returns blank, but on view order it has a tracking number. (image below)
orders->shipping_number field is blank.
Thanks.
adding on invoice.tpl
{foreach from=$order->getShipping() item=line}
{if $line.url != '' || $line.tracking_number != ''}
{'Tracking Number : '}
{$line.tracking_number}
{/if}
{/foreach}
solves the issue.
Related
Im trying to pass my own variable from module to template file .tpl
I have this code that is used for displaying availability in eshop. Product.tpl
{if $product.availability == 'available'}
{if $product.quantity <= 0 && $product.allow_oosp}
{if isset($product.available_date) && $product.available_date != '0000-00-00'}
<i class="fa fa-truck rtl-no-flip" aria-hidden="true"></i>
{$product.availability_message}
({if $product.available_date|strtotime > $smarty.now}<span class="available-date">{l s='naskladnění' d='Shop.Theme.Catalog'} {$product.available_date|date_format:"%d.%m.%Y"}</span>{/if})
{/if}
{/if}{/if}
Then Im having my own module where im assigning value to smarty
Mymodule.php
$in_stock = 1;
$this->context->smarty->assign("is_in_stock", $in_stock);
My question is if there is any way to access my smarty variable directly from theme tpl? I need to set up another {if else} with that variable but cant access it.
When I add variable to custom hook I cant access it neither.. Or maybe I dont know how. I tried to create front controller but nothing happened.
Something like
{if isset($product.available_date) && $mymodule.is_in_stock = 1 && $product.available_date != '0000-00-00'}
You can access functions of your module anywhere in .tpl files by
{YourModule::yourFunction()}
and set if like
{if YourModule::yourFunction() != 1}
Hello
{/if}
I use this code in Prestashop
{if (strpos($product.name, 'TVNUMBER1') !== false)}
THIS PRODUCT IS IN SALE
{/if}
So whenever I want to display that certain products are in sale, I have to go line by line, specifying the same product i.e."TVNUMBER1". I want to be able to write an array detailing all the products I have in sale "TV1, TV2, TV3", and get a code like this:
{if (strpos($product.name, '$array') !== false)}
THIS PRODUCT IS IN SALE
{/if}
I've tried similar examples found here, but I can't get them to work, either in Prestashop or in PHP testers online. It looks super simple, but I can't get around it.
I think what you want is the in_array php function, that check if a given $needle is or not in an array.
So what you should do is :
{if (in_array($product.name, '$array') !== false)}
THIS PRODUCT IS IN SALE
{/if}
Then in your controller you can assign the array to smarty :
$arr = array('TVNUMBER1', 'TVNUMBER2', 'TVNUMBER3');
$smarty->assign('myArray', $arr);
It seems you are using Smarty as template engine. So you could do something like this (from the doc).
In the controller
//Give it to the view
$arr = array('TVNUMBER1', 'TVNUMBER2');
$smarty->assign('myArray', $arr);
And in the view
//In the view, loop over the array
{foreach from=$myArray item=productName}
//If your product is among the in-sale ones, show the message
{if (strpos($product.name, productName) !== false)}
THIS PRODUCT IS IN SALE
{/if}
{/foreach}
I'm doing this:
{if $categories->id !=86 && $categories->id !=87}
xxxx code
{/if}
The categories is a vector and has id's from 1 to 140 or so, the id's 86 and 87 exist, I don't want to do the code on the pages with id's 86 and 87, but it is not working properly.
This will always execute because when you are in category 86 it evaluates to:
if (true && false) // returns false
You need to use XOR operator
{if $categories->id !=86 xor $categories->id !=87}
xxxx code
{/if}
EDIT
Sorry missed the dont wan't to execute part
{if !($categories->id ==86 || $categories->id ==87)}
xxx code
{/if}
Should be fine
I'd like to replace left_column with center_column just on mobile. It works well on tablet and laptop.
As you can see in attachment I have tried to replace left_column -which is marked with red rectangle- with center_column -which is marked with blue rectangle- just on mobile device.
http://i.imgur.com/9z8XHvI.png
{if isset($left_column_size) && !empty($left_column_size)}
{$HOOK_LEFT_COLUMN}
{/if}
{if isset($left_column_size) && isset($right_column_size)}{assign var='cols' value=(12 - $left_column_size - $right_column_size)}{else}{assign var='cols' value=12}{/if}
{/if}
I am using Smarty to output an array to an HTML table. I want each row of the table to have no more than 8 items in it. If the array has more than 8 items then the code would make a new row for the overflowing items.
How can I do this? Is this clear?
It's been a long time since I've used Smarty, but you should be able to do this like this:
<tr>
{foreach from=$items key=myId item=i name=foo}
{if $smarty.foreach.foo.index % 8 == 0 && $smarty.foreach.foo.index > 0 }
</tr><tr>
{/if}
<td>{$i.label}</td>
{/foreach}
</tr>
The modulus operator only returns 0 if the index is dividable by 8, So before every 9th item it adds a new row. We don't want this for the first item to happend so let's check that as well.
Here's how I did it in the past:
<table>
{foreach from=$array item='array_item' name='array_items'}
{if $smarty.foreach.array_items.first}
{* first item - start of all the rows *}
<tr><td>{$array_item}</td>
{elseif $smarty.foreach.array_items.index % 8 == 0}
{* 8 items added to row - start new row *}
</tr><tr><td>{$array_item}</td>
{elseif $smarty.foreach.array_items.last}
{* last item - end the row (or add logic to fill out row with empty cells if needed) *}
<td>{$array_item}</td></tr>
{else}
{* normal item - add cell *}
<td>{$array_item}</td>
{/if}
{/foreach}
</table>