/** * Set the return item from an OrderItem. * * @param OrderItem $item * @return Assembler */ public function setReturnItemFromOrderItem(OrderItem $item) { $this->_return->item = $returnItem = new OrderReturnItem(); $this->setCurrency($item->order->currencyID); $returnItem->order = $item->order; $returnItem->orderItem = $item; $returnItem->listPrice = $item->listPrice; $returnItem->actualPrice = $item->actualPrice; $returnItem->returnedValue = $item->gross; $returnItem->calculatedBalance = 0 - $item->gross; $returnItem->net = $item->net; $returnItem->discount = $item->discount; $returnItem->tax = $item->tax; $returnItem->gross = $item->gross; $returnItem->rrp = $item->rrp; $returnItem->taxRate = $item->taxRate; $returnItem->productTaxRate = $item->productTaxRate; $returnItem->taxStrategy = $item->taxStrategy; $returnItem->productID = $item->productID; $returnItem->productName = $item->productName; $returnItem->unit = $item->getUnit(); $returnItem->unitID = $item->unitID; $returnItem->unitRevision = $item->unitRevision; $returnItem->sku = $item->sku; $returnItem->barcode = $item->barcode; $returnItem->options = $item->options; $returnItem->brand = $item->brand; $returnItem->status = $this->_defaultStatus; $returnItem->taxes = $item->getTaxRates(); return $this; }
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; }