Skip to content

Commit b3d6dc8

Browse files
committed
Merge branch 'MAGETWO-60594' into bugfix
2 parents bd22a2c + 2786d73 commit b3d6dc8

File tree

10 files changed

+184
-23
lines changed

10 files changed

+184
-23
lines changed

app/code/Magento/Bundle/Model/CartItemProcessor.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,28 @@ public function processOptions(CartItemInterface $cartItem)
8484
$productOptions = [];
8585
$bundleOptions = $cartItem->getBuyRequest()->getBundleOption();
8686
$bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty();
87-
foreach ($bundleOptions as $optionId => $optionSelections) {
88-
if (empty($optionSelections)) {
89-
continue;
90-
}
91-
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
92-
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;
87+
if (is_array($bundleOptions)) {
88+
foreach ($bundleOptions as $optionId => $optionSelections) {
89+
if (empty($optionSelections)) {
90+
continue;
91+
}
92+
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
93+
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;
9394

94-
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
95-
$productOption = $this->bundleOptionFactory->create();
96-
$productOption->setOptionId($optionId);
97-
$productOption->setOptionSelections($optionSelections);
98-
$productOption->setOptionQty($optionQty);
99-
$productOptions[] = $productOption;
100-
}
95+
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
96+
$productOption = $this->bundleOptionFactory->create();
97+
$productOption->setOptionId($optionId);
98+
$productOption->setOptionSelections($optionSelections);
99+
$productOption->setOptionQty($optionQty);
100+
$productOptions[] = $productOption;
101+
}
101102

102-
$extension = $this->productOptionExtensionFactory->create()->setBundleOptions($productOptions);
103-
if (!$cartItem->getProductOption()) {
104-
$cartItem->setProductOption($this->productOptionFactory->create());
103+
$extension = $this->productOptionExtensionFactory->create()->setBundleOptions($productOptions);
104+
if (!$cartItem->getProductOption()) {
105+
$cartItem->setProductOption($this->productOptionFactory->create());
106+
}
107+
$cartItem->getProductOption()->setExtensionAttributes($extension);
105108
}
106-
$cartItem->getProductOption()->setExtensionAttributes($extension);
107109
return $cartItem;
108110
}
109111
}

app/code/Magento/Bundle/Test/Unit/Model/CartItemProcessorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,22 @@ public function testProcessProductOptionsInvalidType()
180180
$cartItemMock->expects($this->once())->method('getProductType')->willReturn(Type::TYPE_SIMPLE);
181181
$this->assertSame($cartItemMock, $this->model->processOptions($cartItemMock));
182182
}
183+
184+
public function testProcessProductOptionsifBundleOptionsNotExists()
185+
{
186+
$buyRequestMock = new \Magento\Framework\DataObject(
187+
[]
188+
);
189+
$methods = ['getProductType', 'getBuyRequest'];
190+
$cartItemMock = $this->getMock(
191+
\Magento\Quote\Model\Quote\Item::class,
192+
$methods,
193+
[],
194+
'',
195+
false
196+
);
197+
$cartItemMock->expects($this->once())->method('getProductType')->willReturn(Type::TYPE_BUNDLE);
198+
$cartItemMock->expects($this->exactly(2))->method('getBuyRequest')->willReturn($buyRequestMock);
199+
$this->assertSame($cartItemMock, $this->model->processOptions($cartItemMock));
200+
}
183201
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ define([
112112
};
113113
}
114114

115-
if (!$.isEmptyObject(dataToAdd)) {
116-
self._removeExcessiveData(params, dataToAdd);
117-
}
118-
119115
params.data = $.extend({}, params.data, dataToAdd, {
120116
'qty': $(self.options.qtyInfo).val()
121117
});
@@ -128,6 +124,7 @@ define([
128124
* @param {Object} array2
129125
* @return {Object}
130126
* @private
127+
* @deprecated
131128
*/
132129
_arrayDiffByKeys: function (array1, array2) {
133130
var result = {};
@@ -186,6 +183,7 @@ define([
186183
* @param {Object} params
187184
* @param {Object} dataToAdd
188185
* @private
186+
* @deprecated
189187
*/
190188
_removeExcessiveData: function (params, dataToAdd) {
191189
var dataToRemove = this._arrayDiffByKeys(params.data, dataToAdd);

dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,5 +449,34 @@
449449
<item name="dataset" xsi:type="string">bundle_default_dynamic</item>
450450
</field>
451451
</dataset>
452+
453+
<dataset name="default_with_one_simple_product_and_custom_option">
454+
<field name="name" xsi:type="string">Bundle dynamic product %isolation%</field>
455+
<field name="url_key" xsi:type="string">bundle-dynamic-product-%isolation%</field>
456+
<field name="sku" xsi:type="string">sku_bundle_dynamic_product_%isolation%</field>
457+
<field name="sku_type" xsi:type="string">Yes</field>
458+
<field name="price_type" xsi:type="string">Yes</field>
459+
<field name="shipment_type" xsi:type="string">Together</field>
460+
<field name="quantity_and_stock_status" xsi:type="array">
461+
<item name="is_in_stock" xsi:type="string">In Stock</item>
462+
</field>
463+
<field name="price" xsi:type="array">
464+
<item name="dataset" xsi:type="string">bundle_dynamic_with_category</item>
465+
</field>
466+
<field name="website_ids" xsi:type="array">
467+
<item name="0" xsi:type="array">
468+
<item name="dataset" xsi:type="string">default</item>
469+
</item>
470+
</field>
471+
<field name="bundle_selections" xsi:type="array">
472+
<item name="dataset" xsi:type="string">one_simple_product</item>
473+
</field>
474+
<field name="custom_options" xsi:type="array">
475+
<item name="dataset" xsi:type="string">two_fixed_radio_options</item>
476+
</field>
477+
<field name="checkout_data" xsi:type="array">
478+
<item name="dataset" xsi:type="string">default_with_one_simple_product_and_custom_option</item>
479+
</field>
480+
</dataset>
452481
</repository>
453482
</config>

dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct/CheckoutData.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,5 +451,16 @@
451451
</item>
452452
</field>
453453
</dataset>
454+
455+
<dataset name="default_with_one_simple_product_and_custom_option">
456+
<field name="options" xsi:type="array">
457+
<item name="custom_options" xsi:type="array">
458+
<item name="0" xsi:type="array">
459+
<item name="title" xsi:type="string">attribute_key_0</item>
460+
<item name="value" xsi:type="string">option_key_0</item>
461+
</item>
462+
</item>
463+
</field>
464+
</dataset>
454465
</repository>
455466
</config>

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Link.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ public function proceedToCheckout()
2424
{
2525
$this->_rootElement->click();
2626
}
27+
28+
/**
29+
* Get title of Proceed to Checkout link
30+
*
31+
* @return string
32+
*/
33+
public function getTitle()
34+
{
35+
return $this->_rootElement->getText();
36+
}
2737
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\Constraint;
8+
9+
use Magento\Checkout\Test\Page\CheckoutCart;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Mtf\Fixture\FixtureInterface;
12+
13+
/**
14+
* Class AssertProceedToCheckoutButton
15+
* Assert it is possible to proceed to checkout from Shopping Cart page
16+
*/
17+
class AssertProceedToCheckoutButton extends AbstractConstraint
18+
{
19+
/**
20+
* Success add to cart message
21+
*/
22+
const BUTTON_TITLE = 'Proceed to Checkout';
23+
24+
/**
25+
* Assert success message is appeared on Shopping Cart page
26+
*
27+
* @param CheckoutCart $checkoutCart
28+
* @param FixtureInterface $product
29+
* @return void
30+
*/
31+
public function processAssert(CheckoutCart $checkoutCart)
32+
{
33+
$checkoutCart->open();
34+
\PHPUnit_Framework_Assert::assertEquals(
35+
self::BUTTON_TITLE,
36+
$checkoutCart->getProceedToCheckoutBlock()->getTitle()
37+
);
38+
}
39+
40+
/**
41+
* Returns string representation of successful assertion
42+
*
43+
* @return string
44+
*/
45+
public function toString()
46+
{
47+
return 'Proceed To Checkout button presents in the Shopping Cart.';
48+
}
49+
}

dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class AddProductsToCartFromCustomerWishlistOnFrontendTest extends AbstractWishli
4040
* @param bool $toUpdate
4141
* @return array
4242
*/
43-
public function test(Customer $customer, $products, $qty, $toUpdate = true)
43+
public function test(Customer $customer, $products, $qty, $toUpdate = true, $toConfigure = false)
4444
{
4545
// Preconditions
4646
$customer->persist();
4747
$this->loginCustomer($customer);
4848
$products = $this->createProducts($products);
49-
$this->addToWishlist($products);
49+
$this->addToWishlist($products, $toConfigure);
5050

5151
// Steps
5252
$this->addToCart($products, $qty, $toUpdate);

dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,14 @@
6464
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
6565
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
6666
</variation>
67+
68+
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation9">
69+
<data name="products/0" xsi:type="string">bundleProduct::default_with_one_simple_product_and_custom_option</data>
70+
<data name="qty" xsi:type="string">1</data>
71+
<data name="toConfigure" xsi:type="boolean">true</data>
72+
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
73+
<constraint name="Magento\Checkout\Test\Constraint\AssertProceedToCheckoutButton" />
74+
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
75+
</variation>
6776
</testCase>
6877
</config>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'Magento_Wishlist/js/add-to-wishlist'
9+
], function ($) {
10+
'use strict';
11+
12+
describe('Testing addToWishlist widget', function () {
13+
var wdContainer;
14+
15+
beforeEach(function () {
16+
wdContainer = $('<input type="hidden" class="bundle-option-11 product bundle option" \n' +
17+
'name="bundle_option[11]" value="15" aria-required="true"/>');
18+
});
19+
20+
afterEach(function () {
21+
$(wdContainer).remove();
22+
});
23+
24+
it('widget extends jQuery object', function () {
25+
expect($.fn.addToWishlist).toBeDefined();
26+
});
27+
28+
it('widget gets options', function () {
29+
wdContainer.addToWishlist({
30+
'bundleInfo': 'test'
31+
});
32+
expect(wdContainer.addToWishlist('option', 'bundleInfo')).toBe('test');
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)