Skip to content

Commit f94b4a8

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.3-develop
Accepted Community Pull Requests: - #23425: The best practices for SEO meta sequence. (by @vaseemishak) - #23390: Changed logic so that _scrollToTopIfVisible is called only if element is in viewport. Previously it was called only when the element was outside it. (by @oskarolaussen) - #23048: #22998 : failing order creation with api when no address email is provided (by @Wirson) - #22987: Fixed apply discount coupons for bundle product (by @NikolasSumrak) Fixed GitHub Issues: - #22998: POST on /orders fails when properties in the body are out of sequence (reported by @YurySk) has been fixed in #23048 by @Wirson in 2.3-develop branch Related commits: 1. 5ca9ea7
2 parents 3495a05 + 9a78a3d commit f94b4a8

File tree

7 files changed

+115
-55
lines changed

7 files changed

+115
-55
lines changed

app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Magento\Store\Model\StoreManagerInterface;
1717
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1818

19+
/**
20+
* Test for Magento\OfflineShipping\Model\Quote\Address\FreeShipping class.
21+
*/
1922
class FreeShippingTest extends \PHPUnit\Framework\TestCase
2023
{
2124
private static $websiteId = 1;
@@ -77,12 +80,14 @@ public function testIsFreeShipping(int $addressFree, int $fItemFree, int $sItemF
7780
[$fItem],
7881
[$sItem]
7982
)
80-
->willReturnCallback(function () use ($fItem, $sItem, $addressFree, $fItemFree, $sItemFree) {
81-
// emulate behavior of cart rule calculator
82-
$fItem->getAddress()->setFreeShipping($addressFree);
83-
$fItem->setFreeShipping($fItemFree);
84-
$sItem->setFreeShipping($sItemFree);
85-
});
83+
->willReturnCallback(
84+
function () use ($fItem, $sItem, $addressFree, $fItemFree, $sItemFree) {
85+
// emulate behavior of cart rule calculator
86+
$fItem->getAddress()->setFreeShipping($addressFree);
87+
$fItem->setFreeShipping($fItemFree);
88+
$sItem->setFreeShipping($sItemFree);
89+
}
90+
);
8691

8792
$actual = $this->model->isFreeShipping($quote, $items);
8893
self::assertEquals($expected, $actual);
@@ -133,8 +138,11 @@ private function getQuote(Address $address): Quote
133138
->disableOriginalConstructor()
134139
->setMethods(
135140
[
136-
'getCouponCode', 'getCustomerGroupId', 'getShippingAddress', 'getStoreId', 'getItemsQty',
137-
'getVirtualItemsQty'
141+
'getCouponCode',
142+
'getCustomerGroupId',
143+
'getShippingAddress',
144+
'getStoreId',
145+
'isVirtual'
138146
]
139147
)
140148
->getMock();
@@ -147,10 +155,8 @@ private function getQuote(Address $address): Quote
147155
->willReturn(self::$couponCode);
148156
$quote->method('getShippingAddress')
149157
->willReturn($address);
150-
$quote->method('getItemsQty')
151-
->willReturn(2);
152-
$quote->method('getVirtualItemsQty')
153-
->willReturn(0);
158+
$quote->method('isVirtual')
159+
->willReturn(false);
154160

155161
return $quote;
156162
}

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function beforeSave()
270270
*/
271271
public function getAddress()
272272
{
273-
if ($this->getQuote()->getItemsQty() == $this->getQuote()->getVirtualItemsQty()) {
273+
if ($this->getQuote()->isVirtual()) {
274274
$address = $this->getQuote()->getBillingAddress();
275275
} else {
276276
$address = $this->getQuote()->getShippingAddress();
@@ -282,7 +282,7 @@ public function getAddress()
282282
/**
283283
* Declare quote model object
284284
*
285-
* @param \Magento\Quote\Model\Quote $quote
285+
* @param \Magento\Quote\Model\Quote $quote
286286
* @return $this
287287
*/
288288
public function setQuote(\Magento\Quote\Model\Quote $quote)
@@ -719,6 +719,7 @@ public function getOptionByCode($code)
719719

720720
/**
721721
* Checks that item model has data changes.
722+
*
722723
* Call save item options if model isn't need to save in DB
723724
*
724725
* @return boolean
@@ -813,8 +814,9 @@ public function __clone()
813814
}
814815

815816
/**
816-
* Returns formatted buy request - object, holding request received from
817-
* product view page with keys and options for configured product
817+
* Get formatted buy request.
818+
*
819+
* Returns object, holding request received from product view page with keys and options for configured product.
818820
*
819821
* @return \Magento\Framework\DataObject
820822
*/
@@ -863,6 +865,7 @@ public function setHasError($flag)
863865

864866
/**
865867
* Clears list of errors, associated with this quote item.
868+
*
866869
* Also automatically removes error-flag from oneself.
867870
*
868871
* @return $this
@@ -876,6 +879,7 @@ protected function _clearErrorInfo()
876879

877880
/**
878881
* Adds error information to the quote item.
882+
*
879883
* Automatically sets error flag.
880884
*
881885
* @param string|null $origin Usually a name of module, that embeds error
@@ -930,97 +934,96 @@ public function removeErrorInfosByParams($params)
930934
}
931935

932936
/**
937+
* @inheritdoc
933938
* @codeCoverageIgnoreStart
934-
*
935-
* {@inheritdoc}
936939
*/
937940
public function getItemId()
938941
{
939942
return $this->getData(self::KEY_ITEM_ID);
940943
}
941944

942945
/**
943-
* {@inheritdoc}
946+
* @inheritdoc
944947
*/
945948
public function setItemId($itemID)
946949
{
947950
return $this->setData(self::KEY_ITEM_ID, $itemID);
948951
}
949952

950953
/**
951-
* {@inheritdoc}
954+
* @inheritdoc
952955
*/
953956
public function getSku()
954957
{
955958
return $this->getData(self::KEY_SKU);
956959
}
957960

958961
/**
959-
* {@inheritdoc}
962+
* @inheritdoc
960963
*/
961964
public function setSku($sku)
962965
{
963966
return $this->setData(self::KEY_SKU, $sku);
964967
}
965968

966969
/**
967-
* {@inheritdoc}
970+
* @inheritdoc
968971
*/
969972
public function getQty()
970973
{
971974
return $this->getData(self::KEY_QTY);
972975
}
973976

974977
/**
975-
* {@inheritdoc}
978+
* @inheritdoc
976979
*/
977980
public function getName()
978981
{
979982
return $this->getData(self::KEY_NAME);
980983
}
981984

982985
/**
983-
* {@inheritdoc}
986+
* @inheritdoc
984987
*/
985988
public function setName($name)
986989
{
987990
return $this->setData(self::KEY_NAME, $name);
988991
}
989992

990993
/**
991-
* {@inheritdoc}
994+
* @inheritdoc
992995
*/
993996
public function getPrice()
994997
{
995998
return $this->getData(self::KEY_PRICE);
996999
}
9971000

9981001
/**
999-
* {@inheritdoc}
1002+
* @inheritdoc
10001003
*/
10011004
public function setPrice($price)
10021005
{
10031006
return $this->setData(self::KEY_PRICE, $price);
10041007
}
10051008

10061009
/**
1007-
* {@inheritdoc}
1010+
* @inheritdoc
10081011
*/
10091012
public function setProductType($productType)
10101013
{
10111014
return $this->setData(self::KEY_PRODUCT_TYPE, $productType);
10121015
}
10131016

10141017
/**
1015-
* {@inheritdoc}
1018+
* @inheritdoc
10161019
*/
10171020
public function getQuoteId()
10181021
{
10191022
return $this->getData(self::KEY_QUOTE_ID);
10201023
}
10211024

10221025
/**
1023-
* {@inheritdoc}
1026+
* @inheritdoc
10241027
*/
10251028
public function setQuoteId($quoteId)
10261029
{
@@ -1051,7 +1054,7 @@ public function setProductOption(\Magento\Quote\Api\Data\ProductOptionInterface
10511054
//@codeCoverageIgnoreEnd
10521055

10531056
/**
1054-
* {@inheritdoc}
1057+
* @inheritdoc
10551058
*
10561059
* @return \Magento\Quote\Api\Data\CartItemExtensionInterface|null
10571060
*/
@@ -1061,7 +1064,7 @@ public function getExtensionAttributes()
10611064
}
10621065

10631066
/**
1064-
* {@inheritdoc}
1067+
* @inheritdoc
10651068
*
10661069
* @param \Magento\Quote\Api\Data\CartItemExtensionInterface $extensionAttributes
10671070
* @return $this

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,24 @@ protected function setUp()
135135
public function testGetAddress()
136136
{
137137
$quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
138-
->setMethods(['getShippingAddress', 'getBillingAddress', 'getStoreId', '__wakeup'])
138+
->setMethods(['getShippingAddress', 'getBillingAddress', 'getStoreId', '__wakeup', 'isVirtual'])
139139
->disableOriginalConstructor()
140140
->getMock();
141141
$quote->expects($this->once())
142142
->method('getShippingAddress')
143-
->will($this->returnValue('shipping'));
143+
->willReturn('shipping');
144144
$quote->expects($this->once())
145145
->method('getBillingAddress')
146-
->will($this->returnValue('billing'));
146+
->willReturn('billing');
147147
$quote->expects($this->any())
148148
->method('getStoreId')
149-
->will($this->returnValue(1));
149+
->willReturn(1);
150+
$quote->expects($this->exactly(2))
151+
->method('isVirtual')
152+
->willReturnOnConsecutiveCalls(false, true);
150153

151154
$this->model->setQuote($quote);
152-
153-
$quote->setItemsQty(2);
154-
$quote->setVirtualItemsQty(1);
155155
$this->assertEquals('shipping', $this->model->getAddress(), 'Wrong shipping address');
156-
157-
$quote->setItemsQty(2);
158-
$quote->setVirtualItemsQty(2);
159156
$this->assertEquals('billing', $this->model->getAddress(), 'Wrong billing address');
160157
}
161158

@@ -855,18 +852,20 @@ public function testSetOptionsWithNull()
855852
private function createOptionMock($optionCode, $optionData = [])
856853
{
857854
$optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class)
858-
->setMethods([
859-
'setData',
860-
'setItem',
861-
'getItem',
862-
'getCode',
863-
'__wakeup',
864-
'isDeleted',
865-
'delete',
866-
'getValue',
867-
'getProduct',
868-
'save'
869-
])
855+
->setMethods(
856+
[
857+
'setData',
858+
'setItem',
859+
'getItem',
860+
'getCode',
861+
'__wakeup',
862+
'isDeleted',
863+
'delete',
864+
'getValue',
865+
'getProduct',
866+
'save'
867+
]
868+
)
870869
->disableOriginalConstructor()
871870
->getMock();
872871
$optionMock->expects($this->any())

app/code/Magento/Sales/Model/Order/Address.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,5 +730,16 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\OrderAddressExten
730730
return $this->_setExtensionAttributes($extensionAttributes);
731731
}
732732

733+
/**
734+
* @inheritdoc
735+
*/
736+
public function beforeSave()
737+
{
738+
if ($this->getEmail() === null) {
739+
$this->setEmail($this->getOrder()->getCustomerEmail());
740+
}
741+
return parent::beforeSave();
742+
}
743+
733744
//@codeCoverageIgnoreEnd
734745
}

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
1515
use Magento\Customer\Model\Data\Customer;
1616
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Quote\Api\Data\AddressInterface;
1718
use Magento\TestFramework\Helper\Bootstrap;
1819
use Magento\TestFramework\ObjectManager;
1920
use Magento\Framework\Api\SearchCriteriaBuilder;
@@ -72,6 +73,46 @@ public function testCollectTotalsWithVirtual(): void
7273
$this->assertEquals(20, $quote->getBaseGrandTotal());
7374
}
7475

76+
/**
77+
* @magentoDataFixture Magento/Catalog/_files/product_virtual.php
78+
* @magentoDataFixture Magento/Quote/_files/empty_quote.php
79+
* @return void
80+
*/
81+
public function testGetAddressWithVirtualProduct()
82+
{
83+
/** @var Quote $quote */
84+
$quote = $this->objectManager->create(Quote::class);
85+
$quote->load('reserved_order_id_1', 'reserved_order_id');
86+
$billingAddress = $this->objectManager->create(AddressInterface::class);
87+
$billingAddress->setFirstname('Joe')
88+
->setLastname('Doe')
89+
->setCountryId('US')
90+
->setRegion('TX')
91+
->setCity('Austin')
92+
->setStreet('1000 West Parmer Line')
93+
->setPostcode('11501')
94+
->setTelephone('123456789');
95+
$quote->setBillingAddress($billingAddress);
96+
$shippingAddress = $this->objectManager->create(AddressInterface::class);
97+
$shippingAddress->setFirstname('Joe')
98+
->setLastname('Doe')
99+
->setCountryId('US')
100+
->setRegion('NJ')
101+
->setCity('Newark')
102+
->setStreet('2775 Granville Lane')
103+
->setPostcode('07102')
104+
->setTelephone('9734685221');
105+
$quote->setShippingAddress($shippingAddress);
106+
$productRepository = $this->objectManager->create(
107+
ProductRepositoryInterface::class
108+
);
109+
$product = $productRepository->get('virtual-product', false, null, true);
110+
$quote->addProduct($product);
111+
$quote->save();
112+
$expectedAddress = $quote->getBillingAddress();
113+
$this->assertEquals($expectedAddress, $quote->getAllItems()[0]->getAddress());
114+
}
115+
75116
/**
76117
* @return void
77118
*/

lib/internal/Magento/Framework/View/Page/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ class Config
131131
'charset' => null,
132132
'media_type' => null,
133133
'content_type' => null,
134+
'title' => null,
134135
'description' => null,
135136
'keywords' => null,
136137
'robots' => null,
137-
'title' => null,
138138
];
139139

140140
/**

0 commit comments

Comments
 (0)