Skip to content

Commit

Permalink
Merge pull request #45 from magento-fearless-kiwis/develop
Browse files Browse the repository at this point in the history
[Fearless-Kiwis] Sprint 38 bug fixes
  • Loading branch information
Yu Tang committed Jan 21, 2015
2 parents 4044dc2 + 37d89b4 commit ae383b5
Show file tree
Hide file tree
Showing 58 changed files with 2,851 additions and 253 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct,

/** @var Store $store */
$store = $bundleProduct->getStore();
$roundingMethod = $this->taxHelper->getCalculationAgorithm($store);
$roundingMethod = $this->taxHelper->getCalculationAlgorithm($store);
foreach ($amountList as $amountInfo) {
/** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */
$itemAmount = $amountInfo['amount'];
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,10 @@ public function afterSave()
*/
public function setQty($qty)
{
$this->setData('qty', $qty);
$this->reloadPriceInfo();
if ($this->getData('qty') != $qty) {
$this->setData('qty', $qty);
$this->reloadPriceInfo();
}
return $this;
}

Expand Down
14 changes: 4 additions & 10 deletions app/code/Magento/Directory/Model/PriceCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,12 @@ public function convert($amount, $scope = null, $currency = null)
}

/**
* Convert and round price value for specified store or passed currency
*
* @param float $amount
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @param Currency|string|null $currency
* @param int $precision
* @return float
* {@inheritdoc}
*/
public function convertAndRound($amount, $store = null, $currency = null, $precision = self::DEFAULT_PRECISION)
public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION)
{
$currentCurrency = $this->getCurrency($store, $currency);
$convertedValue = $this->getStore($store)->getBaseCurrency()->convert($amount, $currentCurrency);
$currentCurrency = $this->getCurrency($scope, $currency);
$convertedValue = $this->getStore($scope)->getBaseCurrency()->convert($amount, $currentCurrency);
return round($convertedValue, $precision);
}

Expand Down
35 changes: 2 additions & 33 deletions app/code/Magento/Sales/Model/Order/Invoice/Total/Subtotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,15 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)

$allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
$baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
$allowedSubtotalInclTax = $allowedSubtotal +
$order->getHiddenTaxAmount() +
$order->getTaxAmount() -
$order->getTaxInvoiced() -
$order->getHiddenTaxInvoiced();
$baseAllowedSubtotalInclTax = $baseAllowedSubtotal +
$order->getBaseHiddenTaxAmount() +
$order->getBaseTaxAmount() -
$order->getBaseTaxInvoiced() -
$order->getBaseHiddenTaxInvoiced();

/**
* Check if shipping tax calculation is included to current invoice.
*/
$includeShippingTax = true;
foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
$includeShippingTax = false;
break;
}
}

if ($includeShippingTax) {
$allowedSubtotalInclTax -= $order->getShippingTaxAmount();
$baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
} else {
$allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
$baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
}
//Note: The $subtotalInclTax and $baseSubtotalInclTax are not adjusted from those provide by the line items
//because the "InclTax" is displayed before any tax adjustments based on discounts, shipping, etc.

if ($invoice->isLast()) {
$subtotal = $allowedSubtotal;
$baseSubtotal = $baseAllowedSubtotal;
$subtotalInclTax = $allowedSubtotalInclTax;
$baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
} else {
$subtotal = min($allowedSubtotal, $subtotal);
$baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
$subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
$baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
}

$invoice->setSubtotal($subtotal);
Expand Down
36 changes: 18 additions & 18 deletions app/code/Magento/Tax/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public function getCalculationSequence($store = null)
* @param null|string|bool|int|Store $store
* @return string
*/
public function getCalculationAgorithm($store = null)
public function getCalculationAlgorithm($store = null)
{
return $this->_config->getAlgorithm($store);
}
Expand Down Expand Up @@ -797,23 +797,6 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface

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

// Apply any taxes for shipping
$shippingTaxAmount = $salesItem->getShippingTaxAmount();
$originalShippingTaxAmount = $order->getShippingTaxAmount();
if ($shippingTaxAmount && $originalShippingTaxAmount &&
$shippingTaxAmount != 0 && floatval($originalShippingTaxAmount)
) {
//An invoice or credit memo can have a different qty than its order
$shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount;
$itemTaxDetails = $orderTaxDetails->getItems();
foreach ($itemTaxDetails as $itemTaxDetail) {
//Aggregate taxable items associated with shipping
if ($itemTaxDetail->getType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) {
$taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio);
}
}
}

// Apply any taxes for the items
/** @var $item \Magento\Sales\Model\Order\Invoice\Item|\Magento\Sales\Model\Order\Creditmemo\Item */
foreach ($salesItem->getItems() as $item) {
Expand Down Expand Up @@ -845,6 +828,23 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface
}
}

// Apply any taxes for shipping
$shippingTaxAmount = $salesItem->getShippingTaxAmount();
$originalShippingTaxAmount = $order->getShippingTaxAmount();
if ($shippingTaxAmount && $originalShippingTaxAmount &&
$shippingTaxAmount != 0 && floatval($originalShippingTaxAmount)
) {
//An invoice or credit memo can have a different qty than its order
$shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount;
$itemTaxDetails = $orderTaxDetails->getItems();
foreach ($itemTaxDetails as $itemTaxDetail) {
//Aggregate taxable items associated with shipping
if ($itemTaxDetail->getType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) {
$taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio);
}
}
}

return $taxClassAmount;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Tax/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function getNeedUseShippingExcludeTax()
}

/**
* Get defined tax calculation agorithm
* Get defined tax calculation algorithm
*
* @param null|string|bool|int|Store $store
* @return string
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Tax/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function updateProductOptions(\Magento\Framework\Event\Observer $observer
return $this;
}

$algorithm = $this->_taxData->getCalculationAgorithm();
$algorithm = $this->_taxData->getCalculationAlgorithm();
$options['calculationAlgorithm'] = $algorithm;
// prepare correct template for options render
if ($this->_taxData->displayBothPrices()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,23 @@ protected function escape($price, $currency = '$')
* Get price excluding tax
*
* @param string $currency
* @return string
* @return string|null
*/
public function getPriceExcludingTax($currency = '$')
{
return trim($this->_rootElement->find($this->priceExcludingTax)->getText(), $currency);
$priceElement = $this->_rootElement->find($this->priceExcludingTax);
return $priceElement->isVisible() ? trim($priceElement->getText(), $currency) : null;
}

/**
* Get price including tax
*
* @param string $currency
* @return string
* @return string|null
*/
public function getPriceIncludingTax($currency = '$')
{
return trim($this->_rootElement->find($this->priceIncludingTax)->getText(), $currency);
$priceElement = $this->_rootElement->find($this->priceIncludingTax);
return $priceElement->isVisible() ? trim($priceElement->getText(), $currency) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function getDataConfig()
}

/**
* Get preset array
*
* @param string $name
* @return mixed|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function run()
if ($product->hasData('id') === false) {
$product->persist();
}

return ['product' => $product];
return ['product' => $product];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,16 @@ public function __construct(array $defaultConfig = [], array $defaultData = [])
'simple_action' => 'By Fixed Amount',
'discount_amount' => '10',
];

$this->_data['catalog_price_rule_all_groups'] = [
'name' => 'catalog_price_rule_all_groups_%isolation%',
'description' => '-50% of price, Priority = 0',
'is_active' => 'Active',
'website_ids' => ['Main Website'],
'customer_group_ids' => ['NOT LOGGED IN', 'General', 'Wholesale', 'Retailer'],
'sort_order' => '0',
'simple_action' => 'By Percentage of the Original Price',
'discount_amount' => '50',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogRule\Test\TestStep;

use Mtf\Fixture\FixtureFactory;
use Mtf\TestStep\TestStepInterface;

/**
* Creating catalog rule
*/
class CreateCatalogRuleStep implements TestStepInterface
{
/**
* Catalog Rule dataset name
*
* @var string
*/
protected $catalogRule;

/**
* Factory for Fixture
*
* @var FixtureFactory
*/
protected $fixtureFactory;

/**
* Preparing step properties
*
* @constructor
* @param FixtureFactory $fixtureFactory
* @param string $catalogRule
*/
public function __construct(FixtureFactory $fixtureFactory, $catalogRule)
{
$this->fixtureFactory = $fixtureFactory;
$this->catalogRule = $catalogRule;
}

/**
* Create catalog rule
*
* @return array
*/
public function run()
{
$result['catalogRule'] = null;
if ($this->catalogRule != '-') {
$catalogRule = $this->fixtureFactory->createByCode(
'catalogRule',
['dataSet' => $this->catalogRule]
);
$catalogRule->persist();
$result['catalogRule'] = $catalogRule;
}
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,27 @@ public function getProductName()
/**
* Get product price
*
* @return string
* @return string|null
*/
public function getPrice()
{
$cartProductPrice = $this->_rootElement->find($this->price, Locator::SELECTOR_XPATH)->getText();
return str_replace(',', '', $this->escapeCurrency($cartProductPrice));
$cartProductPrice = $this->_rootElement->find($this->price, Locator::SELECTOR_XPATH);
return $cartProductPrice->isVisible()
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
: null;
}

/**
* Get product price including tax
*
* @return string
* @return string|null
*/
public function getPriceInclTax()
{
$cartProductPrice = $this->_rootElement->find($this->priceInclTax, Locator::SELECTOR_XPATH)->getText();
return str_replace(',', '', $this->escapeCurrency($cartProductPrice));
$cartProductPrice = $this->_rootElement->find($this->priceInclTax, Locator::SELECTOR_XPATH);
return $cartProductPrice->isVisible()
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
: null;
}

/**
Expand All @@ -112,29 +116,33 @@ public function getQty()
/**
* Get sub-total for the specified item in the cart
*
* @return string
* @return string|null
*/
public function getSubtotalPrice()
{
$price = $this->_rootElement->find($this->subtotalPrice, Locator::SELECTOR_XPATH)->getText();
return str_replace(',', '', $this->escapeCurrency($price));
$cartProductPrice = $this->_rootElement->find($this->subtotalPrice, Locator::SELECTOR_XPATH);
return $cartProductPrice->isVisible()
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
: null;
}

/**
* Get sub-total including tax for the specified item in the cart
*
* @return string
* @return string|null
*/
public function getSubtotalPriceInclTax()
{
$price = $this->_rootElement->find($this->subTotalPriceInclTax, Locator::SELECTOR_XPATH)->getText();
return str_replace(',', '', $this->escapeCurrency($price));
$cartProductPrice = $this->_rootElement->find($this->subTotalPriceInclTax, Locator::SELECTOR_XPATH);
return $cartProductPrice->isVisible()
? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText()))
: null;
}

/**
* Get product options in the cart
*
* @return string
* @return array
*/
public function getOptions()
{
Expand Down
Loading

0 comments on commit ae383b5

Please sign in to comment.