Skip to content

Commit c5f5bc8

Browse files
committed
Merge remote-tracking branch 'mainline/2.3-develop' into php-72-pr
2 parents e94fcd9 + 535486f commit c5f5bc8

File tree

38 files changed

+624
-135
lines changed

38 files changed

+624
-135
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/OptionManagement.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public function getItems($attributeCode)
4040
*/
4141
public function add($attributeCode, $option)
4242
{
43+
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $currentOptions */
44+
$currentOptions = $this->getItems($attributeCode);
45+
if (is_array($currentOptions)) {
46+
array_walk($currentOptions, function (&$attributeOption) {
47+
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface $attributeOption */
48+
$attributeOption = $attributeOption->getLabel();
49+
});
50+
if (in_array($option->getLabel(), $currentOptions)) {
51+
return false;
52+
}
53+
}
4354
return $this->eavOptionManagement->add(
4455
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
4556
$attributeCode,

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/js.phtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ function switchDefaultValueField()
196196

197197
<?php foreach ($this->helper('Magento\Catalog\Helper\Data')->getAttributeHiddenFields() as $type => $fields): ?>
198198
case '<?= /* @escapeNotVerified */ $type ?>':
199+
var isFrontTabHidden = false;
199200
<?php foreach ($fields as $one): ?>
200201
<?php if ($one == '_front_fieldset'): ?>
201202
getFrontTab().hide();
203+
isFrontTabHidden = true;
202204
<?php elseif ($one == '_default_value'): ?>
203205
defaultValueTextVisibility =
204206
defaultValueTextareaVisibility =
@@ -210,6 +212,10 @@ function switchDefaultValueField()
210212
setRowVisibility('<?= /* @escapeNotVerified */ $one ?>', false);
211213
<?php endif; ?>
212214
<?php endforeach; ?>
215+
216+
if (!isFrontTabHidden){
217+
getFrontTab().show();
218+
}
213219
break;
214220
<?php endforeach; ?>
215221

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/Customer/etc/adminhtml/system.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@
198198
<field id="street_lines" translate="label comment" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
199199
<label>Number of Lines in a Street Address</label>
200200
<backend_model>Magento\Customer\Model\Config\Backend\Address\Street</backend_model>
201-
<comment>Leave empty for default (2). Valid range: 1-4</comment>
201+
<comment>Valid range: 1-4</comment>
202+
<validate>required-entry validate-digits validate-digits-range digits-range-1-4</validate>
202203
</field>
203204
<field id="prefix_show" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
204205
<label>Show Prefix</label>

app/code/Magento/Eav/Model/Entity/Attribute/Backend/JsonEncoded.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function afterLoad($object)
5858
{
5959
parent::afterLoad($object);
6060
$attrCode = $this->getAttribute()->getAttributeCode();
61-
$object->setData($attrCode, $this->jsonSerializer->unserialize($object->getData($attrCode)));
61+
$object->setData($attrCode, $this->jsonSerializer->unserialize($object->getData($attrCode) ?: '{}'));
6262
return $this;
6363
}
6464
}

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Backend/JsonEncodedTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,18 @@ public function testAfterLoad()
9595
$this->model->afterLoad($product);
9696
$this->assertEquals([1, 2, 3], $product->getData('json_encoded'));
9797
}
98+
99+
/**
100+
* Test after load handler with null attribute value
101+
*/
102+
public function testAfterLoadWithNullAttributeValue()
103+
{
104+
$product = new \Magento\Framework\DataObject(
105+
[
106+
'json_encoded' => null
107+
]
108+
);
109+
$this->model->afterLoad($product);
110+
$this->assertEquals([], $product->getData('json_encoded'));
111+
}
98112
}

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
9494
*/
9595
protected $_customerSession;
9696

97+
/**
98+
* Date
99+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
100+
*/
101+
private $dateTime;
102+
97103
/**
98104
* Store manager
99105
*
@@ -134,9 +140,10 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
134140
* @param CustomerRepositoryInterface $customerRepository
135141
* @param AccountManagementInterface $customerAccountManagement
136142
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
137-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
138-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
143+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
144+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
139145
* @param array $data
146+
* @param \Magento\Framework\Stdlib\DateTime\DateTime|null $dateTime
140147
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
141148
*/
142149
public function __construct(
@@ -152,13 +159,17 @@ public function __construct(
152159
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
153160
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
154161
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
155-
array $data = []
162+
array $data = [],
163+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime = null
156164
) {
157165
$this->_newsletterData = $newsletterData;
158166
$this->_scopeConfig = $scopeConfig;
159167
$this->_transportBuilder = $transportBuilder;
160168
$this->_storeManager = $storeManager;
161169
$this->_customerSession = $customerSession;
170+
$this->dateTime = $dateTime ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
171+
\Magento\Framework\Stdlib\DateTime\DateTime::class
172+
);
162173
$this->customerRepository = $customerRepository;
163174
$this->customerAccountManagement = $customerAccountManagement;
164175
$this->inlineTranslation = $inlineTranslation;
@@ -812,4 +823,18 @@ public function getSubscriberFullName()
812823
}
813824
return $name;
814825
}
826+
827+
/**
828+
* Set date of last changed status
829+
*
830+
* @return $this
831+
*/
832+
public function beforeSave()
833+
{
834+
parent::beforeSave();
835+
if ($this->dataHasChangedFor('subscriber_status')) {
836+
$this->setChangeStatusAt($this->dateTime->gmtDate());
837+
}
838+
return $this;
839+
}
815840
}

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.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ public function addCustomerAddress(\Magento\Customer\Api\Data\AddressInterface $
10461046
public function updateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
10471047
{
10481048
$quoteCustomer = $this->getCustomer();
1049-
$this->dataObjectHelper->mergeDataObjects(get_class($quoteCustomer), $quoteCustomer, $customer);
1049+
$this->dataObjectHelper->mergeDataObjects(CustomerInterface::class, $quoteCustomer, $customer);
10501050
$this->setCustomer($quoteCustomer);
10511051
return $this;
10521052
}

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/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function _construct()
101101
*/
102102
public function getStoreId()
103103
{
104-
return (int)$this->_quote->getStoreId();
104+
return (int)$this->_productCollectionFactory->create()->getStoreId();
105105
}
106106

107107
/**

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();

0 commit comments

Comments
 (0)