Comments (6)
Thank you for reporting the bug. One thing is for sure. There shouldn't be an exception when you save them. But I don't know, if the underlying constraint is incorrect. A tierprice with the same value and the same price should not exist if the customer group is null. Because if the customer group is null then it applies to all customers. So it will be a matter of which entity is loaded first to determine the price.
What are your thoughts on that?
from syliustierpriceplugin.
Since TierPriceUniqueValidator
won't allow operations into database for duplicates, I don't think the database constraint is needed. Removing the unique constraint from TierPrice.orm.xml/database solves the problem.
from syliustierpriceplugin.
The validator should have been called before it gets inserted into the database. So the validator should have caught that. I will check that.
from syliustierpriceplugin.
Just had a quick look at this, the validator won't pick it up as it stands as it doesn't look at the values in the database, only at the data submitted in the form (I didn't think to test deleting and adding the same tier price in one save).
The UniqueEntitiy Validator (https://symfony.com/doc/current/reference/constraints/UniqueEntity.html) should catch this case I think, however as mentioned in the docs that validator can only validate against collections that have already been persisted and won't catch cases where someone tries to add two identical tier prices in the same save action, hence why I wrote the current TierPriceUniqueValidator
.
Not sure on the best way of handling this, perhaps add a check to TierPriceUniqueValidator
that selects from the database with the same values and if the ids are different flag it as a duplicate, but I think that would then cause an issue of marking the new one as a duplicate whilst it doesn't show the old one at all leading to confusion.
I think technically deleting a tier price then adding a new one should succeed but it seems the way symfony forms/doctrine are handling this the deletes are the last query type to run when for this to work they would have to happen before the inserts.
from syliustierpriceplugin.
My solution so far was to remove the unique constraint from database.
from syliustierpriceplugin.
Yeah, unfortunately the constraint doesn't catch every case anyway as customer_group_id can be null and databases treat nulls as unique values so it doesn't stop you inserting two tier prices with the same quantity if the customer group isn't set (you can see this by repeating your example but by not setting a customer group and this time it submits fine). So removing the constraint might be a better option given it doesn't catch every case anyway.
Not sure if its possible but my ideal solution would be to see if there is a way to make sure the deletes happen before the inserts, but I'm fairly sure that not something you can easily do from a plugin as its likely down to core code in Symfony Forms or Doctrine and I suspect there is a good reason why the database operations happen in the order they do.
from syliustierpriceplugin.
Related Issues (20)
- Adding support for Sylius 1.4 HOT 1
- Does it support Sylius 1.3.x HOT 8
- Feature suggestion: add customer group HOT 8
- Delete button not working HOT 1
- Tag current master HOT 5
- Unable to override plugin templates HOT 3
- Fixtures loading is broken HOT 1
- Price validation is less than or equal to zero
- Form extension priority error
- Exception during the database update HOT 4
- Working with 100's of quantities and adjustments HOT 1
- Schema not updating in default installation. HOT 1
- Plugin installation override the doctrine migration_paths order HOT 3
- sylius 1.11 support HOT 3
- Original price is not set HOT 3
- Support for Sylius 1.12 HOT 18
- I cannot see "tier prices" in a configurable product HOT 4
- Setting tiered price in one variant is showing tables for all variants HOT 3
- Dependency injection fails: non-existent service brille24.factory.tierprice HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from syliustierpriceplugin.