Skip to content

Commit

Permalink
Merge pull request #246 from magento-fearless-kiwis/develop
Browse files Browse the repository at this point in the history
[FearlessKiwis] Bug Fixes
  • Loading branch information
Tang, Yu(ytang1) committed Dec 20, 2015
2 parents 3f148f9 + b895ea1 commit f7226f8
Show file tree
Hide file tree
Showing 29 changed files with 326 additions and 495 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ require([
showTime: false,
showHour: false,
showMinute: false,
localTimezone: <?php /* @escapeNotVerified */ echo $block->getTimezoneOffsetSeconds() ?>,
serverTimezoneSeconds:<?php /* @escapeNotVerified */ echo $block->getStoreTimestamp() ?>,
yearRange: '<?php /* @escapeNotVerified */ echo $block->getYearRange() ?>'
}
});
Expand Down
16 changes: 14 additions & 2 deletions app/code/Magento/Weee/Block/Item/Price/Renderer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ public function getUnitDisplayPriceExclTax()
*/
public function getBaseUnitDisplayPriceExclTax()
{
$basePriceExclTax = $this->getItem()->getBasePrice();
$orderItem = $this->getItem();
if ($orderItem instanceof InvoiceItem || $orderItem instanceof CreditMemoItem) {
$orderItem = $orderItem->getOrderItem();
}

$qty = $orderItem->getQtyOrdered();
$basePriceExclTax = $orderItem->getBaseRowTotal() / $qty;

if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
return $basePriceExclTax;
Expand Down Expand Up @@ -338,7 +344,13 @@ public function getFinalUnitDisplayPriceExclTax()
*/
public function getBaseFinalUnitDisplayPriceExclTax()
{
$basePriceExclTax = $this->getItem()->getBasePrice();
$orderItem = $this->getItem();
if ($orderItem instanceof InvoiceItem || $orderItem instanceof CreditMemoItem) {
$orderItem = $orderItem->getOrderItem();
}

$qty = $orderItem->getQtyOrdered();
$basePriceExclTax = $orderItem->getBaseRowTotal() / $qty;

if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
return $basePriceExclTax;
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Weee/Block/Sales/Order/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public function initTotals()
$store = $this->getSource()->getStore();

$weeeTotal = $this->weeeData->getTotalAmounts($items, $store);
$weeeBaseTotal = $this->weeeData->getBaseTotalAmounts($items, $store);
if ($weeeTotal) {
// Add our total information to the set of other totals
$total = new \Magento\Framework\DataObject(
[
'code' => $this->getNameInLayout(),
'label' => __('FPT'),
'value' => $weeeTotal,
'base_value' => $weeeBaseTotal
]
);
if ($this->getBeforeCondition()) {
Expand Down
47 changes: 41 additions & 6 deletions app/code/Magento/Weee/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,27 @@ public function getTotalAmounts($items, $store = null)
return $weeeTotal;
}

/**
* Returns the base total amount of FPT across all items. Used for displaying the FPT totals line item.
*
* @param \Magento\Quote\Model\Quote\Item\AbstractItem[] $items
* @param null|string|bool|int|Store $store
* @return float
*/
public function getBaseTotalAmounts($items, $store = null)
{
$baseWeeeTotal = 0;
$displayTotalsInclTax = $this->displayTotalsInclTax($store);
foreach ($items as $item) {
if ($displayTotalsInclTax) {
$baseWeeeTotal += $this->getBaseRowWeeeTaxInclTax($item);
} else {
$baseWeeeTotal += $item->getBaseWeeeTaxAppliedRowAmount();
}
}
return $baseWeeeTotal;
}

/**
* Get FPT DISPLAY_INCL setting
*
Expand Down Expand Up @@ -791,19 +812,33 @@ public function getWeeeAttributesForBundle($product)
$typeInstance->getOptionsIds($product),
$product
);
$insertedWeeCodesArray = [];
$insertedWeeeCodesArray = [];
foreach ($selectionCollection as $selectionItem) {
$weeAttributes = $this->getProductWeeeAttributes(
$weeeAttributes = $this->getProductWeeeAttributes(
$selectionItem,
null,
null,
$product->getStore()->getWebsiteId()
$product->getStore()->getWebsiteId(),
true,
false
);
foreach ($weeAttributes as $weeAttribute) {
$insertedWeeCodesArray[$selectionItem->getId()][$weeAttribute->getCode()]=$weeAttribute;
$priceTaxDisplay = $this->getTaxDisplayConfig();
$priceIncludesTax = $this->displayTotalsInclTax();
foreach ($weeeAttributes as $weeeAttribute) {
if ($priceTaxDisplay == \Magento\Tax\Model\Config::DISPLAY_TYPE_INCLUDING_TAX ||
$priceTaxDisplay == \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH) {
if ($priceIncludesTax == false) {
$weeeAttribute['amount'] = $weeeAttribute['amount_excl_tax'] + $weeeAttribute['tax_amount'];
}
} else if ($priceTaxDisplay == \Magento\Tax\Model\Config::DISPLAY_TYPE_EXCLUDING_TAX) {
if ($priceIncludesTax == true) {
$weeeAttribute['amount'] = $weeeAttribute['amount_excl_tax'];
}
}
$insertedWeeeCodesArray[$selectionItem->getId()][$weeeAttribute->getCode()] = $weeeAttribute;
}
}
return $insertedWeeCodesArray;
return $insertedWeeeCodesArray;
}
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ private function insertWeeePrice($holder, $key, $weeeAttributesForBundle)
$weeeSum = 0;
foreach ($weeeAttributesForBundle[$holder['optionId']] as $weeeAttribute) {
$holder[$key]['weeePrice' . $weeeAttribute->getCode()] =
['amount' => (float)$weeeAttribute->getAmountExclTax()];
$weeeSum += (float)$weeeAttribute->getAmountExclTax();
['amount' => (float)$weeeAttribute->getAmount()];
$weeeSum += (float)$weeeAttribute->getAmount();
}
$holder[$key]['weeePrice']['amount'] += (float)$weeeSum;
} else {
Expand Down
164 changes: 0 additions & 164 deletions app/code/Magento/Weee/Observer/Total/Webapi/ItemObserver.php

This file was deleted.

13 changes: 11 additions & 2 deletions app/code/Magento/Weee/Test/Unit/Block/Item/Price/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected function setUp()
'getBaseWeeeTaxAppliedAmount',
'getBaseWeeeTaxInclTax',
'getBasePriceInclTax',
'getQtyOrdered'
])
->getMock();

Expand Down Expand Up @@ -314,9 +315,13 @@ public function testGetBaseUnitDisplayPriceExclTax(
->will($this->returnValue($baseWeeeTaxExclTax));

$this->item->expects($this->once())
->method('getBasePrice')
->method('getBaseRowTotal')
->will($this->returnValue($basePriceExclTax));

$this->item->expects($this->once())
->method('getQtyOrdered')
->will($this->returnValue(1));

$this->weeeHelper->expects($this->any())
->method('typeOfDisplay')
->with([WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL], self::ZONE)
Expand Down Expand Up @@ -610,9 +615,13 @@ public function testGetBaseFinalUnitDisplayPriceExclTax(
->will($this->returnValue($baseWeeeTaxExclTax));

$this->item->expects($this->once())
->method('getBasePrice')
->method('getBaseRowTotal')
->will($this->returnValue($basePriceExclTax));

$this->item->expects($this->once())
->method('getQtyOrdered')
->will($this->returnValue(1));

$this->assertEquals($expectedValue, $this->renderer->getBaseFinalUnitDisplayPriceExclTax());
}

Expand Down
Loading

0 comments on commit f7226f8

Please sign in to comment.