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

fix(storefront): BCTHEME-490 Translation Gap: Compare products error message #2061

Merged
merged 2 commits into from
May 27, 2021
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
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to give more comprehensive name for this message, for example "product_quantity_validation", so with the name of section the full path to this message will be "compare.product_quantity_validation". For me it sounds much more understandable than "compare.no_compare"
I can see you choose that name as it's similar to "no_remove", but still :)
It's not a major point though, so decision is up to you

},
"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