php Magento-Tax-Model-Config类(方法)实例源码

下面列出了php Magento-Tax-Model-Config 类(方法)源码代码实例,从而了解它的用法。

作者:pradeep-wagent    项目:magento   
/**
  * Check if tax amount should be included to grandtotal block
  * array(
  *  $index => array(
  *      'amount'   => $amount,
  *      'label'    => $label,
  *      'font_size'=> $font_size
  *  )
  * )
  * @return array
  */
 public function getTotalsForDisplay()
 {
     $store = $this->getOrder()->getStore();
     if ($this->_taxConfig->displaySalesTaxWithGrandTotal($store)) {
         return [];
     }
     $totals = [];
     if ($this->_taxConfig->displaySalesFullSummary($store)) {
         $totals = $this->getFullTaxInfo();
     }
     $totals = array_merge($totals, parent::getTotalsForDisplay());
     return $totals;
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * Check if tax amount should be included to grandtotals block
  * array(
  *  $index => array(
  *      'amount'   => $amount,
  *      'label'    => $label,
  *      'font_size'=> $font_size
  *  )
  * )
  * @return array
  */
 public function getTotalsForDisplay()
 {
     $store = $this->getOrder()->getStore();
     if (!$this->_taxConfig->displaySalesTaxWithGrandTotal($store)) {
         return parent::getTotalsForDisplay();
     }
     $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
     $amountExclTax = $this->getAmount() - $this->getSource()->getTaxAmount();
     $amountExclTax = $amountExclTax > 0 ? $amountExclTax : 0;
     $amountExclTax = $this->getOrder()->formatPriceTxt($amountExclTax);
     $tax = $this->getOrder()->formatPriceTxt($this->getSource()->getTaxAmount());
     $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
     $totals = [['amount' => $this->getAmountPrefix() . $amountExclTax, 'label' => __('Grand Total (Excl. Tax)') . ':', 'font_size' => $fontSize]];
     if ($this->_taxConfig->displaySalesFullSummary($store)) {
         $totals = array_merge($totals, $this->getFullTaxInfo());
     }
     $totals[] = ['amount' => $this->getAmountPrefix() . $tax, 'label' => __('Tax') . ':', 'font_size' => $fontSize];
     $totals[] = ['amount' => $this->getAmountPrefix() . $amount, 'label' => __('Grand Total (Incl. Tax)') . ':', 'font_size' => $fontSize];
     return $totals;
 }

作者:ViniciusAugust    项目:magento   
/**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool shippingPriceInclTax
  * @param array $expectedValue
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $itemMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterface');
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($baseShippingAmount);
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($shippingAmount);
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setType')->willReturnSelf();
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setValue')->with($shippingTaxClass)->willReturnSelf();
     $this->quoteDetailsItemBuilderMock->expects($this->once())->method('create')->willReturn($itemMock);
     $this->assertEquals($itemMock, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
 }

作者:zhangjiacha    项目:magento   
/**
  * Check if we need display both sobtotals
  *
  * @return bool
  */
 public function displayBoth()
 {
     /**
      * Check without store parameter - we wil get admin configuration value
      */
     return $this->_taxConfig->displayCartSubtotalBoth();
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * @param \Magento\Quote\Model\Cart\TotalsConverter $subject
  * @param \Closure $proceed
  * @param \Magento\Quote\Model\Quote\Address\Total[] $addressTotals
  * @return \Magento\Quote\Api\Data\TotalSegmentInterface[]
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundProcess(\Magento\Quote\Model\Cart\TotalsConverter $subject, \Closure $proceed, array $addressTotals = [])
 {
     $totalSegments = $proceed($addressTotals);
     if (!array_key_exists($this->code, $addressTotals)) {
         return $totalSegments;
     }
     $taxes = $addressTotals['tax']->getData();
     if (!array_key_exists('full_info', $taxes)) {
         return $totalSegments;
     }
     $detailsId = 1;
     $finalData = [];
     foreach (unserialize($taxes['full_info']) as $info) {
         if (array_key_exists('hidden', $info) && $info['hidden'] || $info['amount'] == 0 && $this->taxConfig->displayCartZeroTax()) {
             continue;
         }
         $taxDetails = $this->detailsFactory->create([]);
         $taxDetails->setAmount($info['amount']);
         $taxRates = $this->getRatesData($info['rates']);
         $taxDetails->setRates($taxRates);
         $taxDetails->setGroupId($detailsId);
         $finalData[] = $taxDetails;
         $detailsId++;
     }
     $attributes = $totalSegments[$this->code]->getExtensionAttributes();
     if ($attributes === null) {
         $attributes = $this->totalSegmentExtensionFactory->create();
     }
     $attributes->setTaxGrandtotalDetails($finalData);
     $totalSegments[$this->code]->setExtensionAttributes($attributes);
     return $totalSegments;
 }

作者:pradeep-wagent    项目:magento   
/**
  * Check if we have include tax amount between grandtotal incl/excl tax
  *
  * @return bool
  */
 public function includeTax()
 {
     if ($this->getTotal()->getValue()) {
         return $this->_taxConfig->displayCartTaxWithGrandTotal($this->getStore());
     }
     return false;
 }

作者:shabbirvividad    项目:magento   
/**
  * Tests the getCalculationSequence method
  *
  * @param bool $applyTaxAfterDiscount
  * @param bool $discountTaxIncl
  * @param string $expectedValue
  * @dataProvider dataProviderGetCalculationSequence
  */
 public function testGetCalculationSequence($applyTaxAfterDiscount, $discountTaxIncl, $expectedValue)
 {
     $scopeConfigMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $scopeConfigMock->expects($this->at(0))->method('getValue')->will($this->returnValue($applyTaxAfterDiscount));
     $scopeConfigMock->expects($this->at(1))->method('getValue')->will($this->returnValue($discountTaxIncl));
     /** @var \Magento\Tax\Model\Config */
     $model = new Config($scopeConfigMock);
     $this->assertEquals($expectedValue, $model->getCalculationSequence());
 }

作者:pradeep-wagent    项目:magento   
/**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool $shippingPriceInclTax
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $shippingAssignmentMock = $this->getMock('Magento\\Quote\\Api\\Data\\ShippingAssignmentInterface');
     $methods = ['getShippingDiscountAmount', 'getShippingTaxCalculationAmount', 'setShippingTaxCalculationAmount', 'getShippingAmount', 'setBaseShippingTaxCalculationAmount', 'getBaseShippingAmount', 'getBaseShippingDiscountAmount'];
     $totalsMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address\\Total', $methods, [], '', false);
     $shippingMock = $this->getMock('Magento\\Quote\\Api\\Data\\ShippingInterface');
     $shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
     $shippingMock->expects($this->once())->method('getAddress')->willReturn($this->address);
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $totalsMock->expects($this->any())->method('getShippingTaxCalculationAmount')->willReturn($shippingAmount);
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $totalsMock->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $totalsMock->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $expectedDiscountAmount = $baseShippingAmount;
         } else {
             $totalsMock->expects($this->never())->method('getBaseShippingDiscountAmount');
             $expectedDiscountAmount = $shippingAmount;
         }
     }
     foreach ($addressData as $key => $value) {
         $totalsMock->setData($key, $value);
     }
     $this->assertEquals($this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($shippingAssignmentMock, $totalsMock, $useBaseCurrency));
     if ($shippingAmount) {
         $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount());
     }
 }

作者:nja7    项目:magento   
/**
  * @param CartTotalRepository $subject
  * @param \Closure $proceed
  * @param int $cartId
  * @return \Magento\Quote\Model\Cart\Totals
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGet(CartTotalRepository $subject, \Closure $proceed, $cartId)
 {
     $result = $proceed($cartId);
     $quote = $this->quoteRepository->getActive($cartId);
     $totals = $quote->getTotals();
     if (!array_key_exists('tax', $totals)) {
         return $result;
     }
     $taxes = $totals['tax']->getData();
     if (!array_key_exists('full_info', $taxes)) {
         return $result;
     }
     $detailsId = 1;
     $finalData = [];
     foreach ($taxes['full_info'] as $info) {
         if (array_key_exists('hidden', $info) && $info['hidden'] || $info['amount'] == 0 && $this->taxConfig->displayCartZeroTax()) {
             continue;
         }
         $taxDetails = $this->detailsFactory->create([]);
         $taxDetails->setAmount($info['amount']);
         $taxRates = $this->getRatesData($info['rates']);
         $taxDetails->setRates($taxRates);
         $taxDetails->setGroupId($detailsId);
         $finalData[] = $taxDetails;
         $detailsId++;
     }
     $attributes = $result->getExtensionAttributes();
     if ($attributes === null) {
         $attributes = $this->extensionFactory->create();
     }
     $attributes->setTaxGrandtotalDetails($finalData);
     /** @var $result \Magento\Quote\Model\Cart\Totals */
     $result->setExtensionAttributes($attributes);
     return $result;
 }

作者:aies    项目:magento   
/**
  * Build message text
  * Determine which notification and data to display
  *
  * @return string
  */
 public function getText()
 {
     $messageDetails = '';
     if (!empty($this->storesWithInvalidDisplaySettings) && !$this->taxConfig->isWrongDisplaySettingsIgnored()) {
         $messageDetails .= '<strong>';
         $messageDetails .= __('Warning tax configuration can result in rounding errors. ');
         $messageDetails .= '</strong><br>';
         $messageDetails .= __('Store(s) affected: ');
         $messageDetails .= implode(', ', $this->storesWithInvalidDisplaySettings);
         $messageDetails .= '<br><div style="text-align:right">';
         $messageDetails .= __('Click on the link to <a href="%1">ignore this notification</a>', $this->getIgnoreTaxNotificationUrl('price_display'));
         $messageDetails .= "</div><br>";
     }
     if (!empty($this->storesWithInvalidDiscountSettings) && !$this->taxConfig->isWrongDiscountSettingsIgnored()) {
         $messageDetails .= '<strong>';
         $messageDetails .= __('Warning tax discount configuration might result in different discounts
                             than a customer might expect. ');
         $messageDetails .= '</strong><br>';
         $messageDetails .= __('Store(s) affected: ');
         $messageDetails .= implode(', ', $this->storesWithInvalidDiscountSettings);
         $messageDetails .= '<br><div style="text-align:right">';
         $messageDetails .= __('Click on the link to <a href="%1">ignore this notification</a>', $this->getIgnoreTaxNotificationUrl('discount'));
         $messageDetails .= "</div><br>";
     }
     $messageDetails .= '<br>';
     $messageDetails .= __('Please see <a href="%1">documentation</a> for more details. ', $this->getInfoUrl());
     $messageDetails .= __('Click here to go to <a href="%1">Tax Configuration</a> and change your settings.', $this->getManageUrl());
     return $messageDetails;
 }

作者:shabbirvividad    项目:magento   
/**
  * Get array of arrays with totals information for display in PDF
  * array(
  *  $index => array(
  *      'amount'   => $amount,
  *      'label'    => $label,
  *      'font_size'=> $font_size
  *  )
  * )
  * @return array
  */
 public function getTotalsForDisplay()
 {
     $store = $this->getOrder()->getStore();
     $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
     $amountInclTax = $this->getSource()->getShippingInclTax();
     if (!$amountInclTax) {
         $amountInclTax = $this->getAmount() + $this->getSource()->getShippingTaxAmount();
     }
     $amountInclTax = $this->getOrder()->formatPriceTxt($amountInclTax);
     $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
     if ($this->_taxConfig->displaySalesShippingBoth($store)) {
         $totals = [['amount' => $this->getAmountPrefix() . $amount, 'label' => __('Shipping (Excl. Tax)') . ':', 'font_size' => $fontSize], ['amount' => $this->getAmountPrefix() . $amountInclTax, 'label' => __('Shipping (Incl. Tax)') . ':', 'font_size' => $fontSize]];
     } elseif ($this->_taxConfig->displaySalesShippingInclTax($store)) {
         $totals = [['amount' => $this->getAmountPrefix() . $amountInclTax, 'label' => __($this->getTitle()) . ':', 'font_size' => $fontSize]];
     } else {
         $totals = [['amount' => $this->getAmountPrefix() . $amount, 'label' => __($this->getTitle()) . ':', 'font_size' => $fontSize]];
     }
     return $totals;
 }

作者:shabbirvividad    项目:magento   
/**
  * Get label for shipping total based on configuration settings
  *
  * @return string
  */
 public function getShippingLabel()
 {
     $source = $this->getSource();
     if ($this->_taxConfig->displaySalesShippingInclTax($source->getOrder()->getStoreId())) {
         $label = __('Refund Shipping (Incl. Tax)');
     } elseif ($this->_taxConfig->displaySalesShippingBoth($source->getOrder()->getStoreId())) {
         $label = __('Refund Shipping (Excl. Tax)');
     } else {
         $label = __('Refund Shipping');
     }
     return $label;
 }

作者:shabbirvividad    项目:magento   
/**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool $shippingPriceInclTax
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $expectedDiscountAmount = $baseShippingAmount;
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $expectedDiscountAmount = $shippingAmount;
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->assertEquals($this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
     if ($shippingAmount) {
         $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount());
     }
 }

作者:Doabilit    项目:magento2de   
/**
  * situation: The admin user specified the desired refund amount that has taxes embedded within it
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function testCollectUsingTaxInclShippingAmount()
 {
     $this->taxConfig->expects($this->any())->method('displaySalesShippingInclTax')->willReturn(true);
     $orderShippingAmount = 15;
     $shippingTaxAmount = 3;
     $orderShippingInclTax = $orderShippingAmount + $shippingTaxAmount;
     $orderShippingAmountRefunded = 5;
     $shippingTaxRefunded = 1;
     $refundedInclTax = $orderShippingAmountRefunded + $shippingTaxRefunded;
     $currencyMultiple = 2;
     $baseOrderShippingAmount = $orderShippingAmount * $currencyMultiple;
     $baseShippingTaxAmount = $shippingTaxAmount * $currencyMultiple;
     $baseOrderShippingInclTax = $orderShippingInclTax * $currencyMultiple;
     $baseOrderShippingAmountRefunded = $orderShippingAmountRefunded * $currencyMultiple;
     $baseShippingTaxRefunded = $shippingTaxRefunded * $currencyMultiple;
     $baseRefundedInclTax = $refundedInclTax * $currencyMultiple;
     //determine expected amounts
     $desiredRefundAmount = $baseOrderShippingInclTax - $baseRefundedInclTax;
     $expectedShippingAmount = $orderShippingAmount - $orderShippingAmountRefunded;
     $expectedShippingAmountInclTax = $orderShippingInclTax - $refundedInclTax;
     $expectedBaseShippingAmount = $expectedShippingAmount * $currencyMultiple;
     $expectedBaseShippingAmountInclTax = $expectedShippingAmountInclTax * $currencyMultiple;
     $grandTotalBefore = 100;
     $baseGrandTotalBefore = 200;
     $expectedGrandTotal = $grandTotalBefore + $expectedShippingAmount;
     $expectedBaseGrandTtoal = $baseGrandTotalBefore + $expectedBaseShippingAmount;
     $order = new \Magento\Framework\DataObject(['shipping_amount' => $orderShippingAmount, 'base_shipping_amount' => $baseOrderShippingAmount, 'shipping_refunded' => $orderShippingAmountRefunded, 'base_shipping_refunded' => $baseOrderShippingAmountRefunded, 'shipping_incl_tax' => $orderShippingInclTax, 'base_shipping_incl_tax' => $baseOrderShippingInclTax, 'shipping_tax_amount' => $shippingTaxAmount, 'shipping_tax_refunded' => $shippingTaxRefunded, 'base_shipping_tax_amount' => $baseShippingTaxAmount, 'base_shipping_tax_refunded' => $baseShippingTaxRefunded]);
     $this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($order);
     $this->creditmemoMock->expects($this->once())->method('hasBaseShippingAmount')->willReturn(true);
     $this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn($desiredRefundAmount);
     $this->creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn($grandTotalBefore);
     $this->creditmemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn($baseGrandTotalBefore);
     //verify
     $this->creditmemoMock->expects($this->once())->method('setShippingAmount')->with($expectedShippingAmount)->willReturnSelf();
     $this->creditmemoMock->expects($this->once())->method('setBaseShippingAmount')->with($expectedBaseShippingAmount)->willReturnSelf();
     $this->creditmemoMock->expects($this->once())->method('setShippingInclTax')->with($expectedShippingAmountInclTax)->willReturnSelf();
     $this->creditmemoMock->expects($this->once())->method('setBaseShippingInclTax')->with($expectedBaseShippingAmountInclTax)->willReturnSelf();
     $this->creditmemoMock->expects($this->once())->method('setGrandTotal')->with($expectedGrandTotal)->willReturnSelf();
     $this->creditmemoMock->expects($this->once())->method('setBaseGrandTotal')->with($expectedBaseGrandTtoal)->willReturnSelf();
     $this->shippingCollector->collect($this->creditmemoMock);
 }

作者:shabbirvividad    项目:magento   
public function testGetDisplaySubtotalBoth()
 {
     $this->taxConfig->expects($this->once())->method('displayCartSubtotalBoth');
     $this->totalsObj->getDisplaySubtotalBoth();
 }

作者:nja7    项目:magento   
/**
  * Check if we need display grid totals include tax
  *
  * @return bool
  */
 public function displayTotalsIncludeTax()
 {
     $result = $this->_taxConfig->displayCartSubtotalInclTax($this->getStore()) || $this->_taxConfig->displayCartSubtotalBoth($this->getStore());
     return $result;
 }

作者:tingyee    项目:magento   
/**
  * @return bool
  */
 public function displayBoth()
 {
     return $this->_taxConfig->displayCartSubtotalBoth($this->getStore());
 }

作者:whoopl    项目:magento2-testin   
/**
  * Get totals config
  *
  * @return array
  */
 protected function getTotalsConfig()
 {
     return ['display_subtotal_incl_tax' => (int) $this->taxConfig->displayCartSubtotalInclTax(), 'display_cart_subtotal_excl_tax' => (int) $this->taxConfig->displayCartSubtotalExclTax()];
 }

作者:pradeep-wagent    项目:magento   
/**
  * Display tax in grand total section or not
  *
  * @return bool
  */
 public function isTaxDisplayedInGrandTotal()
 {
     return $this->taxConfig->displayCartTaxWithGrandTotal();
 }

作者:aies    项目:magento   
/**
  * Check if we need display shipping include tax
  *
  * @return bool
  */
 public function displayIncludeTax()
 {
     return $this->_taxConfig->displayCartShippingInclTax($this->getStore());
 }


问题


面经


文章

微信
公众号

扫码关注公众号