Skip to content

Commit

Permalink
fix(storefront): BCTHEME-490 Translation Gap: Compare products error …
Browse files Browse the repository at this point in the history
…message (#2061)

Co-authored-by: yurytut1993 <66325265+yurytut1993@users.noreply.github.com>
  • Loading branch information
bc-vlad-dlogush and yurytut1993 authored May 27, 2021
1 parent 9ca4c74 commit 64348b2
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Translation Gap: Compare products error message. [#2061](https://github.com/bigcommerce/cornerstone/pull/2061)
- Translation Gap: Gift Certificate -> Code required message. [#2064](https://github.com/bigcommerce/cornerstone/pull/2064)
- Added translation for invalid quantity value error on Cart. [#2062](https://github.com/bigcommerce/cornerstone/pull/2062)
- Translation Gap: Delete from Cart confirmation popup. [#2065](https://github.com/bigcommerce/cornerstone/pull/2065)
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Account extends PageManager {
const $reorderForm = classifyForm('[data-account-reorder-form]');
const $invoiceButton = $('[data-print-invoice]');

compareProducts(this.context.urls);
compareProducts(this.context);

// Injected via template
this.passwordRequirements = this.context.passwordRequirements;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/brand.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Brand extends CatalogPage {
}

onReady() {
compareProducts(this.context.urls);
compareProducts(this.context);

if ($('#facetedSearch').length > 0) {
this.initFacetedSearch();
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Category extends CatalogPage {

this.makeShopByPriceFilterAccessible();

compareProducts(this.context.urls);
compareProducts(this.context);

if ($('#facetedSearch').length > 0) {
this.initFacetedSearch();
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import compareProducts from './global/compare-products';

export default class Compare extends PageManager {
onReady() {
compareProducts(this.context.urls);
compareProducts(this.context);

const message = this.context.compareRemoveMessage;

Expand Down
14 changes: 7 additions & 7 deletions assets/js/theme/global/compare-products.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ function incrementCounter(counter, item) {
counter.push(item);
}

function updateCounterNav(counter, $link, urlContext) {
function updateCounterNav(counter, $link, urls) {
if (counter.length !== 0) {
if (!$link.is('visible')) {
$link.addClass('show');
}
$link.attr('href', `${urlContext.compare}/${counter.join('/')}`);
$link.attr('href', `${urls.compare}/${counter.join('/')}`);
$link.find('span.countPill').html(counter.length);
} else {
$link.removeClass('show');
}
}

export default function (urlContext) {
export default function ({ noCompareMessage, urls }) {
let compareCounter = [];

const $compareLink = $('a[data-compare-nav]');
Expand All @@ -33,7 +33,7 @@ export default function (urlContext) {
const $checked = $('body').find('input[name="products\[\]"]:checked');

compareCounter = $checked.length ? $checked.map((index, element) => element.value).get() : [];
updateCounterNav(compareCounter, $compareLink, urlContext);
updateCounterNav(compareCounter, $compareLink, urls);
});

$('body').triggerHandler('compareReset');
Expand All @@ -48,15 +48,15 @@ export default function (urlContext) {
decrementCounter(compareCounter, product);
}

updateCounterNav(compareCounter, $clickedCompareLink, urlContext);
updateCounterNav(compareCounter, $clickedCompareLink, urls);
});

$('body').on('submit', '[data-product-compare]', event => {
const $this = $(event.currentTarget);
const productsToCompare = $this.find('input[name="products\[\]"]:checked');

if (productsToCompare.length <= 1) {
showAlertModal('You must select at least two products to compare');
showAlertModal(noCompareMessage);
event.preventDefault();
}
});
Expand All @@ -65,7 +65,7 @@ export default function (urlContext) {
const $clickedCheckedInput = $('body').find('input[name="products\[\]"]:checked');

if ($clickedCheckedInput.length <= 1) {
showAlertModal('You must select at least two products to compare');
showAlertModal(noCompareMessage);
return false;
}
});
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default class Search extends CatalogPage {
}

onReady() {
compareProducts(this.context.urls);
compareProducts(this.context);
this.arrangeFocusOnSortBy();

const $searchForm = $('[data-advanced-search-form]');
Expand Down
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@
"header": "Comparing {products, plural, one {# Product} other {# Products}}",
"remove": "Remove",
"no_remove": "At least 2 products are needed to make a valid comparison.",
"add_to_cart": "Add to cart"
"add_to_cart": "Add to cart",
"no_compare": "You must select at least two products to compare"
},
"category": {
"label": "Categories",
Expand Down
2 changes: 2 additions & 0 deletions templates/components/brand/product-listing.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject 'noCompareMessage' (lang 'compare.no_compare')}}

{{> components/products/filter sort=pagination.brand.sort}}

<form action="{{urls.compare}}" method='POST' {{#if settings.data_tag_enabled}} data-list-name="Brand: {{brand.name}}" {{/if}} data-product-compare>
Expand Down
2 changes: 2 additions & 0 deletions templates/components/category/product-listing.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject 'noCompareMessage' (lang 'compare.no_compare')}}

{{#if category.products}}
{{> components/products/filter sort=pagination.category.sort}}

Expand Down
2 changes: 2 additions & 0 deletions templates/components/search/product-listing.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{inject 'noCompareMessage' (lang 'compare.no_compare')}}

{{#if product_results.products.length}}
{{> components/products/filter sort=pagination.product_results.sort}}
{{/if}}
Expand Down

0 comments on commit 64348b2

Please sign in to comment.