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

[Products][Admin][UI] Display the channel name instead of the channel code in the variant list #14377

Merged
merged 1 commit into from
Sep 29, 2022
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 @@ -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