Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d43916

Browse files
authored
bug #11848 [Product] Add possibility to create product/variant without price in disabled channels (AdamKasp)
This PR was merged into the 1.7 branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | 1.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | License | MIT <!-- - Bug fixes must be submitted against the 1.7 branch (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- 13ffd07 [Product] deleteing only price from obsolete channel 8eedea1 [Product] Adding product/variant without price
2 parents 497e449 + 8eedea1 commit 9d43916

10 files changed

Lines changed: 149 additions & 5 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sylius\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
final class Version20200916093101 extends AbstractMigration
11+
{
12+
public function getDescription(): string
13+
{
14+
return 'Make a price on channel pricing nullable';
15+
}
16+
17+
public function up(Schema $schema): void
18+
{
19+
// this up() migration is auto-generated, please modify it to your needs
20+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
21+
22+
$this->addSql('ALTER TABLE sylius_channel_pricing CHANGE price price INT DEFAULT NULL');
23+
}
24+
25+
public function down(Schema $schema): void
26+
{
27+
// this down() migration is auto-generated, please modify it to your needs
28+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
29+
30+
$this->addSql('ALTER TABLE sylius_channel_pricing CHANGE price price INT NOT NULL');
31+
}
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@managing_product_variants
2+
Feature: Adding a product variant with only original price
3+
In order to prepare product variant in all channel
4+
As an Administrator
5+
I want to be able to create product variant without price in disabled channel
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And the store has a "Wyborowa Vodka" configurable product
10+
And this product is disabled in "United States" channel
11+
And I am logged in as an administrator
12+
13+
@ui
14+
Scenario: Adding a new product variant without price
15+
When I want to create a new variant of this product
16+
And I specify its code as "VODKA_WYBOROWA_DELUX"
17+
And I set its original price to "$100.00" for "United States" channel
18+
And I add it
19+
Then I should be notified that it has been successfully created
20+
And the "VODKA_WYBOROWA_DELUX" variant of the "Wyborowa Vodka" product should appear in the store
21+
And the variant with code "VODKA_WYBOROWA_DELUX" should be originally priced at $100.00 for channel "United States"

features/product/managing_product_variants/removing_product_variant_price_from_obsolete_channel.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Feature: Removing a product variant's price from obsolete channel
1010
And the store has a "PHP Mug" configurable product
1111
And this product has "Medium PHP Mug" variant priced at "$20" in "Web-US" channel
1212
And "Medium PHP Mug" variant priced at "£25" in "Web-GB" channel
13+
And "Medium PHP Mug" variant is originally priced at "£50.00" in "Web-GB" channel
1314
And this product is disabled in "Web-GB" channel
1415
And I am logged in as an administrator
1516

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

2325
@ui
2426
Scenario: Removing a product variant's price from disabled channel
@@ -27,3 +29,4 @@ Feature: Removing a product variant's price from obsolete channel
2729
And I remove its price for "Web-GB" channel
2830
And I save my changes
2931
Then I should not have configured price for "Web-GB" channel
32+
But I should have original price equal to "£50.00" in "Web-GB" channel
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@managing_products
2+
Feature: Adding a product with only original price
3+
In order to prepare product in all channel
4+
As an Administrator
5+
I want to be able to create product without price in disabled channel
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And I am logged in as an administrator
10+
11+
@ui
12+
Scenario: Adding a new simple product without price
13+
When I want to create a new simple product
14+
And I specify its code as "BOARD_DICE_BREWING"
15+
And I name it "Dice Brewing" in "English (United States)"
16+
And I set its slug to "games/Dice-brewing" in "English (United States)"
17+
And I set its original price to "$100.00" for "United States" channel
18+
And I add it
19+
Then I should be notified that it has been successfully created
20+
And I should have original price equal to "$100.00" in "United States" channel

features/product/managing_products/removing_product_price_from_obsolete_channel.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Feature: Removing a product's price from the channel where it is not available i
99
And the store operates on another channel named "Web-GB" in "GBP" currency
1010
And the store has a product "Dice Brewing" priced at "$10.00" in "Web-US" channel
1111
And this product is also priced at "£5.00" in "Web-GB" channel
12+
And this product is originally priced at "£70.00" in "Web-GB" channel
1213
And this product is disabled in "Web-GB" channel
1314
And I am logged in as an administrator
1415

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

2325
@ui
2426
Scenario: Removing a product's price from obsolete channel
@@ -27,3 +29,4 @@ Feature: Removing a product's price from the channel where it is not available i
2729
And I remove its price for "Web-GB" channel
2830
And I save my changes
2931
Then I should not have configured price for "Web-GB" channel
32+
But I should have original price equal to "£70.00" in "Web-GB" channel

src/Sylius/Behat/Context/Setup/ProductContext.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ public function storeHasAProductPricedAt($productName, int $price = 100, Channel
149149
$this->saveProduct($product);
150150
}
151151

152+
/**
153+
* @Given /^(this product) is originally priced at ("[^"]+") in ("[^"]+" channel)$/
154+
*/
155+
public function thisProductHasOriginallyPriceInChannel(
156+
ProductInterface $product,
157+
int $originalPrice,
158+
ChannelInterface $channel
159+
): void {
160+
/** @var ProductVariantInterface $productVariant */
161+
$productVariant = $this->defaultVariantResolver->getVariant($product);
162+
163+
/** @var ChannelPricingInterface $channelPricing */
164+
$channelPricing = $productVariant->getChannelPricingForChannel($channel);
165+
$channelPricing->setOriginalPrice($originalPrice);
166+
167+
$this->saveProduct($product);
168+
}
169+
152170
/**
153171
* @Given /^(this product) is(?:| also) priced at ("[^"]+") in ("[^"]+" channel)$/
154172
*/
@@ -328,6 +346,19 @@ public function variantPricedAtInChannel(
328346
$this->sharedStorage->set('variant', $productVariant);
329347
}
330348

349+
/**
350+
* @Given /^("[^"]+" variant) is originally priced at ("[^"]+") in ("[^"]+" channel)$/
351+
*/
352+
public function variantIsOriginalPricedAtInChannel(
353+
ProductVariantInterface $productVariant,
354+
int $originalPrice,
355+
ChannelInterface $channel
356+
): void {
357+
/** @var ChannelPricingInterface $channelPricing */
358+
$channelPricing = $productVariant->getChannelPricingForChannel($channel);
359+
$channelPricing->setOriginalPrice($originalPrice);
360+
}
361+
331362
/**
332363
* @Given /^the (product "[^"]+") has(?:| a| an) "([^"]+)" variant$/
333364
* @Given /^(this product) has(?:| a| an) "([^"]+)" variant$/

src/Sylius/Behat/Context/Ui/Admin/ManagingProductVariantsContext.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ public function theVariantWithCodeShouldBePricedAtForChannel(ProductVariantInter
232232
Assert::same($this->updatePage->getPriceForChannel($channelName), $price);
233233
}
234234

235+
/**
236+
* @Then /^the (variant with code "[^"]+") should be originally priced at (?:€|£|\$)([^"]+) for channel "([^"]+)"$/
237+
*/
238+
public function theVariantWithCodeShouldBeOriginalPricedAtForChannel(
239+
ProductVariantInterface $productVariant,
240+
string $price,
241+
string $channelName
242+
): void {
243+
$this->updatePage->open(['id' => $productVariant->getId(), 'productId' => $productVariant->getProduct()->getId()]);
244+
245+
Assert::same($this->updatePage->getOriginalPriceForChannel($channelName), $price);
246+
}
247+
235248
/**
236249
* @Then /^the (variant with code "[^"]+") should be named "([^"]+)" in ("([^"]+)" locale)$/
237250
*/
@@ -563,6 +576,19 @@ public function iShouldNotHaveConfiguredPriceForChannel(string $channelName): vo
563576
Assert::same($this->updatePage->getPriceForChannel($channelName), '');
564577
}
565578

579+
/**
580+
* @Then I should have original price equal to :price in :channelName channel
581+
*/
582+
public function iShouldHaveOriginalPriceEqualInChannel(string $price, string $channelName): void
583+
{
584+
/** @var ProductVariantInterface $product */
585+
$productVariant = $this->sharedStorage->get('variant');
586+
587+
$this->updatePage->open(['productId' => $productVariant->getProduct()->getId(), 'id' => $productVariant->getId()]);
588+
589+
Assert::contains($price, $this->updatePage->getOriginalPriceForChannel($channelName));
590+
}
591+
566592
/**
567593
* @Then I should see the :optionName option as :valueName
568594
*/

src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,14 @@ public function iShouldNotHaveConfiguredPriceForChannel(string $channelName): vo
10541054
Assert::same($this->updateSimpleProductPage->getPriceForChannel($channelName), '');
10551055
}
10561056

1057+
/**
1058+
* @Then I should have original price equal to :price in :channelName channel
1059+
*/
1060+
public function iShouldHaveOriginalPriceEqualInChannel(string $price, string $channelName): void
1061+
{
1062+
Assert::contains($price, $this->updateSimpleProductPage->getOriginalPriceForChannel($channelName));
1063+
}
1064+
10571065
/**
10581066
* @param string $element
10591067
* @param string $value

src/Sylius/Bundle/CoreBundle/Form/Type/Product/ChannelPricingType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6363
return;
6464
}
6565

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

6969
if ($channelPricing->getId() !== null) {

src/Sylius/Bundle/CoreBundle/Resources/config/doctrine/model/ChannelPricing.orm.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
<unique-constraints>
2222
<unique-constraint columns="product_variant_id,channel_code" name="product_variant_channel_idx" />
2323
</unique-constraints>
24-
24+
2525
<id name="id" column="id" type="integer">
2626
<generator strategy="AUTO" />
2727
</id>
28-
<field name="price" column="price" type="integer"/>
29-
<field name="originalPrice" column="original_price" type="integer" nullable="true"/>
30-
<field name="channelCode" column="channel_code" type="string"/>
28+
<field name="price" column="price" type="integer" nullable="true" />
29+
<field name="originalPrice" column="original_price" type="integer" nullable="true" />
30+
<field name="channelCode" column="channel_code" type="string" />
3131

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

0 commit comments

Comments
 (0)