diff --git a/app/code/Magento/Catalog/CustomerData/CompareProducts.php b/app/code/Magento/Catalog/CustomerData/CompareProducts.php index bdac4dfde64d1..27e3ab2b0889a 100644 --- a/app/code/Magento/Catalog/CustomerData/CompareProducts.php +++ b/app/code/Magento/Catalog/CustomerData/CompareProducts.php @@ -63,7 +63,6 @@ public function getSectionData() $count = $this->helper->getItemCount(); return [ 'count' => $count, - 'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count), 'listUrl' => $this->helper->getListUrl(), 'items' => $count ? $this->getItems() : [], ]; diff --git a/app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php b/app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php index 3a3656fe63b9e..8bb41a2875824 100644 --- a/app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php +++ b/app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Catalog\Test\Unit\CustomerData; @@ -30,22 +29,22 @@ class CompareProductsTest extends TestCase /** * @var Compare|MockObject */ - private $helperMock; + private $objectManagerHelper; /** * @var Url|MockObject */ - private $productUrlMock; + private $helperMock; /** * @var Output|MockObject */ - private $outputHelperMock; + private $productUrlMock; /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var Output|MockObject */ - private $objectManagerHelper; + private $outputHelperMock; /** * @var ScopeConfigInterface|MockObject @@ -115,7 +114,7 @@ private function getItemCollectionMock(array $items) : MockObject * @param array $dataSet * @return array */ - private function prepareProductsWithCorrespondingMocks(array $dataSet) : array + private function prepareProductsWithCorrespondingMocks(array $dataSet):array { $items = []; $urlMap = []; @@ -171,7 +170,10 @@ private function getProductMock(array $data) : MockObject return $product; } - public function testGetSectionData() + /** + * @return void + */ + public function testGetSectionData():void { $dataSet = [ ['id' => 1, 'name' => 'product#1'], @@ -200,7 +202,6 @@ public function testGetSectionData() $this->assertEquals( [ 'count' => $count, - 'countCaption' => __('%1 items', $count), 'listUrl' => 'http://list.url', 'items' => [ [ @@ -230,7 +231,10 @@ public function testGetSectionData() ); } - public function testGetSectionDataNoItems() + /** + * @return void + */ + public function testGetSectionDataNoItems():void { $count = 0; @@ -248,7 +252,6 @@ public function testGetSectionDataNoItems() $this->assertEquals( [ 'count' => $count, - 'countCaption' => __('%1 items', $count), 'listUrl' => 'http://list.url', 'items' => [] ], @@ -256,7 +259,10 @@ public function testGetSectionDataNoItems() ); } - public function testGetSectionDataSingleItem() + /** + * @return void + */ + public function testGetSectionDataSingleItem():void { $count = 1; @@ -286,7 +292,6 @@ public function testGetSectionDataSingleItem() $this->assertEquals( [ 'count' => 1, - 'countCaption' => __('1 item'), 'listUrl' => 'http://list.url', 'items' => [ [ diff --git a/app/code/Magento/Catalog/ViewModel/Product/Compare/Sidebar.php b/app/code/Magento/Catalog/ViewModel/Product/Compare/Sidebar.php new file mode 100644 index 0000000000000..0815803a694f0 --- /dev/null +++ b/app/code/Magento/Catalog/ViewModel/Product/Compare/Sidebar.php @@ -0,0 +1,39 @@ +compareHelper = $compareHelper; + } + + /** + * Get parameters to clear compare list + * + * @return string + */ + public function getClearCompareListParameters() + { + return $this->compareHelper->getPostDataClearList(); + } +} diff --git a/app/code/Magento/Catalog/view/frontend/layout/default.xml b/app/code/Magento/Catalog/view/frontend/layout/default.xml index 8f414724f51db..3906f5c4e0548 100644 --- a/app/code/Magento/Catalog/view/frontend/layout/default.xml +++ b/app/code/Magento/Catalog/view/frontend/layout/default.xml @@ -59,6 +59,7 @@ + Magento\Catalog\ViewModel\Product\Compare\Sidebar diff --git a/app/code/Magento/Catalog/view/frontend/templates/product/compare/link.phtml b/app/code/Magento/Catalog/view/frontend/templates/product/compare/link.phtml index 05a5649135ef5..a935c1148c708 100644 --- a/app/code/Magento/Catalog/view/frontend/templates/product/compare/link.phtml +++ b/app/code/Magento/Catalog/view/frontend/templates/product/compare/link.phtml @@ -11,9 +11,17 @@ data-bind="attr: {'href': compareProducts().listUrl}, css: {'no-display': !compareProducts().count}" > escapeHtml(__('Compare Products')) ?> - + + + + + diff --git a/app/code/Magento/Catalog/view/frontend/templates/product/compare/sidebar.phtml b/app/code/Magento/Catalog/view/frontend/templates/product/compare/sidebar.phtml index 809ddc5c61701..10bd94dcbc824 100644 --- a/app/code/Magento/Catalog/view/frontend/templates/product/compare/sidebar.phtml +++ b/app/code/Magento/Catalog/view/frontend/templates/product/compare/sidebar.phtml @@ -5,16 +5,27 @@ */ // phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis - -/* @var $block \Magento\Framework\View\Element\Template */ +?> +getData('compare_view_model'); ?>
- escapeHtml(__('Compare Products')) ?> - + + escapeHtml(__('Compare Products')) ?> + + + + + +
-
+
  1. @@ -31,12 +42,16 @@
diff --git a/app/code/Magento/Catalog/view/frontend/web/js/view/compare-products.js b/app/code/Magento/Catalog/view/frontend/web/js/view/compare-products.js index 5b73f477dea63..50abdedcf8088 100644 --- a/app/code/Magento/Catalog/view/frontend/web/js/view/compare-products.js +++ b/app/code/Magento/Catalog/view/frontend/web/js/view/compare-products.js @@ -7,9 +7,10 @@ define([ 'uiComponent', 'Magento_Customer/js/customer-data', 'jquery', + 'mage/translate', 'mage/mage', 'mage/decorate' -], function (Component, customerData, $) { +], function (Component, customerData, $, $t) { 'use strict'; var sidebarInitialized = false; @@ -33,6 +34,21 @@ define([ this.compareProducts = customerData.get('compare-products'); initSidebar(); + }, + + /** + * Get counter label + * + * @returns {String} + */ + getCounterLabel: function () { + var counter = this.compareProducts().count; + + if (counter === 1) { + return counter + ' ' + $t('item'); + } + + return $t('%1 items').replace('%1', counter); } }); }); diff --git a/app/code/Magento/Wishlist/Block/Customer/Sidebar.php b/app/code/Magento/Wishlist/Block/Customer/Sidebar.php index b260b8cc947f7..f90039f2b99a0 100644 --- a/app/code/Magento/Wishlist/Block/Customer/Sidebar.php +++ b/app/code/Magento/Wishlist/Block/Customer/Sidebar.php @@ -4,15 +4,14 @@ * See COPYING.txt for license details. */ -/** - * Wishlist sidebar block - */ namespace Magento\Wishlist\Block\Customer; use Magento\Catalog\Model\Product; use Magento\Framework\Pricing\Render; /** + * Wishlist Sidebar block + * * @api * @since 100.0.2 */ diff --git a/app/code/Magento/Wishlist/CustomerData/Wishlist.php b/app/code/Magento/Wishlist/CustomerData/Wishlist.php index 2f6b57a8650c4..952b139021ab0 100644 --- a/app/code/Magento/Wishlist/CustomerData/Wishlist.php +++ b/app/code/Magento/Wishlist/CustomerData/Wishlist.php @@ -80,29 +80,13 @@ public function getSectionData() } /** - * Get counter + * Get number of Wishlist items * * @return string */ protected function getCounter() { - return $this->createCounter($this->wishlistHelper->getItemCount()); - } - - /** - * Create button label based on wishlist item quantity - * - * @param int $count - * @return \Magento\Framework\Phrase|null - */ - protected function createCounter($count) - { - if ($count > 1) { - return __('%1 items', $count); - } elseif ($count == 1) { - return __('1 item'); - } - return null; + return (string) $this->wishlistHelper->getItemCount(); } /** diff --git a/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php index 0a1e40253b71c..e0ef0e64db1cd 100644 --- a/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php @@ -103,7 +103,7 @@ public function testGetSectionData() $itemRemoveParams = ['remove_params']; $result = [ - 'counter' => __('1 item'), + 'counter' => 1, 'items' => [ [ 'image' => [ @@ -289,7 +289,7 @@ public function testGetSectionDataWithTwoItems() $items = [$itemMock, $itemMock]; $result = [ - 'counter' => __('%1 items', count($items)), + 'counter' => 2, 'items' => [ [ 'image' => [ @@ -466,7 +466,7 @@ public function testGetSectionDataWithoutItems() $items = []; $result = [ - 'counter' => null, + 'counter' => 0, 'items' => [], ]; diff --git a/app/code/Magento/Wishlist/view/frontend/templates/link.phtml b/app/code/Magento/Wishlist/view/frontend/templates/link.phtml index e3ef3cf4f009b..6adab82260ab8 100644 --- a/app/code/Magento/Wishlist/view/frontend/templates/link.phtml +++ b/app/code/Magento/Wishlist/view/frontend/templates/link.phtml @@ -9,13 +9,15 @@