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

Commit 4c99249

Browse files
authored
Merge pull request #3640 from magento-engcom/2.3-develop-prs
[EngCom] Public Pull Requests - 2.3-develop
2 parents 8e38439 + 648ea36 commit 4c99249

File tree

17 files changed

+124
-15
lines changed

17 files changed

+124
-15
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,9 +3067,7 @@ private function formatStockDataForRow(array $rowData): array
30673067

30683068
if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($sku)['type_id'])) {
30693069
$stockItemDo->setData($row);
3070-
$row['is_in_stock'] = isset($row['is_in_stock']) && $stockItemDo->getBackorders()
3071-
? $row['is_in_stock']
3072-
: $this->stockStateProvider->verifyStock($stockItemDo);
3070+
$row['is_in_stock'] = $row['is_in_stock'] ?? $this->stockStateProvider->verifyStock($stockItemDo);
30733071
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
30743072
$date = $this->dateTimeFactory->create('now', new \DateTimeZone('UTC'));
30753073
$row['low_stock_date'] = $date->format(DateTime::DATETIME_PHP_FORMAT);

app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ private function removePlacedItemsFromQuote(array $shippingAddresses, array $pla
11821182
{
11831183
foreach ($shippingAddresses as $address) {
11841184
foreach ($address->getAllItems() as $addressItem) {
1185-
if (in_array($addressItem->getId(), $placedAddressItems)) {
1185+
if (in_array($addressItem->getQuoteItemId(), $placedAddressItems)) {
11861186
if ($addressItem->getProduct()->getIsVirtual()) {
11871187
$addressItem->isDeleted(true);
11881188
} else {
@@ -1232,7 +1232,7 @@ private function searchQuoteAddressId(OrderInterface $order, array $addresses):
12321232
$item = array_pop($items);
12331233
foreach ($addresses as $address) {
12341234
foreach ($address->getAllItems() as $addressItem) {
1235-
if ($addressItem->getId() == $item->getQuoteItemId()) {
1235+
if ($addressItem->getQuoteItemId() == $item->getQuoteItemId()) {
12361236
return (int)$address->getId();
12371237
}
12381238
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ public function validateMinimumAmount($multishipping = false)
22462246
if (!$minOrderActive) {
22472247
return true;
22482248
}
2249+
$includeDiscount = $this->_scopeConfig->getValue(
2250+
'sales/minimum_order/include_discount_amount',
2251+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
2252+
$storeId
2253+
);
22492254
$minOrderMulti = $this->_scopeConfig->isSetFlag(
22502255
'sales/minimum_order/multi_address',
22512256
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
@@ -2279,7 +2284,10 @@ public function validateMinimumAmount($multishipping = false)
22792284
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
22802285
foreach ($address->getQuote()->getItemsCollection() as $item) {
22812286
/** @var \Magento\Quote\Model\Quote\Item $item */
2282-
$amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes;
2287+
$amount = $includeDiscount ?
2288+
$item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes :
2289+
$item->getBaseRowTotal() + $taxes;
2290+
22832291
if ($amount < $minAmount) {
22842292
return false;
22852293
}
@@ -2289,7 +2297,9 @@ public function validateMinimumAmount($multishipping = false)
22892297
$baseTotal = 0;
22902298
foreach ($addresses as $address) {
22912299
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
2292-
$baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
2300+
$baseTotal += $includeDiscount ?
2301+
$address->getBaseSubtotalWithDiscount() + $taxes :
2302+
$address->getBaseSubtotal() + $taxes;
22932303
}
22942304
if ($baseTotal < $minAmount) {
22952305
return false;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,11 @@ public function validateMinimumAmount()
11491149
return true;
11501150
}
11511151

1152+
$includeDiscount = $this->_scopeConfig->getValue(
1153+
'sales/minimum_order/include_discount_amount',
1154+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1155+
$storeId
1156+
);
11521157
$amount = $this->_scopeConfig->getValue(
11531158
'sales/minimum_order/amount',
11541159
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
@@ -1159,9 +1164,12 @@ public function validateMinimumAmount()
11591164
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
11601165
$storeId
11611166
);
1167+
11621168
$taxes = $taxInclude ? $this->getBaseTaxAmount() : 0;
11631169

1164-
return ($this->getBaseSubtotalWithDiscount() + $taxes >= $amount);
1170+
return $includeDiscount ?
1171+
($this->getBaseSubtotalWithDiscount() + $taxes >= $amount) :
1172+
($this->getBaseSubtotal() + $taxes >= $amount);
11651173
}
11661174

11671175
/**

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Quote\Model\Quote;
99

1010
/**
11+
* Quote item model.
12+
*
1113
* @api
1214
* @method int getParentItemId()
1315
* @method \Magento\Quote\Model\Quote\Address\Item setParentItemId(int $value)
@@ -46,6 +48,8 @@
4648
* @method \Magento\Quote\Model\Quote\Address\Item setSuperProductId(int $value)
4749
* @method int getParentProductId()
4850
* @method \Magento\Quote\Model\Quote\Address\Item setParentProductId(int $value)
51+
* @method int getStoreId()
52+
* @method \Magento\Quote\Model\Quote\Address\Item setStoreId(int $value)
4953
* @method string getSku()
5054
* @method \Magento\Quote\Model\Quote\Address\Item setSku(string $value)
5155
* @method string getImage()
@@ -101,15 +105,15 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem
101105
protected $_quote;
102106

103107
/**
104-
* @return void
108+
* @inheritdoc
105109
*/
106110
protected function _construct()
107111
{
108112
$this->_init(\Magento\Quote\Model\ResourceModel\Quote\Address\Item::class);
109113
}
110114

111115
/**
112-
* @return $this|\Magento\Quote\Model\Quote\Item\AbstractItem
116+
* @inheritdoc
113117
*/
114118
public function beforeSave()
115119
{
@@ -154,6 +158,8 @@ public function getQuote()
154158
}
155159

156160
/**
161+
* Import quote item.
162+
*
157163
* @param \Magento\Quote\Model\Quote\Item $quoteItem
158164
* @return $this
159165
*/
@@ -168,6 +174,8 @@ public function importQuoteItem(\Magento\Quote\Model\Quote\Item $quoteItem)
168174
$quoteItem->getProductId()
169175
)->setProduct(
170176
$quoteItem->getProduct()
177+
)->setStoreId(
178+
$quoteItem->getStoreId()
171179
)->setSku(
172180
$quoteItem->getSku()
173181
)->setName(
@@ -190,10 +198,9 @@ public function importQuoteItem(\Magento\Quote\Model\Quote\Item $quoteItem)
190198
}
191199

192200
/**
193-
* @param string $code
194-
* @return \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface|null
201+
* @inheritdoc
195202
*/
196-
public function getOptionBycode($code)
203+
public function getOptionByCode($code)
197204
{
198205
if ($this->getQuoteItem()) {
199206
return $this->getQuoteItem()->getOptionBycode($code);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Quote\Model\Quote\Address;
77

88
/**
9+
* Class Total
10+
*
911
* @method string getCode()
1012
*
1113
* @api
@@ -54,6 +56,8 @@ public function __construct(
5456
*/
5557
public function setTotalAmount($code, $amount)
5658
{
59+
$amount = is_float($amount) ? round($amount, 4) : $amount;
60+
5761
$this->totalAmounts[$code] = $amount;
5862
if ($code != 'subtotal') {
5963
$code = $code . '_amount';
@@ -72,6 +76,8 @@ public function setTotalAmount($code, $amount)
7276
*/
7377
public function setBaseTotalAmount($code, $amount)
7478
{
79+
$amount = is_float($amount) ? round($amount, 4) : $amount;
80+
7581
$this->baseTotalAmounts[$code] = $amount;
7682
if ($code != 'subtotal') {
7783
$code = $code . '_amount';
@@ -167,6 +173,7 @@ public function getAllBaseTotalAmounts()
167173

168174
/**
169175
* Set the full info, which is used to capture tax related information.
176+
*
170177
* If a string is used, it is assumed to be serialized.
171178
*
172179
* @param array|string $info

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __construct(
4848
}
4949

5050
/**
51+
* Convert quote item(quote address item) into order item.
52+
*
5153
* @param Item|AddressItem $item
5254
* @param array $data
5355
* @return OrderItemInterface
@@ -63,6 +65,16 @@ public function convert($item, $data = [])
6365
'to_order_item',
6466
$item
6567
);
68+
if ($item instanceof \Magento\Quote\Model\Quote\Address\Item) {
69+
$orderItemData = array_merge(
70+
$orderItemData,
71+
$this->objectCopyService->getDataFromFieldset(
72+
'quote_convert_address_item',
73+
'to_order_item',
74+
$item
75+
)
76+
);
77+
}
6678
if (!$item->getNoDiscount()) {
6779
$data = array_merge(
6880
$data,

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public function testValidateMinimumAmountVirtual()
216216
$scopeConfigValues = [
217217
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
218218
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
219+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
219220
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
220221
];
221222

@@ -240,6 +241,31 @@ public function testValidateMinimumAmount()
240241
$scopeConfigValues = [
241242
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
242243
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
244+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
245+
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
246+
];
247+
248+
$this->quote->expects($this->once())
249+
->method('getStoreId')
250+
->willReturn($storeId);
251+
$this->quote->expects($this->once())
252+
->method('getIsVirtual')
253+
->willReturn(false);
254+
255+
$this->scopeConfig->expects($this->once())
256+
->method('isSetFlag')
257+
->willReturnMap($scopeConfigValues);
258+
259+
$this->assertTrue($this->address->validateMinimumAmount());
260+
}
261+
262+
public function testValidateMiniumumAmountWithoutDiscount()
263+
{
264+
$storeId = 1;
265+
$scopeConfigValues = [
266+
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
267+
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
268+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, false],
243269
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
244270
];
245271

@@ -263,6 +289,7 @@ public function testValidateMinimumAmountNegative()
263289
$scopeConfigValues = [
264290
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
265291
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
292+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
266293
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
267294
];
268295

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ public function testValidateMinimumAmount()
975975
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
976976
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
977977
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
978+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
978979
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
979980
];
980981
$this->scopeConfig->expects($this->any())
@@ -1001,6 +1002,7 @@ public function testValidateMinimumAmountNegative()
10011002
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
10021003
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
10031004
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
1005+
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
10041006
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
10051007
];
10061008
$this->scopeConfig->expects($this->any())

app/code/Magento/Quote/etc/db_schema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@
352352
comment="Super Product Id"/>
353353
<column xsi:type="int" name="parent_product_id" padding="10" unsigned="true" nullable="true" identity="false"
354354
comment="Parent Product Id"/>
355+
<column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="true" identity="false"
356+
comment="Store Id"/>
355357
<column xsi:type="varchar" name="sku" nullable="true" length="255" comment="Sku"/>
356358
<column xsi:type="varchar" name="image" nullable="true" length="255" comment="Image"/>
357359
<column xsi:type="varchar" name="name" nullable="true" length="255" comment="Name"/>
@@ -403,6 +405,9 @@
403405
<index referenceId="QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID" indexType="btree">
404406
<column name="quote_item_id"/>
405407
</index>
408+
<index referenceId="QUOTE_ADDRESS_ITEM_STORE_ID" indexType="btree">
409+
<column name="store_id"/>
410+
</index>
406411
</table>
407412
<table name="quote_item_option" resource="checkout" engine="innodb" comment="Sales Flat Quote Item Option">
408413
<column xsi:type="int" name="option_id" padding="10" unsigned="true" nullable="false" identity="true"

app/code/Magento/Quote/etc/db_schema_whitelist.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
"product_id": true,
213213
"super_product_id": true,
214214
"parent_product_id": true,
215+
"store_id": true,
215216
"sku": true,
216217
"image": true,
217218
"name": true,
@@ -233,7 +234,8 @@
233234
"index": {
234235
"QUOTE_ADDRESS_ITEM_QUOTE_ADDRESS_ID": true,
235236
"QUOTE_ADDRESS_ITEM_PARENT_ITEM_ID": true,
236-
"QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID": true
237+
"QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID": true,
238+
"QUOTE_ADDRESS_ITEM_STORE_ID": true
237239
},
238240
"constraint": {
239241
"PRIMARY": true,

app/code/Magento/Quote/etc/fieldset.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@
186186
<aspect name="to_order_address" />
187187
</field>
188188
</fieldset>
189+
<fieldset id="quote_convert_address_item">
190+
<field name="quote_item_id">
191+
<aspect name="to_order_item" />
192+
</field>
193+
</fieldset>
189194
<fieldset id="quote_convert_item">
190195
<field name="sku">
191196
<aspect name="to_order_item" />

app/code/Magento/Sales/etc/adminhtml/system.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
<label>Minimum Amount</label>
9090
<comment>Subtotal after discount</comment>
9191
</field>
92+
<field id="include_discount_amount" translate="label" sortOrder="12" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
93+
<label>Include Discount Amount</label>
94+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
95+
<comment>Choosing yes will be used subtotal after discount, otherwise only subtotal will be used</comment>
96+
</field>
9297
<field id="tax_including" translate="label" sortOrder="15" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
9398
<label>Include Tax to Amount</label>
9499
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

app/code/Magento/Sales/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<allow_zero_grandtotal>1</allow_zero_grandtotal>
2323
</zerograndtotal_creditmemo>
2424
<minimum_order>
25+
<include_discount_amount>1</include_discount_amount>
2526
<tax_including>1</tax_including>
2627
</minimum_order>
2728
<orders>

app/code/Magento/Swatches/view/adminhtml/web/css/swatches.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@
150150
}
151151

152152
.col-swatch-min-width {
153-
min-width: 30px;
153+
min-width: 65px;
154+
}
155+
156+
.data-table .col-swatch-min-width input[type="text"] {
157+
padding: inherit;
154158
}
155159

156160
.swatches-visual-col.unavailable:after {

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,20 @@ public function testImportWithBackordersEnabled(): void
22722272
$this->assertFalse($product->getDataByKey('quantity_and_stock_status')['is_in_stock']);
22732273
}
22742274

2275+
/**
2276+
* Test that imported product stock status with stock quantity > 0 and backorders functionality disabled
2277+
* can be set to 'out of stock'.
2278+
*
2279+
* @magentoDbIsolation enabled
2280+
* @magentoAppIsolation enabled
2281+
*/
2282+
public function testImportWithBackordersDisabled(): void
2283+
{
2284+
$this->importFile('products_to_import_with_backorders_disabled_and_not_0_qty.csv');
2285+
$product = $this->getProductBySku('simple_new');
2286+
$this->assertFalse($product->getDataByKey('quantity_and_stock_status')['is_in_stock']);
2287+
}
2288+
22752289
/**
22762290
* Import file by providing import filename in parameters.
22772291
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,crosssell_skus,upsell_skus,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
2+
simple_new,,Default,simple,,base,New Product,,,,1,Taxable Goods,"Catalog, Search",10,,,,new-product,New Product,New Product,New Product ,,,,,,,10/20/2015 7:05,10/20/2015 7:05,,,Block after Info Column,,,,,,,,,,,,,"has_options=1,quantity_and_stock_status=In Stock,required_options=1",100,0,1,0,0,0,1,1,10000,1,0,1,1,1,0,1,1,0,0,0,1,,,,,,,,,,,,,

0 commit comments

Comments
 (0)