Skip to content

Commit

Permalink
Merge pull request #3640 from magento-engcom/2.3-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.3-develop
  • Loading branch information
sivaschenko authored Jan 27, 2019
2 parents 8e38439 + 648ea36 commit 4c99249
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3067,9 +3067,7 @@ private function formatStockDataForRow(array $rowData): array

if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($sku)['type_id'])) {
$stockItemDo->setData($row);
$row['is_in_stock'] = isset($row['is_in_stock']) && $stockItemDo->getBackorders()
? $row['is_in_stock']
: $this->stockStateProvider->verifyStock($stockItemDo);
$row['is_in_stock'] = $row['is_in_stock'] ?? $this->stockStateProvider->verifyStock($stockItemDo);
if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
$date = $this->dateTimeFactory->create('now', new \DateTimeZone('UTC'));
$row['low_stock_date'] = $date->format(DateTime::DATETIME_PHP_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ private function removePlacedItemsFromQuote(array $shippingAddresses, array $pla
{
foreach ($shippingAddresses as $address) {
foreach ($address->getAllItems() as $addressItem) {
if (in_array($addressItem->getId(), $placedAddressItems)) {
if (in_array($addressItem->getQuoteItemId(), $placedAddressItems)) {
if ($addressItem->getProduct()->getIsVirtual()) {
$addressItem->isDeleted(true);
} else {
Expand Down Expand Up @@ -1232,7 +1232,7 @@ private function searchQuoteAddressId(OrderInterface $order, array $addresses):
$item = array_pop($items);
foreach ($addresses as $address) {
foreach ($address->getAllItems() as $addressItem) {
if ($addressItem->getId() == $item->getQuoteItemId()) {
if ($addressItem->getQuoteItemId() == $item->getQuoteItemId()) {
return (int)$address->getId();
}
}
Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/Quote/Model/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,11 @@ public function validateMinimumAmount($multishipping = false)
if (!$minOrderActive) {
return true;
}
$includeDiscount = $this->_scopeConfig->getValue(
'sales/minimum_order/include_discount_amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
$minOrderMulti = $this->_scopeConfig->isSetFlag(
'sales/minimum_order/multi_address',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Expand Down Expand Up @@ -2279,7 +2284,10 @@ public function validateMinimumAmount($multishipping = false)
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
foreach ($address->getQuote()->getItemsCollection() as $item) {
/** @var \Magento\Quote\Model\Quote\Item $item */
$amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes;
$amount = $includeDiscount ?
$item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $taxes :
$item->getBaseRowTotal() + $taxes;

if ($amount < $minAmount) {
return false;
}
Expand All @@ -2289,7 +2297,9 @@ public function validateMinimumAmount($multishipping = false)
$baseTotal = 0;
foreach ($addresses as $address) {
$taxes = ($taxInclude) ? $address->getBaseTaxAmount() : 0;
$baseTotal += $address->getBaseSubtotalWithDiscount() + $taxes;
$baseTotal += $includeDiscount ?
$address->getBaseSubtotalWithDiscount() + $taxes :
$address->getBaseSubtotal() + $taxes;
}
if ($baseTotal < $minAmount) {
return false;
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Quote/Model/Quote/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,11 @@ public function validateMinimumAmount()
return true;
}

$includeDiscount = $this->_scopeConfig->getValue(
'sales/minimum_order/include_discount_amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
$amount = $this->_scopeConfig->getValue(
'sales/minimum_order/amount',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
Expand All @@ -1159,9 +1164,12 @@ public function validateMinimumAmount()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);

$taxes = $taxInclude ? $this->getBaseTaxAmount() : 0;

return ($this->getBaseSubtotalWithDiscount() + $taxes >= $amount);
return $includeDiscount ?
($this->getBaseSubtotalWithDiscount() + $taxes >= $amount) :
($this->getBaseSubtotal() + $taxes >= $amount);
}

/**
Expand Down
17 changes: 12 additions & 5 deletions app/code/Magento/Quote/Model/Quote/Address/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Quote\Model\Quote;

/**
* Quote item model.
*
* @api
* @method int getParentItemId()
* @method \Magento\Quote\Model\Quote\Address\Item setParentItemId(int $value)
Expand Down Expand Up @@ -46,6 +48,8 @@
* @method \Magento\Quote\Model\Quote\Address\Item setSuperProductId(int $value)
* @method int getParentProductId()
* @method \Magento\Quote\Model\Quote\Address\Item setParentProductId(int $value)
* @method int getStoreId()
* @method \Magento\Quote\Model\Quote\Address\Item setStoreId(int $value)
* @method string getSku()
* @method \Magento\Quote\Model\Quote\Address\Item setSku(string $value)
* @method string getImage()
Expand Down Expand Up @@ -101,15 +105,15 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem
protected $_quote;

/**
* @return void
* @inheritdoc
*/
protected function _construct()
{
$this->_init(\Magento\Quote\Model\ResourceModel\Quote\Address\Item::class);
}

/**
* @return $this|\Magento\Quote\Model\Quote\Item\AbstractItem
* @inheritdoc
*/
public function beforeSave()
{
Expand Down Expand Up @@ -154,6 +158,8 @@ public function getQuote()
}

/**
* Import quote item.
*
* @param \Magento\Quote\Model\Quote\Item $quoteItem
* @return $this
*/
Expand All @@ -168,6 +174,8 @@ public function importQuoteItem(\Magento\Quote\Model\Quote\Item $quoteItem)
$quoteItem->getProductId()
)->setProduct(
$quoteItem->getProduct()
)->setStoreId(
$quoteItem->getStoreId()
)->setSku(
$quoteItem->getSku()
)->setName(
Expand All @@ -190,10 +198,9 @@ public function importQuoteItem(\Magento\Quote\Model\Quote\Item $quoteItem)
}

/**
* @param string $code
* @return \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface|null
* @inheritdoc
*/
public function getOptionBycode($code)
public function getOptionByCode($code)
{
if ($this->getQuoteItem()) {
return $this->getQuoteItem()->getOptionBycode($code);
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Address/Total.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Quote\Model\Quote\Address;

/**
* Class Total
*
* @method string getCode()
*
* @api
Expand Down Expand Up @@ -54,6 +56,8 @@ public function __construct(
*/
public function setTotalAmount($code, $amount)
{
$amount = is_float($amount) ? round($amount, 4) : $amount;

$this->totalAmounts[$code] = $amount;
if ($code != 'subtotal') {
$code = $code . '_amount';
Expand All @@ -72,6 +76,8 @@ public function setTotalAmount($code, $amount)
*/
public function setBaseTotalAmount($code, $amount)
{
$amount = is_float($amount) ? round($amount, 4) : $amount;

$this->baseTotalAmounts[$code] = $amount;
if ($code != 'subtotal') {
$code = $code . '_amount';
Expand Down Expand Up @@ -167,6 +173,7 @@ public function getAllBaseTotalAmounts()

/**
* Set the full info, which is used to capture tax related information.
*
* If a string is used, it is assumed to be serialized.
*
* @param array|string $info
Expand Down
12 changes: 12 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Item/ToOrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function __construct(
}

/**
* Convert quote item(quote address item) into order item.
*
* @param Item|AddressItem $item
* @param array $data
* @return OrderItemInterface
Expand All @@ -63,6 +65,16 @@ public function convert($item, $data = [])
'to_order_item',
$item
);
if ($item instanceof \Magento\Quote\Model\Quote\Address\Item) {
$orderItemData = array_merge(
$orderItemData,
$this->objectCopyService->getDataFromFieldset(
'quote_convert_address_item',
'to_order_item',
$item
)
);
}
if (!$item->getNoDiscount()) {
$data = array_merge(
$data,
Expand Down
27 changes: 27 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function testValidateMinimumAmountVirtual()
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

Expand All @@ -240,6 +241,31 @@ public function testValidateMinimumAmount()
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

$this->quote->expects($this->once())
->method('getStoreId')
->willReturn($storeId);
$this->quote->expects($this->once())
->method('getIsVirtual')
->willReturn(false);

$this->scopeConfig->expects($this->once())
->method('isSetFlag')
->willReturnMap($scopeConfigValues);

$this->assertTrue($this->address->validateMinimumAmount());
}

public function testValidateMiniumumAmountWithoutDiscount()
{
$storeId = 1;
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, false],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

Expand All @@ -263,6 +289,7 @@ public function testValidateMinimumAmountNegative()
$scopeConfigValues = [
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];

Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/QuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ public function testValidateMinimumAmount()
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];
$this->scopeConfig->expects($this->any())
Expand All @@ -1001,6 +1002,7 @@ public function testValidateMinimumAmountNegative()
['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
];
$this->scopeConfig->expects($this->any())
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Quote/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@
comment="Super Product Id"/>
<column xsi:type="int" name="parent_product_id" padding="10" unsigned="true" nullable="true" identity="false"
comment="Parent Product Id"/>
<column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="true" identity="false"
comment="Store Id"/>
<column xsi:type="varchar" name="sku" nullable="true" length="255" comment="Sku"/>
<column xsi:type="varchar" name="image" nullable="true" length="255" comment="Image"/>
<column xsi:type="varchar" name="name" nullable="true" length="255" comment="Name"/>
Expand Down Expand Up @@ -403,6 +405,9 @@
<index referenceId="QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID" indexType="btree">
<column name="quote_item_id"/>
</index>
<index referenceId="QUOTE_ADDRESS_ITEM_STORE_ID" indexType="btree">
<column name="store_id"/>
</index>
</table>
<table name="quote_item_option" resource="checkout" engine="innodb" comment="Sales Flat Quote Item Option">
<column xsi:type="int" name="option_id" padding="10" unsigned="true" nullable="false" identity="true"
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Quote/etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"product_id": true,
"super_product_id": true,
"parent_product_id": true,
"store_id": true,
"sku": true,
"image": true,
"name": true,
Expand All @@ -233,7 +234,8 @@
"index": {
"QUOTE_ADDRESS_ITEM_QUOTE_ADDRESS_ID": true,
"QUOTE_ADDRESS_ITEM_PARENT_ITEM_ID": true,
"QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID": true
"QUOTE_ADDRESS_ITEM_QUOTE_ITEM_ID": true,
"QUOTE_ADDRESS_ITEM_STORE_ID": true
},
"constraint": {
"PRIMARY": true,
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Quote/etc/fieldset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
<aspect name="to_order_address" />
</field>
</fieldset>
<fieldset id="quote_convert_address_item">
<field name="quote_item_id">
<aspect name="to_order_item" />
</field>
</fieldset>
<fieldset id="quote_convert_item">
<field name="sku">
<aspect name="to_order_item" />
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Sales/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<label>Minimum Amount</label>
<comment>Subtotal after discount</comment>
</field>
<field id="include_discount_amount" translate="label" sortOrder="12" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Include Discount Amount</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Choosing yes will be used subtotal after discount, otherwise only subtotal will be used</comment>
</field>
<field id="tax_including" translate="label" sortOrder="15" type="select" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Include Tax to Amount</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Sales/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<allow_zero_grandtotal>1</allow_zero_grandtotal>
</zerograndtotal_creditmemo>
<minimum_order>
<include_discount_amount>1</include_discount_amount>
<tax_including>1</tax_including>
</minimum_order>
<orders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@
}

.col-swatch-min-width {
min-width: 30px;
min-width: 65px;
}

.data-table .col-swatch-min-width input[type="text"] {
padding: inherit;
}

.swatches-visual-col.unavailable:after {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,20 @@ public function testImportWithBackordersEnabled(): void
$this->assertFalse($product->getDataByKey('quantity_and_stock_status')['is_in_stock']);
}

/**
* Test that imported product stock status with stock quantity > 0 and backorders functionality disabled
* can be set to 'out of stock'.
*
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
public function testImportWithBackordersDisabled(): void
{
$this->importFile('products_to_import_with_backorders_disabled_and_not_0_qty.csv');
$product = $this->getProductBySku('simple_new');
$this->assertFalse($product->getDataByKey('quantity_and_stock_status')['is_in_stock']);
}

/**
* Import file by providing import filename in parameters.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
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 comments on commit 4c99249

Please sign in to comment.