Skip to content

Commit

Permalink
bug #13397 [CatalogPromotion][Admin] Fix displaying fixed discount ac…
Browse files Browse the repository at this point in the history
…tion on catalog show page (GSadee)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.11
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #13325
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.10 or 1.11 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
-------

98c7cd3 [CatalogPromotion][Admin] Fix displaying fixed discount action on catalog show page
  • Loading branch information
AdamKasp committed Dec 16, 2021
2 parents 6957ecb + 98c7cd3 commit 551d34d
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Seeing catalog promotion's details
And this product has "PHP T-Shirt" variant priced at "$20.00" in "Web-US" channel
And there is a catalog promotion "Winter sale" available in "Web-US" channel that reduces price by "30%" and applies on "PHP T-shirt" variant
And it applies also on "T-Shirt" product
And it reduces also price by fixed "$10.00" in the "Web-US" channel
And the catalog promotion "Winter sale" operates between "2021-11-10" and "2022-01-08"
And its priority is 1200
And I am logged in as an administrator
Expand All @@ -19,6 +20,7 @@ Feature: Seeing catalog promotion's details
When I view details of the catalog promotion "Winter sale"
Then its name should be "Winter sale"
And it should reduce price by "30%"
And it should reduce price by "$10.00" in the "Web-US" channel
And it should apply on "PHP T-Shirt" variant
And it should apply on "T-Shirt" product
And it should start at "2021-11-10" and end at "2022-01-08"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,27 @@ public function theCatalogPromotionShouldHaveFixedDiscountInTheChannel(

/**
* @Then /^this catalog promotion should have ("[^"]+") of fixed discount in the ("[^"]+" channel)$/
* @Then /^it should reduce price by ("[^"]+") in the ("[^"]+" channel)$/
*/
public function thisCatalogPromotionShouldHaveFixedDiscountInTheChannel(int $amount, ChannelInterface $channel): void
{
$catalogPromotionActions = $this->responseChecker->getValue($this->client->getLastResponse(), 'actions');

Assert::same($catalogPromotionActions[0]['type'], CatalogPromotionActionInterface::TYPE_FIXED_DISCOUNT);
Assert::same($catalogPromotionActions[0]['configuration'][$channel->getCode()]['amount'], $amount);
foreach ($catalogPromotionActions as $catalogPromotionAction) {
if (
$catalogPromotionAction['type'] === CatalogPromotionActionInterface::TYPE_FIXED_DISCOUNT &&
$catalogPromotionAction['configuration'][$channel->getCode()]['amount'] === $amount
) {
return;
}
}

throw new \Exception(sprintf(
'There is no "%s" action with %d for "%s" channel',
CatalogPromotionActionInterface::TYPE_FIXED_DISCOUNT,
$amount,
$channel->getName()
));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ public function itWillReducePrice(CatalogPromotionInterface $catalogPromotion, f
$this->entityManager->flush();
}

/**
* @Given /^(it) reduces(?:| also) price by fixed ("[^"]+") in the ("[^"]+" channel)$/
*/
public function itReducesPriceByFixedInTheChannel(
CatalogPromotionInterface $catalogPromotion,
int $discount,
ChannelInterface $channel
): void {
/** @var CatalogPromotionActionInterface $catalogPromotionAction */
$catalogPromotionAction = $this->catalogPromotionActionFactory->createNew();
$catalogPromotionAction->setType(CatalogPromotionActionInterface::TYPE_FIXED_DISCOUNT);
$catalogPromotionAction->setConfiguration([$channel->getCode() => ['amount' => $discount]]);

$catalogPromotion->addAction($catalogPromotionAction);

$this->entityManager->flush();
}

/**
* @Given /^there is a catalog promotion "([^"]*)" that reduces price by ("[^"]+") and applies on ("[^"]+" variant) and ("[^"]+" variant)$/
* @Given /^there is a catalog promotion "([^"]*)" that reduces price by ("[^"]+") and applies on ("[^"]+" variant)$/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,14 @@ public function thisCatalogPromotionShouldHavePercentageDiscount(string $amount)
Assert::true($this->showPage->hasActionWithPercentageDiscount($amount));
}

/**
* @Then it should reduce price by :amount in the :channel channel
*/
public function itShouldReducePriceByInTheChannel(string $amount, ChannelInterface $channel): void
{
Assert::true($this->showPage->hasActionWithFixedDiscount($amount, $channel));
}

/**
* @Then it should apply on :variant variant
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Sylius/Behat/Page/Admin/CatalogPromotion/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Page\Admin\CatalogPromotion;

use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;

Expand Down Expand Up @@ -56,6 +57,18 @@ public function hasActionWithPercentageDiscount(string $amount): bool
return false;
}

public function hasActionWithFixedDiscount(string $amount, ChannelInterface $channel): bool
{
$amountsElements = $this->getDocument()->findAll('css', '[data-test-action-' . $channel->getCode() . '-amount]');
foreach ($amountsElements as $amountElement) {
if ($amountElement->getText() === $amount) {
return true;
}
}

return false;
}

public function hasScopeWithVariant(ProductVariantInterface $variant): bool
{
$variantsElements = $this->getDocument()->findAll('css', '[data-test-scope-variants]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Page\Admin\CatalogPromotion;

use FriendsOfBehat\PageObjectExtension\Page\PageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;

Expand All @@ -29,6 +30,8 @@ public function getPriority(): int;

public function hasActionWithPercentageDiscount(string $amount): bool;

public function hasActionWithFixedDiscount(string $amount, ChannelInterface $channel): bool;

public function hasScopeWithVariant(ProductVariantInterface $variant): bool;

public function hasScopeWithProduct(ProductInterface $product): bool;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% import "@SyliusAdmin/Common/Macro/money.html.twig" as money %}

<table class="ui very basic celled table">
<tbody>
<tr>
<td class="five wide"><strong class="gray text">{{ 'sylius.ui.type'|trans }}</strong></td>
<td>{{ 'sylius.ui.fixed_discount'|trans }}</td>
</tr>
{% set currencies = sylius_channels_currencies() %}
{% for channelCode, channelConfiguration in action.configuration %}
<tr>
<td class="five wide"><strong class="gray text">{{ channelCode }}</strong></td>
<td {{ sylius_test_html_attribute('action-' ~ channelCode ~ '-amount') }}>
{{ money.format(channelConfiguration.amount, currencies[channelCode]) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ sylius:
filter: 'Filter'
filters: 'Filters'
first_name: 'First name'
fixed_discount: 'Fixed discount'
for_products: 'For products'
for_taxons: 'For taxons'
for_variants: 'For variants'
Expand Down

0 comments on commit 551d34d

Please sign in to comment.