Skip to content

Commit

Permalink
Added option to force shipping prices to include tax
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin-Magmodules committed Sep 9, 2021
1 parent 597fcca commit a212ca1
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ public function isFreeShippingEnabled($store = null)
return $this->getValue(self::API_CONFIG_PATH . '/freeshipping_enabled', $store);
}

/**
* @return mixed
*/
public function isPriceIncludesTax($store = null)
{
return $this->getValue(self::API_CONFIG_PATH . '/price_incl_tax', $store);
}

/**
* @param null|Store|int|string $store
*
Expand Down
92 changes: 92 additions & 0 deletions Plugin/Tax/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Copyright © 2019 Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Paazl\CheckoutWidget\Plugin\Tax;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Tax\Model\Config as TaxConfigModel;
use Paazl\CheckoutWidget\Helper\Order as OrderHelper;
use Paazl\CheckoutWidget\Model\Config as PaazlConfig;
use Magento\Quote\Api\Data\ShippingMethodInterface;
use Magento\Checkout\Model\Session;
use Magento\Quote\Api\CartRepositoryInterface;

/**
* Tax Config Plugin
*/
class Config
{
/**
* @var OrderHelper
*/
private $orderHelper;

/**
* @var PaazlConfig
*/
private $paazlConfig;
/**
* @var Session
*/
private $session;
/**
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* Config constructor.
*
* @param OrderHelper $orderHelper
* @param PaazlConfig $paazlConfig
* @param ShippingMethodInterface $shippingMethod
* @param Session $session
* @param CartRepositoryInterface $cartRepository
*/
public function __construct(
OrderHelper $orderHelper,
PaazlConfig $paazlConfig,
ShippingMethodInterface $shippingMethod,
Session $session,
CartRepositoryInterface $cartRepository
) {
$this->orderHelper = $orderHelper;
$this->paazlConfig = $paazlConfig;
$this->shippingMethod = $shippingMethod;
$this->session = $session;
$this->cartRepository = $cartRepository;
}

/**
* @param TaxConfigModel $subject
* @param bool $result
* @param null $store
*
* @return bool
*/
public function afterShippingPriceIncludesTax(
TaxConfigModel $subject,
bool $result,
$store = null
) {
try {
$cartId = $this->session->getQuoteId();
//we can't use Magento\Checkout\Model\Session::getQuote() because of infinity loop on place order
$quote = $this->cartRepository->getActive($cartId);
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
if ($shippingMethod
&& $this->orderHelper->isPaazlShippingMethod($shippingMethod)
&& $this->paazlConfig->isPriceIncludesTax($store)
) {
return true;
}
} catch (NoSuchEntityException $e) {
return $result;
}

return $result;
}
}
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@
</depends>
<comment><![CDATA[API Matrix letter for free shipping]]></comment>
</field>
<field id="price_incl_tax" translate="label" type="select" sortOrder="67" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Price Includes Tax</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>If yes - shipping price will always includes tax regardless Magento settings</comment>
</field>
<field id="debug" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Debug</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
type="Paazl\CheckoutWidget\Plugin\Quote\AfterAddProduct" sortOrder="1" disabled="false" />
</type>

<type name="Magento\Tax\Model\Config">
<plugin name="tax_config_plugin" type="Paazl\CheckoutWidget\Plugin\Tax\Config" disabled="false"/>
</type>

<preference for="Magento\Framework\HTTP\Client\Curl"
type="Paazl\CheckoutWidget\Model\Api\CurlExtra"/>

Expand Down

0 comments on commit a212ca1

Please sign in to comment.