Skip to content

Commit ae479dd

Browse files
author
okarpenko
committed
Merge branch 'MAGETWO-34757' into BUGS
2 parents cce7a6a + 15c8500 commit ae479dd

File tree

2 files changed

+65
-51
lines changed

2 files changed

+65
-51
lines changed

app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,20 @@ public function save($product)
326326
return $this;
327327
}
328328

329+
protected function getProductInfo(\Magento\Framework\Object $buyRequest, $product)
330+
{
331+
$productsInfo = $buyRequest->getSuperGroup() ?: [];
332+
333+
$associatedProducts = $this->getAssociatedProducts($product);
334+
foreach ($associatedProducts as $subProduct) {
335+
if (!isset($productsInfo[$subProduct->getId()])) {
336+
$productsInfo[$subProduct->getId()] = intval($subProduct->getQty());
337+
}
338+
}
339+
340+
return $productsInfo;
341+
}
342+
329343
/**
330344
* Prepare product and its configuration to be added to some products list.
331345
* Perform standard preparation process and add logic specific to Grouped product type.
@@ -338,67 +352,63 @@ public function save($product)
338352
*/
339353
protected function _prepareProduct(\Magento\Framework\Object $buyRequest, $product, $processMode)
340354
{
341-
$productsInfo = $buyRequest->getSuperGroup();
355+
$products = [];
356+
$associatedProductsInfo = [];
357+
$productsInfo = $this->getProductInfo($buyRequest, $product);
342358
$isStrictProcessMode = $this->_isStrictProcessMode($processMode);
359+
$associatedProducts = !$isStrictProcessMode || !empty($productsInfo)
360+
? $this->getAssociatedProducts($product)
361+
: false;
343362

344-
if (!$isStrictProcessMode || !empty($productsInfo) && is_array($productsInfo)) {
345-
$products = [];
346-
$associatedProductsInfo = [];
347-
$associatedProducts = $this->getAssociatedProducts($product);
348-
if ($associatedProducts || !$isStrictProcessMode) {
349-
foreach ($associatedProducts as $subProduct) {
350-
$subProductId = $subProduct->getId();
351-
if (isset($productsInfo[$subProductId])) {
352-
$qty = $productsInfo[$subProductId];
353-
if (!empty($qty) && is_numeric($qty)) {
354-
$_result = $subProduct->getTypeInstance()->_prepareProduct(
355-
$buyRequest,
356-
$subProduct,
357-
$processMode
358-
);
359-
if (is_string($_result) && !is_array($_result)) {
360-
return $_result;
361-
}
362-
363-
if (!isset($_result[0])) {
364-
return __('We cannot process the item.')->render();
365-
}
366-
367-
if ($isStrictProcessMode) {
368-
$_result[0]->setCartQty($qty);
369-
$_result[0]->addCustomOption(
370-
'info_buyRequest',
371-
serialize(
372-
[
373-
'super_product_config' => [
374-
'product_type' => self::TYPE_CODE,
375-
'product_id' => $product->getId(),
376-
],
377-
]
378-
)
379-
);
380-
$products[] = $_result[0];
381-
} else {
382-
$associatedProductsInfo[] = [$subProductId => $qty];
383-
$product->addCustomOption('associated_product_' . $subProductId, $qty);
384-
}
385-
}
386-
}
387-
}
363+
if ($associatedProducts && empty($productsInfo)) {
364+
return __('Please specify the quantity of product(s).')->render();
365+
}
366+
367+
foreach ($associatedProducts as $subProduct) {
368+
$qty = $productsInfo[$subProduct->getId()];
369+
if (!is_numeric($qty)) {
370+
continue;
388371
}
389372

390-
if (!$isStrictProcessMode || count($associatedProductsInfo)) {
391-
$product->addCustomOption('product_type', self::TYPE_CODE, $product);
392-
$product->addCustomOption('info_buyRequest', serialize($buyRequest->getData()));
373+
$_result = $subProduct->getTypeInstance()->_prepareProduct($buyRequest, $subProduct,$processMode);
393374

394-
$products[] = $product;
375+
if (is_string($_result)) {
376+
return $_result;
377+
} elseif (!isset($_result[0])) {
378+
return __('Cannot process the item.')->render();
395379
}
396380

397-
if (count($products)) {
398-
return $products;
381+
if ($isStrictProcessMode) {
382+
$_result[0]->setCartQty($qty);
383+
$_result[0]->addCustomOption(
384+
'info_buyRequest',
385+
serialize(
386+
[
387+
'super_product_config' => [
388+
'product_type' => self::TYPE_CODE,
389+
'product_id' => $product->getId(),
390+
],
391+
]
392+
)
393+
);
394+
$products[] = $_result[0];
395+
} else {
396+
$associatedProductsInfo[] = [$subProduct->getId() => $qty];
397+
$product->addCustomOption('associated_product_' . $subProduct->getId(), $qty);
399398
}
400399
}
401400

401+
if (!$isStrictProcessMode || count($associatedProductsInfo)) {
402+
$product->addCustomOption('product_type', self::TYPE_CODE, $product);
403+
$product->addCustomOption('info_buyRequest', serialize($buyRequest->getData()));
404+
405+
$products[] = $product;
406+
}
407+
408+
if (count($products)) {
409+
return $products;
410+
}
411+
402412
return __('Please specify the quantity of product(s).')->render();
403413
}
404414

app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ define([
3939
dataOrigin = $.extend({}, dataOrigin, self._getElementData(element, 1));
4040
if ($(element).is(':checked') || $(element).find(':checked').length) {
4141
dataToAdd = $.extend({}, dataToAdd, self._getElementData(element));
42+
} else {
43+
dataToAdd = dataOrigin;
4244
}
4345
});
4446
$('[data-action="add-to-wishlist"]').each(function(index, element) {
4547
var params = $(element).data('post');
4648
if (!params)
4749
params = {};
50+
4851
self._removeExcessiveData(params, dataOrigin, dataToAdd);
4952
params.data = $.extend({}, params.data, dataToAdd, {'qty': $(self.options.qtyInfo).val()});
53+
5054
$(element).data('post', params);
5155
});
5256
event.stopPropagation();

0 commit comments

Comments
 (0)