Skip to content

#13157 - Last Ordered Items block - bad js code #19039

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

Merged
merged 4 commits into from
Nov 22, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@
<ol id="cart-sidebar-reorder" class="product-items product-items-names"
data-bind="foreach: lastOrderedItems().items">
<li class="product-item">
<div class="field item choice no-display" data-bind="css: {'no-display': !is_saleable}">
<div class="field item choice">
<label class="label" data-bind="attr: {'for': 'reorder-item-' + id}">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</label>
<div class="control">
<input type="checkbox" name="order_items[]"
data-bind="attr: {id: 'reorder-item-' + id, value: id}"
title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>"
data-bind="attr: {
id: 'reorder-item-' + id,
value: id,
title: is_saleable ? '<?= /* @escapeNotVerified */ __('Add to Cart') ?>' : '<?= /* @escapeNotVerified */ __('Product is not salable.') ?>'
},
disable: !is_saleable"
class="checkbox" data-validate='{"validate-one-checkbox-required-by-name": true}'/>
</div>
</div>
Expand All @@ -46,8 +50,8 @@
</ol>
<div id="cart-sidebar-reorder-advice-container"></div>
<div class="actions-toolbar">
<div class="primary no-display"
data-bind="css: {'no-display': !lastOrderedItems().isShowAddToCart}">
<div class="primary"
data-bind="visible: isShowAddToCart">
<button type="submit" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>" class="action tocart primary">
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,43 @@

define([
'uiComponent',
'Magento_Customer/js/customer-data'
], function (Component, customerData) {
'Magento_Customer/js/customer-data',
'underscore'
], function (Component, customerData, _) {
'use strict';

return Component.extend({
defaults: {
isShowAddToCart: false
},

/** @inheritdoc */
initialize: function () {
var isShowAddToCart = false,
item;

this._super();
this.lastOrderedItems = customerData.get('last-ordered-items');
this.lastOrderedItems.subscribe(this.checkSalableItems.bind(this));
this.checkSalableItems();

return this;
},

/** @inheritdoc */
initObservable: function () {
this._super()
.observe('isShowAddToCart');

return this;
},

for (item in this.lastOrderedItems.items) {
if (item['is_saleable']) {
isShowAddToCart = true;
break;
}
}
/**
* Check if items is_saleable and change add to cart button visibility.
*/
checkSalableItems: function () {
var isShowAddToCart = _.some(this.lastOrderedItems().items, {
'is_saleable': true
});

this.lastOrderedItems.isShowAddToCart = isShowAddToCart;
this.isShowAddToCart(isShowAddToCart);
}
});
});