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

[CatalogPromotion] fix pricing clearer #13208

Merged
merged 1 commit into from
Oct 18, 2021
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 @@ -23,3 +23,9 @@ Feature: Reapplying catalog promotions on variant once its prices changes
When I change the original price of the "PHP T-Shirt" product variant to "$50.00" in "Web-US" channel
Then the visitor should see "$17.50" as the price of the "T-Shirt" product in the "Web-US" channel
And the visitor should see "$50.00" as the original price of the "T-Shirt" product in the "Web-US" channel

@api @ui
Scenario: Removing the original price of the variant
When I remove the original price of the "PHP T-Shirt" product variant in "Web-US" channel
Then the visitor should see "$12.25" as the price of the "T-Shirt" product in the "Web-US" channel
And the visitor should see "$35.00" as the original price of the "T-Shirt" product in the "Web-US" channel
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ public function iChangeTheOriginalPriceOfTheProductVariantInChannel(
$this->updateChannelPricingField($variant, $channel, $originalPrice, 'originalPrice');
}

/**
* @When /^I remove the original price of the ("[^"]+" product variant) in ("[^"]+" channel)$/
*/
public function iRemoveTheOriginalPriceOfTheProductVariantInChannel(
ProductVariantInterface $variant,
ChannelInterface $channel
): void {
$this->updateChannelPricingField($variant, $channel, null, 'originalPrice');
}

private function updateChannelPricingField(
ProductVariantInterface $variant,
ChannelInterface $channel,
int $price,
?int $price,
string $field
): void {
$this->client->buildUpdateRequest($variant->getCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ public function iChangeTheOriginalPriceOfTheProductVariantInChannel(
$this->updatePage->specifyOriginalPrice($originalPrice, $channel);
$this->updatePage->saveChanges();
}

/**
* @When /^I remove the original price of the ("[^"]+" product variant) in ("[^"]+" channel)$/
*/
public function iRemoveTheOriginalPriceOfTheProductVariantInChannel(
ProductVariantInterface $variant,
ChannelInterface $channel
): void {
$this->updatePage->open(['productId' => $variant->getProduct()->getId(), 'id' => $variant->getId()]);
$this->updatePage->specifyOriginalPrice(null, $channel);
$this->updatePage->saveChanges();
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/ProductVariant/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function specifyPrice(int $price, ?ChannelInterface $channel = null): voi
$this->getElement('price', ['%channelCode%' => $channel->getCode()])->setValue($price);
}

public function specifyOriginalPrice(int $originalPrice, ?ChannelInterface $channel = null): void
public function specifyOriginalPrice(?int $originalPrice, ?ChannelInterface $channel = null): void
{
if ($channel === null) {
$this->getDocument()->fillField('Original price', $originalPrice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function specifyCurrentStock(int $amount): void;

public function specifyPrice(int $price, ?ChannelInterface $channelName = null): void;

public function specifyOriginalPrice(int $originalPrice, ?ChannelInterface $channel = null): void;
public function specifyOriginalPrice(?int $originalPrice, ?ChannelInterface $channel = null): void;

public function disable(): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public function clearChannelPricing(ChannelPricingInterface $channelPricing): vo
return;
}

$channelPricing->setPrice($channelPricing->getOriginalPrice());
if ($channelPricing->getOriginalPrice() !== null) {
$channelPricing->setPrice($channelPricing->getOriginalPrice());
}
$channelPricing->clearAppliedPromotions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Bundle\CoreBundle\Processor\CatalogPromotionClearerInterface;
use Sylius\Component\Core\Model\ChannelPricingInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
Expand Down Expand Up @@ -87,4 +88,15 @@ function it_clears_given_channel_pricing_with_catalog_promotions_applied(

$this->clearChannelPricing($channelPricing);
}

function it_does_not_copy_update_price_when_original_price_is_null(
ChannelPricingInterface $channelPricing
): void {
$channelPricing->getAppliedPromotions()->willReturn(['winter_sale' => ['en_US' => ['name' => 'Winter sale']]]);
$channelPricing->getOriginalPrice()->willReturn(null);
$channelPricing->setPrice(Argument::any())->shouldNotBeCalled();
$channelPricing->clearAppliedPromotions()->shouldBeCalled();

$this->clearChannelPricing($channelPricing);
}
}