Skip to content

M2C-22090 Translate Wishlist and Compare label in template #25583

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

Open
wants to merge 29 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f56b4ca
M2C-22090 Translate wishlist and counter label in template
ptylek Nov 13, 2019
7578451
M2C-22090 Fix tests
ptylek Nov 14, 2019
dfd123d
M2C-22090 Fix tests
ptylek Nov 15, 2019
0313531
M2C-22090 Refactor $this->helper into $block functions
ptylek Nov 15, 2019
b2cc15f
M2C-22090 Add short description to Sidebar Class
ptylek Nov 15, 2019
6aa7ae7
M2C-22090 Add Sidebar ViewModel
ptylek Jan 7, 2020
5f398d0
M2C-22090 Add compare viewModel
ptylek Jan 7, 2020
a6f3979
M2C-22090 Fix namespace
ptylek Jan 7, 2020
94e66d9
M2C-22090 Fix namespace
ptylek Jan 7, 2020
75f1487
M2C-22090 Use private modifier
ptylek Jan 8, 2020
463e0b1
Merge branch '2.4-develop' of https://github.com/magento/magento2 int…
Nazar65 Jan 9, 2020
c4ec968
Merge branch '2.4-develop' into fix-wishlist_and_compare_label-M2C-22090
ptylek Feb 18, 2020
de361d3
Merge branch '2.4-develop' into fix-wishlist_and_compare_label-M2C-22090
ptylek Mar 25, 2020
9e684f9
Update Wishlist.php
ptylek Apr 4, 2020
5bb3c23
Fix integration test for WishList as counter now only returns a number
ptylek Apr 4, 2020
baf5d26
Change counter to number in integration tests
ptylek Apr 4, 2020
9d93bae
Merge branch '2.4-develop' of http://github.com/magento/magento2 into…
engcom-Echo Apr 10, 2020
5e9f5aa
Fix static test
engcom-Echo Apr 10, 2020
72d52e0
Merge branch '2.4-develop' of http://github.com/magento/magento2 into…
engcom-Echo Apr 16, 2020
ccd1d9f
Merge branch '2.4-develop' into fix-wishlist_and_compare_label-M2C-22090
ptylek Jun 8, 2020
0ab84fd
Merge branch '2.4-develop' of github.com:ptylek/magento2 into fix-wis…
ptylek Jun 22, 2020
f925a4d
M2C-22090 Move logic to js
ptylek Jun 22, 2020
4ba36df
Fix static tests
ptylek Jul 9, 2020
1d98cae
Update app/code/Magento/Wishlist/CustomerData/Wishlist.php
ptylek Oct 12, 2020
dd546cd
Merge branch '2.4-develop' into fix-wishlist_and_compare_label-M2C-22090
Oct 13, 2020
ed824ce
M2C-22090 Fix Unit test
ptylek Oct 14, 2020
9c261c2
Merge branch '2.4-develop' into fix-wishlist_and_compare_label-M2C-22090
Nov 12, 2020
4df77f8
Merge branch '2.4-develop' into fix-wishlist_and_compare_label-M2C-22090
ptylek Jun 30, 2021
85549f9
Remove wishlist ViewModel becasue it already exists
ptylek Jun 30, 2021
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
1 change: 0 additions & 1 deletion app/code/Magento/Catalog/CustomerData/CompareProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() : [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -200,7 +202,6 @@ public function testGetSectionData()
$this->assertEquals(
[
'count' => $count,
'countCaption' => __('%1 items', $count),
'listUrl' => 'http://list.url',
'items' => [
[
Expand Down Expand Up @@ -230,7 +231,10 @@ public function testGetSectionData()
);
}

public function testGetSectionDataNoItems()
/**
* @return void
*/
public function testGetSectionDataNoItems():void
{
$count = 0;

Expand All @@ -248,15 +252,17 @@ public function testGetSectionDataNoItems()
$this->assertEquals(
[
'count' => $count,
'countCaption' => __('%1 items', $count),
'listUrl' => 'http://list.url',
'items' => []
],
$this->model->getSectionData()
);
}

public function testGetSectionDataSingleItem()
/**
* @return void
*/
public function testGetSectionDataSingleItem():void
{
$count = 1;

Expand Down Expand Up @@ -286,7 +292,6 @@ public function testGetSectionDataSingleItem()
$this->assertEquals(
[
'count' => 1,
'countCaption' => __('1 item'),
'listUrl' => 'http://list.url',
'items' => [
[
Expand Down
39 changes: 39 additions & 0 deletions app/code/Magento/Catalog/ViewModel/Product/Compare/Sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\ViewModel\Product\Compare;

use Magento\Catalog\Helper\Product\Compare as CompareHelper;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* ViewModel for Compare Product List
*/
class Sidebar implements ArgumentInterface
{
/**
* @var CompareHelper
*/
private $compareHelper;

/**
* @param CompareHelper $compareHelper
*/
public function __construct(CompareHelper $compareHelper)
{
$this->compareHelper = $compareHelper;
}

/**
* Get parameters to clear compare list
*
* @return string
*/
public function getClearCompareListParameters()
{
return $this->compareHelper->getPostDataClearList();
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</item>
</item>
</argument>
<argument name="compare_view_model" xsi:type="object">Magento\Catalog\ViewModel\Product\Compare\Sidebar</argument>
</arguments>
</block>
</referenceContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@
data-bind="attr: {'href': compareProducts().listUrl}, css: {'no-display': !compareProducts().count}"
>
<?= $block->escapeHtml(__('Compare Products')) ?>
<span class="counter qty" data-bind="text: compareProducts().countCaption"></span>
<!-- ko if: compareProducts().count -->
<span class="counter qty">
<span data-bind="text: getCounterLabel()"></span>
</span>
<!-- /ko -->
</a>
</li>
<script type="text/x-magento-init">
{"[data-role=compare-products-link]": {"Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>}}
{
"[data-role=compare-products-link]": {
"Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@
*/

// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis

/* @var $block \Magento\Framework\View\Element\Template */
?>
<?php
/** @var \Magento\Framework\View\Element\Template $block */
/** @var \Magento\Catalog\ViewModel\Product\Compare\Sidebar $viewModel */
$viewModel = $block->getData('compare_view_model');
?>
<div class="block block-compare" data-bind="scope: 'compareProducts'" data-role="compare-products-sidebar">
<div class="block-title">
<strong id="block-compare-heading" role="heading" aria-level="2"><?= $block->escapeHtml(__('Compare Products')) ?></strong>
<span class="counter qty no-display" data-bind="text: compareProducts().countCaption, css: {'no-display': !compareProducts().count}"></span>
<strong id="block-compare-heading" role="heading" aria-level="2">
<?= $block->escapeHtml(__('Compare Products')) ?>
</strong>
<!-- ko if: compareProducts().count -->
<span class="counter no-display" data-bind="css: {'no-display': !compareProducts().count}">
<span data-bind="text: getCounterLabel()"></span>
</span>
<!-- /ko -->
</div>
<!-- ko if: compareProducts().count -->
<div class="block-content no-display" aria-labelledby="block-compare-heading" data-bind="css: {'no-display': !compareProducts().count}">
<div class="block-content no-display"
aria-labelledby="block-compare-heading"
data-bind="css: {'no-display': !compareProducts().count}">
<ol id="compare-items" class="product-items product-items-names" data-bind="foreach: compareProducts().items">
<li class="product-item">
<input type="hidden" class="compare-item-id" data-bind="value: id"/>
Expand All @@ -31,12 +42,16 @@
</ol>
<div class="actions-toolbar">
<div class="primary">
<a data-bind="attr: {'href': compareProducts().listUrl}" class="action compare primary"><span><?= $block->escapeHtml(__('Compare')) ?></span></a>
<a data-bind="attr: {'href': compareProducts().listUrl}"
class="action compare primary">
<span><?= $block->escapeHtml(__('Compare')) ?></span>
</a>
</div>
<div class="secondary">
<a id="compare-clear-all" href="#" class="action clear" data-post="<?=$block->escapeHtml(
$this->helper(Magento\Catalog\Helper\Product\Compare::class)->getPostDataClearList()
) ?>">
<a id="compare-clear-all"
href="#"
class="action clear"
data-post="<?=$block->escapeHtml($viewModel->getClearCompareListParameters()) ?>">
<span><?= $block->escapeHtml(__('Clear All')) ?></span>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});
});
5 changes: 2 additions & 3 deletions app/code/Magento/Wishlist/Block/Customer/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
20 changes: 2 additions & 18 deletions app/code/Magento/Wishlist/CustomerData/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testGetSectionData()
$itemRemoveParams = ['remove_params'];

$result = [
'counter' => __('1 item'),
'counter' => 1,
'items' => [
[
'image' => [
Expand Down Expand Up @@ -289,7 +289,7 @@ public function testGetSectionDataWithTwoItems()
$items = [$itemMock, $itemMock];

$result = [
'counter' => __('%1 items', count($items)),
'counter' => 2,
'items' => [
[
'image' => [
Expand Down Expand Up @@ -466,7 +466,7 @@ public function testGetSectionDataWithoutItems()
$items = [];

$result = [
'counter' => null,
'counter' => 0,
'items' => [],
];

Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Wishlist/view/frontend/templates/link.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
<li class="link wishlist" data-bind="scope: 'wishlist'">
<a <?= /* @noEscape */ $block->getLinkAttributes() ?>><?= $block->escapeHtml($block->getLabel()) ?>
<!-- ko if: wishlist().counter -->
<span data-bind="text: wishlist().counter" class="counter qty"></span>
<span class="counter qty">
<span data-bind="text: getCounterLabel()"></span>
</span>
<!-- /ko -->
</a>
</li>
<script type="text/x-magento-init">
{
"*": {
".wishlist.link": {
"Magento_Ui/js/core/app": {
"components": {
"wishlist": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var \Magento\Wishlist\Block\Customer\Sidebar $block */
?>
<?php
$wishlstViewModel = $block->getData('wishlistDataViewModel');
Expand All @@ -14,7 +12,9 @@ $wishlstViewModel = $block->getData('wishlistDataViewModel');
<div class="block-title">
<strong role="heading" aria-level="2"><?= $block->escapeHtml($block->getTitle()) ?></strong>
<!-- ko if: wishlist().counter -->
<span data-bind="text: wishlist().counter" class="counter"></span>
<span class="counter no-display" data-bind="css: {'no-display': !wishlist().counter}">
<span data-bind="text: getCounterLabel()"></span>
</span>
<!-- /ko -->
</div>
<div class="block-content">
Expand Down
Loading