Skip to content

Commit 2b88239

Browse files
committed
Merge branch '2.2-develop' into ENGCOM-2444-magento-magento2-16940
2 parents f9ddaf3 + 74aa43b commit 2b88239

File tree

17 files changed

+170
-99
lines changed

17 files changed

+170
-99
lines changed

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Bundle\Model\Option;
99
use Magento\Catalog\Model\Product;
10+
use Magento\Framework\DataObject;
1011

1112
/**
1213
* Catalog bundle product info block
@@ -166,7 +167,7 @@ public function getJsonConfig()
166167

167168
$defaultValues = [];
168169
$preConfiguredFlag = $currentProduct->hasPreconfiguredValues();
169-
/** @var \Magento\Framework\DataObject|null $preConfiguredValues */
170+
/** @var DataObject|null $preConfiguredValues */
170171
$preConfiguredValues = $preConfiguredFlag ? $currentProduct->getPreconfiguredValues() : null;
171172

172173
$position = 0;
@@ -185,12 +186,13 @@ public function getJsonConfig()
185186
if ($configValue) {
186187
$defaultValues[$optionId] = $configValue;
187188
}
189+
$options = $this->processOptions($optionId, $options, $preConfiguredValues);
188190
}
189191
$position++;
190192
}
191193
$config = $this->getConfigData($currentProduct, $options);
192194

193-
$configObj = new \Magento\Framework\DataObject(
195+
$configObj = new DataObject(
194196
[
195197
'config' => $config,
196198
]
@@ -393,4 +395,30 @@ private function getConfigData(Product $product, array $options)
393395
];
394396
return $config;
395397
}
398+
399+
/**
400+
* Set preconfigured quantities and selections to options.
401+
*
402+
* @param string $optionId
403+
* @param array $options
404+
* @param DataObject $preConfiguredValues
405+
* @return array
406+
*/
407+
private function processOptions(string $optionId, array $options, DataObject $preConfiguredValues)
408+
{
409+
$preConfiguredQtys = $preConfiguredValues->getData("bundle_option_qty/${optionId}") ?? [];
410+
$selections = $options[$optionId]['selections'];
411+
array_walk($selections, function (&$selection, $selectionId) use ($preConfiguredQtys) {
412+
if (is_array($preConfiguredQtys) && isset($preConfiguredQtys[$selectionId])) {
413+
$selection['qty'] = $preConfiguredQtys[$selectionId];
414+
} else {
415+
if ((int)$preConfiguredQtys > 0) {
416+
$selection['qty'] = $preConfiguredQtys;
417+
}
418+
}
419+
});
420+
$options[$optionId]['selections'] = $selections;
421+
422+
return $options;
423+
}
396424
}

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ protected function _getSelectedOptions()
169169
*/
170170
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
171171
{
172-
if ($selectionId && $option->getSelectionById($selectionId)) {
172+
if (is_array($selectionId)) {
173+
$this->_selectedOptions = $selectionId;
174+
} else if ($selectionId && $option->getSelectionById($selectionId)) {
173175
$this->_selectedOptions = $selectionId;
174176
} elseif (!$option->getRequired()) {
175177
$this->_selectedOptions = 'None';

app/code/Magento/Bundle/Test/Mftf/Test/StorefrontEditBundleProductTest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@
9696
<click selector="{{CheckoutCartProductSection.editItemParametersButton('1')}}" stepKey="clickEdit"/>
9797
<waitForPageLoad stepKey="waitForStorefront2"/>
9898

99-
<!-- Choose both of the options on the storefront -->
100-
<click selector="{{StorefrontBundledSection.bundleOption('1','1')}}" stepKey="selectFirstBundleOption2"/>
99+
<!-- Check second one option to choose both of the options on the storefront -->
101100
<click selector="{{StorefrontBundledSection.bundleOption('1','2')}}" stepKey="selectSecondBundleOption2"/>
102101

103102
<waitForPageLoad stepKey="waitForPriceUpdate3"/>

app/code/Magento/Customer/Controller/Section/Load.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function execute()
7070
$sectionNames = $this->getRequest()->getParam('sections');
7171
$sectionNames = $sectionNames ? array_unique(\explode(',', $sectionNames)) : null;
7272

73-
$updateSectionId = $this->getRequest()->getParam('update_section_id');
74-
if ('false' === $updateSectionId) {
75-
$updateSectionId = false;
73+
$forceNewSectionTimestamp = $this->getRequest()->getParam('force_new_section_timestamp');
74+
if ('false' === $forceNewSectionTimestamp) {
75+
$forceNewSectionTimestamp = false;
7676
}
77-
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$updateSectionId);
77+
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$forceNewSectionTimestamp);
7878
} catch (\Exception $e) {
7979
$resultJson->setStatusHeader(
8080
\Zend\Http\Response::STATUS_CODE_400,

app/code/Magento/Customer/CustomerData/Section/Identifier.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function __construct(
4343
/**
4444
* Init mark(identifier) for sections
4545
*
46-
* @param bool $forceUpdate
46+
* @param bool $forceNewTimestamp
4747
* @return int
4848
*/
49-
public function initMark($forceUpdate)
49+
public function initMark($forceNewTimestamp)
5050
{
51-
if ($forceUpdate) {
51+
if ($forceNewTimestamp) {
5252
$this->markId = time();
5353
return $this->markId;
5454
}
@@ -68,18 +68,18 @@ public function initMark($forceUpdate)
6868
*
6969
* @param array $sectionsData
7070
* @param null $sectionNames
71-
* @param bool $updateIds
71+
* @param bool $forceNewTimestamp
7272
* @return array
7373
*/
74-
public function markSections(array $sectionsData, $sectionNames = null, $updateIds = false)
74+
public function markSections(array $sectionsData, $sectionNames = null, $forceNewTimestamp = false)
7575
{
7676
if (!$sectionNames) {
7777
$sectionNames = array_keys($sectionsData);
7878
}
79-
$markId = $this->initMark($updateIds);
79+
$markId = $this->initMark($forceNewTimestamp);
8080

8181
foreach ($sectionNames as $name) {
82-
if ($updateIds || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
82+
if ($forceNewTimestamp || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
8383
$sectionsData[$name][self::SECTION_KEY] = $markId;
8484
}
8585
}

app/code/Magento/Customer/CustomerData/SectionPool.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public function __construct(
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
public function getSectionsData(array $sectionNames = null, $updateIds = false)
58+
public function getSectionsData(array $sectionNames = null, $forceNewTimestamp = false)
5959
{
6060
$sectionsData = $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
61-
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $updateIds);
61+
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $forceNewTimestamp);
6262
return $sectionsData;
6363
}
6464

app/code/Magento/Customer/CustomerData/SectionPoolInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ interface SectionPoolInterface
1414
* Get section data by section names. If $sectionNames is null then return all sections data
1515
*
1616
* @param array $sectionNames
17-
* @param bool $updateIds
17+
* @param bool $forceNewTimestamp
1818
* @return array
1919
*/
20-
public function getSectionsData(array $sectionNames = null, $updateIds = false);
20+
public function getSectionsData(array $sectionNames = null, $forceNewTimestamp = false);
2121
}

app/code/Magento/Customer/Test/Unit/Controller/Section/LoadTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ protected function setUp()
8181
}
8282

8383
/**
84-
* @param $sectionNames
85-
* @param $updateSectionID
86-
* @param $sectionNamesAsArray
87-
* @param $updateIds
84+
* @param string $sectionNames
85+
* @param bool $forceNewSectionTimestamp
86+
* @param string[] $sectionNamesAsArray
87+
* @param bool $forceNewTimestamp
8888
* @dataProvider executeDataProvider
8989
*/
90-
public function testExecute($sectionNames, $updateSectionID, $sectionNamesAsArray, $updateIds)
90+
public function testExecute($sectionNames, $forceNewSectionTimestamp, $sectionNamesAsArray, $forceNewTimestamp)
9191
{
9292
$this->resultJsonFactoryMock->expects($this->once())
9393
->method('create')
@@ -101,12 +101,12 @@ public function testExecute($sectionNames, $updateSectionID, $sectionNamesAsArra
101101

102102
$this->httpRequestMock->expects($this->exactly(2))
103103
->method('getParam')
104-
->withConsecutive(['sections'], ['update_section_id'])
105-
->willReturnOnConsecutiveCalls($sectionNames, $updateSectionID);
104+
->withConsecutive(['sections'], ['force_new_section_timestamp'])
105+
->willReturnOnConsecutiveCalls($sectionNames, $forceNewSectionTimestamp);
106106

107107
$this->sectionPoolMock->expects($this->once())
108108
->method('getSectionsData')
109-
->with($sectionNamesAsArray, $updateIds)
109+
->with($sectionNamesAsArray, $forceNewTimestamp)
110110
->willReturn([
111111
'message' => 'some message',
112112
'someKey' => 'someValue'
@@ -131,15 +131,15 @@ public function executeDataProvider()
131131
return [
132132
[
133133
'sectionNames' => 'sectionName1,sectionName2,sectionName3',
134-
'updateSectionID' => 'updateSectionID',
134+
'forceNewSectionTimestamp' => 'forceNewSectionTimestamp',
135135
'sectionNamesAsArray' => ['sectionName1', 'sectionName2', 'sectionName3'],
136-
'updateIds' => true
136+
'forceNewTimestamp' => true
137137
],
138138
[
139139
'sectionNames' => null,
140-
'updateSectionID' => null,
140+
'forceNewSectionTimestamp' => null,
141141
'sectionNamesAsArray' => null,
142-
'updateIds' => false
142+
'forceNewTimestamp' => false
143143
],
144144
];
145145
}

app/code/Magento/Customer/Test/Unit/CustomerData/SectionPoolTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testGetSectionsDataAllSections()
6363

6464
$this->identifierMock->expects($this->once())
6565
->method('markSections')
66-
//check also default value for $updateIds = false
66+
//check also default value for $forceTimestamp = false
6767
->with($allSectionsData, $sectionNames, false)
6868
->willReturn($identifierResult);
6969
$modelResult = $this->model->getSectionsData($sectionNames);

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ define([
7575

7676
/**
7777
* @param {Object} sectionNames
78-
* @param {Number} updateSectionId
78+
* @param {Boolean} forceNewSectionTimestamp
7979
* @return {*}
8080
*/
81-
getFromServer: function (sectionNames, updateSectionId) {
81+
getFromServer: function (sectionNames, forceNewSectionTimestamp) {
8282
var parameters;
8383

8484
sectionNames = sectionConfig.filterClientSideSections(sectionNames);
8585
parameters = _.isArray(sectionNames) ? {
8686
sections: sectionNames.join(',')
8787
} : [];
88-
parameters['update_section_id'] = updateSectionId;
88+
parameters['force_new_section_timestamp'] = forceNewSectionTimestamp;
8989

9090
return $.getJSON(options.sectionLoadUrl, parameters).fail(function (jqXHR) {
9191
throw new Error(jqXHR);
@@ -326,11 +326,11 @@ define([
326326

327327
/**
328328
* @param {Array} sectionNames
329-
* @param {Number} updateSectionId
329+
* @param {Boolean} forceNewSectionTimestamp
330330
* @return {*}
331331
*/
332-
reload: function (sectionNames, updateSectionId) {
333-
return dataProvider.getFromServer(sectionNames, updateSectionId).done(function (sections) {
332+
reload: function (sectionNames, forceNewSectionTimestamp) {
333+
return dataProvider.getFromServer(sectionNames, forceNewSectionTimestamp).done(function (sections) {
334334
$(document).trigger('customer-data-reload', [sectionNames]);
335335
buffer.update(sections);
336336
});

app/code/Magento/Payment/Observer/SalesOrderBeforeSaveObserver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ class SalesOrderBeforeSaveObserver implements ObserverInterface
1515
*
1616
* @param \Magento\Framework\Event\Observer $observer
1717
* @return $this
18+
* @throws \Magento\Framework\Exception\LocalizedException in case order has no payment specified.
1819
*/
1920
public function execute(\Magento\Framework\Event\Observer $observer)
2021
{
2122
/** @var \Magento\Sales\Model\Order $order */
2223
$order = $observer->getEvent()->getOrder();
2324

25+
if (!$order->getPayment()) {
26+
throw new \Magento\Framework\Exception\LocalizedException(
27+
__('Please provide payment for the order.')
28+
);
29+
}
30+
2431
if ($order->getPayment()->getMethodInstance()->getCode() != 'free') {
2532
return $this;
2633
}

app/code/Magento/Payment/Test/Unit/Observer/SalesOrderBeforeSaveObserverTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testSalesOrderBeforeSaveCantUnhold()
6161
$paymentMock = $this->getMockBuilder(
6262
\Magento\Sales\Model\Order\Payment::class
6363
)->disableOriginalConstructor()->setMethods([])->getMock();
64-
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
64+
$order->method('getPayment')->will($this->returnValue($paymentMock));
6565
$methodInstance = $this->getMockBuilder(
6666
\Magento\Payment\Model\MethodInterface::class
6767
)->getMockForAbstractClass();
@@ -86,7 +86,7 @@ public function testSalesOrderBeforeSaveIsCanceled()
8686
$paymentMock = $this->getMockBuilder(
8787
\Magento\Sales\Model\Order\Payment::class
8888
)->disableOriginalConstructor()->setMethods([])->getMock();
89-
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
89+
$order->method('getPayment')->will($this->returnValue($paymentMock));
9090
$methodInstance = $this->getMockBuilder(
9191
\Magento\Payment\Model\MethodInterface::class
9292
)->getMockForAbstractClass();
@@ -114,7 +114,7 @@ public function testSalesOrderBeforeSaveIsClosed()
114114
$paymentMock = $this->getMockBuilder(
115115
\Magento\Sales\Model\Order\Payment::class
116116
)->disableOriginalConstructor()->setMethods([])->getMock();
117-
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
117+
$order->method('getPayment')->will($this->returnValue($paymentMock));
118118
$methodInstance = $this->getMockBuilder(
119119
\Magento\Payment\Model\MethodInterface::class
120120
)->getMockForAbstractClass();
@@ -156,6 +156,29 @@ public function testSalesOrderBeforeSaveSetForced()
156156
$this->salesOrderBeforeSaveObserver->execute($this->observerMock);
157157
}
158158

159+
/**
160+
* The method should check that the payment is available, as this is not always the case.
161+
*
162+
* @expectedException \Magento\Framework\Exception\LocalizedException
163+
* @exceptedExceptionMessage Please provide payment for the order.
164+
*/
165+
public function testDoesNothingWhenNoPaymentIsAvailable()
166+
{
167+
$this->_prepareEventMockWithMethods(['getOrder']);
168+
169+
$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)->disableOriginalConstructor()->setMethods(
170+
array_merge(['__wakeup', 'getPayment'])
171+
)->getMock();
172+
173+
$this->eventMock->expects($this->once())->method('getOrder')->will(
174+
$this->returnValue($order)
175+
);
176+
177+
$order->expects($this->exactly(1))->method('getPayment')->willReturn(null);
178+
179+
$this->salesOrderBeforeSaveObserver->execute($this->observerMock);
180+
}
181+
159182
/**
160183
* Prepares EventMock with set of methods
161184
*
@@ -184,7 +207,7 @@ private function _getPreparedOrderMethod($methodCode, $orderMethods = [])
184207
$paymentMock = $this->getMockBuilder(
185208
\Magento\Sales\Model\Order\Payment::class
186209
)->disableOriginalConstructor()->setMethods([])->getMock();
187-
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
210+
$order->method('getPayment')->will($this->returnValue($paymentMock));
188211
$methodInstance = $this->getMockBuilder(
189212
\Magento\Payment\Model\MethodInterface::class
190213
)->getMockForAbstractClass();

app/code/Magento/Paypal/Plugin/OrderCanInvoice.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function __construct(Express $express)
3838
*/
3939
public function afterCanInvoice(Order $order, $result): bool
4040
{
41+
if (!$order->getPayment()) {
42+
return false;
43+
}
44+
4145
if ($this->express->isOrderAuthorizationAllowed($order->getPayment())) {
4246
return false;
4347
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Placeholder

0 commit comments

Comments
 (0)