-
Notifications
You must be signed in to change notification settings - Fork 137
Add cart_rule column total_quantity #1693
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,40 @@ | ||
| /* https://github.com/PrestaShop/PrestaShop/pull/40224 */ | ||
| SET SESSION sql_mode=''; | ||
| SET NAMES 'utf8mb4'; | ||
|
|
||
| -- https://github.com/PrestaShop/PrestaShop/pull/40830 | ||
| /* PHP:add_column('cart_rule', 'total_quantity', 'int(10) UNSIGNED DEFAULT NULL AFTER `minimum_product_quantity`'); */; | ||
|
|
||
| -- Populate the new total_quantity column for existing cart rules. | ||
| -- Previously, the `quantity` field represented the number of uses LEFT (decremented on each use). | ||
| -- The new `total_quantity` field represents the ORIGINAL total number of allowed uses. | ||
| -- Formula: total_quantity = quantity (remaining) + quantityUsed (consumed in non-error orders) | ||
| -- Cart rules with quantity IS NULL are unlimited and keep total_quantity as NULL. | ||
| -- The subquery mirrors the logic from DiscountRepository::getQuantityUsedInOrders, | ||
| -- counting non-deleted order_cart_rule entries on orders not in error state. | ||
| UPDATE `PREFIX_cart_rule` cr | ||
| LEFT JOIN ( | ||
| SELECT ocr.`id_cart_rule`, COUNT(*) as quantity_used | ||
|
Comment on lines
+15
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering the impact of having a nest subquery when running it on large tables.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look fine We don't have a DEPENDENT SUBQUERY in the list. The subrequest is made once. |
||
| FROM `PREFIX_order_cart_rule` ocr | ||
| INNER JOIN `PREFIX_orders` o ON ocr.`id_order` = o.`id_order` | ||
| WHERE ocr.`deleted` = 0 | ||
| AND o.`current_state` != ( | ||
| SELECT CAST(`value` AS UNSIGNED) | ||
| FROM `PREFIX_configuration` | ||
| WHERE `name` = 'PS_OS_ERROR' | ||
| ) | ||
| GROUP BY ocr.`id_cart_rule` | ||
| ) used ON used.`id_cart_rule` = cr.`id_cart_rule` | ||
| SET cr.`total_quantity` = cr.`quantity` + COALESCE(used.`quantity_used`, 0) | ||
| WHERE cr.`quantity` IS NOT NULL; | ||
|
|
||
| -- New B2B feature | ||
|
|
||
| -- https://github.com/PrestaShop/PrestaShop/pull/40224 | ||
| INSERT INTO `PREFIX_feature_flag` (`name`, `type`, `label_wording`, `label_domain`, `description_wording`, `description_domain`, `state`, `stability`) VALUES | ||
| ('improved_b2b', 'env,dotenv,db', 'Improved B2B', 'Admin.Advparameters.Feature', 'Enable / Disable the improved B2B mode. To use the feature activate the B2B mode in General Settings', 'Admin.Advparameters.Help', 0, 'beta'); | ||
|
|
||
| /* Insert B2B foundation */ | ||
| /* https://github.com/PrestaShop/PrestaShop/pull/40632 */ | ||
| -- Insert B2B foundation | ||
| -- https://github.com/PrestaShop/PrestaShop/pull/40632 | ||
| CREATE TABLE `PREFIX_business_entity` | ||
| ( | ||
| `id_business_entity` INT UNSIGNED AUTO_INCREMENT NOT NULL, | ||
|
|
@@ -97,3 +128,5 @@ CREATE TABLE `PREFIX_b2b_role_authorization_role` | |
|
|
||
| -- https://github.com/PrestaShop/PrestaShop/pull/41028 | ||
| /* PHP:ps_920_business_entities_tabs(); */; | ||
|
|
||
| -- End of B2B feature | ||
Uh oh!
There was an error while loading. Please reload this page.