SubtotalPlugin.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Plugin;
  7. use Magento\Quote\Api\Data\ShippingAssignmentInterface;
  8. use Magento\Quote\Model\Quote;
  9. use Magento\Tax\Api\Data\QuoteDetailsItemInterface;
  10. use Magento\Tax\Model\Sales\Total\Quote\Subtotal;
  11. use Vertex\Tax\Model\VertexUsageDeterminer;
  12. /**
  13. * Prevent Subtotal Tax calculation when Vertex is enabled
  14. *
  15. * @see Subtotal
  16. */
  17. class SubtotalPlugin
  18. {
  19. /** @var VertexUsageDeterminer */
  20. private $usageDeterminer;
  21. /**
  22. * @param VertexUsageDeterminer $usageDeterminer
  23. */
  24. public function __construct(VertexUsageDeterminer $usageDeterminer)
  25. {
  26. $this->usageDeterminer = $usageDeterminer;
  27. }
  28. /**
  29. * Prevent Subtotal Tax calculation when Vertex is enabled
  30. *
  31. * Vertex doesn't support post-tax discounts, so this isn't necessary
  32. *
  33. * @param Subtotal $subject
  34. * @param callable $super
  35. * @param Quote $quote
  36. * @param ShippingAssignmentInterface $shippingAssignment
  37. * @param Quote\Address\Total $total
  38. * @return QuoteDetailsItemInterface
  39. * @throws \InvalidArgumentException
  40. * @SuppressWarnings(PHPMD.UnusedFormalParameter) $subject is a necessary part of a plugin
  41. */
  42. public function aroundCollect(
  43. Subtotal $subject,
  44. callable $super,
  45. Quote $quote,
  46. ShippingAssignmentInterface $shippingAssignment,
  47. Quote\Address\Total $total
  48. ) {
  49. if (!$this->usageDeterminer->shouldUseVertex(
  50. $quote->getStoreId(),
  51. $shippingAssignment->getShipping()->getAddress(),
  52. $quote->getCustomerId(),
  53. $quote->isVirtual(),
  54. true
  55. )) {
  56. // Allows forward compatibility with argument additions
  57. $arguments = func_get_args();
  58. array_splice($arguments, 0, 2);
  59. return call_user_func_array($super, $arguments);
  60. }
  61. }
  62. }