Skip to content

Commit

Permalink
ENGCOM-1336: Display Wrong Data On Cart Update Page #14765
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Apr 22, 2018
2 parents 73af74a + 175c938 commit 93752e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $_product->getId() ?>" />
<input type="hidden" name="selected_configurable_option" value="" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
<input type="hidden" name="item" value="<?= /* @noEscape */ $block->getRequest()->getParam('id') ?>" />
<?= $block->getBlockHtml('formkey') ?>
<?= $block->getChildHtml('form_top') ?>
<?php if (!$block->hasOptions()):?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ require([

var selectors = {
qtySelector: '#product_addtocart_form [name="qty"]',
productIdSelector: '#product_addtocart_form [name="product"]'
productIdSelector: '#product_addtocart_form [name="product"]',
itemIdSelector: '#product_addtocart_form [name="item"]'
},
cartData = customerData.get('cart'),
productId = $(selectors.productIdSelector).val(),
itemId = $(selectors.itemIdSelector).val(),
productQty,
productQtyInput,

Expand Down Expand Up @@ -40,8 +42,10 @@ require([
return;
}
product = data.items.find(function (item) {
return item['product_id'] === productId ||
item['item_id'] === productId;
if (item['item_id'] === itemId) {
return item['product_id'] === productId ||
item['item_id'] === productId;
}
});

if (!product) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ define([

var selectors = {
formSelector: '#product_addtocart_form',
productIdSelector: '#product_addtocart_form [name="product"]'
productIdSelector: '#product_addtocart_form [name="product"]',
itemIdSelector: '#product_addtocart_form [name="item"]'
},
cartData = customerData.get('cart'),
productId = $(selectors.productIdSelector).val(),
itemId = $(selectors.itemIdSelector).val(),

/**
* set productOptions according to cart data from customer-data
Expand All @@ -24,8 +26,10 @@ define([
if (!(data && data.items && data.items.length && productId)) {
return false;
}
changedProductOptions = _.find(data.items, function (item) {
return item['product_id'] === productId;
changedProductOptions = data.items.find(function (item) {
if (item['item_id'] === itemId) {
return item['product_id'] === productId;
}
});
changedProductOptions = changedProductOptions && changedProductOptions.options &&
changedProductOptions.options.reduce(function (obj, val) {
Expand Down

0 comments on commit 93752e3

Please sign in to comment.