Skip to content

Commit 17f69be

Browse files
author
Robert He
committed
Merge branch 'develop-hero' into develop-PR
Conflicts: app/code/Magento/Weee/Observer/UpdateProductOptionsObserver.php
2 parents 02e0378 + a11a2d4 commit 17f69be

File tree

22 files changed

+503
-68
lines changed

22 files changed

+503
-68
lines changed

app/code/Magento/Bundle/Pricing/Adjustment/BundleCalculatorInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ interface BundleCalculatorInterface extends CalculatorInterface
1717
/**
1818
* @param float|string $amount
1919
* @param Product $saleableItem
20-
* @param null|bool $exclude
20+
* @param null|bool|string|array $exclude
2121
* @return \Magento\Framework\Pricing\Amount\AmountInterface
2222
*/
2323
public function getMaxAmount($amount, Product $saleableItem, $exclude = null);
2424

2525
/**
2626
* @param float|string $amount
2727
* @param Product $saleableItem
28-
* @param null|bool $exclude
28+
* @param null|bool|string|array $exclude
2929
* @return \Magento\Framework\Pricing\Amount\AmountInterface
3030
*/
3131
public function getMaxRegularAmount($amount, Product $saleableItem, $exclude = null);
3232

3333
/**
3434
* @param float|string $amount
3535
* @param Product $saleableItem
36-
* @param null|bool $exclude
36+
* @param null|bool|string|array $exclude
3737
* @return \Magento\Framework\Pricing\Amount\AmountInterface
3838
*/
3939
public function getMinRegularAmount($amount, Product $saleableItem, $exclude = null);
@@ -42,7 +42,7 @@ public function getMinRegularAmount($amount, Product $saleableItem, $exclude = n
4242
* Option amount calculation for saleable item
4343
*
4444
* @param Product $saleableItem
45-
* @param null|string $exclude
45+
* @param null|bool|string|array $exclude
4646
* @param bool $searchMin
4747
* @param \Magento\Framework\Pricing\Amount\AmountInterface|null $bundleProductAmount
4848
* @return \Magento\Framework\Pricing\Amount\AmountInterface
@@ -60,7 +60,7 @@ public function getOptionsAmount(
6060
* @param float $basePriceValue
6161
* @param Product $bundleProduct
6262
* @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
63-
* @param null|string $exclude code of adjustment that has to be excluded
63+
* @param null|bool|string|array $exclude code of adjustment that has to be excluded
6464
* @return \Magento\Framework\Pricing\Amount\AmountInterface
6565
*/
6666
public function calculateBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude = null);

app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __construct(
7777
*
7878
* @param float|string $amount
7979
* @param SaleableInterface $saleableItem
80-
* @param null|string $exclude
80+
* @param null|bool|string|array $exclude
8181
* @param null|array $context
8282
* @return \Magento\Framework\Pricing\Amount\AmountInterface
8383
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -92,7 +92,7 @@ public function getAmount($amount, SaleableInterface $saleableItem, $exclude = n
9292
*
9393
* @param float $amount
9494
* @param Product $saleableItem
95-
* @param null|string $exclude
95+
* @param null|bool|string|array $exclude
9696
* @return \Magento\Framework\Pricing\Amount\AmountInterface
9797
*/
9898
public function getMinRegularAmount($amount, Product $saleableItem, $exclude = null)
@@ -105,7 +105,7 @@ public function getMinRegularAmount($amount, Product $saleableItem, $exclude = n
105105
*
106106
* @param float $amount
107107
* @param Product $saleableItem
108-
* @param null|string $exclude
108+
* @param null|bool|string|array $exclude
109109
* @return \Magento\Framework\Pricing\Amount\AmountInterface
110110
*/
111111
public function getMaxAmount($amount, Product $saleableItem, $exclude = null)
@@ -118,7 +118,7 @@ public function getMaxAmount($amount, Product $saleableItem, $exclude = null)
118118
*
119119
* @param float $amount
120120
* @param Product $saleableItem
121-
* @param null|string $exclude
121+
* @param null|bool|string|array $exclude
122122
* @return \Magento\Framework\Pricing\Amount\AmountInterface
123123
*/
124124
public function getMaxRegularAmount($amount, Product $saleableItem, $exclude = null)
@@ -130,7 +130,7 @@ public function getMaxRegularAmount($amount, Product $saleableItem, $exclude = n
130130
* Option amount calculation for bundle product
131131
*
132132
* @param Product $saleableItem
133-
* @param null|string $exclude
133+
* @param null|bool|string|array $exclude
134134
* @param bool $searchMin
135135
* @param float $baseAmount
136136
* @param bool $useRegularPrice
@@ -260,7 +260,7 @@ protected function getBundleOptions(Product $saleableItem)
260260
* @param float $basePriceValue
261261
* @param Product $bundleProduct
262262
* @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
263-
* @param null|string $exclude
263+
* @param null|bool|string|array $exclude
264264
* @return \Magento\Framework\Pricing\Amount\AmountInterface
265265
*/
266266
public function calculateBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude = null)
@@ -278,7 +278,7 @@ public function calculateBundleAmount($basePriceValue, $bundleProduct, $selectio
278278
* @param float $basePriceValue
279279
* @param Product $bundleProduct
280280
* @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
281-
* @param null|string $exclude
281+
* @param null|bool|string|arrayy $exclude
282282
* @return \Magento\Framework\Pricing\Amount\AmountInterface
283283
*/
284284
protected function calculateFixedBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude)
@@ -297,7 +297,7 @@ protected function calculateFixedBundleAmount($basePriceValue, $bundleProduct, $
297297
* @param float $basePriceValue
298298
* @param Product $bundleProduct
299299
* @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
300-
* @param null|string $exclude
300+
* @param null|bool|string|array $exclude
301301
* @return \Magento\Framework\Pricing\Amount\AmountInterface
302302
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
303303
*/
@@ -340,9 +340,18 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct,
340340
}
341341
}
342342
}
343-
if ($exclude && isset($adjustments[$exclude])) {
344-
$fullAmount -= $adjustments[$exclude];
345-
unset($adjustments[$exclude]);
343+
if (is_array($exclude) == false) {
344+
if ($exclude && isset($adjustments[$exclude])) {
345+
$fullAmount -= $adjustments[$exclude];
346+
unset($adjustments[$exclude]);
347+
}
348+
} else {
349+
foreach ($exclude as $oneExclusion) {
350+
if ($oneExclusion && isset($adjustments[$oneExclusion])) {
351+
$fullAmount -= $adjustments[$oneExclusion];
352+
unset($adjustments[$oneExclusion]);
353+
}
354+
}
346355
}
347356
return $this->amountFactory->create($fullAmount, $adjustments);
348357
}

app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BundleSelectionPrice extends AbstractPrice
6868
* @param ManagerInterface $eventManager
6969
* @param DiscountCalculator $discountCalculator
7070
* @param bool $useRegularPrice
71-
* @param string $excludeAdjustment
71+
* @param array $excludeAdjustment
7272
*/
7373
public function __construct(
7474
Product $saleableItem,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CustomOptionPrice extends AbstractPrice implements CustomOptionPriceInterf
4141
* @param float $quantity
4242
* @param CalculatorInterface $calculator
4343
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
44-
* @param string $excludeAdjustment
44+
* @param array $excludeAdjustment
4545
*/
4646
public function __construct(
4747
SaleableInterface $saleableItem,
@@ -113,7 +113,7 @@ public function getValue()
113113

114114
/**
115115
* @param float $amount
116-
* @param null|bool|string $exclude
116+
* @param null|bool|string|array $exclude
117117
* @param null|array $context
118118
* @return AmountInterface|bool|float
119119
*/

app/code/Magento/Tax/Pricing/Render/Adjustment.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public function displayBothPrices()
9191
*/
9292
public function getDisplayAmountExclTax($exclude = null, $includeContainer = false)
9393
{
94+
//If exclude is not supplied, use the default
95+
if ($exclude === null) {
96+
$exclude = $this->getDefaultExclusions();
97+
}
98+
9499
return $this->formatCurrency(
95100
$this->getRawAmount($exclude),
96101
$includeContainer

app/code/Magento/Weee/Helper/Data.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/**
1414
* WEEE data helper
15+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1516
*/
1617
class Data extends \Magento\Framework\App\Helper\AbstractHelper
1718
{
@@ -269,26 +270,29 @@ public function typeOfDisplay(
269270
/**
270271
* Proxy for \Magento\Weee\Model\Tax::getProductWeeeAttributes()
271272
*
272-
* @param \Magento\Catalog\Model\Product $product
273-
* @param null|false|\Magento\Framework\DataObject $shipping
274-
* @param null|false|\Magento\Framework\DataObject $billing
275-
* @param Website $website
276-
* @param bool $calculateTaxes
273+
* @param \Magento\Catalog\Model\Product $product
274+
* @param null|false|\Magento\Framework\DataObject $shipping
275+
* @param null|false|\Magento\Framework\DataObject $billing
276+
* @param Website $website
277+
* @param bool $calculateTaxes
278+
* @param bool $round
277279
* @return \Magento\Framework\DataObject[]
278280
*/
279281
public function getProductWeeeAttributes(
280282
$product,
281283
$shipping = null,
282284
$billing = null,
283285
$website = null,
284-
$calculateTaxes = false
286+
$calculateTaxes = false,
287+
$round = true
285288
) {
286289
return $this->_weeeTax->getProductWeeeAttributes(
287290
$product,
288291
$shipping,
289292
$billing,
290293
$website,
291-
$calculateTaxes
294+
$calculateTaxes,
295+
$round
292296
);
293297
}
294298

@@ -397,7 +401,8 @@ public function getProductWeeeAttributesForDisplay($product)
397401
$store = $product->getStore();
398402

399403
if ($this->isEnabled($store)) {
400-
return $this->getProductWeeeAttributes($product, null, null, null, $this->typeOfDisplay(1));
404+
$calculateTax = ($this->typeOfDisplay(1) || $this->typeOfDisplay(2)) ? 1 : 0;
405+
return $this->getProductWeeeAttributes($product, null, null, null, $calculateTax);
401406
}
402407
return [];
403408
}
@@ -798,6 +803,17 @@ public function isDisplayExcl($storeId = null)
798803
);
799804
}
800805

806+
/**
807+
* Get tax price display settings
808+
*
809+
* @param null|string|bool|int|Store $store
810+
* @return int
811+
*/
812+
public function getTaxDisplayConfig($store = null)
813+
{
814+
return $this->_taxData->getPriceDisplayType($store);
815+
}
816+
801817
/**
802818
* Return an array of FPT attributes for a bundle product
803819
*

app/code/Magento/Weee/Model/Tax.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public function getWeeeTaxAttributeCodes($store = null, $forceEnabled = false)
200200
* @param null|false|\Magento\Quote\Model\Quote\Address $billing
201201
* @param Website $website
202202
* @param bool $calculateTax
203+
* @param bool $round
203204
* @return \Magento\Framework\DataObject[]
204205
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
205206
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -210,7 +211,8 @@ public function getProductWeeeAttributes(
210211
$shipping = null,
211212
$billing = null,
212213
$website = null,
213-
$calculateTax = null
214+
$calculateTax = null,
215+
$round = true
214216
) {
215217
$result = [];
216218

@@ -283,19 +285,29 @@ public function getProductWeeeAttributes(
283285
//round the "golden price"
284286
$amountInclTax = $this->priceCurrency->round($amountInclTax);
285287
$taxAmount = $amountInclTax - $amountInclTax / (100 + $currentPercent) * 100;
286-
$taxAmount = $this->priceCurrency->round($taxAmount);
288+
if ($round) {
289+
$taxAmount = $this->priceCurrency->round($taxAmount);
290+
}
287291
} else {
288292
$appliedRates = $this->_calculationFactory->create()->getAppliedRates($rateRequest);
289293
if (count($appliedRates) > 1) {
290294
$taxAmount = 0;
291295
foreach ($appliedRates as $appliedRate) {
292296
$taxRate = $appliedRate['percent'];
293-
$taxAmount += $this->priceCurrency->round($value * $taxRate / 100);
297+
if ($round) {
298+
$taxAmount += $this->priceCurrency->round($value * $taxRate / 100);
299+
} else {
300+
$taxAmount += $value * $taxRate / 100;
301+
}
294302
}
295303
} else {
296-
$taxAmount = $this->priceCurrency->round(
297-
$value * $currentPercent / 100
298-
);
304+
if ($round) {
305+
$taxAmount = $this->priceCurrency->round(
306+
$value * $currentPercent / 100
307+
);
308+
} else {
309+
$taxAmount = $value * $currentPercent / 100;
310+
}
299311
}
300312
}
301313
}

app/code/Magento/Weee/Observer/GetPriceConfigurationObserver.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,20 @@ private function insertWeeePrice($holder, $key, $weeeAttributes)
138138
*
139139
* @param int|null $storeId
140140
* @return string
141+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
141142
*/
142143
protected function getWhichCalcPriceToUse($storeId = null)
143144
{
144145
$calcPrice = 'finalPrice';
145-
if ($this->weeeData->isDisplayExcl($storeId) ||
146-
$this->weeeData->isDisplayExclDescIncl($storeId) ||
147-
($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax())
148-
) {
146+
147+
// Does catalog price include tax? (true, false)
148+
$isPriceIncludesTax = $this->weeeData->displayTotalsInclTax();
149+
// Price display configurations (DISPLAY_TYPE_EXCLUDING_TAX, DISPLAY_TYPE_INCLUDING_TAX, DISPLAY_TYPE_BOTH)
150+
$priceDisplayConfig = $this->weeeData->getTaxDisplayConfig();
151+
152+
if ($isPriceIncludesTax == true &&
153+
$priceDisplayConfig == \Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX &&
154+
$this->weeeData->typeOfDisplay([\Magento\Weee\Model\Tax::DISPLAY_EXCL_DESCR_INCL])) {
149155
$calcPrice = 'basePrice';
150156
}
151157
return $calcPrice;

app/code/Magento/Weee/Pricing/Adjustment.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Framework\Pricing\Adjustment\AdjustmentInterface;
1111
use Magento\Framework\Pricing\SaleableInterface;
1212
use Magento\Framework\Pricing\PriceCurrencyInterface;
13-
use Magento\Tax\Pricing\Adjustment as TaxAdjustment;
1413
use Magento\Weee\Helper\Data as WeeeHelper;
1514

1615
/**
@@ -99,6 +98,7 @@ public function isIncludedInDisplayPrice()
9998
* @param SaleableInterface $saleableItem
10099
* @param null|array $context
101100
* @return float
101+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
102102
*/
103103
public function extractAdjustment($amount, SaleableInterface $saleableItem, $context = [])
104104
{
@@ -132,7 +132,8 @@ public function applyAdjustment($amount, SaleableInterface $saleableItem, $conte
132132
*/
133133
public function isExcludedWith($adjustmentCode)
134134
{
135-
return (($adjustmentCode == self::ADJUSTMENT_CODE) || ($adjustmentCode == TaxAdjustment::ADJUSTMENT_CODE));
135+
return (($adjustmentCode == self::ADJUSTMENT_CODE) ||
136+
($adjustmentCode == \Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE));
136137
}
137138

138139
/**
@@ -155,6 +156,6 @@ protected function getAmount(SaleableInterface $saleableItem)
155156
*/
156157
public function getSortOrder()
157158
{
158-
return $this->weeeHelper->isTaxable() ? $this->sortOrder : -1;
159+
return $this->sortOrder;
159160
}
160161
}

0 commit comments

Comments
 (0)