protected function _calculateTaxForItem(Item $item) { // populate for taxStrategy $item->populate($item->getUnit()); if (false === $item->order->taxable) { // Resetting the gross is important because if the tax strategy is // exclusive this will include the tax amount $item->gross = $item->net; $item->taxRate = 0; $item->tax = 0; return; } // Set the tax rate to whatever the product's tax rate is $item->taxRate = $item->productTaxRate; // Get the adjusted gross based on tax rate differences. // Takes off included tax and add actual tax. if ('exclusive' === $item->taxStrategy) { // actual $adjustedGross = $item->getDiscountedPrice(); } else { // actual - included tax $includedTax = $this->_calculateInclusiveTax($item->getDiscountedPrice(), $item->getProduct()->getTaxStrategy()->getIncludedTaxRate()); $adjustedGross = $item->getDiscountedPrice() - $includedTax; } // adjusted + tax $adjustedGross += $adjustedGross * ($item->taxRate / 100); // Gross is the product gross - discount $item->gross = $adjustedGross; $item->tax = $this->_calculateInclusiveTax($item->gross, $item->taxRate); $item->net = round($item->gross - $item->tax, 2); $item->gross = round($item->gross, 2); $item->discount = round($item->discount, 2); }
/** * Check if an item matches the criteria set by the product row * * @param Order\Entity\Item\Item $item * @param ProductRow $row * * @return bool */ public function itemIsApplicable(Order\Entity\Item\Item $item, ProductRow $row) { if (in_array($item->id, $this->_alreadyInBundle)) { return false; } if ((int) $item->getProduct()->id !== $row->getProductID()) { return false; } if (count($row->getOptions()) <= 0) { return true; } $unit = $item->getUnit(); foreach ($row->getOptions() as $name => $value) { if (!($unit->hasOption($name) && $unit->getOption($name) === $value)) { return false; } } return true; }