LayoutProcessor.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Block\Checkout;
  6. use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
  7. use Magento\Framework\Exception\NoSuchEntityException;
  8. use Magento\Store\Model\StoreManagerInterface;
  9. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  10. /**
  11. * Checkout LayoutProcessor
  12. *
  13. * @package Temando\Shipping\Block
  14. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  15. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link https://www.temando.com/
  17. *
  18. * @api
  19. */
  20. class LayoutProcessor implements LayoutProcessorInterface
  21. {
  22. /**
  23. * @var ModuleConfigInterface
  24. */
  25. private $config;
  26. /**
  27. * @var StoreManagerInterface
  28. */
  29. private $storeManager;
  30. /**
  31. * LayoutProcessor constructor.
  32. *
  33. * @param ModuleConfigInterface $moduleConfig
  34. * @param StoreManagerInterface $storeManager
  35. */
  36. public function __construct(ModuleConfigInterface $moduleConfig, StoreManagerInterface $storeManager)
  37. {
  38. $this->config = $moduleConfig;
  39. $this->storeManager = $storeManager;
  40. }
  41. /**
  42. * Process js Layout, unset delivery option for collection points based on config.
  43. *
  44. * @param mixed[] $jsLayout
  45. * @return mixed[]
  46. */
  47. public function process($jsLayout)
  48. {
  49. try {
  50. $storeId = $this->storeManager->getStore()->getId();
  51. } catch (NoSuchEntityException $exception) {
  52. $storeId = null;
  53. }
  54. $isCheckoutEnabled = $this->config->isEnabled($storeId);
  55. if (!$isCheckoutEnabled) {
  56. $shippingStep = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'];
  57. unset($shippingStep['children']['shippingAddress']['children']['checkoutFields']);
  58. // @codingStandardsIgnoreLine
  59. unset($shippingStep['children']['step-config']['children']['shipping-rates-validation']['children']['temando-rates-validation']);
  60. unset($shippingStep['children']['shippingAddress']['children']['deliveryOptions']);
  61. }
  62. return $jsLayout;
  63. }
  64. }