Skip to content

Commit 72df274

Browse files
author
Michael Logvin
committed
Merge branch 'MAGETWO-46695' into MAGETWO-46472
2 parents 9fd5ed3 + 91074f2 commit 72df274

File tree

3 files changed

+140
-98
lines changed

3 files changed

+140
-98
lines changed

app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php

Lines changed: 98 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -87,71 +87,115 @@ public function afterInitialize(
8787
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject,
8888
\Magento\Catalog\Model\Product $product
8989
) {
90-
if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
90+
$compositeReadonly = $product->getCompositeReadonly();
91+
$selections = $this->request->getPost('bundle_selections');
92+
if ($selections && !$compositeReadonly) {
9193
$product->setBundleSelectionsData($selections);
9294
}
93-
if (($items = $this->request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
95+
96+
$items = $this->request->getPost('bundle_options');
97+
if ($items && !$compositeReadonly) {
9498
$product->setBundleOptionsData($items);
9599
}
96100

97-
if ($product->getBundleOptionsData()) {
98-
$options = [];
99-
foreach ($product->getBundleOptionsData() as $key => $optionData) {
100-
if (!(bool)$optionData['delete']) {
101-
$option = $this->optionFactory->create(['data' => $optionData]);
102-
$option->setSku($product->getSku());
103-
$option->setOptionId(null);
104-
105-
$links = [];
106-
$bundleLinks = $product->getBundleSelectionsData();
107-
if (!empty($bundleLinks[$key])) {
108-
foreach ($bundleLinks[$key] as $linkData) {
109-
if (!(bool)$linkData['delete']) {
110-
$link = $this->linkFactory->create(['data' => $linkData]);
111-
$linkProduct = $this->productRepository->getById($linkData['product_id']);
112-
$link->setSku($linkProduct->getSku());
113-
$link->setQty($linkData['selection_qty']);
114-
if (isset($linkData['selection_can_change_qty'])) {
115-
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
116-
}
117-
$links[] = $link;
118-
}
119-
}
120-
$option->setProductLinks($links);
121-
$options[] = $option;
122-
}
123-
}
124-
}
125-
$extension = $product->getExtensionAttributes();
126-
$extension->setBundleProductOptions($options);
127-
$product->setExtensionAttributes($extension);
101+
$this->processBundleOptionsData($product);
102+
103+
$this->processDynamicOptionsData($product);
104+
105+
$affectProductSelections = (bool)$this->request->getPost('affect_bundle_product_selections');
106+
$product->setCanSaveBundleSelections($affectProductSelections && !$compositeReadonly);
107+
return $product;
108+
}
109+
110+
/**
111+
* @param \Magento\Catalog\Model\Product $product
112+
* @return void
113+
*/
114+
protected function processBundleOptionsData(\Magento\Catalog\Model\Product $product)
115+
{
116+
$bundleOptionsData = $product->getBundleOptionsData();
117+
if (!$bundleOptionsData) {
118+
return;
128119
}
120+
$options = [];
121+
foreach ($bundleOptionsData as $key => $optionData) {
122+
if ((bool)$optionData['delete']) {
123+
continue;
124+
}
125+
$option = $this->optionFactory->create(['data' => $optionData]);
126+
$option->setSku($product->getSku());
127+
$option->setOptionId(null);
128+
129+
$links = [];
130+
$bundleLinks = $product->getBundleSelectionsData();
131+
if (empty($bundleLinks[$key])) {
132+
continue;
133+
}
134+
135+
foreach ($bundleLinks[$key] as $linkData) {
136+
if ((bool)$linkData['delete']) {
137+
continue;
138+
}
139+
$link = $this->linkFactory->create(['data' => $linkData]);
129140

130-
if (
131-
$product->getPriceType() === \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC
132-
&& !$product->getOptionsReadonly()
133-
) {
134-
$product->setCanSaveCustomOptions(true);
135-
if ($customOptions = $product->getProductOptions()) {
136-
foreach (array_keys($customOptions) as $key) {
137-
$customOptions[$key]['is_delete'] = 1;
141+
if (array_key_exists('selection_price_value', $linkData)) {
142+
$link->setPrice($linkData['selection_price_value']);
138143
}
139-
$newOptions = $product->getOptions();
140-
foreach ($customOptions as $customOptionData) {
141-
if (!(bool)$customOptionData['is_delete']) {
142-
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
143-
$customOption->setProductSku($product->getSku());
144-
$customOption->setOptionId(null);
145-
$newOptions[] = $customOption;
146-
}
144+
145+
if (array_key_exists('selection_price_type', $linkData)) {
146+
$link->setPriceType($linkData['selection_price_type']);
147147
}
148-
$product->setOptions($newOptions);
148+
149+
$linkProduct = $this->productRepository->getById($linkData['product_id']);
150+
$link->setSku($linkProduct->getSku());
151+
$link->setQty($linkData['selection_qty']);
152+
153+
if (array_key_exists('selection_can_change_qty', $linkData)) {
154+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
155+
}
156+
$links[] = $link;
149157
}
158+
$option->setProductLinks($links);
159+
$options[] = $option;
150160
}
151161

152-
$product->setCanSaveBundleSelections(
153-
(bool)$this->request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly()
154-
);
155-
return $product;
162+
$extension = $product->getExtensionAttributes();
163+
$extension->setBundleProductOptions($options);
164+
$product->setExtensionAttributes($extension);
165+
return;
166+
}
167+
168+
/**
169+
* @param \Magento\Catalog\Model\Product $product
170+
* @return void
171+
*/
172+
protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $product)
173+
{
174+
if ($product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
175+
return;
176+
}
177+
178+
if ($product->getOptionsReadonly()) {
179+
return;
180+
}
181+
$product->setCanSaveCustomOptions(true);
182+
$customOptions = $product->getProductOptions();
183+
if (!$customOptions) {
184+
return;
185+
}
186+
foreach (array_keys($customOptions) as $key) {
187+
$customOptions[$key]['is_delete'] = 1;
188+
}
189+
$newOptions = $product->getOptions();
190+
foreach ($customOptions as $customOptionData) {
191+
if ((bool)$customOptionData['is_delete']) {
192+
continue;
193+
}
194+
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
195+
$customOption->setProductSku($product->getSku());
196+
$customOption->setOptionId(null);
197+
$newOptions[] = $customOption;
198+
}
199+
$product->setOptions($newOptions);
156200
}
157201
}

dev/tests/functional/tests/app/Magento/Bundle/Test/TestCase/CreateBundleProductEntityTest.xml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,27 +300,26 @@
300300
<data name="product/data/checkout_data/dataset" xsi:type="string">bundle_default</data>
301301
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
302302
</variation>
303-
<!-- Must be reverted after fix https://jira.corp.x.com/browse/MAGETWO-46695 -->
304-
<!--<variation name="CreateBundleProductEntityTestVariation15" summary="Create Bundle (fixed) Product and Assign it to Category" ticketId="MAGETWO-12622">-->
305-
<!--<data name="product/data/url_key" xsi:type="string">bundle-product-%isolation%</data>-->
306-
<!--<data name="product/data/name" xsi:type="string">Bundle Fixed %isolation%</data>-->
307-
<!--<data name="product/data/sku_type" xsi:type="string">Fixed</data>-->
308-
<!--<data name="product/data/sku" xsi:type="string">sku_bundle_fixed_%isolation%</data>-->
309-
<!--<data name="product/data/price_type" xsi:type="string">Fixed</data>-->
310-
<!--<data name="product/data/price/value" xsi:type="string">100</data>-->
311-
<!--<data name="product/data/price/dataset" xsi:type="string">fixed-100</data>-->
312-
<!--<data name="product/data/tax_class_id/dataset" xsi:type="string">taxable_goods</data>-->
313-
<!--<data name="product/data/weight_type" xsi:type="string">Fixed</data>-->
314-
<!--<data name="product/data/weight" xsi:type="string">1</data>-->
315-
<!--<data name="product/data/category" xsi:type="string">category_%isolation%</data>-->
316-
<!--<data name="product/data/shipment_type" xsi:type="string">Together</data>-->
317-
<!--<data name="product/data/bundle_selections/dataset" xsi:type="string">two_options_with_fixed_and_percent_prices</data>-->
318-
<!--<data name="tag" xsi:type="string">test_type:acceptance_test</data>-->
319-
<!--<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />-->
320-
<!--<constraint name="Magento\Catalog\Test\Constraint\AssertProductInGrid" />-->
321-
<!--<constraint name="Magento\Bundle\Test\Constraint\AssertBundleInCategory" />-->
322-
<!--<constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductPage" />-->
323-
<!--</variation>-->
303+
<variation name="CreateBundleProductEntityTestVariation15" summary="Create Bundle (fixed) Product and Assign it to Category" ticketId="MAGETWO-12622">
304+
<data name="product/data/url_key" xsi:type="string">bundle-product-%isolation%</data>
305+
<data name="product/data/name" xsi:type="string">Bundle Fixed %isolation%</data>
306+
<data name="product/data/sku_type" xsi:type="string">Fixed</data>
307+
<data name="product/data/sku" xsi:type="string">sku_bundle_fixed_%isolation%</data>
308+
<data name="product/data/price_type" xsi:type="string">Fixed</data>
309+
<data name="product/data/price/value" xsi:type="string">100</data>
310+
<data name="product/data/price/dataset" xsi:type="string">fixed-100</data>
311+
<data name="product/data/tax_class_id/dataset" xsi:type="string">taxable_goods</data>
312+
<data name="product/data/weight_type" xsi:type="string">Fixed</data>
313+
<data name="product/data/weight" xsi:type="string">1</data>
314+
<data name="product/data/category" xsi:type="string">category_%isolation%</data>
315+
<data name="product/data/shipment_type" xsi:type="string">Together</data>
316+
<data name="product/data/bundle_selections/dataset" xsi:type="string">two_options_with_fixed_and_percent_prices</data>
317+
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
318+
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
319+
<constraint name="Magento\Catalog\Test\Constraint\AssertProductInGrid" />
320+
<constraint name="Magento\Bundle\Test\Constraint\AssertBundleInCategory" />
321+
<constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductPage" />
322+
</variation>
324323
<variation name="CreateBundleProductEntityTestVariation16" summary="Create Bundle (dynamic) Product and Assign it to the Category" ticketId="MAGETWO-12702">
325324
<data name="product/data/url_key" xsi:type="string">bundle-product-%isolation%</data>
326325
<data name="product/data/name" xsi:type="string">Bundle Dynamic %isolation%</data>

dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,27 @@
8787
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />
8888
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal"/>
8989
</variation>
90-
<!-- Must be reverted after fix https://jira.corp.x.com/browse/MAGETWO-46695 -->
91-
<!--<variation name="OnePageCheckoutTestVariation5" summary="Guest Checkout using Check/Money Order and Free Shipping with Prices/Taxes Verifications" ticketId="MAGETWO-12412">-->
92-
<!--<data name="products" xsi:type="string">catalogProductSimple::product_10_dollar, configurableProduct::with_one_option, bundleProduct::bundle_fixed_100_dollar_product</data>-->
93-
<!--<data name="taxRule" xsi:type="string">us_ca_ny_rule</data>-->
94-
<!--<data name="checkoutMethod" xsi:type="string">guest</data>-->
95-
<!--<data name="shippingAddress/dataset" xsi:type="string">US_address_1</data>-->
96-
<!--<data name="shipping/shipping_service" xsi:type="string">Free Shipping</data>-->
97-
<!--<data name="shipping/shipping_method" xsi:type="string">Free</data>-->
98-
<!--<data name="prices" xsi:type="array">-->
99-
<!--<item name="grandTotal" xsi:type="string">130.98</item>-->
100-
<!--</data>-->
101-
<!--<data name="cart/data/subtotal" xsi:type="string">121.00</data>-->
102-
<!--<data name="cart/data/tax_amount" xsi:type="string">9.98</data>-->
103-
<!--<data name="cart/data/shipping_amount" xsi:type="string">0.00</data>-->
104-
<!--<data name="cart/data/grand_total" xsi:type="string">130.98</data>-->
105-
<!--<data name="billingCheckboxState" xsi:type="string">Yes</data>-->
106-
<!--<data name="payment/method" xsi:type="string">checkmo</data>-->
107-
<!--<data name="configData" xsi:type="string">checkmo, freeshipping_minimum_order_amount_100</data>-->
108-
<!--<data name="tag" xsi:type="string">test_type:acceptance_test</data>-->
109-
<!--<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage"/>-->
110-
<!--<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />-->
111-
<!--<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal"/>-->
112-
<!--</variation>-->
90+
<variation name="OnePageCheckoutTestVariation5" summary="Guest Checkout using Check/Money Order and Free Shipping with Prices/Taxes Verifications" ticketId="MAGETWO-12412">
91+
<data name="products" xsi:type="string">catalogProductSimple::product_10_dollar, configurableProduct::with_one_option, bundleProduct::bundle_fixed_100_dollar_product</data>
92+
<data name="taxRule" xsi:type="string">us_ca_ny_rule</data>
93+
<data name="checkoutMethod" xsi:type="string">guest</data>
94+
<data name="shippingAddress/dataset" xsi:type="string">US_address_1</data>
95+
<data name="shipping/shipping_service" xsi:type="string">Free Shipping</data>
96+
<data name="shipping/shipping_method" xsi:type="string">Free</data>
97+
<data name="prices" xsi:type="array">
98+
<item name="grandTotal" xsi:type="string">130.98</item>
99+
</data>
100+
<data name="cart/data/subtotal" xsi:type="string">121.00</data>
101+
<data name="cart/data/tax_amount" xsi:type="string">9.98</data>
102+
<data name="cart/data/shipping_amount" xsi:type="string">0.00</data>
103+
<data name="cart/data/grand_total" xsi:type="string">130.98</data>
104+
<data name="billingCheckboxState" xsi:type="string">Yes</data>
105+
<data name="payment/method" xsi:type="string">checkmo</data>
106+
<data name="configData" xsi:type="string">checkmo, freeshipping_minimum_order_amount_100</data>
107+
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
108+
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage"/>
109+
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />
110+
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal"/>
111+
</variation>
113112
</testCase>
114113
</config>

0 commit comments

Comments
 (0)