Giter Site home page Giter Site logo

Comments (6)

mamazu avatar mamazu commented on May 13, 2024

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.

tavy315 avatar tavy315 commented on May 13, 2024

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.

mamazu avatar mamazu commented on May 13, 2024

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.

markbeazley avatar markbeazley commented on May 13, 2024

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.

tavy315 avatar tavy315 commented on May 13, 2024

My solution so far was to remove the unique constraint from database.

from syliustierpriceplugin.

markbeazley avatar markbeazley commented on May 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.