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

Fix variant without options values generation #10242

Merged
merged 7 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add new exception, translation flashes and refactor
  • Loading branch information
Tomanhez committed Mar 29, 2019
commit 3228f93c218425e83029c9b9da284a607b90ae8c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Feature: Preventing the generation of product variants from options without any values
In order to prevented from invalid variant generation
As an Administrator
I want to not be able to generate variants without any option values
I want to be prevented from generating of product variants from options without any values

Background:
Given the store operates on a single channel in "United States"
Expand All @@ -12,6 +12,6 @@ Feature: Preventing the generation of product variants from options without any

@ui
Scenario: Trying to generate a product variant for a product without options values
When I want to generate new variants for this product
Then It has been impossible to generate
When I try to generate new variants for this product
Then I should be notified that variants cannot be generated from options without any values
And I should not be able to generate any variants
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,6 @@ public function iShouldBeNotifiedThatPricesInAllChannelsMustBeDefined()
);
}

/**
* @Then It has been impossible to generate
*/
public function itHasBeenImpossibleToGenerate(): void
{
$this->notificationChecker->checkNotification('Cannot generate variants for a product without options values', NotificationType::failure());
}

/**
* @When I save my changes
* @When I try to save my changes
Expand Down Expand Up @@ -415,14 +407,6 @@ public function thisProductVariantShouldBeTracked(ProductVariantInterface $produ
Assert::true($this->updatePage->isTracked());
}

/**
* @When /^I want to generate new variants for (this product)$/
*/
public function iWantToGenerateNewVariantsForThisProduct(ProductInterface $product)
{
$this->generatePage->open(['productId' => $product->getId()]);
}

/**
* @When I generate it
* @When I try to generate it
Expand Down Expand Up @@ -474,9 +458,9 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyGenerated()
}

/**
* @Then /^I should not be able to generate any variants$/
* @Then I should not be able to generate any variants
*/
public function iShouldNotBeAbleToGenerateAnyVariantsToThisProduct()
public function iShouldNotBeAbleToGenerateAnyVariants(): void
{
Assert::false($this->generatePage->isGenerationPossible());
}
Expand Down Expand Up @@ -526,6 +510,23 @@ public function iShouldBeNotifiedThatOnHandQuantityMustBeGreaterThanTheNumberOfO
);
}

/**
* @Then I should be notified that variants cannot be generated from options without any values
*/
public function iShouldBeNotifiedThatVariantsCannotBeGeneratedFromOptionsWithoutAnyValues(): void
{
$this->notificationChecker->checkNotification('Cannot generate variants for a product without options values', NotificationType::failure());
}

/**
* @When /^I want to generate new variants for (this product)$/
* @When /^I try to generate new variants for (this product)$/
*/
public function iTryToGenerateNewVariantsForThisProduct(ProductInterface $product): void
{
$this->generatePage->open(['productId' => $product->getId()]);
}

/**
* @param string $element
* @param string $message
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

sylius:
product_variant:
cannot_generate_variants: 'Cannot generate variants for a product without options values.'
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function preSetData(FormEvent $event): void

Assert::isInstanceOf($product, ProductInterface::class);

try{
try {
$this->generator->generate($product);
} catch (VariantWithNoOptionsValuesException $exception) {
$this->session->getFlashBag()->add('error', $exception->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@

<service id="sylius.form.event_subscriber.product_variant_generator" class="Sylius\Bundle\ProductBundle\Form\EventSubscriber\GenerateProductVariantsSubscriber">
<argument type="service" id="sylius.generator.product_variant" />
<argument type="service" id="session"/>
<argument type="service" id="session" />
</service>

<service id="sylius.form.type.data_transformer.products_to_product_associations" class="Sylius\Bundle\ProductBundle\Form\DataTransformer\ProductsToProductAssociationsTransformer">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Sylius\Component\Resource\Exception;

final class VariantWithNoOptionsValuesException extends \Exception
{
public function __construct()
{
parent::__construct('sylius.product_variant.cannot_generate_variants');
}
}