CountryGuard.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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;
  7. use Magento\Sales\Model\Order;
  8. /**
  9. * Class for preventing tax calculation on unsupported countries
  10. */
  11. class CountryGuard
  12. {
  13. /** @var Config */
  14. private $config;
  15. /**
  16. * @param Config $config
  17. */
  18. public function __construct(Config $config)
  19. {
  20. $this->config = $config;
  21. }
  22. /**
  23. * Determine if an Order can be serviced by Vertex
  24. *
  25. * @param Order $order
  26. * @return bool
  27. */
  28. public function isOrderServiceableByVertex(Order $order)
  29. {
  30. if ($order->getIsVirtual() || !$order->getShippingAddress()) {
  31. $address = $order->getBillingAddress();
  32. } else {
  33. $address = $order->getShippingAddress();
  34. }
  35. return $address && $this->isCountryIdServiceableByVertex($address->getCountryId());
  36. }
  37. /**
  38. * Determine if a country can be serviced by Vertex
  39. *
  40. * @param string $countryId
  41. * @return bool
  42. */
  43. public function isCountryIdServiceableByVertex($countryId)
  44. {
  45. return in_array($countryId, $this->config->getAllowedCountries(), false);
  46. }
  47. }