Skip to content

Commit

Permalink
Merged in fixbug (pull request #5)
Browse files Browse the repository at this point in the history
Fix bug: crash on product page
  • Loading branch information
JaJuMa committed Jan 17, 2023
2 parents 54ebcb0 + 7e9de58 commit 4816e54
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Plugin/Tax/Config/AroundGetShippingTaxClassPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Jajuma\DynamicShippingTax\Plugin\Tax\Config;

use Magento\Quote\Model\QuoteRepository;
use Magento\Store\Model\Store;
use Jajuma\DynamicShippingTax\Model\Config;
use Magento\Tax\Model\Calculation;
Expand Down Expand Up @@ -51,21 +52,25 @@ class AroundGetShippingTaxClassPlugin
*/
protected $session;

private $quoteRepository;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Customer\Model\ResourceModel\GroupRepository $groupRepository
* @param \Magento\Tax\Model\Calculation\Proxy $taxCalculation
* @param Calculation $taxCalculation
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param Session $session
* @param \Magento\Checkout\Model\Session $session
* @param QuoteRepository $quoteRepository
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Customer\Model\Session $customerSession,
\Magento\Customer\Model\ResourceModel\GroupRepository $groupRepository,
Calculation $taxCalculation,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Checkout\Model\Session $session
\Magento\Checkout\Model\Session $session,
QuoteRepository $quoteRepository
)
{
$this->scopeConfig = $scopeConfig;
Expand All @@ -74,6 +79,7 @@ public function __construct(
$this->taxCalculation = $taxCalculation;
$this->storeManager = $storeManager;
$this->session = $session;
$this->quoteRepository = $quoteRepository;
}

/**
Expand All @@ -86,7 +92,7 @@ public function aroundGetShippingTaxClass(\Magento\Tax\Model\Config $subject, \C
{
$currentUrl = $this->storeManager->getStore()->getCurrentUrl(false);

//check step place order page checkout
//check step place order page checkout

if (strpos($currentUrl, 'payment-information') !== false) {
return $proceed($store);
Expand All @@ -99,7 +105,9 @@ public function aroundGetShippingTaxClass(\Magento\Tax\Model\Config $subject, \C
);

// get all item in cart
$quoteItems = $this->session->getQuote()->getAllVisibleItems();
$quoteId = $this->session->getQuoteId();
$quote = $this->quoteRepository->get($quoteId);
$quoteItems = $quote->getAllVisibleItems();

// If not items in cart or dynamic shipping type is default of magento, use default tax class for shipping
if (count($quoteItems) == 0 || $dynamicShippingType == Config::SHIPPING_TAX_TYPE_DEFAULT) {
Expand Down

0 comments on commit 4816e54

Please sign in to comment.