Skip to content

Commit

Permalink
Merge pull request #520 from magento-folks/bugs
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
slavvka authored Oct 19, 2016
2 parents a5b4aea + 8d163ee commit 8d0dc6f
Show file tree
Hide file tree
Showing 30 changed files with 825 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ define(
addressData.region.region_code = region['code'];
addressData.region.region = region['name'];
}
} else if (
!addressData.region_id
&& countryData()[addressData.country_id]
&& countryData()[addressData.country_id]['regions']
) {
addressData.region.region_code = '';
addressData.region.region = '';
}
delete addressData.region_id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ define([], function () {
return {
email: addressData.email,
countryId: addressData['country_id'] || addressData.countryId || window.checkoutConfig.defaultCountryId,
regionId: regionId,
regionId: regionId || addressData.regionId,
regionCode: (addressData.region) ? addressData.region.region_code : null,
region: (addressData.region) ? addressData.region.region : null,
customerId: addressData.customer_id,
street: addressData.street,
company: addressData.company,
telephone: addressData.telephone,
fax: addressData.fax,
postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode,
postcode: addressData.postcode ? addressData.postcode : window.checkoutConfig.defaultPostcode || undefined,
city: addressData.city,
firstname: addressData.firstname,
lastname: addressData.lastname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ define(
address;

if (this.validateAddressData(addressFlat)) {
addressFlat = $.extend(true, {}, quote.shippingAddress(), addressFlat);
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
selectShippingAddress(address);
}
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Quote/Model/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,12 @@ public function reserveOrderId()
{
if (!$this->getReservedOrderId()) {
$this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
} else {
//checking if reserved order id was already used for some order
//if yes reserving new one if not using old one
if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) {
$this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
}
}
return $this;
}
Expand Down
14 changes: 8 additions & 6 deletions app/code/Magento/Quote/Model/Quote/Address/Total/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ public function collect(

$addressWeight = $address->getWeight();
$freeMethodWeight = $address->getFreeMethodWeight();
$addressFreeShipping = $address->getFreeShipping();

$address->setFreeShipping(
$this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems())
);
$total->setTotalAmount($this->getCode(), 0);
$total->setBaseTotalAmount($this->getCode(), 0);

Expand Down Expand Up @@ -98,7 +96,7 @@ public function collect(
$itemQty = $child->getTotalQty();
$rowWeight = $itemWeight * $itemQty;
$addressWeight += $rowWeight;
if ($address->getFreeShipping() || $child->getFreeShipping() === true) {
if ($addressFreeShipping || $child->getFreeShipping() === true) {
$rowWeight = 0;
} elseif (is_numeric($child->getFreeShipping())) {
$freeQty = $child->getFreeShipping();
Expand All @@ -116,7 +114,7 @@ public function collect(
$itemWeight = $item->getWeight();
$rowWeight = $itemWeight * $item->getQty();
$addressWeight += $rowWeight;
if ($address->getFreeShipping() || $item->getFreeShipping() === true) {
if ($addressFreeShipping || $item->getFreeShipping() === true) {
$rowWeight = 0;
} elseif (is_numeric($item->getFreeShipping())) {
$freeQty = $item->getFreeShipping();
Expand All @@ -136,7 +134,7 @@ public function collect(
$itemWeight = $item->getWeight();
$rowWeight = $itemWeight * $item->getQty();
$addressWeight += $rowWeight;
if ($address->getFreeShipping() || $item->getFreeShipping() === true) {
if ($addressFreeShipping || $item->getFreeShipping() === true) {
$rowWeight = 0;
} elseif (is_numeric($item->getFreeShipping())) {
$freeQty = $item->getFreeShipping();
Expand All @@ -157,6 +155,10 @@ public function collect(

$address->setWeight($addressWeight);
$address->setFreeMethodWeight($freeMethodWeight);
$address->setFreeShipping(
$this->freeShipping->isFreeShipping($quote, $shippingAssignment->getItems())
);

$address->collectShippingRates();

if ($method) {
Expand Down
23 changes: 23 additions & 0 deletions app/code/Magento/Quote/Model/ResourceModel/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ public function getReservedOrderId($quote)
->getNextValue();
}

/**
* Check if order increment ID is already used.
* Method can be used to avoid collisions of order IDs.
*
* @param int $orderIncrementId
* @return bool
*/
public function isOrderIncrementIdUsed($orderIncrementId)
{
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
$adapter = $this->getConnection();
$bind = [':increment_id' => $orderIncrementId];
/** @var \Magento\Framework\DB\Select $select */
$select = $adapter->select();
$select->from($this->getTable('sales_order'), 'entity_id')->where('increment_id = :increment_id');
$entity_id = $adapter->fetchOne($select, $bind);
if ($entity_id > 0) {
return true;
}

return false;
}

/**
* Mark quotes - that depend on catalog price rules - to be recollected on demand
*
Expand Down
31 changes: 30 additions & 1 deletion app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ protected function setUp()
'customerRepository' => $this->customerRepositoryMock,
'objectCopyService' => $this->objectCopyServiceMock,
'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
'customerDataFactory' => $this->customerDataFactoryMock
'customerDataFactory' => $this->customerDataFactoryMock,
'data' => [
'reserved_order_id' => 1000001
]
]
);
}
Expand Down Expand Up @@ -1237,4 +1240,30 @@ public function testGetAllItems()

$this->assertEquals($itemResult, $this->quote->getAllItems());
}

/**
* Test to verify if existing reserved_order_id in use
*
* @param bool $isReservedOrderIdExist
* @param int $reservedOrderId
* @dataProvider reservedOrderIdDataProvider
*/
public function testReserveOrderId($isReservedOrderIdExist, $reservedOrderId)
{
$this->resourceMock
->expects($this->once())
->method('isOrderIncrementIdUsed')
->with(1000001)->willReturn($isReservedOrderIdExist);
$this->resourceMock->expects($this->any())->method('getReservedOrderId')->willReturn($reservedOrderId);
$this->quote->reserveOrderId();
$this->assertEquals($reservedOrderId, $this->quote->getReservedOrderId());
}

public function reservedOrderIdDataProvider()
{
return [
'id_already_in_use' => [true, 100002],
'id_not_in_use' => [false, 1000001]
];
}
}
84 changes: 84 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Quote\Test\Unit\Model\ResourceModel;

class QuoteTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Quote\Model\ResourceModel\Quote
*/
private $model;

/**
* @var \Magento\Framework\App\ResourceConnection
*/
private $resourceMock;

/**
* @var \Magento\Framework\DB\Adapter\Pdo\Mysql
*/
private $adapterMock;

/**
* @var \Magento\Framework\DB\Select
*/
private $selectMock;

protected function setUp()
{
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->getMock();
$this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
$this->selectMock->expects($this->any())->method('where');

$this->adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
->disableOriginalConstructor()
->getMock();
$this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));

$this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
->disableOriginalConstructor()
->getMock();
$this->resourceMock->expects(
$this->any()
)->method(
'getConnection'
)->will(
$this->returnValue($this->adapterMock)
);

$this->model = $objectManagerHelper->getObject(
\Magento\Quote\Model\ResourceModel\Quote::class,
[
'resource' => $this->resourceMock
]
);
}

/**
* Unit test to verify if isOrderIncrementIdUsed method works with different types increment ids
*
* @param array $value
* @dataProvider isOrderIncrementIdUsedDataProvider
*/
public function testIsOrderIncrementIdUsed($value)
{
$expectedBind = [':increment_id' => $value];
$this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind);
$this->model->isOrderIncrementIdUsed($value);
}

/**
* @return array
*/
public function isOrderIncrementIdUsedDataProvider()
{
return [[100000001], ['10000000001'], ['M10000000001']];
}
}
5 changes: 5 additions & 0 deletions app/code/Magento/Wishlist/Controller/Index/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function __construct(
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function execute()
{
Expand All @@ -137,6 +138,10 @@ public function execute()

// Set qty
$qty = $this->getRequest()->getParam('qty');
$postQty = $this->getRequest()->getPostValue('qty');
if ($postQty !== null && $qty !== $postQty) {
$qty = $postQty;
}
if (is_array($qty)) {
if (isset($qty[$itemId])) {
$qty = $qty[$itemId];
Expand Down
Loading

0 comments on commit 8d0dc6f

Please sign in to comment.