Skip to content
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

Bugfix(PricingRules): Prevent Error when adding a new Pricing Rule with a name that exists #214

Closed
wants to merge 16 commits into from

Conversation

ctippler
Copy link
Contributor

When you create a Pricing Rule with an name that already exists in the backend, a invalid Database entry is added. Therefore the admin interface is not loading the pricing rules anymore.

The reason is because the create() call is successfully but in the update() call you get an error because a pricing Rule with that name already exists. Solution -> wrap it into a transaction so both queries have to be executed successfully

Copy link

github-actions bot commented Nov 19, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@ctippler
Copy link
Contributor Author

recheck

Comment on lines 79 to 85
$this->db->beginTransaction();
if (!$this->model->getId()) {
$this->create();
}

$this->update();
$this->db->commit();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also rollback on error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sure - added the rollback

$this->update();
$this->update();
$this->db->commit();
} catch (\Exception $e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please import the Exception instead of using the global namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... but it is like this everywhere in the bundle, so I would keep it like this.
image
If you want it differently - feel free to change it, but I would then suggest to also change it in the other places to be consistent.

BR

Copy link
Contributor

Choose a reason for hiding this comment

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

I know, but improving bit by bit also works :)
In other bundles we already have CS Fixer Rules in place, but it's only a small change so I will do it quickly :)

@mattamon mattamon self-assigned this Nov 22, 2024
Copy link
Contributor

@mattamon mattamon left a comment

Choose a reason for hiding this comment

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

Could you also please rebase the PR to 1.2 since it is a bugfix?

@ctippler ctippler changed the base branch from 1.x to 1.2 November 22, 2024 08:06
@ctippler ctippler changed the base branch from 1.2 to 1.x November 22, 2024 08:07
jan888adams and others added 5 commits November 22, 2024 10:48
…tal (#200)

* Set amount to the subtotal when the discount amount exceeds the subtotal

* Make not discounting price modifications optional

* Remove deprecation
* [WIP] Initial opensearch draft

* Apply php-cs-fixer changes

* Indexing works with opensearch

* add small cleanup

* add small cleanup

* Check productlisting with opensearch tenant

* Apply php-cs-fixer changes

* Replace elastic search everywhere

* add more cleanup

* add more cleanup

* add more cleanup

* add original sync command

* remove debug

* Apply php-cs-fixer changes

* Add deprecations and duplicate filtertypes for opensearch

* Apply php-cs-fixer changes

* Add docs for OpenSearch

* Apply php-cs-fixer changes

* Add to ignore 404 on create-index

* Apply php-cs-fixer changes

* fix: ignore 404 as we handle it differently

* fix: ignore 404 as we handle it differently

* Prepare groups for multi select

---------

Co-authored-by: mattamon <[email protected]>
Co-authored-by: lukmzig <[email protected]>
Co-authored-by: lukmzig <[email protected]>
…th a name that exists

When you create a Pricing Rule with an name that already exists the backend interface is not loading the pricing rules anymore because it inserts a row with "null" values.

The reason is because the create() call is successfully but at the update() call you get an errror because a pricing Rule with that name already exists. Solution -> wrap it into a transaction
@ctippler ctippler changed the base branch from 1.x to 1.2 November 22, 2024 09:52
@ctippler ctippler changed the base branch from 1.2 to 1.x November 22, 2024 10:00
@ctippler ctippler force-pushed the bugfix-pricing-rule branch from f57131c to 7bda5e2 Compare November 22, 2024 10:47
@ctippler ctippler changed the base branch from 1.x to 1.2 November 22, 2024 10:50
jan888adams and others added 9 commits November 22, 2024 12:05
…tal (#200)

* Set amount to the subtotal when the discount amount exceeds the subtotal

* Make not discounting price modifications optional

* Remove deprecation
* [WIP] Initial opensearch draft

* Apply php-cs-fixer changes

* Indexing works with opensearch

* add small cleanup

* add small cleanup

* Check productlisting with opensearch tenant

* Apply php-cs-fixer changes

* Replace elastic search everywhere

* add more cleanup

* add more cleanup

* add more cleanup

* add original sync command

* remove debug

* Apply php-cs-fixer changes

* Add deprecations and duplicate filtertypes for opensearch

* Apply php-cs-fixer changes

* Add docs for OpenSearch

* Apply php-cs-fixer changes

* Add to ignore 404 on create-index

* Apply php-cs-fixer changes

* fix: ignore 404 as we handle it differently

* fix: ignore 404 as we handle it differently

* Prepare groups for multi select

---------

Co-authored-by: mattamon <[email protected]>
Co-authored-by: lukmzig <[email protected]>
Co-authored-by: lukmzig <[email protected]>
…th a name that exists

When you create a Pricing Rule with an name that already exists the backend interface is not loading the pricing rules anymore because it inserts a row with "null" values.

The reason is because the create() call is successfully but at the update() call you get an errror because a pricing Rule with that name already exists. Solution -> wrap it into a transaction
…th a name that exists

When you create a Pricing Rule with an name that already exists the backend interface is not loading the pricing rules anymore because it inserts a row with "null" values.

The reason is because the create() call is successfully but at the update() call you get an errror because a pricing Rule with that name already exists. Solution -> wrap it into a transaction
@ctippler ctippler closed this by deleting the head repository Nov 22, 2024
ctippler added a commit to ctippler/ecommerce-framework-bundle that referenced this pull request Nov 22, 2024
@ctippler
Copy link
Contributor Author

I shomehow destroyed my fork with trying to rebase this.
I created a new PR from 1.2 as base #216

ctippler added a commit to ctippler/ecommerce-framework-bundle that referenced this pull request Nov 25, 2024
mattamon pushed a commit that referenced this pull request Nov 29, 2024
…th a name that exists (#216)

* Bugfix Pricing Rules -> #214

* Revert "Bugfix Pricing Rules -> #214"

This reverts commit 8806162.

* fix copy paste error

* Update src/PricingManager/Rule/Dao.php

Co-authored-by: Jacob Dreesen <[email protected]>

---------

Co-authored-by: Jacob Dreesen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants