File tree 2 files changed +37
-17
lines changed
app/code/Magento/Sales/view/frontend 2 files changed +37
-17
lines changed Original file line number Diff line number Diff line change 26
26
<ol id="cart-sidebar-reorder" class="product-items product-items-names"
27
27
data-bind="foreach: lastOrderedItems().items">
28
28
<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">
30
30
<label class="label" data-bind="attr: {'for': 'reorder-item-' + id}">
31
31
<span><?= /* @escapeNotVerified */ __ ('Add to Cart ' ) ?> </span>
32
32
</label>
33
33
<div class="control">
34
34
<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"
37
41
class="checkbox" data-validate='{"validate-one-checkbox-required-by-name": true}'/>
38
42
</div>
39
43
</div>
46
50
</ol>
47
51
<div id="cart-sidebar-reorder-advice-container"></div>
48
52
<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">
51
55
<button type="submit" title="<?= /* @escapeNotVerified */ __ ('Add to Cart ' ) ?> " class="action tocart primary">
52
56
<span><?= /* @escapeNotVerified */ __ ('Add to Cart ' ) ?> </span>
53
57
</button>
Original file line number Diff line number Diff line change 5
5
6
6
define ( [
7
7
'uiComponent' ,
8
- 'Magento_Customer/js/customer-data'
9
- ] , function ( Component , customerData ) {
8
+ 'Magento_Customer/js/customer-data' ,
9
+ 'underscore'
10
+ ] , function ( Component , customerData , _ ) {
10
11
'use strict' ;
11
12
12
13
return Component . extend ( {
14
+ defaults : {
15
+ isShowAddToCart : false
16
+ } ,
17
+
13
18
/** @inheritdoc */
14
19
initialize : function ( ) {
15
- var isShowAddToCart = false ,
16
- item ;
17
-
18
20
this . _super ( ) ;
19
21
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
+ } ,
20
35
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
+ } ) ;
27
43
28
- this . lastOrderedItems . isShowAddToCart = isShowAddToCart ;
44
+ this . isShowAddToCart ( isShowAddToCart ) ;
29
45
}
30
46
} ) ;
31
47
} ) ;
You can’t perform that action at this time.
0 commit comments