Skip to content

Commit

Permalink
merged logic of m1 discount.php t0 m2 discount
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavlyan committed Nov 8, 2017
1 parent d82571c commit 2313cc1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Helper/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Discount
{
const VERSION = '1.0.11';
const VERSION = '1.0.12';

protected $generalHelper = null;

Expand Down Expand Up @@ -79,19 +79,20 @@ protected function runCalculation()
{
if ($this->checkSpread()) {
$this->applyDiscount();

$this->generalHelper->addLog("'Apply Discount' logic was applied");
return;
}
//Это случай, когда не нужно размазывать копейки по позициям
//и при этом, позиции могут иметь скидки, равномерно делимые.
$this->setSimplePrices();
$this->generalHelper->addLog("'Simple prices' logic was applied");
}

public function applyDiscount()
{
$subTotal = $this->_entity->getData('subtotal_incl_tax');
$shippingAmount = $this->_entity->getData('shipping_incl_tax');
$grandTotal = $this->_entity->getData('grand_total');
$grandTotal = round($this->_entity->getData('grand_total'), 2);
$grandDiscount = $grandTotal - $subTotal - $shippingAmount;

$percentageSum = 0;
Expand Down Expand Up @@ -175,7 +176,7 @@ public function setSimplePrices()

public function buildFinalArray()
{
$grandTotal = $this->_entity->getData('grand_total');
$grandTotal = round($this->_entity->getData('grand_total'), 2);

$items = $this->getAllItems();
$itemsFinal = [];
Expand All @@ -188,7 +189,7 @@ public function buildFinalArray()
$taxValue = $this->_taxAttributeCode
? $this->addTaxValue($this->_taxAttributeCode, $item)
: $this->_taxValue;
$price = $item->getData(self::NAME_UNIT_PRICE) ?: $item->getData('price_incl_tax');
$price = !is_null($item->getData(self::NAME_UNIT_PRICE)) ? $item->getData(self::NAME_UNIT_PRICE) : $item->getData('price_incl_tax');
$entityItem = $this->_buildItem($item, $price, $taxValue);

$itemsFinal[$item->getId()] = $entityItem;
Expand Down Expand Up @@ -333,7 +334,7 @@ public function checkSpread()
$sumDiscountAmount += $item->getData('discount_amount');
}

$grandTotal = $this->_entity->getData('grand_total');
$grandTotal = round($this->_entity->getData('grand_total'), 2);
$shippingAmount = $this->_entity->getData('shipping_incl_tax');

//Есть ли общая скидка на Чек. bccomp returns 0 if operands are equal
Expand Down

0 comments on commit 2313cc1

Please sign in to comment.