Skip to content

Commit 8d0dc6f

Browse files
authored
Merge pull request #520 from magento-folks/bugs
[Folks] Bugs - MAGETWO-58334 [Github] Free shipping is not applied if cart price rule match #6584 - MAGETWO-57278 For Dutch locale, ZIP in checkout is already giving out a "validation failed" error at page load - MAGETWO-57675 [GITHUB] WYSIWYG editor does not show. #6222 #4828 #6815 - MAGETWO-56836 [FT] Update wishlist button doesn't receive the click in AddProductsToCartFromCustomerWishlistOnFrontendTest - MAGETWO-54412 [MERCHANT] Integrity Constraint Violation when creating orders #4580 - MAGETWO-58730 [Github] Incorrect province code sent on Checkout to UPS #6564
2 parents a5b4aea + 8d163ee commit 8d0dc6f

File tree

30 files changed

+825
-15
lines changed

30 files changed

+825
-15
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ define(
4444
addressData.region.region_code = region['code'];
4545
addressData.region.region = region['name'];
4646
}
47+
} else if (
48+
!addressData.region_id
49+
&& countryData()[addressData.country_id]
50+
&& countryData()[addressData.country_id]['regions']
51+
) {
52+
addressData.region.region_code = '';
53+
addressData.region.region = '';
4754
}
4855
delete addressData.region_id;
4956

app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ define([], function () {
2222
return {
2323
email: addressData.email,
2424
countryId: addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId,
25-
regionId: regionId,
25+
regionId: regionId || addressData.regionId,
2626
regionCode: (addressData.region) ? addressData.region.region_code : null,
2727
region: (addressData.region) ? addressData.region.region : null,
2828
customerId: addressData.customer_id,
2929
street: addressData.street,
3030
company: addressData.company,
3131
telephone: addressData.telephone,
3232
fax: addressData.fax,
33-
postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode,
33+
postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode || undefined,
3434
city: addressData.city,
3535
firstname: addressData.firstname,
3636
lastname: addressData.lastname,

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ define(
176176
address;
177177

178178
if (this.validateAddressData(addressFlat)) {
179-
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
179+
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
180180
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
181181
selectShippingAddress(address);
182182
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,12 @@ public function reserveOrderId()
21572157
{
21582158
if (!$this->getReservedOrderId()) {
21592159
$this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
2160+
} else {
2161+
//checking if reserved order id was already used for some order
2162+
//if yes reserving new one if not using old one
2163+
if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) {
2164+
$this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
2165+
}
21602166
}
21612167
return $this;
21622168
}

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ public function collect(
5959

6060
$addressWeight = $address->getWeight();
6161
$freeMethodWeight = $address->getFreeMethodWeight();
62+
$addressFreeShipping = $address->getFreeShipping();
6263

63-
$address->setFreeShipping(
64-
$this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems())
65-
);
6664
$total->setTotalAmount($this->getCode(), 0);
6765
$total->setBaseTotalAmount($this->getCode(), 0);
6866

@@ -98,7 +96,7 @@ public function collect(
9896
$itemQty = $child->getTotalQty();
9997
$rowWeight = $itemWeight * $itemQty;
10098
$addressWeight += $rowWeight;
101-
if ($address->getFreeShipping() || $child->getFreeShipping() === true) {
99+
if ($addressFreeShipping || $child->getFreeShipping() === true) {
102100
$rowWeight = 0;
103101
} elseif (is_numeric($child->getFreeShipping())) {
104102
$freeQty = $child->getFreeShipping();
@@ -116,7 +114,7 @@ public function collect(
116114
$itemWeight = $item->getWeight();
117115
$rowWeight = $itemWeight * $item->getQty();
118116
$addressWeight += $rowWeight;
119-
if ($address->getFreeShipping() || $item->getFreeShipping() === true) {
117+
if ($addressFreeShipping || $item->getFreeShipping() === true) {
120118
$rowWeight = 0;
121119
} elseif (is_numeric($item->getFreeShipping())) {
122120
$freeQty = $item->getFreeShipping();
@@ -136,7 +134,7 @@ public function collect(
136134
$itemWeight = $item->getWeight();
137135
$rowWeight = $itemWeight * $item->getQty();
138136
$addressWeight += $rowWeight;
139-
if ($address->getFreeShipping() || $item->getFreeShipping() === true) {
137+
if ($addressFreeShipping || $item->getFreeShipping() === true) {
140138
$rowWeight = 0;
141139
} elseif (is_numeric($item->getFreeShipping())) {
142140
$freeQty = $item->getFreeShipping();
@@ -157,6 +155,10 @@ public function collect(
157155

158156
$address->setWeight($addressWeight);
159157
$address->setFreeMethodWeight($freeMethodWeight);
158+
$address->setFreeShipping(
159+
$this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems())
160+
);
161+
160162
$address->collectShippingRates();
161163

162164
if ($method) {

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

+23
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,29 @@ public function getReservedOrderId($quote)
172172
->getNextValue();
173173
}
174174

175+
/**
176+
* Check if order increment ID is already used.
177+
* Method can be used to avoid collisions of order IDs.
178+
*
179+
* @param int $orderIncrementId
180+
* @return bool
181+
*/
182+
public function isOrderIncrementIdUsed($orderIncrementId)
183+
{
184+
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
185+
$adapter = $this->getConnection();
186+
$bind = [':increment_id' => $orderIncrementId];
187+
/** @var \Magento\Framework\DB\Select $select */
188+
$select = $adapter->select();
189+
$select->from($this->getTable('sales_order'), 'entity_id')->where('increment_id = :increment_id');
190+
$entity_id = $adapter->fetchOne($select, $bind);
191+
if ($entity_id > 0) {
192+
return true;
193+
}
194+
195+
return false;
196+
}
197+
175198
/**
176199
* Mark quotes - that depend on catalog price rules - to be recollected on demand
177200
*

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

+30-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ protected function setUp()
314314
'customerRepository' => $this->customerRepositoryMock,
315315
'objectCopyService' => $this->objectCopyServiceMock,
316316
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
317-
'customerDataFactory' => $this->customerDataFactoryMock
317+
'customerDataFactory' => $this->customerDataFactoryMock,
318+
'data' => [
319+
'reserved_order_id' => 1000001
320+
]
318321
]
319322
);
320323
}
@@ -1237,4 +1240,30 @@ public function testGetAllItems()
12371240

12381241
$this->assertEquals($itemResult, $this->quote->getAllItems());
12391242
}
1243+
1244+
/**
1245+
* Test to verify if existing reserved_order_id in use
1246+
*
1247+
* @param bool $isReservedOrderIdExist
1248+
* @param int $reservedOrderId
1249+
* @dataProvider reservedOrderIdDataProvider
1250+
*/
1251+
public function testReserveOrderId($isReservedOrderIdExist, $reservedOrderId)
1252+
{
1253+
$this->resourceMock
1254+
->expects($this->once())
1255+
->method('isOrderIncrementIdUsed')
1256+
->with(1000001)->willReturn($isReservedOrderIdExist);
1257+
$this->resourceMock->expects($this->any())->method('getReservedOrderId')->willReturn($reservedOrderId);
1258+
$this->quote->reserveOrderId();
1259+
$this->assertEquals($reservedOrderId, $this->quote->getReservedOrderId());
1260+
}
1261+
1262+
public function reservedOrderIdDataProvider()
1263+
{
1264+
return [
1265+
'id_already_in_use' => [true, 100002],
1266+
'id_not_in_use' => [false, 1000001]
1267+
];
1268+
}
12401269
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Quote\Test\Unit\Model\ResourceModel;
8+
9+
class QuoteTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Quote\Model\ResourceModel\Quote
13+
*/
14+
private $model;
15+
16+
/**
17+
* @var \Magento\Framework\App\ResourceConnection
18+
*/
19+
private $resourceMock;
20+
21+
/**
22+
* @var \Magento\Framework\DB\Adapter\Pdo\Mysql
23+
*/
24+
private $adapterMock;
25+
26+
/**
27+
* @var \Magento\Framework\DB\Select
28+
*/
29+
private $selectMock;
30+
31+
protected function setUp()
32+
{
33+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34+
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
35+
->disableOriginalConstructor()
36+
->getMock();
37+
$this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
38+
$this->selectMock->expects($this->any())->method('where');
39+
40+
$this->adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
41+
->disableOriginalConstructor()
42+
->getMock();
43+
$this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
44+
45+
$this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
46+
->disableOriginalConstructor()
47+
->getMock();
48+
$this->resourceMock->expects(
49+
$this->any()
50+
)->method(
51+
'getConnection'
52+
)->will(
53+
$this->returnValue($this->adapterMock)
54+
);
55+
56+
$this->model = $objectManagerHelper->getObject(
57+
\Magento\Quote\Model\ResourceModel\Quote::class,
58+
[
59+
'resource' => $this->resourceMock
60+
]
61+
);
62+
}
63+
64+
/**
65+
* Unit test to verify if isOrderIncrementIdUsed method works with different types increment ids
66+
*
67+
* @param array $value
68+
* @dataProvider isOrderIncrementIdUsedDataProvider
69+
*/
70+
public function testIsOrderIncrementIdUsed($value)
71+
{
72+
$expectedBind = [':increment_id' => $value];
73+
$this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind);
74+
$this->model->isOrderIncrementIdUsed($value);
75+
}
76+
77+
/**
78+
* @return array
79+
*/
80+
public function isOrderIncrementIdUsedDataProvider()
81+
{
82+
return [[100000001], ['10000000001'], ['M10000000001']];
83+
}
84+
}

app/code/Magento/Wishlist/Controller/Index/Cart.php

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function __construct(
113113
* @return \Magento\Framework\Controller\ResultInterface
114114
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
115115
* @SuppressWarnings(PHPMD.NPathComplexity)
116+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
116117
*/
117118
public function execute()
118119
{
@@ -137,6 +138,10 @@ public function execute()
137138

138139
// Set qty
139140
$qty = $this->getRequest()->getParam('qty');
141+
$postQty = $this->getRequest()->getPostValue('qty');
142+
if ($postQty !== null && $qty !== $postQty) {
143+
$qty = $postQty;
144+
}
140145
if (is_array($qty)) {
141146
if (isset($qty[$itemId])) {
142147
$qty = $qty[$itemId];

0 commit comments

Comments
 (0)