I would like to add the shippingtime of an item in my shop to the current date. So that I get an availability date.
I have to program the whole thing in smarty.
I tried this but it doesn't work:
<g:availability_date>
{if $sArticle.shippingtime > 0}
Verfügbar ab:
{assign var="estimated_days" value=$smarty.now|date_format:"%a, %d %b %Y %T %Z"}
{"$estimated_days $Article.shippingtime"|strtotime|date_format:"%a, %d %b %Y %T %Z"}
{/if}
</g:availability_date>
But when I just add a few days to the current date then I get a valid Output...
Verfügbar ab:
{assign var="estimated_days" value=$smarty.now|date_format:"%a, %d %b %Y %T %Z"}
{"$estimated_days 3 days"|strtotime|date_format:"%a, %d %b %Y %T %Z"}
{/if}
</g:availability_date>
Can someone help me with that problem?
Best regards Lukas
CodePudding user response:
It's $estimated_days $Article.shippingtime
vs. $estimated_days 3 days
.
So what is $Article.shippingtime
? Despite the question doesn't feature any output,
you're once adding an absolute timestamp and once a relative offset.
Likely you have to convert from absolute timestamp to relative offset first.
"I have to program the whole thing in smarty" sounds meaningless to me,
most commonly one would provide calculated values to the template engine.
It's not even a duty of the controller, but of the underlying model already.
For simple calculations it's still ok in the template, not for complex ones.
CodePudding user response:
You just need to adjust your output tag a bit, PHP can't interpolate the dot notation inside the single quotes. Add braces around $Article.shippingtime
and add "days" after that.
{assign var="estimated_days" value=$smarty.now|date_format:"%a, %d %b %Y %T %Z"}
{"$estimated_days {$Article.shippingtime} days"|strtotime|date_format:"%a, %d %b %Y %T %Z"}