Skip to content

Commit 4f3e5fc

Browse files
committed
Merge remote-tracking branch 'main/develop' into MAGETWO-49845
2 parents fc635bd + f278923 commit 4f3e5fc

File tree

39 files changed

+713
-196
lines changed

39 files changed

+713
-196
lines changed

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ protected function getBundleSelections()
569569
'arguments' => [
570570
'data' => [
571571
'config' => [
572+
'component' => 'Magento_Bundle/js/components/bundle-option-qty',
572573
'formElement' => Form\Element\Input::NAME,
573574
'componentType' => Form\Field::NAME,
574575
'dataType' => Form\Element\DataType\Number::NAME,
@@ -577,8 +578,12 @@ protected function getBundleSelections()
577578
'value' => '1',
578579
'sortOrder' => 100,
579580
'validation' => [
581+
'required-entry' => true,
580582
'validate-number' => true,
581583
],
584+
'imports' => [
585+
'isInteger' => '${ $.provider }:${ $.parentScope }.selection_qty_is_integer'
586+
],
582587
],
583588
],
584589
],

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/Composite.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public function modifyMeta(array $meta)
8888

8989
/**
9090
* {@inheritdoc}
91+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
92+
* @SuppressWarnings(PHPMD.NPathComplexity)
9193
*/
9294
public function modifyData(array $data)
9395
{
@@ -103,6 +105,12 @@ public function modifyData(array $data)
103105
/** @var \Magento\Bundle\Api\Data\LinkInterface $productLink */
104106
foreach ($option->getProductLinks() as $productLink) {
105107
$linkedProduct = $this->productRepository->get($productLink->getSku());
108+
$integerQty = 1;
109+
if ($linkedProduct->getExtensionAttributes()->getStockItem()) {
110+
if ($linkedProduct->getExtensionAttributes()->getStockItem()->getIsQtyDecimal()) {
111+
$integerQty = 0;
112+
}
113+
}
106114
$selections[] = [
107115
'selection_id' => $productLink->getId(),
108116
'option_id' => $productLink->getOptionId(),
@@ -112,8 +120,9 @@ public function modifyData(array $data)
112120
'is_default' => ($productLink->getIsDefault()) ? '1' : '0',
113121
'selection_price_value' => $productLink->getPrice(),
114122
'selection_price_type' => $productLink->getPriceType(),
115-
'selection_qty' => $productLink->getQty(),
123+
'selection_qty' => (bool)$integerQty ? (int)$productLink->getQty() : $productLink->getQty(),
116124
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
125+
'selection_qty_is_integer' => (bool)$integerQty,
117126
'position' => $productLink->getPosition(),
118127
];
119128
}

app/code/Magento/Bundle/view/adminhtml/templates/product/edit/bundle/option/selection.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Bundle.Selection.prototype = {
164164
if (data.can_read_price != undefined && !data.can_read_price) {
165165
data.selection_price_value = '';
166166
} else {
167-
data.selection_price_value = Number(data.selection_price_value).toFixed(2);
167+
data.selection_price_value = Number(Math.round(data.selection_price_value + "e+2") + "e-2").toFixed(2);
168168
}
169169

170170
data.index = this.itemsCount++;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/form/element/abstract'
8+
], function (Abstract) {
9+
'use strict';
10+
11+
return Abstract.extend({
12+
defaults: {
13+
valueUpdate: 'input',
14+
isInteger: true
15+
},
16+
17+
/**
18+
* update event
19+
*/
20+
onUpdate: function () {
21+
this.validation['validate-number'] = true;
22+
this.validation['validate-digits'] = this.isInteger;
23+
this.validate();
24+
}
25+
});
26+
});

app/code/Magento/Catalog/view/base/web/js/price-utils.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ define([
4343
pattern = format.pattern || '%s',
4444
s = '',
4545
i, pad,
46-
j, re, r;
46+
j, re, r, am;
4747

4848
if (isShowSign === undefined || isShowSign === true) {
4949
s = amount < 0 ? '-' : (isShowSign ? '+' : '');
@@ -52,7 +52,9 @@ define([
5252
}
5353
pattern = pattern.indexOf('{sign}') < 0 ? s + pattern : pattern.replace('{sign}', s);
5454

55-
i = parseInt(amount = Math.abs(+amount || 0).toFixed(precision), 10) + '';
55+
// we're avoiding the usage of to fixed, and using round instead with the e representation to address
56+
// numbers like 1.005 = 1.01. Using ToFixed to only provide trailig zeroes in case we have a whole number
57+
i = parseInt(amount = Number(Math.round(Math.abs(+amount || 0) + 'e+' + precision) + ('e-' + precision)) , 10) + '';
5658
pad = (i.length < integerRequired) ? (integerRequired - i.length) : 0;
5759

5860
i = stringPad('0', pad) + i;
@@ -63,9 +65,12 @@ define([
6365
// replace(/-/, 0) is only for fixing Safari bug which appears
6466
// when Math.abs(0).toFixed() executed on '0' number.
6567
// Result is '0.-0' :(
68+
69+
70+
am = Number(Math.round(Math.abs(amount - i) + 'e+' + precision) + ('e-' + precision));
6671
r = (j ? i.substr(0, j) + groupSymbol : '') +
6772
i.substr(j).replace(re, '$1' + groupSymbol) +
68-
(precision ? decimalSymbol + Math.abs(amount - i).toFixed(precision).replace(/-/, 0).slice(2) : '');
73+
(precision ? decimalSymbol + am.toFixed(2).replace(/-/, 0).slice(2) : '');
6974

7075
return pattern.replace('%s', r).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
7176
}

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/configurable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Product.Config.prototype = {
214214
}
215215
}
216216

217-
var roundedPrice = (Math.round(price*100)/100).toString();
217+
var roundedPrice = Number(Math.round(price + "e+2") + "e-2").toString();
218218

219219
if (this.prices && this.prices[roundedPrice]) {
220220
str+= this.prices[roundedPrice];

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ define([
124124
},
125125
name: product.name || product.sku,
126126
options: options,
127-
price: parseFloat(product.price.replace(/[^\d.]+/g, '')).toFixed(4),
127+
price: parseFloat(Math.round(product.price.replace(/[^\d.]+/g, '') + "e+4") + "e-4").toFixed(4),
128128
productId: productId,
129129
productUrl: this.buildProductUrl(productId),
130130
quantity: product.quantity || null,

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,13 +931,13 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
931931
$select = $connection->select();
932932
if ($attribute->getBackend()->getType() === 'static') {
933933
$value = $object->getData($attribute->getAttributeCode());
934-
$bind = ['attribute_code' => trim($value)];
934+
$bind = ['value' => trim($value)];
935935

936936
$select->from(
937937
$this->getEntityTable(),
938938
$this->getEntityIdField()
939939
)->where(
940-
$attribute->getAttributeCode() . ' = :attribute_code'
940+
$attribute->getAttributeCode() . ' = :value'
941941
);
942942
} else {
943943
$value = $object->getData($attribute->getAttributeCode());
@@ -950,7 +950,7 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
950950
];
951951
$select->from(
952952
$attribute->getBackend()->getTable(),
953-
$attribute->getBackend()->getEntityIdField()
953+
$object->getResource()->getLinkField()
954954
)->where(
955955
'attribute_id = :attribute_id'
956956
)->where(

app/code/Magento/Eav/Model/ResourceModel/UpdateHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function execute($entityType, $data)
134134
if ((!array_key_exists($attribute->getAttributeCode(), $snapshot)
135135
|| $snapshot[$attribute->getAttributeCode()] === false)
136136
&& array_key_exists($attribute->getAttributeCode(), $data)
137+
&& $data[$attribute->getAttributeCode()] !== false
137138
&& !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])
138139
) {
139140
$this->attributePersistor->registerInsert(
@@ -147,6 +148,7 @@ public function execute($entityType, $data)
147148
if (array_key_exists($attribute->getAttributeCode(), $snapshot)
148149
&& $snapshot[$attribute->getAttributeCode()] !== false
149150
&& array_key_exists($attribute->getAttributeCode(), $data)
151+
&& $data[$attribute->getAttributeCode()] !== false
150152
&& $snapshot[$attribute->getAttributeCode()] != $data[$attribute->getAttributeCode()]
151153
&& !$attribute->isValueEmpty($data[$attribute->getAttributeCode()])
152154
) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@
247247
<field name="row_total">
248248
<aspect name="to_order_item" />
249249
</field>
250+
<field name="base_price">
251+
<aspect name="to_order_item" />
252+
</field>
250253
<field name="base_original_price">
251254
<aspect name="to_order_item" />
252255
</field>

app/code/Magento/Sales/Model/Order/Creditmemo/Total/Shipping.php

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class Shipping extends AbstractTotal
1717
*/
1818
protected $priceCurrency;
1919

20+
/**
21+
* Tax config
22+
*
23+
* @var \Magento\Tax\Model\Config
24+
*/
25+
private $taxConfig;
26+
2027
/**
2128
* @param PriceCurrencyInterface $priceCurrency
2229
* @param array $data
@@ -37,62 +44,64 @@ public function __construct(
3744
public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
3845
{
3946
$order = $creditmemo->getOrder();
40-
$allowedAmount = $order->getShippingAmount() - $order->getShippingRefunded();
41-
$baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded();
4247

48+
// amounts without tax
4349
$orderShippingAmount = $order->getShippingAmount();
4450
$orderBaseShippingAmount = $order->getBaseShippingAmount();
51+
$allowedAmount = $orderShippingAmount - $order->getShippingRefunded();
52+
$baseAllowedAmount = $orderBaseShippingAmount - $order->getBaseShippingRefunded();
53+
54+
// amounts including tax
4555
$orderShippingInclTax = $order->getShippingInclTax();
4656
$orderBaseShippingInclTax = $order->getBaseShippingInclTax();
57+
$allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
58+
$baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
59+
$allowedAmountInclTax = $allowedAmount + $allowedTaxAmount;
60+
$baseAllowedAmountInclTax = $baseAllowedAmount + $baseAllowedTaxAmount;
4761

62+
// for the credit memo
4863
$shippingAmount = $baseShippingAmount = $shippingInclTax = $baseShippingInclTax = 0;
4964

50-
/**
51-
* Check if shipping amount was specified (from invoice or another source).
52-
* Using has magic method to allow setting 0 as shipping amount.
53-
*/
65+
// Check if the desired shipping amount to refund was specified (from invoice or another source).
5466
if ($creditmemo->hasBaseShippingAmount()) {
55-
$baseShippingAmount = $this->priceCurrency->round($creditmemo->getBaseShippingAmount());
56-
/*
57-
* Rounded allowed shipping refund amount is the highest acceptable shipping refund amount.
58-
* Shipping refund amount shouldn't cause errors, if it doesn't exceed that limit.
59-
* Note: ($x < $y + 0.0001) means ($x <= $y) for floats
60-
*/
61-
if ($baseShippingAmount < $this->priceCurrency->round($baseAllowedAmount) + 0.0001) {
67+
// For the conditional logic, we will either use amounts that always include tax -OR- never include tax.
68+
// The logic uses the 'base' currency to be consistent with what the user (admin) provided as input.
69+
$useAmountsWithTax = $this->isSuppliedShippingAmountInclTax($order);
70+
71+
// Since the user (admin) supplied 'desiredAmount' it already has tax -OR- does not include tax
72+
$desiredAmount = $this->priceCurrency->round($creditmemo->getBaseShippingAmount());
73+
$maxAllowedAmount = ($useAmountsWithTax ? $baseAllowedAmountInclTax : $baseAllowedAmount);
74+
$originalTotalAmount = ($useAmountsWithTax ? $orderBaseShippingInclTax : $orderBaseShippingAmount);
75+
76+
// Note: ($x < $y + 0.0001) means ($x <= $y) for floats
77+
if ($desiredAmount < $this->priceCurrency->round($maxAllowedAmount) + 0.0001) {
78+
// since the admin is returning less than the allowed amount, compute the ratio being returned
6279
$ratio = 0;
63-
if ($orderBaseShippingAmount > 0) {
64-
$ratio = $baseShippingAmount / $orderBaseShippingAmount;
80+
if ($originalTotalAmount > 0) {
81+
$ratio = $desiredAmount / $originalTotalAmount;
6582
}
66-
/*
67-
* Shipping refund amount should be equated to allowed refund amount,
68-
* if it exceeds that limit.
69-
* Note: ($x > $y - 0.0001) means ($x >= $y) for floats
70-
*/
71-
if ($baseShippingAmount > $baseAllowedAmount - 0.0001) {
83+
// capture amounts without tax
84+
// Note: ($x > $y - 0.0001) means ($x >= $y) for floats
85+
if ($desiredAmount > $maxAllowedAmount - 0.0001) {
7286
$shippingAmount = $allowedAmount;
7387
$baseShippingAmount = $baseAllowedAmount;
7488
} else {
7589
$shippingAmount = $this->priceCurrency->round($orderShippingAmount * $ratio);
90+
$baseShippingAmount = $this->priceCurrency->round($orderBaseShippingAmount * $ratio);
7691
}
7792
$shippingInclTax = $this->priceCurrency->round($orderShippingInclTax * $ratio);
7893
$baseShippingInclTax = $this->priceCurrency->round($orderBaseShippingInclTax * $ratio);
7994
} else {
80-
$baseAllowedAmount = $order->getBaseCurrency()->format($baseAllowedAmount, null, false);
95+
$maxAllowedAmount = $order->getBaseCurrency()->format($maxAllowedAmount, null, false);
8196
throw new \Magento\Framework\Exception\LocalizedException(
82-
__('Maximum shipping amount allowed to refund is: %1', $baseAllowedAmount)
97+
__('Maximum shipping amount allowed to refund is: %1', $maxAllowedAmount)
8398
);
8499
}
85100
} else {
86101
$shippingAmount = $allowedAmount;
87102
$baseShippingAmount = $baseAllowedAmount;
88-
89-
$allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
90-
$baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
91-
92-
$shippingInclTax = $this->priceCurrency->round($allowedAmount + $allowedTaxAmount);
93-
$baseShippingInclTax = $this->priceCurrency->round(
94-
$baseAllowedAmount + $baseAllowedTaxAmount
95-
);
103+
$shippingInclTax = $this->priceCurrency->round($allowedAmountInclTax);
104+
$baseShippingInclTax = $this->priceCurrency->round($baseAllowedAmountInclTax);
96105
}
97106

98107
$creditmemo->setShippingAmount($shippingAmount);
@@ -104,4 +113,32 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
104113
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseShippingAmount);
105114
return $this;
106115
}
116+
117+
/**
118+
* Returns whether the user specified a shipping amount that already includes tax
119+
*
120+
* @param \Magento\Sales\Model\Order $order
121+
* @return bool
122+
*/
123+
private function isSuppliedShippingAmountInclTax($order)
124+
{
125+
// returns true if we are only displaying shipping including tax, otherwise returns false
126+
return $this->getTaxConfig()->displaySalesShippingInclTax($order->getStoreId());
127+
}
128+
129+
/**
130+
* Get the Tax Config.
131+
* In a future release, will become a constructor parameter.
132+
*
133+
* @return \Magento\Tax\Model\Config
134+
*
135+
* @deprecated
136+
*/
137+
private function getTaxConfig()
138+
{
139+
if ($this->taxConfig === null) {
140+
$this->taxConfig = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Tax\Model\Config');
141+
}
142+
return $this->taxConfig;
143+
}
107144
}

0 commit comments

Comments
 (0)