Skip to content

Commit e7afcda

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into 2.3-develop-pr30
2 parents 1497ba6 + 8ad9684 commit e7afcda

File tree

11 files changed

+256
-30
lines changed

11 files changed

+256
-30
lines changed

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ define([
99
'Magento_Customer/js/customer-data',
1010
'Magento_Ui/js/modal/alert',
1111
'Magento_Ui/js/modal/confirm',
12+
'underscore',
1213
'jquery/ui',
1314
'mage/decorate',
1415
'mage/collapsible',
1516
'mage/cookies'
16-
], function ($, authenticationPopup, customerData, alert, confirm) {
17+
], function ($, authenticationPopup, customerData, alert, confirm, _) {
1718
'use strict';
1819

1920
$.widget('mage.sidebar', {
@@ -219,8 +220,12 @@ define([
219220
* @param {HTMLElement} elem
220221
*/
221222
_updateItemQtyAfter: function (elem) {
223+
var productData = this._getProductById(Number(elem.data('cart-item')));
224+
225+
if (!_.isUndefined(productData)) {
226+
$(document).trigger('ajax:updateCartItemQty', productData['product_sku']);
227+
}
222228
this._hideItemButton(elem);
223-
$(document).trigger('ajax:updateItemQty');
224229
},
225230

226231
/**
@@ -242,11 +247,24 @@ define([
242247
* @private
243248
*/
244249
_removeItemAfter: function (elem) {
245-
var productData = customerData.get('cart')().items.find(function (item) {
246-
return Number(elem.data('cart-item')) === Number(item['item_id']);
247-
});
250+
var productData = this._getProductById(Number(elem.data('cart-item')));
251+
252+
if (!_.isUndefined(productData)) {
253+
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
254+
}
255+
},
248256

249-
$(document).trigger('ajax:removeFromCart', productData['product_sku']);
257+
/**
258+
* Retrieves product data by Id.
259+
*
260+
* @param {Number} productId - product Id
261+
* @returns {Object|undefined}
262+
* @private
263+
*/
264+
_getProductById: function (productId) {
265+
return _.find(customerData.get('cart')().items, function (item) {
266+
return productId === Number(item['item_id']);
267+
});
250268
},
251269

252270
/**

app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
require([
22
'jquery',
33
'Magento_Customer/js/customer-data',
4+
'underscore',
45
'domReady!'
5-
], function ($, customerData) {
6+
], function ($, customerData, _) {
67
'use strict';
78

89
var selectors = {
@@ -41,7 +42,7 @@ require([
4142
if (!(data && data.items && data.items.length && productId)) {
4243
return;
4344
}
44-
product = data.items.find(function (item) {
45+
product = _.find(data.items, function (item) {
4546
if (item['item_id'] === itemId) {
4647
return item['product_id'] === productId ||
4748
item['item_id'] === productId;

app/code/Magento/Customer/Model/Metadata/AttributeMetadataHydrator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Api\Data\OptionInterfaceFactory;
1212
use Magento\Customer\Api\Data\ValidationRuleInterface;
1313
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
14+
use Magento\Customer\Model\Data\AttributeMetadata;
1415
use Magento\Framework\Reflection\DataObjectProcessor;
1516

1617
/**
@@ -120,7 +121,7 @@ public function extract($attributeMetadata)
120121
{
121122
return $this->dataObjectProcessor->buildOutputDataArray(
122123
$attributeMetadata,
123-
AttributeMetadataInterface::class
124+
AttributeMetadata::class
124125
);
125126
}
126127
}

app/code/Magento/Customer/Test/Unit/Model/Metadata/AttributeMetadataHydratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function testExtract()
205205
->method('buildOutputDataArray')
206206
->with(
207207
$this->attributeMetadataMock,
208-
AttributeMetadataInterface::class
208+
AttributeMetadata::class
209209
)
210210
->willReturn($data);
211211
$this->assertSame(

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
namespace Magento\Fedex\Model;
88

99
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\DataObject;
1011
use Magento\Framework\Module\Dir;
1112
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\Framework\Webapi\Soap\ClientFactory;
1214
use Magento\Framework\Xml\Security;
1315
use Magento\Quote\Model\Quote\Address\RateRequest;
1416
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
@@ -17,7 +19,6 @@
1719
/**
1820
* Fedex shipping implementation
1921
*
20-
* @author Magento Core Team <core@magentocommerce.com>
2122
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2223
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2324
*/
@@ -143,6 +144,11 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
143144
*/
144145
private $serializer;
145146

147+
/**
148+
* @var ClientFactory
149+
*/
150+
private $soapClientFactory;
151+
146152
/**
147153
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
148154
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -164,7 +170,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
164170
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
165171
* @param array $data
166172
* @param Json|null $serializer
167-
*
173+
* @param ClientFactory|null $soapClientFactory
168174
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
169175
*/
170176
public function __construct(
@@ -187,7 +193,8 @@ public function __construct(
187193
\Magento\Framework\Module\Dir\Reader $configReader,
188194
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
189195
array $data = [],
190-
Json $serializer = null
196+
Json $serializer = null,
197+
ClientFactory $soapClientFactory = null
191198
) {
192199
$this->_storeManager = $storeManager;
193200
$this->_productCollectionFactory = $productCollectionFactory;
@@ -214,6 +221,7 @@ public function __construct(
214221
$this->_rateServiceWsdl = $wsdlBasePath . 'RateService_v10.wsdl';
215222
$this->_trackServiceWsdl = $wsdlBasePath . 'TrackService_v' . self::$trackServiceVersion . '.wsdl';
216223
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
224+
$this->soapClientFactory = $soapClientFactory ?: ObjectManager::getInstance()->get(ClientFactory::class);
217225
}
218226

219227
/**
@@ -225,7 +233,7 @@ public function __construct(
225233
*/
226234
protected function _createSoapClient($wsdl, $trace = false)
227235
{
228-
$client = new \SoapClient($wsdl, ['trace' => $trace]);
236+
$client = $this->soapClientFactory->create($wsdl, ['trace' => $trace]);
229237
$client->__setLocation(
230238
$this->getConfigFlag(
231239
'sandbox_mode'
@@ -1263,7 +1271,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
12631271
$countriesOfManufacture[] = $product->getCountryOfManufacture();
12641272
}
12651273

1266-
$paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
1274+
$paymentType = $this->getPaymentType($request);
12671275
$optionType = $request->getShippingMethod() == self::RATE_REQUEST_SMARTPOST
12681276
? 'SERVICE_DEFAULT' : $packageParams->getDeliveryConfirmation();
12691277
$requestClient = [
@@ -1749,4 +1757,18 @@ private function parseDate($timestamp)
17491757

17501758
return false;
17511759
}
1760+
1761+
/**
1762+
* Defines payment type by request.
1763+
* Two values are available: RECIPIENT or SENDER.
1764+
*
1765+
* @param DataObject $request
1766+
* @return string
1767+
*/
1768+
private function getPaymentType(DataObject $request): string
1769+
{
1770+
return $request->getIsReturn() && $request->getShippingMethod() !== self::RATE_REQUEST_SMARTPOST
1771+
? 'RECIPIENT'
1772+
: 'SENDER';
1773+
}
17521774
}

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Account.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ protected function _prepareForm()
132132
$this->_addAttributesToForm($attributes, $fieldset);
133133

134134
$this->_form->addFieldNameSuffix('order[account]');
135-
$this->_form->setValues($this->getFormValues());
135+
136+
$formValues = $this->getFormValues();
137+
foreach ($attributes as $code => $attribute) {
138+
$defaultValue = $attribute->getDefaultValue();
139+
if (isset($defaultValue) && !isset($formValues[$code])) {
140+
$formValues[$code] = $defaultValue;
141+
}
142+
}
143+
$this->_form->setValues($formValues);
136144

137145
return $this;
138146
}

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Form/Items.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function getItemProductBlock($productSku)
5151
*/
5252
public function clickUpdateQty()
5353
{
54-
$this->_rootElement->find($this->updateQty)->click();
54+
$button = $this->_rootElement->find($this->updateQty);
55+
if (!$button->isDisabled()) {
56+
$button->click();
57+
}
5558
}
5659
}

dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertNoCreditMemoButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $orderI
3030
$orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]);
3131
\PHPUnit\Framework\Assert::assertFalse(
3232
$salesOrderView->getPageActions()->isActionButtonVisible('Credit Memo'),
33-
'Credit memo button is present on order view page.'
33+
'Credit memo button should not be present on order view page.'
3434
);
3535
}
3636

dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form/AccountTest.php

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,50 @@
55
* Copyright © Magento, Inc. All rights reserved.
66
* See COPYING.txt for license details.
77
*/
8+
9+
declare(strict_types=1);
10+
811
namespace Magento\Sales\Block\Adminhtml\Order\Create\Form;
912

13+
use Magento\Backend\Model\Session\Quote as SessionQuote;
14+
use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
15+
use Magento\Customer\Model\Metadata\Form;
16+
use Magento\Customer\Model\Metadata\FormFactory;
17+
use Magento\Framework\View\LayoutInterface;
18+
use Magento\Quote\Model\Quote;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
1021
/**
1122
* @magentoAppArea adminhtml
1223
*/
1324
class AccountTest extends \PHPUnit\Framework\TestCase
1425
{
15-
/** @var \Magento\Sales\Block\Adminhtml\Order\Create\Form\Account */
16-
protected $_accountBlock;
26+
/** @var Account */
27+
private $accountBlock;
1728

1829
/**
19-
* @var \Magento\TestFramework\Helper\Bootstrap
30+
* @var Bootstrap
2031
*/
21-
protected $_objectManager;
32+
private $objectManager;
2233

2334
/**
2435
* @magentoDataFixture Magento/Sales/_files/quote.php
2536
*/
2637
protected function setUp()
2738
{
28-
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
29-
$quote = $this->_objectManager->create(\Magento\Quote\Model\Quote::class)->load(1);
39+
$this->objectManager = Bootstrap::getObjectManager();
40+
$quote = $this->objectManager->create(Quote::class)->load(1);
3041
$sessionQuoteMock = $this->getMockBuilder(
31-
\Magento\Backend\Model\Session\Quote::class
42+
SessionQuote::class
3243
)->disableOriginalConstructor()->setMethods(
3344
['getCustomerId', 'getStore', 'getStoreId', 'getQuote']
3445
)->getMock();
3546
$sessionQuoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
3647
$sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quote));
37-
/** @var \Magento\Framework\View\LayoutInterface $layout */
38-
$layout = $this->_objectManager->get(\Magento\Framework\View\LayoutInterface::class);
39-
$this->_accountBlock = $layout->createBlock(
40-
\Magento\Sales\Block\Adminhtml\Order\Create\Form\Account::class,
48+
/** @var LayoutInterface $layout */
49+
$layout = $this->objectManager->get(LayoutInterface::class);
50+
$this->accountBlock = $layout->createBlock(
51+
Account::class,
4152
'address_block' . rand(),
4253
['sessionQuote' => $sessionQuoteMock]
4354
);
@@ -50,7 +61,7 @@ protected function setUp()
5061
public function testGetForm()
5162
{
5263
$expectedFields = ['group_id', 'email'];
53-
$form = $this->_accountBlock->getForm();
64+
$form = $this->accountBlock->getForm();
5465
$this->assertEquals(1, $form->getElements()->count(), "Form has invalid number of fieldsets");
5566
$fieldset = $form->getElements()[0];
5667

@@ -63,4 +74,56 @@ public function testGetForm()
6374
);
6475
}
6576
}
77+
78+
/**
79+
* Tests a case when user defined custom attribute has default value.
80+
*
81+
* @magentoDataFixture Magento/Customer/_files/customer.php
82+
*/
83+
public function testGetFormWithUserDefinedAttribute()
84+
{
85+
$formFactory = $this->getFormFactoryMock();
86+
$this->objectManager->addSharedInstance($formFactory, FormFactory::class);
87+
88+
/** @var LayoutInterface $layout */
89+
$layout = $this->objectManager->get(LayoutInterface::class);
90+
$accountBlock = $layout->createBlock(Account::class, 'address_block' . rand());
91+
92+
$form = $accountBlock->getForm();
93+
$form->setUseContainer(true);
94+
95+
$this->assertContains(
96+
'<option value="1" selected="selected">Yes</option>',
97+
$form->toHtml(),
98+
'Default value for user defined custom attribute should be selected'
99+
);
100+
}
101+
102+
/**
103+
* @return \PHPUnit_Framework_MockObject_MockObject
104+
*/
105+
private function getFormFactoryMock(): \PHPUnit_Framework_MockObject_MockObject
106+
{
107+
/** @var AttributeMetadataInterfaceFactory $attributeMetadataFactory */
108+
$attributeMetadataFactory = $this->objectManager->create(AttributeMetadataInterfaceFactory::class);
109+
$booleanAttribute = $attributeMetadataFactory->create()
110+
->setAttributeCode('boolean')
111+
->setBackendType('boolean')
112+
->setFrontendInput('boolean')
113+
->setDefaultValue('1')
114+
->setFrontendLabel('Yes/No');
115+
116+
$form = $this->getMockBuilder(Form::class)
117+
->disableOriginalConstructor()
118+
->getMock();
119+
$form->method('getUserAttributes')->willReturn([$booleanAttribute]);
120+
$form->method('getSystemAttributes')->willReturn([]);
121+
122+
$formFactory = $this->getMockBuilder(FormFactory::class)
123+
->disableOriginalConstructor()
124+
->getMock();
125+
$formFactory->method('create')->willReturn($form);
126+
127+
return $formFactory;
128+
}
66129
}

dev/tests/integration/testsuite/Magento/Sales/_files/address_data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
return [
88
'region' => 'CA',
9+
'region_id' => '12',
910
'postcode' => '11111',
1011
'lastname' => 'lastname',
1112
'firstname' => 'firstname',

0 commit comments

Comments
 (0)