public function testCollect() { $this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping); $this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address); $this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate'); $this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]); $this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true); $this->address->expects($this->once())->method('setFreeShipping')->with(true); $this->total->expects($this->atLeastOnce())->method('setTotalAmount'); $this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount'); $this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf(); $this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false); $this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false); $this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false); $this->cartItem->expects($this->once())->method('getWeight')->willReturn(2); $this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2); $this->address->expects($this->once())->method('getFreeShipping')->willReturn(true); $this->cartItem->expects($this->once())->method('setRowWeight')->with(0); $this->address->expects($this->once())->method('setItemQty')->with(2); $this->address->expects($this->atLeastOnce())->method('setWeight'); $this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight'); $this->address->expects($this->once())->method('collectShippingRates'); $this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]); $this->rate->expects($this->once())->method('getCode')->willReturn('flatrate'); $this->quote->expects($this->once())->method('getStore')->willReturn($this->store); $this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5); $this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5); $this->total->expects($this->once())->method('setShippingAmount')->with(5); $this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title'); $this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title'); $this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title'); $this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total); }
/** * @param \Magento\Quote\Model\Quote $quote * @param Address\Total $total * @return array|null */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { if ($total->getShippingInclTax()) { return ['code' => 'shipping', 'shipping_incl_tax' => $total->getShippingInclTax()]; } return null; }
/** * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * * @return array|null */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $result = null; $amount = $total->getDiscountCouponAmount(); $result = ['code' => $this->getCode(), 'title' => __('Discount Mercado Pago'), 'value' => $amount]; return $result; }
/** * Merge numeric total values * * @param \Magento\Quote\Model\Quote\Address\Total $total * @return $this */ public function merge(\Magento\Quote\Model\Quote\Address\Total $total) { $newData = $total->getData(); foreach ($newData as $key => $value) { if (is_numeric($value)) { $this->setData($key, $this->_getData($key) + $value); } } return $this; }
/** * @param \Magento\Quote\Model\Quote\Address\Total $total */ protected function clearValues(\Magento\Quote\Model\Quote\Address\Total $total) { // $enabled = $this->helperData->isModuleEnabled(); // $minimumOrderAmount = $this->helperData->getMinimumOrderAmount(); // $subtotal = $total->getTotalAmount('subtotal'); $total->setTotalAmount('subtotal', 0); $total->setBaseTotalAmount('subtotal', 0); $total->setTotalAmount('tax', 0); $total->setBaseTotalAmount('tax', 0); $total->setTotalAmount('discount_tax_compensation', 0); $total->setBaseTotalAmount('discount_tax_compensation', 0); $total->setTotalAmount('shipping_discount_tax_compensation', 0); $total->setBaseTotalAmount('shipping_discount_tax_compensation', 0); $total->setSubtotalInclTax(0); $total->setBaseSubtotalInclTax(0); }
/** * @param Total $totalInstance * @param array $output * @return array */ protected function merge($totalInstance, $output) { if (array_key_exists($totalInstance->getCode(), $output)) { $output[$totalInstance->getCode()] = $output[$totalInstance->getCode()]->addData($totalInstance->getData()); } else { $output[$totalInstance->getCode()] = $totalInstance; } return $output; }
/** * Add shipping totals information to address object * * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * @return array */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $amount = $total->getShippingAmount(); $shippingDescription = $total->getShippingDescription(); $title = $amount != 0 && $shippingDescription ? __('Shipping & Handling (%1)', $shippingDescription) : __('Shipping & Handling'); return ['code' => $this->getCode(), 'title' => $title, 'value' => $amount]; }
/** * Adds minimal tax information to the "total" data structure * * @param \Magento\Quote\Model\Quote $quote * @param Address\Total $total * @return null */ protected function enhanceTotalData(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $taxAmount = 0; $shippingTaxAmount = 0; $discountTaxCompensation = 0; $subtotalInclTax = $total->getSubtotalInclTax(); $computeSubtotalInclTax = true; if ($total->getSubtotalInclTax() > 0) { $computeSubtotalInclTax = false; } /** @var \Magento\Quote\Model\Quote\Address $address */ foreach ($quote->getAllAddresses() as $address) { $taxAmount += $address->getTaxAmount(); $shippingTaxAmount += $address->getShippingTaxAmount(); $discountTaxCompensation += $address->getDiscountTaxCompensationAmount(); if ($computeSubtotalInclTax) { $subtotalInclTax += $address->getSubtotalInclTax(); } } $total->setTaxAmount($taxAmount); $total->setShippingTaxAmount($shippingTaxAmount); $total->setDiscountTaxCompensationAmount($discountTaxCompensation); // accessed via 'discount_tax_compensation' $total->setSubtotalInclTax($subtotalInclTax); return; }
/** * Collect applied tax rates information on address level * * @param QuoteAddress\Total $total * @param array $applied * @param float $amount * @param float $baseAmount * @param float $rate * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _saveAppliedTaxes(QuoteAddress\Total $total, $applied, $amount, $baseAmount, $rate) { $previouslyAppliedTaxes = $total->getAppliedTaxes(); $process = count($previouslyAppliedTaxes); foreach ($applied as $row) { if ($row['percent'] == 0) { continue; } if (!isset($previouslyAppliedTaxes[$row['id']])) { $row['process'] = $process; $row['amount'] = 0; $row['base_amount'] = 0; $previouslyAppliedTaxes[$row['id']] = $row; } if (!is_null($row['percent'])) { $row['percent'] = $row['percent'] ? $row['percent'] : 1; $rate = $rate ? $rate : 1; $appliedAmount = $amount / $rate * $row['percent']; $baseAppliedAmount = $baseAmount / $rate * $row['percent']; } else { $appliedAmount = 0; $baseAppliedAmount = 0; foreach ($row['rates'] as $rate) { $appliedAmount += $rate['amount']; $baseAppliedAmount += $rate['base_amount']; } } if ($appliedAmount || $previouslyAppliedTaxes[$row['id']]['amount']) { $previouslyAppliedTaxes[$row['id']]['amount'] += $appliedAmount; $previouslyAppliedTaxes[$row['id']]['base_amount'] += $baseAppliedAmount; } else { unset($previouslyAppliedTaxes[$row['id']]); } } $total->setAppliedTaxes($previouslyAppliedTaxes); }
/** * Process row amount based on FPT total amount configuration setting * * @param \Magento\Quote\Model\Quote\Address\Total $total * @param float $rowValueExclTax * @param float $baseRowValueExclTax * @param float $rowValueInclTax * @param float $baseRowValueInclTax * @return $this */ protected function processTotalAmount($total, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax) { if (!$this->weeeData->isTaxable($this->_store)) { //Accumulate the values. Will be used later in the 'weee tax' collector $this->weeeTotalExclTax += $this->priceCurrency->round($rowValueExclTax); $this->weeeBaseTotalExclTax += $this->priceCurrency->round($baseRowValueExclTax); } //This value is used to calculate shipping cost; it will be overridden by tax collector $total->setSubtotalInclTax($total->getSubtotalInclTax() + $this->priceCurrency->round($rowValueInclTax)); $total->setBaseSubtotalInclTax($total->getBaseSubtotalInclTax() + $this->priceCurrency->round($baseRowValueInclTax)); return $this; }
/** * Add tax totals information to address object * * @param \Magento\Quote\Model\Quote $quote * @param Address\Total $total * @return array|null * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $totals = []; $store = $quote->getStore(); $applied = $total->getAppliedTaxes(); $amount = $total->getTaxAmount(); $taxAmount = $amount + $total->getTotalAmount('discount_tax_compensation'); $area = null; if ($this->_config->displayCartTaxWithGrandTotal($store) && $total->getGrandTotal()) { $area = 'taxes'; } if ($amount != 0 || $this->_config->displayCartZeroTax($store)) { $totals[] = ['code' => $this->getCode(), 'title' => __('Tax'), 'full_info' => $applied ? $applied : [], 'value' => $amount, 'area' => $area]; } /** * Modify subtotal */ if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) { if ($total->getSubtotalInclTax() > 0) { $subtotalInclTax = $total->getSubtotalInclTax(); } else { $subtotalInclTax = $total->getSubtotal() + $taxAmount - $total->getShippingTaxAmount(); } $totals[] = ['code' => 'subtotal', 'title' => __('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $total->getSubtotal()]; } if (empty($totals)) { return null; } return $totals; }
public function testGetBaseTotalAmountAbsent() { $this->assertEquals(0, $this->model->getBaseTotalAmount('great')); }
/** * Add grand total information to address * * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * @return $this */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { return ['code' => $this->getCode(), 'title' => __('Grand Total'), 'value' => $total->getGrandTotal(), 'area' => 'footer']; }
/** * Verify handling of serialized, non-serialized input into and out of getFullInfo() * * @param $input * @param $expected * @dataProvider getFullInfoDataProvider */ public function testGetFullInfo($input, $expected) { $this->model->setFullInfo($input); $this->assertEquals($expected, $this->model->getFullInfo()); }
/** * Process row amount based on FPT total amount configuration setting * * @param \Magento\Quote\Model\Quote\Address\Total $total * @param float $rowValueExclTax * @param float $baseRowValueExclTax * @param float $rowValueInclTax * @param float $baseRowValueInclTax * @return $this */ protected function processTotalAmount($total, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax) { if ($this->weeeData->includeInSubtotal($this->_store)) { $total->addTotalAmount('subtotal', $rowValueExclTax); $total->addBaseTotalAmount('subtotal', $baseRowValueExclTax); } else { $total->addTotalAmount('weee', $rowValueExclTax); $total->addBaseTotalAmount('weee', $baseRowValueExclTax); } $total->setSubtotalInclTax($total->getSubtotalInclTax() + $rowValueInclTax); $total->setBaseSubtotalInclTax($total->getBaseSubtotalInclTax() + $baseRowValueInclTax); return $this; }
/** * Assign subtotal amount and label to address object * * @param \Magento\Quote\Model\Quote $quote * @param Address\Total $total * @return array */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { return ['code' => $this->getCode(), 'title' => $this->getLabel(), 'value' => $total->getSubtotal()]; }
/** * Add discount total information to address * * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * @return array|null */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $result = null; $amount = $total->getDiscountAmount(); if ($amount != 0) { $description = $total->getDiscountDescription(); $result = ['code' => $this->getCode(), 'title' => strlen($description) ? __('Discount (%1)', $description) : __('Discount'), 'value' => $amount]; } return $result; }
/** * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * * @return array|null */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $result = null; $amount = $total->getFinanceCostAmount(); $result = ['code' => $this->getCode(), 'title' => __('Financing Cost'), 'value' => $amount]; return $result; }