Jump to content

Estimate delivery date in product page code (help)


juanmlg

Recommended Posts

I am trying to create a code to add at product page to show a Estimate delivery time, I have all my items in my warehouse and I only ship to my country so all my delivery time are the next 24h, for that I created this code:
 
{if $product->quantity > 1}{l s='If you order before 12am you will receive it tomorrow}{/if}
 
But the problem now is the weekends, I am not sure how to create a conditional to show:
 
-On Fridays Before 12am:  "You will receive it the next Monday"
-On Fridays After 12am ,Saturdays and Sundays: "You will receive it the next Tuesday"
 
​I don't know how prestashop system knows the day of the week to add it to a {if}
 
Any help?
 

 

I am using Prestashop 1.5.3.1
Link to comment
Share on other sites

No matter if with 1.5x or 1.6x, the following code should work:

if $product->quantity > 1}  
  {assign var="Delivery_day" value=$smarty.now|date_format:"%u"}
  {l s='If you order before 12am you will receive it until '}
    {if $Delivery_day == 1}
	    {"+2 days"|strtotime|date_format:"Y-m-d"}
    {/if}
    {if $Delivery_day == 6}
	    {"+3 days"|strtotime|date_format:"Y-m-d"}
    {/if}    {if $Delivery_day > 0 && $Delivery_day < 6}
	    {"tomorrow"|strtotime|date_format:"Y-m-d"}
    {/if}
{/if}

The smarty variable "%u" represents the week days starting from Monday = 1.

If you want to specify the day's name you would have to change it to:

if $product->quantity > 1}
  {assign var="Delivery_day" value=$smarty.now|date_format:"%u"}
  {l s='If you order before 12am you will receive it until '}
    {if $Delivery_day == 1}
        {"+2 days"|strtotime|date_format:"%A, %B %e, %Y"}
    {/if}
    {if $Delivery_day == 6}
        {"+3 days"|strtotime|date_format:"%A, %B %e, %Y"}
    {/if}
    {if $Delivery_day > 0 && $Delivery_day < 6}
        {"tomorrow"|strtotime|date_format:"%A, %B %e, %Y"}
    {/if}
{/if}

%A = day of week as string
%B = month as string
%e = day of month as decimal with preceding zero if necessary
%Y = year as 4-digit decimal

Edited by eleazar  (see edit history)
  • Like 3
Link to comment
Share on other sites

No matter if with 1.5x or 1.6x, the following code should work:

if $product->quantity > 1}  
  {assign var="Delivery_day" value=$smarty.now|date_format:"%u"}
  {l s='If you order before 12am you will receive it until '}
    {if $Delivery_day = 0}
	    {"+2 days"|strtotime|date_format:"Y-m-d"}
    {/if}
    {if $Delivery_day = 6}
	    {"+3 days"|strtotime|date_format:"Y-m-d"}
    {/if}    {if $Delivery_day > 0 && $Delivery_day < 6}
	    {"tomorrow"|strtotime|date_format:"Y-m-d"}
    {/if}
{/if}

The smarty variable "%u" represents the week days starting from sunday = 0.

 

If you want to specify the day's name you would have to change it to:

if $product->quantity > 1}
  {assign var="Delivery_day" value=$smarty.now|date_format:"%u"}
  {l s='If you order before 12am you will receive it until '}
    {if $Delivery_day = 0}
        {"+2 days"|strtotime|date_format:"%A, %B %e, %Y"}
    {/if}
    {if $Delivery_day = 6}
        {"+3 days"|strtotime|date_format:"%A, %B %e, %Y"}
    {/if}
    {if $Delivery_day > 0 && $Delivery_day < 6}
        {"tomorrow"|strtotime|date_format:"%A, %B %e, %Y"}
    {/if}
{/if}

%A = day of week as string

%B = month as string

%e = day of month as decimal with preceding zero if necessary

%Y = year as 4-digit decimal

 

Thanks so much ! its perfect! Do you know if there is any smarty variable for the exact time?

 

thanks

Edited by juanmlg (see edit history)
  • Like 1
Link to comment
Share on other sites

This is a full list of the Smarty date_format conversion specifiers:
 

    %a - abbreviated weekday name according to the current locale
    %A - full weekday name according to the current locale
    %b - abbreviated month name according to the current locale
    %B - full month name according to the current locale
    %c - preferred date and time representation for the current locale
    %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
    %d - day of the month as a decimal number (range 01 to 31)
    %D - same as %m/%d/%y
    %e - day of the month as a decimal number, a single digit is preceded by a space (range 1 to 31)
    %g - Week-based year within century [00,99]
    %G - Week-based year, including the century [0000,9999]
    %h - same as %b
    %H - hour as a decimal number using a 24-hour clock (range 00 to 23)
    %I - hour as a decimal number using a 12-hour clock (range 01 to 12)
    %j - day of the year as a decimal number (range 001 to 366)
    %k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
    %l - hour as a decimal number using a 12-hour clock, single digits preceded by a space (range 1 to 12)
    %m - month as a decimal number (range 01 to 12)
    %M - minute as a decimal number
    %n - newline character
    %p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
    %r - time in a.m. and p.m. notation
    %R - time in 24 hour notation
    %S - second as a decimal number
    %t - tab character
    %T - current time, equal to %H:%M:%S
    %u - weekday as a decimal number [1,7], with 1 representing Monday
    %U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
    %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
    %w - day of the week as a decimal, Sunday being 0
    %W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
    %x - preferred date representation for the current locale without the time
    %X - preferred time representation for the current locale without the date
    %y - year as a decimal number without a century (range 00 to 99)
    %Y - year as a decimal number including the century
    %Z - time zone or name or abbreviation

 

  • Like 1
Link to comment
Share on other sites

  • 4 months later...
  • 4 weeks later...
  • 1 year later...

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...