Skip to content

Commit fd14d87

Browse files
ENGCOM-3540: [Backport] #13157 - Last Ordered Items block - bad js code #19357
- Merge Pull Request #19357 from gelanivishal/magento2:2.2-develop-PR-port-19039 - Merged commits: 1. 7559e3e 2. 58550b9 3. f1bb98e
2 parents 13de5a7 + f1bb98e commit fd14d87

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

app/code/Magento/Sales/view/frontend/templates/reorder/sidebar.phtml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
<ol id="cart-sidebar-reorder" class="product-items product-items-names"
2727
data-bind="foreach: lastOrderedItems().items">
2828
<li class="product-item">
29-
<div class="field item choice no-display" data-bind="css: {'no-display': !is_saleable}">
29+
<div class="field item choice">
3030
<label class="label" data-bind="attr: {'for': 'reorder-item-' + id}">
3131
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
3232
</label>
3333
<div class="control">
3434
<input type="checkbox" name="order_items[]"
35-
data-bind="attr: {id: 'reorder-item-' + id, value: id}"
36-
title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>"
35+
data-bind="attr: {
36+
id: 'reorder-item-' + id,
37+
value: id,
38+
title: is_saleable ? '<?= /* @escapeNotVerified */ __('Add to Cart') ?>' : '<?= /* @escapeNotVerified */ __('Product is not salable.') ?>'
39+
},
40+
disable: !is_saleable"
3741
class="checkbox" data-validate='{"validate-one-checkbox-required-by-name": true}'/>
3842
</div>
3943
</div>
@@ -46,8 +50,8 @@
4650
</ol>
4751
<div id="cart-sidebar-reorder-advice-container"></div>
4852
<div class="actions-toolbar">
49-
<div class="primary no-display"
50-
data-bind="css: {'no-display': !lastOrderedItems().isShowAddToCart}">
53+
<div class="primary"
54+
data-bind="visible: isShowAddToCart">
5155
<button type="submit" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>" class="action tocart primary">
5256
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
5357
</button>

app/code/Magento/Sales/view/frontend/web/js/view/last-ordered-items.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,43 @@
55

66
define([
77
'uiComponent',
8-
'Magento_Customer/js/customer-data'
9-
], function (Component, customerData) {
8+
'Magento_Customer/js/customer-data',
9+
'underscore'
10+
], function (Component, customerData, _) {
1011
'use strict';
1112

1213
return Component.extend({
14+
defaults: {
15+
isShowAddToCart: false
16+
},
17+
1318
/** @inheritdoc */
1419
initialize: function () {
15-
var isShowAddToCart = false,
16-
item;
17-
1820
this._super();
1921
this.lastOrderedItems = customerData.get('last-ordered-items');
22+
this.lastOrderedItems.subscribe(this.checkSalableItems.bind(this));
23+
this.checkSalableItems();
24+
25+
return this;
26+
},
27+
28+
/** @inheritdoc */
29+
initObservable: function () {
30+
this._super()
31+
.observe('isShowAddToCart');
32+
33+
return this;
34+
},
2035

21-
for (item in this.lastOrderedItems.items) {
22-
if (item['is_saleable']) {
23-
isShowAddToCart = true;
24-
break;
25-
}
26-
}
36+
/**
37+
* Check if items is_saleable and change add to cart button visibility.
38+
*/
39+
checkSalableItems: function () {
40+
var isShowAddToCart = _.some(this.lastOrderedItems().items, {
41+
'is_saleable': true
42+
});
2743

28-
this.lastOrderedItems.isShowAddToCart = isShowAddToCart;
44+
this.isShowAddToCart(isShowAddToCart);
2945
}
3046
});
3147
});

0 commit comments

Comments
 (0)