Smarty check if date is between - smarty

i need check if smarty now date is equal or between my two dates.
If dates is the same months its work. But if:
Start = 19.01.2015 and
Stop = 1.02.2015 and
smarty now is 19.01.2015 it show no. Only if i change months it don't work
{if ($smarty.now|date_format:"%d.%m.%Y") >= ($value->getVariableValue('Start')) AND ($smarty.now|date_format:"%d.%m.%Y") <= ($value->getVariableValue('Stop'))}
yes
{else}
no
{/if}

try this i hope it will work :
Php file :
<?php
$start_date = "19.01.2015";
$end_date = "1.02.2015";
$smarty->assign('start', $start_date);
$smarty->assign('stop', $end_date);
$smarty->display("date.tpl");
?>
tpl file(date.tpl) :
<{if (($smarty.now|date_format:"%d.%m.%Y") >= ($start)) AND (($smarty.now|date_format:"%d.%m.%Y") <= ($stop)) }>
yes
{else}
no
{/if}

Related

Laravel having space output issue in blade file

I have Laravel code in Blade like this :
<span id="pk_dens" name="pk_dens" class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif">
{{$productpages->pk_dens}}%
</span>
So in class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif"
it will add space in class like text- danger and text- success so class not apply
so how can I avoid that spce in if else condition ?
Use ternary operator
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">
{{$productpages->pk_dens}}%
</span>
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
I think you are missing here is ? in ternary syntax and to remove space just remove all white spaces from the span tag and make it in just one line.
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">{{$productpages->pk_dens}}%</span>

Prestashop 1.6. How to check if product isPack in .tpl?

I want to check in theme (front) product.tpl file (PS 1.6.1.4) if state if product is Standard product or Pack of existing products
{if $product_type == Product::PTYPE_PACK} not working....
I want to return boolean.
use:
{if $packItems|#count > 0}
an example of using you can find it in product.tpl in the theme folder.
used in this way:
{if $packItems|#count > 0}
<div class="short_description_pack">
<h3>{l s='Pack content'}</h3>
{foreach from=$packItems item=packItem}
<div class="pack_content">
{$packItem.pack_quantity} x {$packItem.name|escape:'html':'UTF-8'}
<p>{$packItem.description_short}</p>
</div>
{/foreach}
</div>
{/if}
in addition, there is in a products object:
$product->id_pack_product_attribute = null
$product->cache_is_pack = 0
for non-pack products

Magento echo shipping totals with tax and currency

I have found this old piece of code, which seems to work just perfectly in Magento 1.6.2.
My problem is, that it is not showing the value with Tax, and it's showing the value as ex. 60.0000
Would it somehow be possible to get it to show with tax and as a currency?
Or maby just somehow (I've already tried this with no luck, no matter how I put together the if statement..) build an if statement so that if it's 60.000 then it will echo 75$ ?
$totals = Mage::getModel('checkout/session')->getQuote()->getTotals();
if(isset($totals['shipping']))
print $totals['shipping']->getData('value');
To get your cart total (assuming that the customer is log in or enter the shipping info)
$cart = Mage::getModel('checkout/session')->getQuote();
echo Mage::helper('core')->currency($cart->getGrandTotal(),true,false);
To get Shipping amount
$shippingMethod = $cart->getShippingAddress();
echo Mage::helper('core')->currency($shippingMethod['shipping_amount'],true,false);
Source http://www.magentocommerce.com/boards/viewthread/278544/
I made this crude solution, it's ugly, but it's working, if there's any suggestions to minimize this then please come with suggestions :) .
<?php $fragt = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount();
if (($fragt >= 0) && ($fragt <= 60))
echo $this->__('Fragt: 75 DKK ');
else
if (($fragt >= 75) && ($fragt <= 78))
echo $this->__('Fragt: 95 DKK ');
else
if (($fragt >= 79) && ($fragt <= 99))
echo $this->__('Fragt: 100 DKK ');
else
if (($fragt >= 100) && ($fragt <= 110))
echo $this->__('Fragt: 120 DKK ');
else
if (($fragt >= 120) && ($fragt <= 151))
echo $this->__('Fragt: 150 DKK ');
else
if (($fragt >= 200) && ($fragt <= 301))
echo $this->__('Fragt: 300 DKK ');
?>
</span>

Smarty if statement with date?

If I have a smarty variable
{$test.date_created}
that displays a date in a smarty template, for example:
02/2/2012
On the smarty website, it says that you can display today's date with the following.
{$smarty.now|date_format:'%m/%d/%Y'}
How can I use it in an if statement to display a message when its 3 days old or more from today's date?
If its 3 days old or more, display "Old". If not, Display "New".
You can use strtotime() to get the timestamp corresponding to three days ago, and then compare this to the date of your message. For example, assuming $message is your message record and $message['date'] is the timestamp you have to check:
$isMessageOld = ($message['date'] <= strtotime('-3 days'));
$smarty->assign('isMessageOld', $isMessageOld);
And then, in your template:
{if $isMessageOld} ... {/if}
I'm not 100% sure, but you can also test it directly in Smarty. Assuming you have $message passed to Smarty:
{if $message.date <= strtotime('-3 days')} ... {/if}
You can easily check already passed date in smarty by using this $smarty.now
$smarty.now|date_format:"%Y%m%d"
Here is an example of cross the old(passed) date
<{foreach from=$meetings item=m}>
<{if $smarty.now|date_format:"%Y%m%d" <= $m.date|date_format:"%Y%m%d"}>
<tr>
<td><{counter}></td>
<td><{$m.title}> on </td>
<td><{$m.date}></td>
</tr>
<{else}>
<tr>
<td><strike><{counter}></strike></td>
<td><strike><{$m.title}> on </strike></td>
<td><strike><{$m.date}></strike></td>
</tr>
<{/if}>
<{/foreach}>
We need to create meeting list array in php and assign it in smarty
$meetings[0]['title'] = "Speech on Gandhi Janyanti";
$meetings[0]['date'] = "2-Oct-2011";
$meetings[1]['title'] = "Meet friend";
$meetings[1]['date'] = "10-Oct-2013";
$meetings[2]['title'] = "Goto USA";
$meetings[2]['date'] = "22-Oct-2013";
$meetings[3]['title'] = "Speech on Gandhi Janyanti";
$meetings[3]['date'] = "2-Oct-2014";
$meetings[4]['title'] = "Meeting with John";
$meetings[4]['date'] = "22-Oct-2014";
$meetings[5]['title'] = "Speech on Gandhi Janyanti";
$meetings[5]['date'] = "2-Oct-2015";
$meetings[6]['title'] = "Meeting with Uncle";
$meetings[6]['date'] = "22-Oct-2015";
$theme->assign("meetings",$meetings);
echo $theme->fetch("index.tpl");

Problem with math in smarty!

I'm trying to plus and multiply three values in my template file but smarty is messing with me
{assign var="x" value="`$smarty.get.pageID * $perPage`"}
{$x + $smarty.section.co.index_next}
How can I do that?!
sorry that was a silly question i solve it like this :
{if $smarty.get.pageID ne 1 }
{assign var="x" value=$smarty.get.pageID}
{math equation="(( x * y ) + z )" x=$x y=$perPage z=$smarty.section.co.index_next}
{else}
{$smarty.section.co.index_next}
{/if}

Resources