Skip to content

Commit

Permalink
bug #14377 [Products][Admin][UI] Display the channel name instead of …
Browse files Browse the repository at this point in the history
…the channel code in the variant list (Rafikooo)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11  <!-- see the comment below -->                  |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no<!-- don't forget to update the UPGRADE-*.md file --> |
| License         | MIT                                                          |
Before:
<img width="863" alt="image" src="https://user-images.githubusercontent.com/40125720/192798840-808adc62-b455-45e4-b8e7-48572d55f492.png">
After:
<img width="1114" alt="image" src="https://user-images.githubusercontent.com/40125720/192798991-e9f040bf-dcfe-4b42-b7a2-7811923b6a1f.png">

In the simple product `show`, we also display the translated name

Commits
-------

3d138a5 [Products][Admin][UI] Display the channel name instead of the channel code in the variant list
  • Loading branch information
GSadee committed Sep 29, 2022
2 parents 0ec8d1a + 3d138a5 commit fccd17d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Feature: Viewing details of a product with variants
Scenario: Viewing variants block
When I access "Iron Shield" product page
Then I should see 2 variants
And I should see "Iron shield - very big" variant with code "123456789-xl", priced "$25.00" and current stock 5
And I should see "Iron shield - very small" variant with code "123456789-xs", priced "$15.00" and current stock 12
And I should see "Iron shield - very big" variant with code "123456789-xl", priced "$25.00" and current stock 5 and in "United States" channel
And I should see "Iron shield - very small" variant with code "123456789-xs", priced "$15.00" and current stock 12 and in "United States" channel

@ui @javascript
Scenario: Viewing media block
Expand Down
21 changes: 16 additions & 5 deletions src/Sylius/Behat/Context/Ui/Admin/ProductShowPageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,22 @@ public function iShouldSeeVariants(int $count): void
}

/**
* @Then I should see :variantName variant with code :code, priced :price and current stock :currentStock
*/
public function iShouldSeeVariantWithCodePriceAndCurrentStock(string $variantName, string $code, string $price, string $currentStock): void
{
Assert::true($this->variantsElement->hasProductVariantWithCodePriceAndCurrentStock($variantName, $code, $price, $currentStock));
* @Then I should see :variantName variant with code :code, priced :price and current stock :currentStock and in :channel channel
*/
public function iShouldSeeVariantWithCodePriceAndCurrentStock(
string $variantName,
string $code,
string $price,
string $currentStock,
string $channel,
): void {
Assert::true($this->variantsElement->hasProductVariantWithCodePriceAndCurrentStock(
$variantName,
$code,
$price,
$currentStock,
$channel,
));
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/Sylius/Behat/Element/Product/ShowPage/VariantsElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ public function hasProductVariantWithCodePriceAndCurrentStock(
string $code,
string $price,
string $currentStock,
string $channel,
): bool {
/** @var NodeElement $variantRow */
$variantRows = $this->getDocument()->findAll('css', '#variants .variants-accordion__title');

/** @var NodeElement $variant */
foreach ($variantRows as $variant) {
if (
$this->hasProductWithGivenNameCodePriceAndCurrentStock($variant, $name, $code, $price, $currentStock)
$this->hasProductWithGivenNameCodePriceAndCurrentStock(
$variant,
$name,
$code,
$price,
$currentStock,
$channel,
)
) {
return true;
}
Expand All @@ -53,6 +61,7 @@ private function hasProductWithGivenNameCodePriceAndCurrentStock(
string $code,
string $price,
string $currentStock,
string $channel,
): bool {
$variantContent = $variant->getParent()->find(
'css',
Expand All @@ -65,7 +74,7 @@ private function hasProductWithGivenNameCodePriceAndCurrentStock(
if (
$variant->find('css', '.content .variant-name')->getText() === $name &&
$variant->find('css', '.content .variant-code')->getText() === $code &&
$variantContent->find('css', 'tr.pricing:contains("WEB-US") td:nth-child(2)')->getText() === $price &&
$variantContent->find('css', sprintf('tr.pricing:contains("%s") td:nth-child(2)', $channel))->getText() === $price &&
$variant->find('css', '.current-stock')->getText() === $currentStock
) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ interface VariantsElementInterface
{
public function countVariantsOnPage(): int;

public function hasProductVariantWithCodePriceAndCurrentStock(string $name, string $code, string $price, string $currentStock): bool;
public function hasProductVariantWithCodePriceAndCurrentStock(
string $name,
string $code,
string $price,
string $currentStock,
string $channel,
): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% for channelPricing in variant.channelPricings %}
<tr class="pricing">
<td class="five wide gray text">
<strong>{{ channelPricing.channelCode }}</strong>
<strong>{{ channelPricing.channelCode|sylius_channel_name }}</strong>
</td>
{% set channelCode = channelPricing.channelCode %}
<td>{{ money.format(channelPricing.price, currencies[channelCode]) }}</td>
Expand Down

0 comments on commit fccd17d

Please sign in to comment.