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

[API][ProductTaxon] Add unique combination validation #14916

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
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 @@ -21,3 +21,8 @@ Feature: Modifying taxons assigned to an exisiting product
Scenario: Adding taxons to product
When I add "Clothes" taxon to the "Shirt" product
Then the product "Shirt" should have the "Clothes" taxon

@api @no-ui
Scenario: Being prevented from adding the same taxon twice
When I try to add "Clothes" taxon to the "T-Shirt" product
Then I should be notified that this taxon is already assigned to this product
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ Feature: Products validation
Then I should be notified that name is required
And this product should still be named "Dice Brewing"

@ui @api
Scenario: Not seeing validation error for duplicated code if product code has not been changed
Given the store has a "Dice Brewing" product
When I want to modify this product
And I remove its name from "English (United States)" translation
And I try to save my changes
Then this product should still be named "Dice Brewing"

@ui
Scenario: Trying to assign new channel to an existing configurable product without specifying its all variant prices for this channel
Given the store has a "7 Wonders" configurable product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sylius\Behat\Context\Api\Resources;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;

final class ManagingProductTaxonsContext implements Context
{
Expand All @@ -38,7 +39,7 @@ public function iChangeThatTheProductBelongsToTheTaxon(ProductInterface $product

/**
* @When I assign the :taxon taxon to the :product product
* @When I add :taxon taxon to the :product product
* @When I (try to) add :taxon taxon to the :product product
*/
public function iAddTaxonToTheProduct(TaxonInterface $taxon, ProductInterface $product): void
{
Expand All @@ -47,4 +48,15 @@ public function iAddTaxonToTheProduct(TaxonInterface $taxon, ProductInterface $p
$this->client->addRequestData('product', $this->iriConverter->getIriFromItem($product));
$this->client->create();
}

/**
* @Then I should be notified that this taxon is already assigned to this product
*/
public function iShouldBeNotifiedThatThisTaxonIsAlreadyAssignedToThisProduct(): void
{
Assert::contains(
$this->client->getLastResponse()->getContent(),
'This taxon is already assigned to this product.',
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!--

This file is part of the Sylius package.

(c) Paweł Jędrzejewski

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

-->

<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="Sylius\Component\Core\Model\ProductTaxon">
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="fields">
<value>product</value>
<value>taxon</value>
</option>
<option name="message">sylius.product_taxon.unique</option>
<option name="groups">sylius</option>
</constraint>
</class>
</constraint-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ sylius:
file:
max_size: The image is too big - {{ size }}{{ suffix }}. Maximum allowed size is {{ limit }}{{ suffix }}.
upload_ini_size: The image is too big. Maximum allowed size is {{ limit }}{{ suffix }}.
product_taxon:
unique: This taxon is already assigned to this product.
product_variant:
onHand:
min: On hand must be greater than {{ limit }}.
Expand Down