Skip to content

Fix SQL error throwed when websiteId is NULL #36802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,9 @@ public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = n
'customer_group_ids.' .
$entityInfo['entity_id_field'] .
' = cgw.' .
$entityInfo['entity_id_field'] . ' AND ' . $websiteId . ' = cgw.website_id',
$entityInfo['entity_id_field'] . ' AND ' . (int) $websiteId . ' = cgw.website_id',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion there is not solving core of issue because it's looks like unpredictable application behavior.
Everywhere we expect to receive integer value of website id and we need to solve core of this problem specifically why website id is null.

@Sekiphp could you please add total list of steps for reproducing the error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Den4ik It is truth. I was not able to simulate this error, but this part is problematic and I just use same solution, which is used in method, which is also called inside this method. In our website there are a lot of diferrent salesrules and probably not all are configured well and throws this error in some combination of steps.

Copy link
Contributor

@ihor-sviziev ihor-sviziev Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sekiphp,
I just analyzed where this code is used - looks like it might be only in

foreach ($this->rssModel->getDiscountCollection($websiteId, $customerGroupId) as $rule) {

While website id is getting retrieved from store. In case when store doesn't have linked website - this will trigger such error.
$websiteId = $storeModel->getWebsiteId();

In this case, I think direct type conversion is good

[]
)->where(
'cgw.website_id IS NULL',
$websiteId,
\Zend_Db::INT_TYPE
);
)->where('cgw.website_id IS NULL');

$this->getDateApplier()->applyDate($this->getSelect(), $now);

Expand Down