If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Bug Reports / [Done v1.3.9] Salemaker repeatedly turning sale on and off

[Done v1.3.9] Salemaker repeatedly turning sale on and off

Locked

Started by cjpinder on 2 Dec 2008, 8:35 AM · Views: 1,441

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
2 Dec 2008, 8:35 AM
#1
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Post #1 by cjpinder

Hi,

On the day of the end date of a sale created with salemaker, Zen Cart will turn the sale repeatedly on and off every time a page is loaded in Admin. This can lead to excessive server load.

The problem seems to be that zen_expire_salemaker() and zen_start_salemaker() in includes/functions/salemaker.php do not agree on what the end date should be.

I've seen this with Zen Cart v1.3.7 / v1.3.8, PHP 5 and MySQL 4.

I would suggest making following change to zen_start_salemaker() ...

    $salemaker_query = "select sale_id
                       from " . TABLE_SALEMAKER_SALES . "
                       where sale_status = '0'
                       and (((sale_date_start <= curdate() and sale_date_start != '0001-01-01') and (sale_date_end > curdate()))
                       or ((sale_date_start <= curdate() and sale_date_start != '0001-01-01') and (sale_date_end = '0001-01-01'))
                       or (sale_date_start = '0001-01-01' and sale_date_end > curdate()))
                       ";
```The above code changes two of the >= operators to > to fix the bug and for forwards compatibility changes now() to curdate(). The zen_expire_salemaker() function should probably also be changed to use curdate() instead of now() to prevent issues with MySQL 5 compatibility.

Regards,
Christian.
2 Dec 2008, 8:54 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #2 by drbyte

CJPinder:

...for forwards compatibility changes now() to curdate(). The zen_expire_salemaker() function should probably also be changed to use curdate() instead of now() to prevent issues with MySQL 5 compatibility.
Um, I don't see how there is any MySQL 5 compatibility issue at stake here.

According to the documentation at dev.mysql.com for MySQL versions 3.23 thru 6.0, the now() function "returns the date and time"; whereas the curdate() function "returns the current date".

Switching to use "curdate()" instead of "now()" will lose the ability to handle time-based expiries. Thus, is not recommended.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

2 Dec 2008, 9:21 AM
#3
cjpinder avatar

cjpinder

Totally Zenned

Join Date:
Apr 2007
Location:
Herts. UK
Posts:
893
Plugin Contributions:
0

Post #3 by cjpinder

DrByte:

Um, I don't see how there is any MySQL 5 compatibility issue at stake here.

According to the documentation at dev.mysql.com for MySQL versions 3.23 thru 6.0, the now() function "returns the date and time"; whereas the curdate() function "returns the current date".

Switching to use "curdate()" instead of "now()" will lose the ability to handle time-based expiries. Thus, is not recommended.
The main issue is the bug caused by the >= operator instead of the > operator in zen_start_salemaker().

The SQL statement is comparing a date (for the start and end dates) with a datetime. How this works has change slightly between MySQL v4 and v5, though it may have changed yet again in the current MySQL. Comparing two dates (i.e. using curdate() instead of now()) removes any ambiguity.

The thing that needs fixing though is the operator logic to stop the sale from being repeated switchedly on and off on the end day of the sale.

Regards,
Christian.