Skip to content

Commit ae383b5

Browse files
author
Yu Tang
committed
Merge pull request #45 from magento-fearless-kiwis/develop
[Fearless-Kiwis] Sprint 38 bug fixes
2 parents 4044dc2 + 37d89b4 commit ae383b5

File tree

58 files changed

+2851
-253
lines changed

Some content is hidden

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

58 files changed

+2851
-253
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct,
314314

315315
/** @var Store $store */
316316
$store = $bundleProduct->getStore();
317-
$roundingMethod = $this->taxHelper->getCalculationAgorithm($store);
317+
$roundingMethod = $this->taxHelper->getCalculationAlgorithm($store);
318318
foreach ($amountList as $amountInfo) {
319319
/** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
320320
$itemAmount = $amountInfo['amount'];

app/code/Magento/Catalog/Model/Product.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,10 @@ public function afterSave()
777777
*/
778778
public function setQty($qty)
779779
{
780-
$this->setData('qty', $qty);
781-
$this->reloadPriceInfo();
780+
if ($this->getData('qty') != $qty) {
781+
$this->setData('qty', $qty);
782+
$this->reloadPriceInfo();
783+
}
782784
return $this;
783785
}
784786

app/code/Magento/Directory/Model/PriceCurrency.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,12 @@ public function convert($amount, $scope = null, $currency = null)
5858
}
5959

6060
/**
61-
* Convert and round price value for specified store or passed currency
62-
*
63-
* @param float $amount
64-
* @param null|string|bool|int|\Magento\Store\Model\Store $store
65-
* @param Currency|string|null $currency
66-
* @param int $precision
67-
* @return float
61+
* {@inheritdoc}
6862
*/
69-
public function convertAndRound($amount, $store = null, $currency = null, $precision = self::DEFAULT_PRECISION)
63+
public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION)
7064
{
71-
$currentCurrency = $this->getCurrency($store, $currency);
72-
$convertedValue = $this->getStore($store)->getBaseCurrency()->convert($amount, $currentCurrency);
65+
$currentCurrency = $this->getCurrency($scope, $currency);
66+
$convertedValue = $this->getStore($scope)->getBaseCurrency()->convert($amount, $currentCurrency);
7367
return round($convertedValue, $precision);
7468
}
7569

app/code/Magento/Sales/Model/Order/Invoice/Total/Subtotal.php

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,15 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
3737

3838
$allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
3939
$baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
40-
$allowedSubtotalInclTax = $allowedSubtotal +
41-
$order->getHiddenTaxAmount() +
42-
$order->getTaxAmount() -
43-
$order->getTaxInvoiced() -
44-
$order->getHiddenTaxInvoiced();
45-
$baseAllowedSubtotalInclTax = $baseAllowedSubtotal +
46-
$order->getBaseHiddenTaxAmount() +
47-
$order->getBaseTaxAmount() -
48-
$order->getBaseTaxInvoiced() -
49-
$order->getBaseHiddenTaxInvoiced();
50-
51-
/**
52-
* Check if shipping tax calculation is included to current invoice.
53-
*/
54-
$includeShippingTax = true;
55-
foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
56-
if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
57-
$includeShippingTax = false;
58-
break;
59-
}
60-
}
61-
62-
if ($includeShippingTax) {
63-
$allowedSubtotalInclTax -= $order->getShippingTaxAmount();
64-
$baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
65-
} else {
66-
$allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
67-
$baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
68-
}
40+
//Note: The $subtotalInclTax and $baseSubtotalInclTax are not adjusted from those provide by the line items
41+
//because the "InclTax" is displayed before any tax adjustments based on discounts, shipping, etc.
6942

7043
if ($invoice->isLast()) {
7144
$subtotal = $allowedSubtotal;
7245
$baseSubtotal = $baseAllowedSubtotal;
73-
$subtotalInclTax = $allowedSubtotalInclTax;
74-
$baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
7546
} else {
7647
$subtotal = min($allowedSubtotal, $subtotal);
7748
$baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
78-
$subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
79-
$baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
8049
}
8150

8251
$invoice->setSubtotal($subtotal);

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public function getCalculationSequence($store = null)
629629
* @param null|string|bool|int|Store $store
630630
* @return string
631631
*/
632-
public function getCalculationAgorithm($store = null)
632+
public function getCalculationAlgorithm($store = null)
633633
{
634634
return $this->_config->getAlgorithm($store);
635635
}
@@ -797,23 +797,6 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface
797797

798798
$orderTaxDetails = $this->orderTaxManagement->getOrderTaxDetails($order->getId());
799799

800-
// Apply any taxes for shipping
801-
$shippingTaxAmount = $salesItem->getShippingTaxAmount();
802-
$originalShippingTaxAmount = $order->getShippingTaxAmount();
803-
if ($shippingTaxAmount && $originalShippingTaxAmount &&
804-
$shippingTaxAmount != 0 && floatval($originalShippingTaxAmount)
805-
) {
806-
//An invoice or credit memo can have a different qty than its order
807-
$shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount;
808-
$itemTaxDetails = $orderTaxDetails->getItems();
809-
foreach ($itemTaxDetails as $itemTaxDetail) {
810-
//Aggregate taxable items associated with shipping
811-
if ($itemTaxDetail->getType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) {
812-
$taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio);
813-
}
814-
}
815-
}
816-
817800
// Apply any taxes for the items
818801
/** @var $item \Magento\Sales\Model\Order\Invoice\Item|\Magento\Sales\Model\Order\Creditmemo\Item */
819802
foreach ($salesItem->getItems() as $item) {
@@ -845,6 +828,23 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface
845828
}
846829
}
847830

831+
// Apply any taxes for shipping
832+
$shippingTaxAmount = $salesItem->getShippingTaxAmount();
833+
$originalShippingTaxAmount = $order->getShippingTaxAmount();
834+
if ($shippingTaxAmount && $originalShippingTaxAmount &&
835+
$shippingTaxAmount != 0 && floatval($originalShippingTaxAmount)
836+
) {
837+
//An invoice or credit memo can have a different qty than its order
838+
$shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount;
839+
$itemTaxDetails = $orderTaxDetails->getItems();
840+
foreach ($itemTaxDetails as $itemTaxDetail) {
841+
//Aggregate taxable items associated with shipping
842+
if ($itemTaxDetail->getType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) {
843+
$taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio);
844+
}
845+
}
846+
}
847+
848848
return $taxClassAmount;
849849
}
850850
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function getNeedUseShippingExcludeTax()
270270
}
271271

272272
/**
273-
* Get defined tax calculation agorithm
273+
* Get defined tax calculation algorithm
274274
*
275275
* @param null|string|bool|int|Store $store
276276
* @return string

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function updateProductOptions(\Magento\Framework\Event\Observer $observer
300300
return $this;
301301
}
302302

303-
$algorithm = $this->_taxData->getCalculationAgorithm();
303+
$algorithm = $this->_taxData->getCalculationAlgorithm();
304304
$options['calculationAlgorithm'] = $algorithm;
305305
// prepare correct template for options render
306306
if ($this->_taxData->displayBothPrices()) {

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/Price.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,21 +294,23 @@ protected function escape($price, $currency = '$')
294294
* Get price excluding tax
295295
*
296296
* @param string $currency
297-
* @return string
297+
* @return string|null
298298
*/
299299
public function getPriceExcludingTax($currency = '$')
300300
{
301-
return trim($this->_rootElement->find($this->priceExcludingTax)->getText(), $currency);
301+
$priceElement = $this->_rootElement->find($this->priceExcludingTax);
302+
return $priceElement->isVisible() ? trim($priceElement->getText(), $currency) : null;
302303
}
303304

304305
/**
305306
* Get price including tax
306307
*
307308
* @param string $currency
308-
* @return string
309+
* @return string|null
309310
*/
310311
public function getPriceIncludingTax($currency = '$')
311312
{
312-
return trim($this->_rootElement->find($this->priceIncludingTax)->getText(), $currency);
313+
$priceElement = $this->_rootElement->find($this->priceIncludingTax);
314+
return $priceElement->isVisible() ? trim($priceElement->getText(), $currency) : null;
313315
}
314316
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function getDataConfig()
6969
}
7070

7171
/**
72+
* Get preset array
73+
*
7274
* @param string $name
7375
* @return mixed|null
7476
*/

dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductStep.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function run()
5555
if ($product->hasData('id') === false) {
5656
$product->persist();
5757
}
58-
59-
return ['product' => $product];
58+
return ['product' => $product];
6059
}
6160
}

dev/tests/functional/tests/app/Magento/CatalogRule/Test/Repository/CatalogRule.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,16 @@ public function __construct(array $defaultConfig = [], array $defaultData = [])
8888
'simple_action' => 'By Fixed Amount',
8989
'discount_amount' => '10',
9090
];
91+
92+
$this->_data['catalog_price_rule_all_groups'] = [
93+
'name' => 'catalog_price_rule_all_groups_%isolation%',
94+
'description' => '-50% of price, Priority = 0',
95+
'is_active' => 'Active',
96+
'website_ids' => ['Main Website'],
97+
'customer_group_ids' => ['NOT LOGGED IN', 'General', 'Wholesale', 'Retailer'],
98+
'sort_order' => '0',
99+
'simple_action' => 'By Percentage of the Original Price',
100+
'discount_amount' => '50',
101+
];
91102
}
92103
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Test\TestStep;
8+
9+
use Mtf\Fixture\FixtureFactory;
10+
use Mtf\TestStep\TestStepInterface;
11+
12+
/**
13+
* Creating catalog rule
14+
*/
15+
class CreateCatalogRuleStep implements TestStepInterface
16+
{
17+
/**
18+
* Catalog Rule dataset name
19+
*
20+
* @var string
21+
*/
22+
protected $catalogRule;
23+
24+
/**
25+
* Factory for Fixture
26+
*
27+
* @var FixtureFactory
28+
*/
29+
protected $fixtureFactory;
30+
31+
/**
32+
* Preparing step properties
33+
*
34+
* @constructor
35+
* @param FixtureFactory $fixtureFactory
36+
* @param string $catalogRule
37+
*/
38+
public function __construct(FixtureFactory $fixtureFactory, $catalogRule)
39+
{
40+
$this->fixtureFactory = $fixtureFactory;
41+
$this->catalogRule = $catalogRule;
42+
}
43+
44+
/**
45+
* Create catalog rule
46+
*
47+
* @return array
48+
*/
49+
public function run()
50+
{
51+
$result['catalogRule'] = null;
52+
if ($this->catalogRule != '-') {
53+
$catalogRule = $this->fixtureFactory->createByCode(
54+
'catalogRule',
55+
['dataSet' => $this->catalogRule]
56+
);
57+
$catalogRule->persist();
58+
$result['catalogRule'] = $catalogRule;
59+
}
60+
return $result;
61+
}
62+
}

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/CartItem.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,27 @@ public function getProductName()
6969
/**
7070
* Get product price
7171
*
72-
* @return string
72+
* @return string|null
7373
*/
7474
public function getPrice()
7575
{
76-
$cartProductPrice = $this->_rootElement->find($this->price, Locator::SELECTOR_XPATH)->getText();
77-
return str_replace(',', '', $this->escapeCurrency($cartProductPrice));
76+
$cartProductPrice = $this->_rootElement->find($this->price, Locator::SELECTOR_XPATH);
77+
return $cartProductPrice->isVisible()
78+
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
79+
: null;
7880
}
7981

8082
/**
8183
* Get product price including tax
8284
*
83-
* @return string
85+
* @return string|null
8486
*/
8587
public function getPriceInclTax()
8688
{
87-
$cartProductPrice = $this->_rootElement->find($this->priceInclTax, Locator::SELECTOR_XPATH)->getText();
88-
return str_replace(',', '', $this->escapeCurrency($cartProductPrice));
89+
$cartProductPrice = $this->_rootElement->find($this->priceInclTax, Locator::SELECTOR_XPATH);
90+
return $cartProductPrice->isVisible()
91+
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
92+
: null;
8993
}
9094

9195
/**
@@ -112,29 +116,33 @@ public function getQty()
112116
/**
113117
* Get sub-total for the specified item in the cart
114118
*
115-
* @return string
119+
* @return string|null
116120
*/
117121
public function getSubtotalPrice()
118122
{
119-
$price = $this->_rootElement->find($this->subtotalPrice, Locator::SELECTOR_XPATH)->getText();
120-
return str_replace(',', '', $this->escapeCurrency($price));
123+
$cartProductPrice = $this->_rootElement->find($this->subtotalPrice, Locator::SELECTOR_XPATH);
124+
return $cartProductPrice->isVisible()
125+
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
126+
: null;
121127
}
122128

123129
/**
124130
* Get sub-total including tax for the specified item in the cart
125131
*
126-
* @return string
132+
* @return string|null
127133
*/
128134
public function getSubtotalPriceInclTax()
129135
{
130-
$price = $this->_rootElement->find($this->subTotalPriceInclTax, Locator::SELECTOR_XPATH)->getText();
131-
return str_replace(',', '', $this->escapeCurrency($price));
136+
$cartProductPrice = $this->_rootElement->find($this->subTotalPriceInclTax, Locator::SELECTOR_XPATH);
137+
return $cartProductPrice->isVisible()
138+
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
139+
: null;
132140
}
133141

134142
/**
135143
* Get product options in the cart
136144
*
137-
* @return string
145+
* @return array
138146
*/
139147
public function getOptions()
140148
{

0 commit comments

Comments
 (0)