Skip to content

Commit d8d701c

Browse files
committed
Merge branch 'MAGETWO-69080' into MPI-PR-2.1.10
2 parents f1c36f7 + adac10b commit d8d701c

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

app/code/Magento/Checkout/CustomerData/DefaultItem.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected function doGetItemData()
7070
'item_id' => $this->item->getId(),
7171
'configure_url' => $this->getConfigureUrl(),
7272
'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(),
73+
'product_id' => $this->item->getProduct()->getId(),
7374
'product_name' => $this->item->getProduct()->getName(),
7475
'product_sku' => $this->item->getProduct()->getSku(),
7576
'product_url' => $this->getProductUrl(),

app/code/Magento/Checkout/view/frontend/layout/checkout_cart_configure.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
-->
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<head>
10+
<link src="Magento_Checkout::js/view/configure/product-customer-data.js"/>
11+
</head>
912
<update handle="catalog_product_view"/>
1013
<body>
1114
<referenceBlock name="head.components">

app/code/Magento/Checkout/view/frontend/templates/cart/item/configure/updatecart.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="field qty">
1818
<label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
1919
<div class="control">
20-
<input type="number" name="qty" id="qty" maxlength="12" value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="{'required-number':true,digits:true}"/>
20+
<input type="number" name="qty" id="qty" maxlength="12" value="" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="{'required-number':true,digits:true}"/>
2121
</div>
2222
</div>
2323
<?php endif; ?>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require([
2+
'jquery',
3+
'Magento_Customer/js/customer-data'
4+
], function ($, customerData) {
5+
'use strict';
6+
7+
var selectors = {
8+
qtySelector: '#product_addtocart_form [name="qty"]',
9+
productIdSelector: '#product_addtocart_form [name="product"]'
10+
},
11+
cartData = customerData.get('cart'),
12+
productId = $(selectors.productIdSelector).val(),
13+
productQty,
14+
productQtyInput,
15+
16+
/**
17+
* Updates product's qty input value according to actual data
18+
*/
19+
updateQty = function () {
20+
21+
if (productQty || productQty === 0) {
22+
productQtyInput = productQtyInput || $(selectors.qtySelector);
23+
24+
if (productQtyInput && productQty.toString() !== productQtyInput.val()) {
25+
productQtyInput.val(productQty);
26+
}
27+
}
28+
},
29+
30+
/**
31+
* Sets productQty according to cart data from customer-data
32+
*
33+
* @param {Object} data - cart data from customer-data
34+
*/
35+
setProductQty = function (data) {
36+
var product;
37+
38+
if (!(data && data.items && data.items.length && productId)) {
39+
return;
40+
}
41+
product = data.items.find(function (item) {
42+
return item['product_id'] === productId ||
43+
item['item_id'] === productId;
44+
});
45+
46+
if (!product) {
47+
return;
48+
}
49+
productQty = product.qty;
50+
};
51+
52+
cartData.subscribe(function (updateCartData) {
53+
setProductQty(updateCartData);
54+
updateQty();
55+
});
56+
57+
setProductQty(cartData());
58+
updateQty();
59+
});

0 commit comments

Comments
 (0)