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

[Product] Add possibility to create product/variant without price in disabled channels #11848

Merged
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
32 changes: 32 additions & 0 deletions app/migrations/Version20200916093101.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Sylius\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200916093101 extends AbstractMigration
{
public function getDescription(): string
{
return 'Make a price on channel pricing nullable';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_channel_pricing CHANGE price price INT DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_channel_pricing CHANGE price price INT NOT NULL');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@managing_product_variants
Feature: Adding a product variant with only original price
In order to prepare product variant in all channel
As an Administrator
I want to be able to create product variant without price in disabled channel

Background:
Given the store operates on a single channel in "United States"
And the store has a "Wyborowa Vodka" configurable product
And this product is disabled in "United States" channel
And I am logged in as an administrator

@ui
Scenario: Adding a new product variant without price
When I want to create a new variant of this product
And I specify its code as "VODKA_WYBOROWA_DELUX"
And I set its original price to "$100.00" for "United States" channel
And I add it
Then I should be notified that it has been successfully created
And the "VODKA_WYBOROWA_DELUX" variant of the "Wyborowa Vodka" product should appear in the store
And the variant with code "VODKA_WYBOROWA_DELUX" should be originally priced at $100.00 for channel "United States"
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Removing a product variant's price from obsolete channel
And the store has a "PHP Mug" configurable product
And this product has "Medium PHP Mug" variant priced at "$20" in "Web-US" channel
And "Medium PHP Mug" variant priced at "£25" in "Web-GB" channel
And "Medium PHP Mug" variant is originally priced at "£50.00" in "Web-GB" channel
And this product is disabled in "Web-GB" channel
And I am logged in as an administrator

Expand All @@ -19,6 +20,7 @@ Feature: Removing a product variant's price from obsolete channel
And I remove its price for "Web-GB" channel
And I save my changes
Then I should not have configured price for "Web-GB" channel
But I should have original price equal to "£50.00" in "Web-GB" channel

@ui
Scenario: Removing a product variant's price from disabled channel
Expand All @@ -27,3 +29,4 @@ Feature: Removing a product variant's price from obsolete channel
And I remove its price for "Web-GB" channel
And I save my changes
Then I should not have configured price for "Web-GB" channel
But I should have original price equal to "£50.00" in "Web-GB" channel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@managing_products
Feature: Adding a product with only original price
In order to prepare product in all channel
As an Administrator
I want to be able to create product without price in disabled channel

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator

@ui
Scenario: Adding a new simple product without price
When I want to create a new simple product
And I specify its code as "BOARD_DICE_BREWING"
And I name it "Dice Brewing" in "English (United States)"
And I set its slug to "games/Dice-brewing" in "English (United States)"
And I set its original price to "$100.00" for "United States" channel
And I add it
Then I should be notified that it has been successfully created
And I should have original price equal to "$100.00" in "United States" channel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Feature: Removing a product's price from the channel where it is not available i
And the store operates on another channel named "Web-GB" in "GBP" currency
And the store has a product "Dice Brewing" priced at "$10.00" in "Web-US" channel
And this product is also priced at "£5.00" in "Web-GB" channel
And this product is originally priced at "£70.00" in "Web-GB" channel
And this product is disabled in "Web-GB" channel
And I am logged in as an administrator

Expand All @@ -19,6 +20,7 @@ Feature: Removing a product's price from the channel where it is not available i
And I remove its price for "Web-GB" channel
And I save my changes
Then I should not have configured price for "Web-GB" channel
But I should have original price equal to "£70.00" in "Web-GB" channel

@ui
Scenario: Removing a product's price from obsolete channel
Expand All @@ -27,3 +29,4 @@ Feature: Removing a product's price from the channel where it is not available i
And I remove its price for "Web-GB" channel
And I save my changes
Then I should not have configured price for "Web-GB" channel
But I should have original price equal to "£70.00" in "Web-GB" channel
31 changes: 31 additions & 0 deletions src/Sylius/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ public function storeHasAProductPricedAt($productName, int $price = 100, Channel
$this->saveProduct($product);
}

/**
* @Given /^(this product) is originally priced at ("[^"]+") in ("[^"]+" channel)$/
*/
public function thisProductHasOriginallyPriceInChannel(
ProductInterface $product,
int $originalPrice,
ChannelInterface $channel
): void {
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);

/** @var ChannelPricingInterface $channelPricing */
$channelPricing = $productVariant->getChannelPricingForChannel($channel);
$channelPricing->setOriginalPrice($originalPrice);

$this->saveProduct($product);
}

/**
* @Given /^(this product) is(?:| also) priced at ("[^"]+") in ("[^"]+" channel)$/
*/
Expand Down Expand Up @@ -328,6 +346,19 @@ public function variantPricedAtInChannel(
$this->sharedStorage->set('variant', $productVariant);
}

/**
* @Given /^("[^"]+" variant) is originally priced at ("[^"]+") in ("[^"]+" channel)$/
*/
public function variantIsOriginalPricedAtInChannel(
ProductVariantInterface $productVariant,
int $originalPrice,
ChannelInterface $channel
): void {
/** @var ChannelPricingInterface $channelPricing */
$channelPricing = $productVariant->getChannelPricingForChannel($channel);
$channelPricing->setOriginalPrice($originalPrice);
}

/**
* @Given /^the (product "[^"]+") has(?:| a| an) "([^"]+)" variant$/
* @Given /^(this product) has(?:| a| an) "([^"]+)" variant$/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ public function theVariantWithCodeShouldBePricedAtForChannel(ProductVariantInter
Assert::same($this->updatePage->getPriceForChannel($channelName), $price);
}

/**
* @Then /^the (variant with code "[^"]+") should be originally priced at (?:€|£|\$)([^"]+) for channel "([^"]+)"$/
*/
public function theVariantWithCodeShouldBeOriginalPricedAtForChannel(
ProductVariantInterface $productVariant,
string $price,
string $channelName
): void {
$this->updatePage->open(['id' => $productVariant->getId(), 'productId' => $productVariant->getProduct()->getId()]);

Assert::same($this->updatePage->getOriginalPriceForChannel($channelName), $price);
}

/**
* @Then /^the (variant with code "[^"]+") should be named "([^"]+)" in ("([^"]+)" locale)$/
*/
Expand Down Expand Up @@ -563,6 +576,19 @@ public function iShouldNotHaveConfiguredPriceForChannel(string $channelName): vo
Assert::same($this->updatePage->getPriceForChannel($channelName), '');
}

/**
* @Then I should have original price equal to :price in :channelName channel
*/
public function iShouldHaveOriginalPriceEqualInChannel(string $price, string $channelName): void
{
/** @var ProductVariantInterface $product */
$productVariant = $this->sharedStorage->get('variant');

$this->updatePage->open(['productId' => $productVariant->getProduct()->getId(), 'id' => $productVariant->getId()]);

Assert::contains($price, $this->updatePage->getOriginalPriceForChannel($channelName));
}

/**
* @Then I should see the :optionName option as :valueName
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,14 @@ public function iShouldNotHaveConfiguredPriceForChannel(string $channelName): vo
Assert::same($this->updateSimpleProductPage->getPriceForChannel($channelName), '');
}

/**
* @Then I should have original price equal to :price in :channelName channel
*/
public function iShouldHaveOriginalPriceEqualInChannel(string $price, string $channelName): void
{
Assert::contains($price, $this->updateSimpleProductPage->getOriginalPriceForChannel($channelName));
}

/**
* @param string $element
* @param string $value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
return;
}

if ($channelPricing->getPrice() === null) {
if ($channelPricing->getPrice() === null && $channelPricing->getOriginalPrice() === null) {
$event->setData(null);

if ($channelPricing->getId() !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<unique-constraints>
<unique-constraint columns="product_variant_id,channel_code" name="product_variant_channel_idx" />
</unique-constraints>

<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="price" column="price" type="integer"/>
<field name="originalPrice" column="original_price" type="integer" nullable="true"/>
<field name="channelCode" column="channel_code" type="string"/>
<field name="price" column="price" type="integer" nullable="true" />
<field name="originalPrice" column="original_price" type="integer" nullable="true" />
<field name="channelCode" column="channel_code" type="string" />

<many-to-one field="productVariant" target-entity="Sylius\Component\Product\Model\ProductVariantInterface" inversed-by="channelPricings">
<join-column name="product_variant_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
Expand Down