private function getProductTaxRate() { /** @var $taxCalculator \Magento\Tax\Model\Calculation */ $taxCalculator = $this->calculation; $request = $taxCalculator->getRateRequest($this->quote->getShippingAddress(), $this->quote->getBillingAddress(), $this->quote->getCustomerTaxClassId(), $this->quote->getStore()); $request->setProductClassId($this->getProduct()->getTaxClassId()); return $taxCalculator->getRate($request); }
public function testGetStore() { $storeId = 1; $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($storeMock)); $this->quote->setStoreId($storeId); $result = $this->quote->getStore(); $this->assertInstanceOf('Magento\\Store\\Model\\Store', $result); }
private function initializeCurrency() { /** @var $currencyHelper \Ess\M2ePro\Model\Currency */ $currencyHelper = $this->currency; if ($currencyHelper->isConvertible($this->proxyOrder->getCurrency(), $this->quote->getStore())) { $currentCurrency = $this->magentoCurrencyFactory->create()->load($this->proxyOrder->getCurrency()); } else { $currentCurrency = $this->quote->getStore()->getBaseCurrency(); } $this->quote->getStore()->setData('current_currency', $currentCurrency); }
/** * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Catalog\Model\Product $product * @param \Magento\Framework\DataObject $config * @return \Magento\Quote\Model\Quote\Item|string */ public function init(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, \Magento\Framework\DataObject $config) { $stockItem = $this->stockRegistry->getStockItem($product->getId(), $quote->getStore()->getWebsiteId()); if ($stockItem->getIsQtyDecimal()) { $product->setIsQtyDecimal(1); } else { $config->setQty((int) $config->getQty()); } $product->setCartQty($config->getQty()); $item = $quote->addProduct($product, $config, \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL); return $item; }
/** * Calculate tax on product items. The result will be used to determine shipping * and discount later. * * @param \Magento\Quote\Model\Quote $quote * @param ShippingAssignmentInterface $shippingAssignment * @param Address\Total $total * @return $this */ public function collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total) { $items = $shippingAssignment->getItems(); if (!$items) { return $this; } $store = $quote->getStore(); $priceIncludesTax = $this->_config->priceIncludesTax($store); //Setup taxable items $itemDataObjects = $this->mapItems($shippingAssignment, $priceIncludesTax, false); $quoteDetails = $this->prepareQuoteDetails($shippingAssignment, $itemDataObjects); $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails, $store->getStoreId()); $itemDataObjects = $this->mapItems($shippingAssignment, $priceIncludesTax, true); $baseQuoteDetails = $this->prepareQuoteDetails($shippingAssignment, $itemDataObjects); $baseTaxDetails = $this->taxCalculationService->calculateTax($baseQuoteDetails, $store->getStoreId()); $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails); if (isset($itemsByType[self::ITEM_TYPE_PRODUCT])) { $this->processProductItems($shippingAssignment, $itemsByType[self::ITEM_TYPE_PRODUCT], $total); } return $this; }
/** * Get reserved order id * * @param \Magento\Quote\Model\Quote $quote * @return string */ public function getReservedOrderId($quote) { return $this->sequenceManager->getSequence(\Magento\Sales\Model\Order::ENTITY, $quote->getStore()->getGroup()->getDefaultStoreId())->getNextValue(); }
/** * Check whether payment method is applicable to quote * Purposed to allow use in controllers some logic that was implemented in blocks only before * * @param PaymentMethodChecksInterface $paymentMethod * @param \Magento\Quote\Model\Quote $quote * @return bool */ public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote) { return $paymentMethod->canUseForCurrency($quote->getStore()->getBaseCurrencyCode()); }
/** * Format price base on store convert price method * * @param float $price * @return string */ protected function _formatPrice($price) { return $this->priceCurrency->convertAndFormat($price, true, PriceCurrencyInterface::DEFAULT_PRECISION, $this->_quote->getStore()); }
/** * 2016-09-07 * @param O|Q $oq [optional] * @return Currency */ private function currencyFromOQ($oq) { return $this->currency($oq->getStore(), dfp_currency($oq)); }
/** * Add tax totals information to address object * * @param \Magento\Quote\Model\Quote $quote * @param Address\Total $total * @return array|null * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { $totals = []; $store = $quote->getStore(); $applied = $total->getAppliedTaxes(); if (is_string($applied)) { $applied = unserialize($applied); } $amount = $total->getTaxAmount(); if ($amount == null) { $this->enhanceTotalData($quote, $total); $amount = $total->getTaxAmount(); } $taxAmount = $amount + $total->getTotalAmount('discount_tax_compensation'); $area = null; if ($this->_config->displayCartTaxWithGrandTotal($store) && $total->getGrandTotal()) { $area = 'taxes'; } $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; }
/** * Fetch the Weee total amount for display in totals block when building the initial quote * * @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) { /** @var $items \Magento\Sales\Model\Order\Item[] */ $items = isset($total['address_quote_items']) ? $total['address_quote_items'] : []; $weeeTotal = $this->weeeData->getTotalAmounts($items, $quote->getStore()); if ($weeeTotal) { return ['code' => $this->getCode(), 'title' => __('FPT'), 'value' => $weeeTotal, 'area' => null]; } return null; }
/** * Create currency rates and set rate on quote * * @param $ratesData * @param \Magento\Quote\Model\Quote $quote */ protected function createCurrencyRate($ratesData, \Magento\Quote\Model\Quote $quote) { $baseCurrencyCode = $ratesData['base_currency_code']; $quoteCurrencyCode = $ratesData['quote_currency_code']; $currencyConversionRate = $ratesData['currency_conversion_rate']; $newRate = [$baseCurrencyCode => [$quoteCurrencyCode => $currencyConversionRate]]; /** @var \Magento\Directory\Model\Currency $currency */ $currency = $this->objectManager->get('Magento\\Directory\\Model\\Currency'); $currency->saveRates($newRate); // Set the currency code on the store so that the \Magento\Quote\Model\Quote::beforeSave() method sets the // quote_currency_code to the appropriate value $quote->getStore()->getCurrentCurrency()->setData('currency_code', $quoteCurrencyCode); // Save the quote to register the quote_currency_code $quote->save(); }