From 3396ddc7c63dd3cffa451024c08a5fc5dcffb6ef Mon Sep 17 00:00:00 2001 From: Mykhailo Sulyma Date: Fri, 13 Dec 2019 17:07:39 +0200 Subject: [PATCH] BB-18526: Product price is not shown in shopping list widget (#26128) - fixed twig template and layout data provider - updated unit test - added behat test --- .../FrontendShoppingListProductsProvider.php | 4 +- .../page/shopping_list_widget.html.twig | 4 +- .../Fixtures/GuestShoppingListsFixture.yml | 62 +++++++++++++++++++ .../Features/guest_shopping_lists.feature | 8 ++- ...ontendShoppingListProductsProviderTest.php | 4 +- 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/Fixtures/GuestShoppingListsFixture.yml diff --git a/src/Oro/Bundle/ShoppingListBundle/Layout/DataProvider/FrontendShoppingListProductsProvider.php b/src/Oro/Bundle/ShoppingListBundle/Layout/DataProvider/FrontendShoppingListProductsProvider.php index 45eb6b20f48..f1567644bb9 100644 --- a/src/Oro/Bundle/ShoppingListBundle/Layout/DataProvider/FrontendShoppingListProductsProvider.php +++ b/src/Oro/Bundle/ShoppingListBundle/Layout/DataProvider/FrontendShoppingListProductsProvider.php @@ -98,10 +98,10 @@ public function getMatchedPrices(array $shoppingLists = []) $prices = []; foreach ($shoppingLists as $shoppingList) { - $prices[] = $this->getMatchedPrice($shoppingList); + $prices[$shoppingList->getId()] = $this->getMatchedPrice($shoppingList); } - return array_merge(...$prices); + return $prices; } /** diff --git a/src/Oro/Bundle/ShoppingListBundle/Resources/views/layouts/default/page/shopping_list_widget.html.twig b/src/Oro/Bundle/ShoppingListBundle/Resources/views/layouts/default/page/shopping_list_widget.html.twig index 8f53778921e..7be70562782 100644 --- a/src/Oro/Bundle/ShoppingListBundle/Resources/views/layouts/default/page/shopping_list_widget.html.twig +++ b/src/Oro/Bundle/ShoppingListBundle/Resources/views/layouts/default/page/shopping_list_widget.html.twig @@ -159,7 +159,7 @@
{% for lineItem in shoppingList.lineItems|default([]) %} {% set product = lineItem.product %} - {% set productMatchedPrice = productsMatchedPrices[product.id][lineItem.productUnit.code] is not empty ? productsMatchedPrices[product.id][lineItem.unit.code] : null %} + {% set productMatchedPrice = productsMatchedPrices[shoppingList.id][product.id][lineItem.productUnit.code] is defined ? productsMatchedPrices[shoppingList.id][product.id][lineItem.unit.code] : null %}
@@ -180,7 +180,7 @@ {{ productMatchedPrice.value|oro_format_currency({'currency': productMatchedPrice.currency}) }} {% else %} -
{{ 'oro.pricing.frontend.product_prices.price_not_found'|trans }}
+ {{ 'oro.pricing.frontend.product_prices.price_not_found'|trans }} {% endif %}
{% set routeOptions = {'id': product.id} %} diff --git a/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/Fixtures/GuestShoppingListsFixture.yml b/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/Fixtures/GuestShoppingListsFixture.yml new file mode 100644 index 00000000000..89963bbe77e --- /dev/null +++ b/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/Fixtures/GuestShoppingListsFixture.yml @@ -0,0 +1,62 @@ +include: + - '@OroShoppingListBundle:ProductFixture.yml' + +Oro\Bundle\PricingBundle\Entity\PriceList: + pricelist: + name: 'pricelist' + default: true + __calls: + - setCurrencies: [['USD']] + active: true + +Oro\Bundle\PricingBundle\Entity\PriceListToWebsite: + priceListToWebsite1: + pricelist: '@pricelist' + website: '@website1' + sortOrder: 100 + +Oro\Bundle\PricingBundle\Entity\ProductPrice: + productPrice{1..3}: + pricelist: '@pricelist' + product: '@product' + productSku: '@product->getSku' + quantity: 1 + unit: '@each' + value: '' + currency: 'USD' + productPrice4: + pricelist: '@pricelist' + product: '@simpleProduct1' + productSku: '@simpleProduct1->getSku' + quantity: 1 + unit: '@each' + value: 4 + currency: 'USD' + +Oro\Bundle\PricingBundle\Entity\CombinedProductPrice: + combinedProductPrice{1..3}: + pricelist: '@combinedPriceList' + product: '@product' + productSku: '@product->getSku' + quantity: 1 + unit: '@each' + value: '' + currency: 'USD' + combinedProductPrice4: + pricelist: '@combinedPriceList' + product: '@simpleProduct1' + productSku: '@simpleProduct1->getSku' + quantity: 1 + unit: '@each' + value: 4 + currency: 'USD' + +Oro\Bundle\PricingBundle\Entity\CombinedPriceListToWebsite: + combinedPriceListToWebsite1: + pricelist: '@combinedPriceList' + website: '@website1' + +Oro\Bundle\PricingBundle\Entity\PriceListToProduct: + priceListToProduct: + product: '@product1' + pricelist: '@pricelist' diff --git a/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/guest_shopping_lists.feature b/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/guest_shopping_lists.feature index e5ffa5087a0..3ac90762477 100644 --- a/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/guest_shopping_lists.feature +++ b/src/Oro/Bundle/ShoppingListBundle/Tests/Behat/Features/guest_shopping_lists.feature @@ -1,6 +1,6 @@ @regression @ticket-BB-10050 -@fixture-OroShoppingListBundle:ProductFixture.yml +@fixture-OroShoppingListBundle:GuestShoppingListsFixture.yml Feature: Guest Shopping Lists In order to allow unregistered customers to select goods they want to purchase As a Sales rep @@ -130,7 +130,7 @@ Feature: Guest Shopping Lists Then I should see "Product has been added to" flash message And I should see "In shopping list" And I hover on "Shopping List Widget" - And I should see "1 Item | $0.00" in the "Shopping List Widget" element + And I should see "1 ea | $3.00" in the "Shopping List Widget" element Scenario: Check Update Shopping List Given I should see "Update Shopping list" @@ -143,6 +143,10 @@ Feature: Guest Shopping Lists And I click "Search Button" Then I should see "In shopping list" + Scenario: Check shopping list widget + When I hover on "Shopping List Widget" + Then I should see "10 ea | $3.00" in the "Shopping List Widget" element + Scenario: Add more products to shopping list from list page (search) Given I type "CONTROL1" in "search" And I click "Search Button" diff --git a/src/Oro/Bundle/ShoppingListBundle/Tests/Unit/Layout/DataProvider/FrontendShoppingListProductsProviderTest.php b/src/Oro/Bundle/ShoppingListBundle/Tests/Unit/Layout/DataProvider/FrontendShoppingListProductsProviderTest.php index d3ebd4eb3a4..4b3c22985dc 100644 --- a/src/Oro/Bundle/ShoppingListBundle/Tests/Unit/Layout/DataProvider/FrontendShoppingListProductsProviderTest.php +++ b/src/Oro/Bundle/ShoppingListBundle/Tests/Unit/Layout/DataProvider/FrontendShoppingListProductsProviderTest.php @@ -129,7 +129,7 @@ public function testGetMatchedPrice($shoppingList) public function testGetMatchedPrices() { - $shoppingList = new ShoppingList(); + $shoppingList = $this->getEntity(ShoppingList::class, ['id' => 42]); $lineItems = []; $this->shoppingListLineItemsDataProvider->expects($this->once()) @@ -144,7 +144,7 @@ public function testGetMatchedPrices() ->willReturn($expected); $result = $this->provider->getMatchedPrices([$shoppingList]); - $this->assertEquals($expected, $result); + $this->assertEquals([42 => $expected], $result); } /**