本文整理汇总了PHP中Magento\Tax\Model\Config类的典型用法代码示例。如果您正苦于以下问题:PHP Config类的具体用法?PHP Config怎么用?PHP Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTotalsForDisplay
/**
* 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;
}
示例2: getTotalsForDisplay
/**
* 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;
}
示例3: testGetShippingDataObject
/**
* @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));
}
示例4: displayBoth
/**
* 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();
}
示例5: aroundProcess
/**
* @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;
}
示例6: includeTax
/**
* 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;
}
示例7: testGetCalculationSequence
/**
* 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());
}
示例8: testGetShippingDataObject
/**
* @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());
}
}
示例9: aroundGet
/**
* @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;
}
示例10: getText
/**
* 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;
}
示例11: getTotalsForDisplay
/**
* 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;
}
示例12: getShippingLabel
/**
* 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;
}
示例13: testGetShippingDataObject
/**
* @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());
}
}
示例14: testCollectUsingTaxInclShippingAmount
/**
* 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);
}
示例15: fetch
/**
* Add tax totals information to address object
*
* @param Address $address
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function fetch(Address $address)
{
$applied = $address->getAppliedTaxes();
$store = $address->getQuote()->getStore();
$amount = $address->getTaxAmount();
$items = $this->_getAddressItems($address);
$discountTaxCompensation = 0;
foreach ($items as $item) {
$discountTaxCompensation += $item->getDiscountTaxCompensation();
}
$taxAmount = $amount + $discountTaxCompensation;
$area = null;
if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
$area = 'taxes';
}
if ($amount != 0 || $this->_config->displayCartZeroTax($store)) {
$address->addTotal(['code' => $this->getCode(), 'title' => __('Tax'), 'full_info' => $applied ? $applied : [], 'value' => $amount, 'area' => $area]);
}
$store = $address->getQuote()->getStore();
/**
* Modify subtotal
*/
if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
if ($address->getSubtotalInclTax() > 0) {
$subtotalInclTax = $address->getSubtotalInclTax();
} else {
$subtotalInclTax = $address->getSubtotal() + $taxAmount - $address->getShippingTaxAmount();
}
$address->addTotal(['code' => 'subtotal', 'title' => __('Subtotal'), 'value' => $subtotalInclTax, 'value_incl_tax' => $subtotalInclTax, 'value_excl_tax' => $address->getSubtotal()]);
}
return $this;
}