Skip to content

Commit 0d35436

Browse files
author
Andrey Konosov
committed
Merge remote-tracking branch 'main/develop' into ie
2 parents 07fecd7 + 6f02d36 commit 0d35436

File tree

161 files changed

+6883
-2392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+6883
-2392
lines changed

app/code/Magento/Braintree/Model/Observer.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class Observer
4141
* @var \Magento\Framework\DB\TransactionFactory
4242
*/
4343
protected $transactionFactory;
44-
4544
/**
4645
* @param Vault $vault
4746
* @param \Magento\Braintree\Model\Config\Cc $config
@@ -80,21 +79,28 @@ public function processBraintreePayment(\Magento\Framework\DataObject $observer)
8079
&& $order->canInvoice() && $this->shouldInvoice()) {
8180
$qtys = [];
8281
foreach ($shipment->getAllItems() as $shipmentItem) {
83-
$qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getQty();
82+
if ($shipmentItem->getOrderItem()->getQtyToInvoice() >= $shipmentItem->getQty()) {
83+
$qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getQty();
84+
} else {
85+
$qtys[$shipmentItem->getOrderItem()->getId()] = $shipmentItem->getOrderItem()->getQtyToInvoice();
86+
}
8487
}
8588
foreach ($order->getAllItems() as $orderItem) {
8689
if (!array_key_exists($orderItem->getId(), $qtys)) {
8790
$qtys[$orderItem->getId()] = 0;
8891
}
8992
}
90-
$invoice = $order->prepareInvoice($qtys);
91-
$invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE);
92-
$invoice->register();
93-
/** @var \Magento\Framework\DB\Transaction $transaction */
94-
$transaction = $this->transactionFactory->create();
95-
$transaction->addObject($invoice)
96-
->addObject($invoice->getOrder())
97-
->save();
93+
if (array_sum($qtys)>0) {
94+
$invoice = $order->prepareInvoice($qtys);
95+
$invoice->setOrder($order);
96+
$invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE);
97+
$invoice->register();
98+
/** @var \Magento\Framework\DB\Transaction $transaction */
99+
$transaction = $this->transactionFactory->create();
100+
$transaction->addObject($invoice)
101+
->addObject($invoice->getOrder())
102+
->save();
103+
}
98104
}
99105
return $this;
100106
}

app/code/Magento/Braintree/Test/Unit/Model/ObserverTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,22 @@ protected function setupOrderShipmentItems($orderMock, $shipmentMock)
104104
$shipment3Qty = 3;
105105

106106
$orderItem1 = new \Magento\Framework\DataObject(
107-
['id' => $orderItem1Id]
107+
[
108+
'id' => $orderItem1Id,
109+
'qty_to_invoice' => $orderItem1Id
110+
]
108111
);
109112
$orderItem2 = new \Magento\Framework\DataObject(
110-
['id' => $orderItem2Id]
113+
[
114+
'id' => $orderItem2Id,
115+
'qty_to_invoice' => $orderItem2Id
116+
]
111117
);
112118
$orderItem3 = new \Magento\Framework\DataObject(
113-
['id' => $orderItem3Id]
119+
[
120+
'id' => $orderItem3Id,
121+
'qty_to_invoice' => $orderItem3Id
122+
]
114123
);
115124
$orderItems = [$orderItem1, $orderItem2, $orderItem3];
116125
$orderMock->expects($this->any())

app/code/Magento/Catalog/Block/Product/View/Options.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Magento\Catalog\Model\Product;
1515

16+
/**
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
*/
1619
class Options extends \Magento\Framework\View\Element\Template
1720
{
1821
/**
@@ -190,6 +193,7 @@ protected function _getPriceConfiguration($option)
190193
],
191194
],
192195
'type' => $option->getPriceType(),
196+
'name' => $option->getTitle()
193197
];
194198
return $data;
195199
}

app/code/Magento/Catalog/Block/Product/View/Options/Type/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getValuesHtml()
5959
);
6060
$select->addOption(
6161
$_value->getOptionTypeId(),
62-
$_value->getTitle() . ' ' . $priceStr . '',
62+
$_value->getTitle() . ' ' . strip_tags($priceStr) . '',
6363
['price' => $this->pricingHelper->currencyByStore($_value->getPrice(true), $store, false)]
6464
);
6565
}

app/code/Magento/Catalog/Pricing/Price/CustomOptionPrice.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Catalog\Model\Product\Option;
1010
use Magento\Catalog\Pricing\Price;
1111
use Magento\Framework\Pricing\Price\AbstractPrice;
12+
use Magento\Framework\Pricing\Object\SaleableInterface;
13+
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
14+
use Magento\Framework\Pricing\Amount\AmountInterface;
1215

1316
/**
1417
* Class OptionPrice
@@ -26,6 +29,31 @@ class CustomOptionPrice extends AbstractPrice implements CustomOptionPriceInterf
2629
*/
2730
protected $priceOptions;
2831

32+
/**
33+
* Code of parent adjustment to be skipped from calculation
34+
*
35+
* @var string
36+
*/
37+
protected $excludeAdjustment = null;
38+
39+
/**
40+
* @param SaleableInterface $saleableItem
41+
* @param float $quantity
42+
* @param CalculatorInterface $calculator
43+
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
44+
* @param string $excludeAdjustment
45+
*/
46+
public function __construct(
47+
SaleableInterface $saleableItem,
48+
$quantity,
49+
CalculatorInterface $calculator,
50+
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
51+
$excludeAdjustment = null
52+
) {
53+
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
54+
$this->excludeAdjustment = $excludeAdjustment;
55+
}
56+
2957
/**
3058
* Get minimal and maximal option values
3159
*
@@ -83,6 +111,23 @@ public function getValue()
83111
return $optionValues;
84112
}
85113

114+
/**
115+
* @param float $amount
116+
* @param null|bool|string $exclude
117+
* @param null|array $context
118+
* @return AmountInterface|bool|float
119+
*/
120+
public function getCustomAmount($amount = null, $exclude = null, $context = [])
121+
{
122+
if (null !== $amount) {
123+
$amount = $this->priceCurrency->convertAndRound($amount);
124+
} else {
125+
$amount = $this->getValue();
126+
}
127+
$exclude = $this->excludeAdjustment;
128+
return $this->calculator->getAmount($amount, $this->getProduct(), $exclude, $context);
129+
}
130+
86131
/**
87132
* Return the minimal or maximal price for custom options
88133
*

app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,28 +252,6 @@
252252
<item name="namespace" xsi:type="string">current.paging</item>
253253
</item>
254254
<item name="displayArea" xsi:type="string">bottom</item>
255-
<item name="options" xsi:type="array">
256-
<item name="20" xsi:type="array">
257-
<item name="value" xsi:type="number">20</item>
258-
<item name="label" xsi:type="string" translate="true">20</item>
259-
</item>
260-
<item name="30" xsi:type="array">
261-
<item name="value" xsi:type="number">30</item>
262-
<item name="label" xsi:type="string" translate="true">30</item>
263-
</item>
264-
<item name="50" xsi:type="array">
265-
<item name="value" xsi:type="number">50</item>
266-
<item name="label" xsi:type="string" translate="true">50</item>
267-
</item>
268-
<item name="100" xsi:type="array">
269-
<item name="value" xsi:type="number">100</item>
270-
<item name="label" xsi:type="string" translate="true">100</item>
271-
</item>
272-
<item name="200" xsi:type="array">
273-
<item name="value" xsi:type="number">200</item>
274-
<item name="label" xsi:type="string" translate="true">200</item>
275-
</item>
276-
</item>
277255
</item>
278256
</argument>
279257
</paging>

app/code/Magento/Catalog/view/base/layout/catalog_product_prices.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<item name="render_template" xsi:type="string">Magento_Catalog::product/price/final_price.phtml</item>
2929
</item>
3030
<item name="custom_option_price" xsi:type="array">
31-
<item name="amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/option.phtml</item>
31+
<item name="amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/default.phtml</item>
3232
</item>
3333
<item name="configured_price" xsi:type="array">
3434
<item name="render_class" xsi:type="string">Magento\Catalog\Pricing\Render\ConfiguredPriceBox</item>

app/code/Magento/Catalog/view/base/templates/product/price/amount/option.phtml

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
define([
66
'jquery',
77
'underscore',
8+
'mage/template',
89
'priceUtils',
10+
'priceBox',
911
'jquery/ui'
10-
], function ($, _, utils) {
12+
], function ($, _, mageTemplate, utils) {
1113
'use strict';
1214

1315
var globalOptions = {
@@ -16,6 +18,10 @@ define([
1618
optionsSelector: '.product-custom-option',
1719
optionConfig: {},
1820
optionHandlers: {},
21+
optionTemplate: '<%- data.label %>' +
22+
'<% if (data.finalPrice.value) { %>' +
23+
' +<%- data.finalPrice.formatted %>' +
24+
'<% } %>',
1925
controlContainer: 'dd'
2026
};
2127

@@ -29,7 +35,17 @@ define([
2935
*/
3036
_create: function createPriceOptions() {
3137
var form = this.element,
32-
options = $(this.options.optionsSelector, form);
38+
options = $(this.options.optionsSelector, form),
39+
priceBox = $(this.options.priceHolderSelector, $(this.options.optionsSelector).element);
40+
41+
if (priceBox.data('magePriceBox') && priceBox.priceBox('option') && priceBox.priceBox('option').priceConfig) {
42+
if (priceBox.priceBox('option').priceConfig.optionTemplate) {
43+
this._setOption('optionTemplate', priceBox.priceBox('option').priceConfig.optionTemplate);
44+
}
45+
this._setOption('priceFormat', priceBox.priceBox('option').priceConfig.priceFormat);
46+
}
47+
48+
this._applyOptionNodeFix(options);
3349

3450
options.on('change', this._onOptionChanged.bind(this));
3551
},
@@ -53,6 +69,64 @@ define([
5369
$(this.options.priceHolderSelector).trigger('updatePrice', changes);
5470
},
5571

72+
73+
/**
74+
* Helper to fix issue with option nodes:
75+
* - you can't place any html in option ->
76+
* so you can't style it via CSS
77+
* @param {jQuery} options
78+
* @private
79+
*/
80+
_applyOptionNodeFix: function applyOptionNodeFix(options) {
81+
var config = this.options,
82+
format = config.priceFormat,
83+
template = config.optionTemplate;
84+
template = mageTemplate(template);
85+
options.filter('select').each(function (index, element) {
86+
var $element = $(element),
87+
optionId = utils.findOptionId($element),
88+
optionName = $element.prop('name'),
89+
optionType = $element.prop('type');
90+
var optionConfig = config.optionConfig && config.optionConfig[optionId];
91+
92+
$element.find('option').each(function (idx, option) {
93+
var $option,
94+
optionValue,
95+
toTemplate,
96+
prices;
97+
98+
$option = $(option);
99+
optionValue = $option.val();
100+
101+
if (!optionValue && optionValue !== 0) {
102+
return;
103+
}
104+
105+
toTemplate = {
106+
data: {
107+
label: optionConfig[optionValue] && optionConfig[optionValue].name
108+
}
109+
};
110+
prices = optionConfig[optionValue] ? optionConfig[optionValue].prices : null;
111+
112+
if (prices) {
113+
_.each(prices, function (price, type) {
114+
var value = +(price.amount);
115+
value += _.reduce(price.adjustments, function (sum, x) {
116+
return sum + x;
117+
}, 0);
118+
toTemplate.data[type] = {
119+
value: value,
120+
formatted: utils.formatPrice(value, format)
121+
};
122+
});
123+
124+
$option.text(template(toTemplate));
125+
}
126+
});
127+
});
128+
},
129+
56130
/**
57131
* Custom behavior on getting options:
58132
* now widget able to deep merge accepted configuration with instance options.

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_listing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<column name="qty">
4444
<argument name="data" xsi:type="array">
4545
<item name="js_config" xsi:type="array">
46-
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/sortable</item>
46+
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
4747
</item>
4848
<item name="config" xsi:type="array">
4949
<item name="add_field" xsi:type="boolean">true</item>

0 commit comments

Comments
 (0)