Skip to content

Commit f1bb98e

Browse files
omiroshnichenkogelanivishal
authored andcommitted
#13157 - Last Ordered Items block - bad js code
1 parent 58550b9 commit f1bb98e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<div id="cart-sidebar-reorder-advice-container"></div>
5252
<div class="actions-toolbar">
5353
<div class="primary"
54-
data-bind="visible: lastOrderedItems.isShowAddToCart">
54+
data-bind="visible: isShowAddToCart">
5555
<button type="submit" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>" class="action tocart primary">
5656
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
5757
</button>

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,37 @@ define([
1111
'use strict';
1212

1313
return Component.extend({
14+
defaults: {
15+
isShowAddToCart: false
16+
},
17+
1418
/** @inheritdoc */
1519
initialize: function () {
16-
var isShowAddToCart;
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-
isShowAddToCart = _.some(this.lastOrderedItems().items, {
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, {
2241
'is_saleable': true
2342
});
2443

25-
this.lastOrderedItems.isShowAddToCart = isShowAddToCart;
44+
this.isShowAddToCart(isShowAddToCart);
2645
}
2746
});
2847
});

0 commit comments

Comments
 (0)