69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace CK\Tax\Plugin;
|
|
|
|
use Magento\Quote\Model\Quote;
|
|
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
|
|
use Magento\Quote\Model\Quote\Address\Total as QuoteTotal;
|
|
use Magento\Tax\Model\Sales\Total\Quote\Tax as TaxCollector;
|
|
|
|
class SkipTaxCollector {
|
|
|
|
/**
|
|
* @var \CK\Logger\Logger
|
|
*/
|
|
protected $logger;
|
|
|
|
/**
|
|
* @var \CK\Logger\LoggerFactory
|
|
*/
|
|
protected $loggerFactory;
|
|
|
|
public function __construct(
|
|
\CK\Logger\LoggerFactory $loggerFactory
|
|
) {
|
|
$this->loggerFactory = $loggerFactory;
|
|
$this->logger = $this->loggerFactory->create();
|
|
}
|
|
|
|
/**
|
|
* Around plugin for Tax::collect
|
|
*
|
|
* @param TaxCollector $subject
|
|
* @param callable $proceed
|
|
* @param Quote $quote
|
|
* @param ShippingAssignmentInterface $shippingAssignment
|
|
* @param QuoteTotal $total
|
|
* @return TaxCollector
|
|
*/
|
|
public function aroundCollect(
|
|
TaxCollector $subject,
|
|
callable $proceed,
|
|
Quote $quote,
|
|
ShippingAssignmentInterface $shippingAssignment,
|
|
QuoteTotal $total
|
|
) {
|
|
$netsuiteOrderId = $quote->getData('netsuite_order_id');
|
|
if ($netsuiteOrderId !== null) {
|
|
$this->logger->info("This quote generated from NS order $netsuiteOrderId, skipping tax calculation.");
|
|
|
|
// zero out tax on totals
|
|
$total->setTotalAmount('tax', 0);
|
|
$total->setBaseTotalAmount('tax', 0);
|
|
|
|
// zero out tax on each item in the shipping assignment
|
|
foreach ($shippingAssignment->getItems() as $item) {
|
|
$item->setTaxAmount(0);
|
|
$item->setBaseTaxAmount(0);
|
|
$item->setTaxPercent(0);
|
|
}
|
|
|
|
return $subject;
|
|
}
|
|
|
|
return $proceed($quote, $shippingAssignment, $total);
|
|
}
|
|
|
|
}
|
|
|