Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 5952772

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1713 from magento-engcom/develop-prs
Public Pull Requests magento/magento2#11903 7691: address with saveInAddressBook 0 are still being added to the address book for new customers by @RomaKis magento/magento2#11503 MAGETWO-81245: All arguments for mapping methods must be compatible with call_user_func_array by @kirmorozov Fixed Public Issues magento/magento2#7691 address with saveInAddressBook 0 are still being added to the address book for new customers magento/magento2#7678 StockItemCriteria::setProductsFilter doesn't work with array of ids
2 parents cf4be3d + d39bbb6 commit 5952772

File tree

13 files changed

+277
-54
lines changed

13 files changed

+277
-54
lines changed

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteria.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StockItemCriteria extends AbstractCriteria implements \Magento\CatalogInve
2121
public function __construct($mapper = '')
2222
{
2323
$this->mapperInterfaceName = $mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\Item\StockItemCriteriaMapper::class;
24-
$this->data['initial_condition'] = true;
24+
$this->data['initial_condition'] = [true];
2525
}
2626

2727
/**
@@ -38,7 +38,7 @@ public function setStockStatus($storeId = null)
3838
*/
3939
public function setStockFilter($stock)
4040
{
41-
$this->data['stock_filter'] = $stock;
41+
$this->data['stock_filter'] = [$stock];
4242
return true;
4343
}
4444

@@ -47,7 +47,7 @@ public function setStockFilter($stock)
4747
*/
4848
public function setScopeFilter($scope)
4949
{
50-
$this->data['website_filter'] = $scope;
50+
$this->data['website_filter'] = [$scope];
5151
return true;
5252
}
5353

@@ -56,7 +56,7 @@ public function setScopeFilter($scope)
5656
*/
5757
public function setProductsFilter($products)
5858
{
59-
$this->data['products_filter'] = $products;
59+
$this->data['products_filter'] = [$products];
6060
return true;
6161
}
6262

@@ -65,7 +65,7 @@ public function setProductsFilter($products)
6565
*/
6666
public function setManagedFilter($isStockManagedInConfig)
6767
{
68-
$this->data['managed_filter'] = $isStockManagedInConfig;
68+
$this->data['managed_filter'] = [$isStockManagedInConfig];
6969
return true;
7070
}
7171

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status/StockStatusCriteria.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ class StockStatusCriteria extends AbstractCriteria implements \Magento\CatalogIn
2121
public function __construct($mapper = '')
2222
{
2323
$this->mapperInterfaceName = $mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\Status\StockStatusCriteriaMapper::class;
24-
$this->data['initial_condition'] = true;
24+
$this->data['initial_condition'] = [true];
2525
}
2626

2727
/**
2828
* @inheritdoc
2929
*/
3030
public function setScopeFilter($scope)
3131
{
32-
$this->data['website_filter'] = $scope;
32+
$this->data['website_filter'] = [$scope];
3333
}
3434

3535
/**
3636
* @inheritdoc
3737
*/
3838
public function setProductsFilter($products)
3939
{
40-
$this->data['products_filter'] = $products;
40+
$this->data['products_filter'] = [$products];
4141
}
4242

4343
/**
4444
* @inheritdoc
4545
*/
4646
public function setQtyFilter($qty)
4747
{
48-
$this->data['qty_filter'] = $qty;
48+
$this->data['qty_filter'] = [$qty];
4949
}
5050

5151
/**

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/StockCriteria.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public function __construct($mapper = '')
1919
{
2020
$this->mapperInterfaceName =
2121
$mapper ?: \Magento\CatalogInventory\Model\ResourceModel\Stock\StockCriteriaMapper::class;
22-
$this->data['initial_condition'] = true;
22+
$this->data['initial_condition'] = [true];
2323
}
2424

2525
/**
2626
* @inheritdoc
2727
*/
2828
public function setScopeFilter($scope)
2929
{
30-
$this->data['website_filter'] = $scope;
30+
$this->data['website_filter'] = [$scope];
3131
return true;
3232
}
3333

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
466466
'email' => $quote->getCustomerEmail()
467467
]
468468
);
469+
$shippingAddress->setData('quote_address_id', $quote->getShippingAddress()->getId());
469470
$addresses[] = $shippingAddress;
470471
$order->setShippingAddress($shippingAddress);
471472
$order->setShippingMethod($quote->getShippingAddress()->getShippingMethod());
@@ -477,6 +478,7 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
477478
'email' => $quote->getCustomerEmail()
478479
]
479480
);
481+
$billingAddress->setData('quote_address_id', $quote->getBillingAddress()->getId());
480482
$addresses[] = $billingAddress;
481483
$order->setBillingAddress($billingAddress);
482484
$order->setAddresses($addresses);

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

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Exception\NoSuchEntityException;
1010

1111
use Magento\Quote\Model\CustomerManagement;
12+
use Magento\Sales\Api\Data\OrderAddressInterface;
1213

1314
/**
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -131,6 +132,11 @@ class QuoteManagementTest extends \PHPUnit\Framework\TestCase
131132
*/
132133
private $addressRepositoryMock;
133134

135+
/**
136+
* @var \PHPUnit_Framework_MockObject_MockObject
137+
*/
138+
private $quoteFactoryMock;
139+
134140
/**
135141
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
136142
*/
@@ -530,12 +536,12 @@ public function testSubmit()
530536
$shippingAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
531537
$payment = $this->createMock(\Magento\Quote\Model\Quote\Payment::class);
532538
$baseOrder = $this->createMock(\Magento\Sales\Api\Data\OrderInterface::class);
533-
$convertedBillingAddress = $this->createMock(\Magento\Sales\Api\Data\OrderAddressInterface::class);
534-
$convertedShippingAddress = $this->createMock(\Magento\Sales\Api\Data\OrderAddressInterface::class);
539+
$convertedBilling = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']);
540+
$convertedShipping = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']);
535541
$convertedPayment = $this->createMock(\Magento\Sales\Api\Data\OrderPaymentInterface::class);
536542
$convertedQuoteItem = $this->createMock(\Magento\Sales\Api\Data\OrderItemInterface::class);
537543

538-
$addresses = [$convertedShippingAddress, $convertedBillingAddress];
544+
$addresses = [$convertedShipping, $convertedBilling];
539545
$quoteItems = [$quoteItem];
540546
$convertedItems = [$convertedQuoteItem];
541547

@@ -564,7 +570,7 @@ public function testSubmit()
564570
'email' => '[email protected]'
565571
]
566572
)
567-
->willReturn($convertedShippingAddress);
573+
->willReturn($convertedShipping);
568574
$this->quoteAddressToOrderAddress->expects($this->at(1))
569575
->method('convert')
570576
->with(
@@ -574,22 +580,26 @@ public function testSubmit()
574580
'email' => '[email protected]'
575581
]
576582
)
577-
->willReturn($convertedBillingAddress);
583+
->willReturn($convertedBilling);
584+
$billingAddress->expects($this->once())->method('getId')->willReturn(4);
585+
$convertedBilling->expects($this->once())->method('setData')->with('quote_address_id', 4);
586+
578587
$this->quoteItemToOrderItem->expects($this->once())->method('convert')
579588
->with($quoteItem, ['parent_item' => null])
580589
->willReturn($convertedQuoteItem);
581590
$this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment)
582591
->willReturn($convertedPayment);
583592
$shippingAddress->expects($this->once())->method('getShippingMethod')->willReturn('free');
584-
593+
$shippingAddress->expects($this->once())->method('getId')->willReturn(5);
594+
$convertedShipping->expects($this->once())->method('setData')->with('quote_address_id', 5);
585595
$order = $this->prepareOrderFactory(
586596
$baseOrder,
587-
$convertedBillingAddress,
597+
$convertedBilling,
588598
$addresses,
589599
$convertedPayment,
590600
$convertedItems,
591601
$quoteId,
592-
$convertedShippingAddress
602+
$convertedShipping
593603
);
594604

595605
$this->orderManagement->expects($this->once())
@@ -857,22 +867,22 @@ protected function getQuote(
857867

858868
/**
859869
* @param \Magento\Sales\Api\Data\OrderInterface $baseOrder
860-
* @param \Magento\Sales\Api\Data\OrderAddressInterface $billingAddress
870+
* @param OrderAddressInterface $billingAddress
861871
* @param array $addresses
862872
* @param $payment
863873
* @param array $items
864874
* @param $quoteId
865-
* @param \Magento\Sales\Api\Data\OrderAddressInterface $shippingAddress
875+
* @param OrderAddressInterface $shippingAddress
866876
* @return \PHPUnit_Framework_MockObject_MockObject
867877
*/
868878
protected function prepareOrderFactory(
869879
\Magento\Sales\Api\Data\OrderInterface $baseOrder,
870-
\Magento\Sales\Api\Data\OrderAddressInterface $billingAddress,
880+
OrderAddressInterface $billingAddress,
871881
array $addresses,
872882
$payment,
873883
array $items,
874884
$quoteId,
875-
\Magento\Sales\Api\Data\OrderAddressInterface $shippingAddress = null,
885+
OrderAddressInterface $shippingAddress = null,
876886
$customerId = null
877887
) {
878888
$order = $this->createPartialMock(
@@ -963,9 +973,6 @@ protected function setPropertyValue(&$object, $property, $value)
963973
return $object;
964974
}
965975

966-
/**
967-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
968-
*/
969976
public function testSubmitForCustomer()
970977
{
971978
$orderData = [];
@@ -978,16 +985,12 @@ public function testSubmitForCustomer()
978985
$shippingAddress = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
979986
$payment = $this->createMock(\Magento\Quote\Model\Quote\Payment::class);
980987
$baseOrder = $this->createMock(\Magento\Sales\Api\Data\OrderInterface::class);
981-
$convertedBillingAddress = $this->createMock(
982-
\Magento\Sales\Api\Data\OrderAddressInterface::class
983-
);
984-
$convertedShippingAddress = $this->createMock(
985-
\Magento\Sales\Api\Data\OrderAddressInterface::class
986-
);
988+
$convertedBilling = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']);
989+
$convertedShipping = $this->createPartialMockForAbstractClass(OrderAddressInterface::class, ['setData']);
987990
$convertedPayment = $this->createMock(\Magento\Sales\Api\Data\OrderPaymentInterface::class);
988991
$convertedQuoteItem = $this->createMock(\Magento\Sales\Api\Data\OrderItemInterface::class);
989992

990-
$addresses = [$convertedShippingAddress, $convertedBillingAddress];
993+
$addresses = [$convertedShipping, $convertedBilling];
991994
$quoteItems = [$quoteItem];
992995
$convertedItems = [$convertedQuoteItem];
993996

@@ -1016,7 +1019,7 @@ public function testSubmitForCustomer()
10161019
'email' => '[email protected]'
10171020
]
10181021
)
1019-
->willReturn($convertedShippingAddress);
1022+
->willReturn($convertedShipping);
10201023
$this->quoteAddressToOrderAddress->expects($this->at(1))
10211024
->method('convert')
10221025
->with(
@@ -1026,22 +1029,23 @@ public function testSubmitForCustomer()
10261029
'email' => '[email protected]'
10271030
]
10281031
)
1029-
->willReturn($convertedBillingAddress);
1032+
->willReturn($convertedBilling);
10301033
$this->quoteItemToOrderItem->expects($this->once())->method('convert')
10311034
->with($quoteItem, ['parent_item' => null])
10321035
->willReturn($convertedQuoteItem);
10331036
$this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment)
10341037
->willReturn($convertedPayment);
10351038
$shippingAddress->expects($this->once())->method('getShippingMethod')->willReturn('free');
1036-
1039+
$shippingAddress->expects($this->once())->method('getId')->willReturn(5);
1040+
$convertedShipping->expects($this->once())->method('setData')->with('quote_address_id', 5);
10371041
$order = $this->prepareOrderFactory(
10381042
$baseOrder,
1039-
$convertedBillingAddress,
1043+
$convertedBilling,
10401044
$addresses,
10411045
$convertedPayment,
10421046
$convertedItems,
10431047
$quoteId,
1044-
$convertedShippingAddress
1048+
$convertedShipping
10451049
);
10461050
$customerAddressMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AddressInterface::class)
10471051
->getMockForAbstractClass();
@@ -1050,6 +1054,8 @@ public function testSubmitForCustomer()
10501054
$quote->expects($this->any())->method('addCustomerAddress')->with($customerAddressMock);
10511055
$billingAddress->expects($this->once())->method('getCustomerId')->willReturn(2);
10521056
$billingAddress->expects($this->once())->method('getSaveInAddressBook')->willReturn(false);
1057+
$billingAddress->expects($this->once())->method('getId')->willReturn(4);
1058+
$convertedBilling->expects($this->once())->method('setData')->with('quote_address_id', 4);
10531059
$this->orderManagement->expects($this->once())
10541060
->method('place')
10551061
->with($order)
@@ -1063,4 +1069,25 @@ public function testSubmitForCustomer()
10631069
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote);
10641070
$this->assertEquals($order, $this->model->submit($quote, $orderData));
10651071
}
1072+
1073+
/**
1074+
* Get mock for abstract class with methods.
1075+
*
1076+
* @param string $className
1077+
* @param array $methods
1078+
*
1079+
* @return \PHPUnit_Framework_MockObject_MockObject
1080+
*/
1081+
private function createPartialMockForAbstractClass($className, $methods = [])
1082+
{
1083+
return $this->getMockForAbstractClass(
1084+
$className,
1085+
[],
1086+
'',
1087+
true,
1088+
true,
1089+
true,
1090+
$methods
1091+
);
1092+
}
10661093
}

0 commit comments

Comments
 (0)