Post by fido-x » Wed Jul 15, 2015 11:14 pm

The end date for specials, discounts and coupons is entered into the database as a date without a timestamp. This is the correct method for doing this.

When the admin user views the product list, the product controller checks today's date to see if it is between the start and end dates of specials/discounts and displays the correct price accordingly. If the end date is "today", the controller also does a time calculation to verify the time.

However, on the front-end, we have a different story. The special, discount and coupon end dates are retrieved directly from the database using the comparison "date_end > NOW()". The problem here is that the date does not include a timestamp, but NOW() does. So, if the end date for the special, discount or coupon is "today", a default timestamp of "00:00:00" is applied. This means that the special, discount or coupon end time is the beginning of the day, not the end of the day as expected. As a result, if the special, discount or coupon end date is "today", it will always be less than "NOW()". Subsequently, instead of specials, discounts and coupons ending at midnight "today" when they are supposed to end, they will end at midnight yesterday.

To get around this, the database query needs to have one day added to the end date, so that the specials, discounts or coupons end at the beginning of the next day.

The Fix

In catalog/model/catalog/product.php, the database queries in the "getProduct()" and "getProducts()" functions should have:

Code: Select all

DATE_ADD(pd2.date_end, INTERVAL 1 DAY) > NOW()
and

Code: Select all

DATE_ADD(ps.date_end, INTERVAL 1 DAY) > NOW()
instead of:

Code: Select all

pd2.date_end > NOW()
and

Code: Select all

ps.date_end > NOW()
respectively.

The "getProductSpecials()" function should have:

Code: Select all

DATE_ADD(ps.date_end, INTERVAL 1 DAY) > NOW()
instead of:

Code: Select all

ps.date_end > NOW()
And, the "getProductDiscounts()" function should have:

Code: Select all

DATE_ADD(date_end, INTERVAL 1 DAY) > NOW()
instead of:

Code: Select all

date_end > NOW()
The same should apply to the "getCoupon()" function in catalog/model/checkout/coupon.php.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by OSWorX » Thu Jul 16, 2015 12:20 am

fido-x wrote:The end date for specials, discounts and coupons is entered into the database as a date without a timestamp. This is the correct method for doing this.
That means, that for them only whole dates (days) are possible, never time based settings.
For example not possible to define a 'happy hour' from 17:00 until 22:00.
Or am I wrong?

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 1 guest