Skip to content

Commit af8a93e

Browse files
author
Oleksii Korshenko
committed
MAGETWO-87064: [EngCom Team] Batch 3. Forwardports to 2.3-develop #1284
- Merge Pull Request magento-engcom/magento2ce#1284 from magento-engcom-team/magento2:batch-3-forwardport-2.3-develop - Merged commits: 1. 97e48a7 2. 88096d1 3. 4c5c952 4. 56f7708 5. 93cba75 6. d6da9b6 7. 3914fda 8. b836052 9. 5130f54 10. 4e965fa 11. 1ad5260 12. 7b99d4f 13. 3f27734 14. 153aa0c 15. fe598ef 16. f3db727 17. 184aab1 18. 0d8ccee 19. 217a451 20. 8463fa4 21. 97a4786 22. b28dcdc
2 parents 8e77e2f + b28dcdc commit af8a93e

File tree

18 files changed

+350
-82
lines changed

18 files changed

+350
-82
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/list/items.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ switch ($type = $block->getType()) {
202202
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
203203
<?php endif; ?>
204204

205-
<?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
205+
<?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
206206
<?php if (!$_item->getRequiredOptions()): ?>
207207
<div class="field choice related">
208208
<input type="checkbox" class="checkbox related" id="related-checkbox<?= /* @escapeNotVerified */ $_item->getId() ?>" name="related_products[]" value="<?= /* @escapeNotVerified */ $_item->getId() ?>" />

app/code/Magento/Checkout/view/frontend/web/js/model/resource-url-manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ define([
7575
quoteId: quoteId
7676
} : {},
7777
urls = {
78-
'guest': '/guest-carts/' + quoteId + '/coupons/' + couponCode,
79-
'customer': '/carts/mine/coupons/' + couponCode
78+
'guest': '/guest-carts/' + quoteId + '/coupons/' + encodeURIComponent(couponCode),
79+
'customer': '/carts/mine/coupons/' + encodeURIComponent(couponCode)
8080
};
8181

8282
return this.getUrl(urls, params);

app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ public function collectRates(RateRequest $request)
113113

114114
// Free shipping by qty
115115
$freeQty = 0;
116+
$freePackageValue = 0;
117+
116118
if ($request->getAllItems()) {
117-
$freePackageValue = 0;
118119
foreach ($request->getAllItems() as $item) {
119120
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
120121
continue;

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,8 @@ public function validateMinimumAmount()
11701170
*/
11711171
public function getAppliedTaxes()
11721172
{
1173-
return $this->serializer->unserialize($this->getData('applied_taxes'));
1173+
$taxes = $this->getData('applied_taxes');
1174+
return $taxes ? $this->serializer->unserialize($taxes) : [];
11741175
}
11751176

11761177
/**

app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Quote\Test\Unit\Model\Quote;
88

99
use Magento\Directory\Model\Currency;
10-
use \Magento\Quote\Model\Quote\Address;
10+
use Magento\Quote\Model\Quote\Address;
1111
use Magento\Quote\Model\Quote\Address\Rate;
1212
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory as RateCollectionFactory;
1313
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\Collection as RatesCollection;
@@ -26,6 +26,7 @@
2626
use Magento\Store\Api\Data\StoreInterface;
2727
use Magento\Store\Api\Data\WebsiteInterface;
2828
use Magento\Quote\Model\Quote\Address\RateResult\AbstractResult;
29+
use Magento\Framework\Serialize\Serializer\Json;
2930

3031
/**
3132
* Test class for sales quote address model
@@ -121,7 +122,7 @@ protected function setUp()
121122
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
122123

123124
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config::class);
124-
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
125+
$this->serializer = new Json();
125126

126127
$this->requestFactory = $this->getMockBuilder(RateRequestFactory::class)
127128
->disableOriginalConstructor()
@@ -283,20 +284,17 @@ public function testValidateMinimumAmountNegative()
283284
public function testSetAndGetAppliedTaxes()
284285
{
285286
$data = ['data'];
286-
$result = json_encode($data);
287-
288-
$this->serializer->expects($this->once())
289-
->method('serialize')
290-
->with($data)
291-
->willReturn($result);
292-
293-
$this->serializer->expects($this->once())
294-
->method('unserialize')
295-
->with($result)
296-
->willReturn($data);
287+
self::assertInstanceOf(Address::class, $this->address->setAppliedTaxes($data));
288+
self::assertEquals($data, $this->address->getAppliedTaxes());
289+
}
297290

298-
$this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data));
299-
$this->assertEquals($data, $this->address->getAppliedTaxes());
291+
/**
292+
* Checks a case, when applied taxes are not provided.
293+
*/
294+
public function testGetAppliedTaxesWithEmptyValue()
295+
{
296+
$this->address->setData('applied_taxes', null);
297+
self::assertEquals([], $this->address->getAppliedTaxes());
300298
}
301299

302300
/**

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Customer\Api\AddressMetadataInterface;
1010
use Magento\Customer\Model\Metadata\Form as CustomerForm;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Quote\Model\Quote\Address;
1113
use Magento\Quote\Model\Quote\Item;
1214

1315
/**
@@ -321,7 +323,7 @@ public function __construct(
321323
$this->dataObjectHelper = $dataObjectHelper;
322324
$this->orderManagement = $orderManagement;
323325
$this->quoteFactory = $quoteFactory;
324-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
326+
$this->serializer = $serializer ?: ObjectManager::getInstance()
325327
->get(\Magento\Framework\Serialize\Serializer\Json::class);
326328
parent::__construct($data);
327329
}
@@ -1454,32 +1456,36 @@ public function getBillingAddress()
14541456
*/
14551457
public function setBillingAddress($address)
14561458
{
1457-
if (is_array($address)) {
1458-
$billingAddress = $this->_objectManager->create(
1459-
\Magento\Quote\Model\Quote\Address::class
1460-
)->setData(
1461-
$address
1462-
)->setAddressType(
1463-
\Magento\Quote\Model\Quote\Address::TYPE_BILLING
1464-
);
1465-
$this->_setQuoteAddress($billingAddress, $address);
1466-
/**
1467-
* save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress,
1468-
* that is why it should be added after _setQuoteAddress call
1469-
*/
1470-
$saveInAddressBook = (int)(!empty($address['save_in_address_book']));
1471-
$billingAddress->setData('save_in_address_book', $saveInAddressBook);
1472-
1473-
if (!$this->getQuote()->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
1474-
$shippingAddress = clone $billingAddress;
1475-
$shippingAddress->setSameAsBilling(true);
1476-
$shippingAddress->setSaveInAddressBook(false);
1477-
$address['save_in_address_book'] = 0;
1478-
$this->setShippingAddress($address);
1479-
}
1459+
if (!is_array($address)) {
1460+
return $this;
1461+
}
1462+
1463+
$billingAddress = $this->_objectManager->create(Address::class)
1464+
->setData($address)
1465+
->setAddressType(Address::TYPE_BILLING);
1466+
1467+
$this->_setQuoteAddress($billingAddress, $address);
1468+
1469+
/**
1470+
* save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress,
1471+
* that is why it should be added after _setQuoteAddress call
1472+
*/
1473+
$saveInAddressBook = (int)(!empty($address['save_in_address_book']));
1474+
$billingAddress->setData('save_in_address_book', $saveInAddressBook);
1475+
1476+
$quote = $this->getQuote();
1477+
if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
1478+
$address['save_in_address_book'] = 0;
1479+
$this->setShippingAddress($address);
1480+
}
14801481

1481-
$this->getQuote()->setBillingAddress($billingAddress);
1482+
// not assigned billing address should be saved as new
1483+
// but if quote already has the billing address it won't be overridden
1484+
if (empty($billingAddress->getCustomerAddressId())) {
1485+
$billingAddress->setCustomerAddressId(null);
1486+
$quote->getBillingAddress()->setCustomerAddressId(null);
14821487
}
1488+
$quote->setBillingAddress($billingAddress);
14831489

14841490
return $this;
14851491
}
@@ -1782,6 +1788,7 @@ public function _prepareCustomer()
17821788
$address = $this->getShippingAddress()->setCustomerId($this->getQuote()->getCustomer()->getId());
17831789
$this->setShippingAddress($address);
17841790
}
1791+
$this->getBillingAddress()->setCustomerId($customer->getId());
17851792
$this->getQuote()->updateCustomerData($this->getQuote()->getCustomer());
17861793

17871794
$customer = $this->getQuote()->getCustomer();

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ define([
157157
}
158158
if(this.addresses[id]){
159159
this.fillAddressFields(container, this.addresses[id]);
160+
160161
}
161162
else{
162163
this.fillAddressFields(container, {});
@@ -190,43 +191,53 @@ define([
190191
}
191192
},
192193

193-
changeAddressField : function(event){
194-
var field = Event.element(event);
195-
var re = /[^\[]*\[([^\]]*)_address\]\[([^\]]*)\](\[(\d)\])?/;
196-
var matchRes = field.name.match(re);
194+
/**
195+
* Triggers on each form's element changes.
196+
*
197+
* @param {Object} event
198+
*/
199+
changeAddressField: function (event) {
200+
var field = Event.element(event),
201+
re = /[^\[]*\[([^\]]*)_address\]\[([^\]]*)\](\[(\d)\])?/,
202+
matchRes = field.name.match(re),
203+
type,
204+
name,
205+
data;
197206

198207
if (!matchRes) {
199208
return;
200209
}
201210

202-
var type = matchRes[1];
203-
var name = matchRes[2];
204-
var data;
211+
type = matchRes[1];
212+
name = matchRes[2];
205213

206-
if(this.isBillingField(field.id)){
207-
data = this.serializeData(this.billingAddressContainer)
208-
}
209-
else{
210-
data = this.serializeData(this.shippingAddressContainer)
214+
if (this.isBillingField(field.id)) {
215+
data = this.serializeData(this.billingAddressContainer);
216+
} else {
217+
data = this.serializeData(this.shippingAddressContainer);
211218
}
212219
data = data.toObject();
213220

214-
if( (type == 'billing' && this.shippingAsBilling)
215-
|| (type == 'shipping' && !this.shippingAsBilling) ) {
221+
if (type === 'billing' && this.shippingAsBilling || type === 'shipping' && !this.shippingAsBilling) {
216222
data['reset_shipping'] = true;
217223
}
218224

219-
data['order['+type+'_address][customer_address_id]'] = $('order-'+type+'_address_customer_address_id').value;
225+
data['order[' + type + '_address][customer_address_id]'] = null;
226+
data['shipping_as_billing'] = jQuery('[name="shipping_same_as_billing"]').is(':checked') ? 1 : 0;
227+
228+
if (name === 'customer_address_id') {
229+
data['order[' + type + '_address][customer_address_id]'] =
230+
$('order-' + type + '_address_customer_address_id').value;
231+
}
220232

221233
if (data['reset_shipping']) {
222234
this.resetShippingMethod(data);
223235
} else {
224236
this.saveData(data);
225-
if (name == 'country_id' || name == 'customer_address_id') {
237+
238+
if (name === 'country_id' || name === 'customer_address_id') {
226239
this.loadArea(['shipping_method', 'billing_method', 'totals', 'items'], true, data);
227240
}
228-
// added for reloading of default sender and default recipient for giftmessages
229-
//this.loadArea(['giftmessage'], true, data);
230241
}
231242
},
232243

app/code/Magento/Ui/view/base/web/js/form/element/abstract.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ define([
118118

119119
this._super();
120120

121-
scope = this.dataScope;
122-
name = scope.split('.').slice(1);
121+
scope = this.dataScope.split('.');
122+
name = scope.length > 1 ? scope.slice(1) : scope;
123123

124124
valueUpdate = this.showFallbackReset ? 'afterkeydown' : this.valueUpdate;
125125

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ define([
360360
],
361361
'pattern': [
362362
function (value, param) {
363-
return param.test(value);
363+
return new RegExp(param).test(value);
364364
},
365365
$.mage.__('Invalid format.')
366366
],

dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public function run()
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function install()
29+
public function install($cleanup)
3030
{
31+
if ($cleanup) {
32+
$this->cleanup();
33+
}
34+
3135
$installOptions = $this->getInstallConfig();
3236

3337
/* Install application */

0 commit comments

Comments
 (0)