Skip to content

Commit a276241

Browse files
Merge pull request #405 from magento-folks/bugs
Bug MAGETWO-56699 [GITHUB] Paypal checkout not possible with products that have custom options #5938 - for mainline MAGETWO-58290 [Github]Empty product option is added on each PUT request #5963 MAGETWO-58136 [Github] Shipping and billing address are not set if order placed with payment action Sale #6438 MAGETWO-55608 [GITHUB] M2.1: Not scrollable picture on mobile / product page #5302 MAGETWO-58285 Ajax error message doesn't display in backend MAGETWO-58338 [Github]Problem adding attribute options that start with a number via REST Api #5715 MAGETWO-52575 Unable to apply free shipping to specified method when creating order in admin MAGETWO-57078 [GITHUB] Can't set customer group when creating a new order in the admin. #6162 MAGETWO-58039 Table rate shipping not applying correctly - for mainline
2 parents 73bf648 + 6934726 commit a276241

File tree

19 files changed

+542
-53
lines changed

19 files changed

+542
-53
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,12 @@ public function addOption(Product\Option $option)
19091909
*/
19101910
public function getOptionById($optionId)
19111911
{
1912-
/** @var \Magento\Catalog\Model\Product\Option $option */
1913-
foreach ($this->getOptions() as $option) {
1914-
if ($option->getId() == $optionId) {
1915-
return $option;
1912+
if (is_array($this->getOptions())) {
1913+
/** @var \Magento\Catalog\Model\Product\Option $option */
1914+
foreach ($this->getOptions() as $option) {
1915+
if ($option->getId() == $optionId) {
1916+
return $option;
1917+
}
19161918
}
19171919
}
19181920

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

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

99
use Magento\Framework\Exception\InputException;
1010
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Eav\Api\Data\AttributeInterface;
1112

1213
/**
1314
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -117,6 +118,8 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
117118
throw NoSuchEntityException::singleField('attribute_code', $existingModel->getAttributeCode());
118119
}
119120

121+
// Attribute code must not be changed after attribute creation
122+
$attribute->setAttributeCode($existingModel->getAttributeCode());
120123
$attribute->setAttributeId($existingModel->getAttributeId());
121124
$attribute->setIsUserDefined($existingModel->getIsUserDefined());
122125
$attribute->setFrontendInput($existingModel->getFrontendInput());
@@ -176,8 +179,11 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
176179
$attribute->setIsUserDefined(1);
177180
}
178181
$this->attributeResource->save($attribute);
179-
foreach ($attribute->getOptions() as $option) {
180-
$this->getOptionManagement()->add($attribute->getAttributeCode(), $option);
182+
183+
if (!empty($attribute->getData(AttributeInterface::OPTIONS))) {
184+
foreach ($attribute->getOptions() as $option) {
185+
$this->getOptionManagement()->add($attribute->getAttributeCode(), $option);
186+
}
181187
}
182188
return $this->get($attribute->getAttributeCode());
183189
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/RepositoryTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace Magento\Catalog\Test\Unit\Model\Product\Attribute;
1111

12-
use \Magento\Catalog\Model\Product\Attribute\Repository;
12+
use Magento\Catalog\Model\Product\Attribute\Repository;
13+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
14+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1315

1416
/**
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -261,4 +263,29 @@ public function testSaveInputExceptionInvalidFieldValue()
261263

262264
$this->model->save($attributeMock);
263265
}
266+
267+
public function testSaveDoesNotSaveAttributeOptionsIfOptionsAreAbsentInPayload()
268+
{
269+
$attributeId = 1;
270+
$attributeCode = 'existing_attribute_code';
271+
$attributeMock = $this->getMock(Attribute::class, [], [], '', false);
272+
$attributeMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
273+
$attributeMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
274+
275+
$existingModelMock = $this->getMock(Attribute::class, [], [], '', false);
276+
$existingModelMock->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode);
277+
$existingModelMock->expects($this->any())->method('getAttributeId')->willReturn($attributeId);
278+
279+
$this->eavAttributeRepositoryMock->expects($this->any())
280+
->method('get')
281+
->with(ProductAttributeInterface::ENTITY_TYPE_CODE, $attributeCode)
282+
->willReturn($existingModelMock);
283+
284+
// Attribute code must not be changed after attribute creation
285+
$attributeMock->expects($this->once())->method('setAttributeCode')->with($attributeCode);
286+
$this->attributeResourceMock->expects($this->once())->method('save')->with($attributeMock);
287+
$this->optionManagementMock->expects($this->never())->method('add');
288+
289+
$this->model->save($attributeMock);
290+
}
264291
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,4 +1467,27 @@ public function testGetTypeId()
14671467
$this->model->setTypeId('typeId');
14681468
$this->model->getTypeInstance();
14691469
}
1470+
1471+
public function testGetOptionById()
1472+
{
1473+
$optionId = 100;
1474+
$optionMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, [], [], '', false);
1475+
$this->model->setOptions([$optionMock]);
1476+
$optionMock->expects($this->once())->method('getId')->willReturn($optionId);
1477+
$this->assertEquals($optionMock, $this->model->getOptionById($optionId));
1478+
}
1479+
1480+
public function testGetOptionByIdWithWrongOptionId()
1481+
{
1482+
$optionId = 100;
1483+
$optionMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, [], [], '', false);
1484+
$this->model->setOptions([$optionMock]);
1485+
$optionMock->expects($this->once())->method('getId')->willReturn(200);
1486+
$this->assertNull($this->model->getOptionById($optionId));
1487+
}
1488+
1489+
public function testGetOptionByIdForProductWithoutOptions()
1490+
{
1491+
$this->assertNull($this->model->getOptionById(100));
1492+
}
14701493
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,13 @@
313313
},
314314

315315
save : function() {
316+
var block;
317+
316318
if ($('messages')) {
317319
$('messages').update();
320+
} else {
321+
block = jQuery('<div/>').attr('id', 'messages');
322+
jQuery('.page-main-actions').after(block);
318323
}
319324
TreePanels.rebuildTrees();
320325
if(!jQuery('#set-prop-form').valid()) {

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ protected function _updateAttributeOption($object, $optionId, $option)
464464
{
465465
$connection = $this->getConnection();
466466
$table = $this->getTable('eav_attribute_option');
467-
$intOptionId = (int)$optionId;
467+
// ignore strings that start with a number
468+
$intOptionId = is_numeric($optionId) ? (int)$optionId : 0;
468469

469470
if (!empty($option['delete'][$optionId])) {
470471
if ($intOptionId) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ public function collect(
6060
$addressWeight = $address->getWeight();
6161
$freeMethodWeight = $address->getFreeMethodWeight();
6262

63-
$isAllFree = $this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems());
64-
if ($isAllFree && !$address->getFreeShipping()) {
65-
$address->setFreeShipping(true);
66-
}
63+
$address->setFreeShipping(
64+
$this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems())
65+
);
6766
$total->setTotalAmount($this->getCode(), 0);
6867
$total->setBaseTotalAmount($this->getCode(), 0);
6968

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ protected function _createCustomerForm(\Magento\Customer\Api\Data\CustomerInterf
12871287
'adminhtml_checkout',
12881288
$this->customerMapper->toFlatArray($customer),
12891289
false,
1290-
CustomerForm::DONT_IGNORE_INVISIBLE
1290+
CustomerForm::IGNORE_INVISIBLE
12911291
);
12921292

12931293
return $customerForm;
@@ -1547,6 +1547,11 @@ public function setPaymentData($data)
15471547
public function applyCoupon($code)
15481548
{
15491549
$code = trim((string)$code);
1550+
$this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
1551+
1552+
if (empty($code)) {
1553+
$this->getQuote()->getShippingAddress()->setFreeShipping(null);
1554+
}
15501555
$this->getQuote()->setCouponCode($code);
15511556
$this->setRecollect(true);
15521557

@@ -1563,13 +1568,11 @@ public function setAccountData($accountData)
15631568
{
15641569
$customer = $this->getQuote()->getCustomer();
15651570
$form = $this->_createCustomerForm($customer);
1566-
$customerData = $this->customerMapper->toFlatArray($customer);
15671571

15681572
// emulate request
15691573
$request = $form->prepareRequest($accountData);
15701574
$data = $form->extractData($request);
15711575
$data = $form->restoreData($data);
1572-
$data = array_merge($customerData, array_filter($data));
15731576
$customer = $this->customerFactory->create();
15741577
$this->dataObjectHelper->populateWithArray(
15751578
$customer,
@@ -1578,6 +1581,7 @@ public function setAccountData($accountData)
15781581
$this->getQuote()->updateCustomerData($customer);
15791582
$data = [];
15801583

1584+
$customerData = $this->customerMapper->toFlatArray($customer);
15811585
foreach ($form->getAttributes() as $attribute) {
15821586
$code = sprintf('customer_%s', $attribute->getAttributeCode());
15831587
$data[$code] = isset($customerData[$attribute->getAttributeCode()])
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Model\Order\Invoice\Plugin;
8+
9+
class AddressUpdate
10+
{
11+
/**
12+
* @var \Magento\Sales\Model\ResourceModel\GridPool
13+
*/
14+
private $gridPool;
15+
16+
/**
17+
* @var \Magento\Sales\Model\ResourceModel\Attribute
18+
*/
19+
private $attribute;
20+
21+
/**
22+
* AddressUpdate constructor.
23+
* @param \Magento\Sales\Model\ResourceModel\GridPool $gridPool
24+
* @param \Magento\Sales\Model\ResourceModel\Attribute $attribute
25+
*/
26+
public function __construct(
27+
\Magento\Sales\Model\ResourceModel\GridPool $gridPool,
28+
\Magento\Sales\Model\ResourceModel\Attribute $attribute
29+
) {
30+
$this->gridPool = $gridPool;
31+
$this->attribute = $attribute;
32+
}
33+
34+
/**
35+
* @param \Magento\Sales\Model\ResourceModel\Order\Handler\Address $subject
36+
* @param \Magento\Sales\Model\ResourceModel\Order\Handler\Address $result
37+
* @param \Magento\Sales\Model\Order $order
38+
* @return void
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterProcess(
42+
\Magento\Sales\Model\ResourceModel\Order\Handler\Address $subject,
43+
\Magento\Sales\Model\ResourceModel\Order\Handler\Address $result,
44+
\Magento\Sales\Model\Order $order
45+
) {
46+
if ($order->hasInvoices()) {
47+
$billingAddress = $order->getBillingAddress();
48+
$shippingAddress = $order->getShippingAddress();
49+
50+
$orderInvoiceHasChanges = false;
51+
/** @var \Magento\Sales\Model\Order\Invoice $invoice */
52+
foreach ($order->getInvoiceCollection()->getItems() as $invoice) {
53+
$invoiceAttributesForSave = [];
54+
55+
if (!$invoice->getBillingAddressId() && $billingAddress) {
56+
$invoice->setBillingAddressId($billingAddress->getId());
57+
$invoiceAttributesForSave[] = 'billing_address_id';
58+
$orderInvoiceHasChanges = true;
59+
}
60+
61+
if (!$invoice->getShippingAddressId() && $shippingAddress) {
62+
$invoice->setShippingAddressId($shippingAddress->getId());
63+
$invoiceAttributesForSave[] = 'shipping_address_id';
64+
$orderInvoiceHasChanges = true;
65+
}
66+
67+
if (!empty($invoiceAttributesForSave)) {
68+
$this->attribute->saveAttribute($invoice, $invoiceAttributesForSave);
69+
}
70+
}
71+
72+
if ($orderInvoiceHasChanges) {
73+
$this->gridPool->refreshByOrderId($order->getId());
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)