|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Ecomteck |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Ecomteck.com license that is |
| 8 | + * available through the world-wide-web at this URL: |
| 9 | + * https://ecomteck.com/LICENSE.txt |
| 10 | + * |
| 11 | + * DISCLAIMER |
| 12 | + * |
| 13 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 14 | + * version in the future. |
| 15 | + * |
| 16 | + * @category Ecomteck |
| 17 | + * @package Ecomteck_OneStepCheckoutCompatible |
| 18 | + * @copyright Copyright (c) 2018 Ecomteck (https://ecomteck.com/) |
| 19 | + * @license https://ecomteck.com/LICENSE.txt |
| 20 | + */ |
| 21 | +namespace Ecomteck\OneStepCheckoutCompatible\Block\Checkout; |
| 22 | + |
| 23 | + |
| 24 | +use Magento\Checkout\Block\Checkout\LayoutProcessorInterface; |
| 25 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 26 | +use Magento\Store\Model\ScopeInterface; |
| 27 | +use \Magento\Framework\Module\Manager as ModuleManager; |
| 28 | +use Magento\Customer\Model\AttributeMetadataDataProvider; |
| 29 | +use Magento\Ui\Component\Form\AttributeMapper; |
| 30 | +use Magento\Checkout\Block\Checkout\AttributeMerger; |
| 31 | +use Magento\Checkout\Model\Session as CheckoutSession; |
| 32 | +use Magento\Framework\Stdlib\ArrayManager; |
| 33 | +class OneStepCheckoutProcessor implements LayoutProcessorInterface |
| 34 | +{ |
| 35 | + const CONFIG_ENABLE_MAGEWORX_MULTIFEES = 'mageworx_multifees/main/enable_cart'; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var ScopeConfigInterface |
| 39 | + */ |
| 40 | + private $scopeConfig; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var ScopeConfigInterface |
| 44 | + */ |
| 45 | + private $moduleManager; |
| 46 | + |
| 47 | + /** |
| 48 | + * @var CheckoutSession |
| 49 | + */ |
| 50 | + public $checkoutSession; |
| 51 | + |
| 52 | + /** |
| 53 | + * @var null |
| 54 | + */ |
| 55 | + public $quote = null; |
| 56 | + |
| 57 | + /** |
| 58 | + * One step checkout helper |
| 59 | + * |
| 60 | + * @var \Ecomteck\OneStepCheckout\Helper\Config |
| 61 | + */ |
| 62 | + protected $_config; |
| 63 | + |
| 64 | + protected $request; |
| 65 | + |
| 66 | + /** |
| 67 | + * @param ScopeConfigInterface $scopeConfig |
| 68 | + * @param ModuleManager $moduleManager |
| 69 | + * @param CheckoutSession $checkoutSession |
| 70 | + * @param \Ecomteck\OneStepCheckout\Helper\Config $config |
| 71 | + * @param \Magento\Framework\App\Request\Http $request |
| 72 | + * @param ArrayManager $arrayManager |
| 73 | + */ |
| 74 | + public function __construct( |
| 75 | + ScopeConfigInterface $scopeConfig, |
| 76 | + ModuleManager $moduleManager, |
| 77 | + CheckoutSession $checkoutSession, |
| 78 | + \Ecomteck\OneStepCheckout\Helper\Config $config, |
| 79 | + \Magento\Framework\App\Request\Http $request, |
| 80 | + ArrayManager $arrayManager |
| 81 | + ) |
| 82 | + { |
| 83 | + $this->scopeConfig = $scopeConfig; |
| 84 | + $this->moduleManager = $moduleManager; |
| 85 | + $this->checkoutSession = $checkoutSession; |
| 86 | + $this->arrayManager = $arrayManager; |
| 87 | + $this->_config = $config; |
| 88 | + $this->request = $request; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Changes cart items to be above totals in the cart summary. |
| 93 | + * |
| 94 | + * @param array $jsLayout |
| 95 | + * @return array |
| 96 | + */ |
| 97 | + private function modifyMageWorxMultiFees($jsLayout) |
| 98 | + { |
| 99 | + if(!$this->moduleManager->isOutputEnabled('MageWorx_MultiFees')){ |
| 100 | + return $jsLayout; |
| 101 | + } |
| 102 | + if ($this->scopeConfig->getValue(self::CONFIG_ENABLE_MAGEWORX_MULTIFEES, ScopeInterface::SCOPE_STORE)) { |
| 103 | + $path = 'components/checkout/children/steps/children/shipping-step/children/shippingAddress/children/shippingAdditional/children/mageworx-shipping-fee-form-container'; |
| 104 | + if($this->arrayManager->get($path, $jsLayout)){ |
| 105 | + $jsLayout = $this->arrayManager->set($path.'/component', $jsLayout,'Ecomteck_OneStepCheckoutCompatible/js/MageWorx/MultiFees/view/shipping-fee'); |
| 106 | + } |
| 107 | + } |
| 108 | + return $jsLayout; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * {@inheritdoc} |
| 113 | + */ |
| 114 | + public function process($jsLayout) |
| 115 | + { |
| 116 | + if (!$this->_config->isEnabled()) { |
| 117 | + return $jsLayout; |
| 118 | + } |
| 119 | + |
| 120 | + $jsLayout = $this->modifyMageWorxMultiFees($jsLayout); |
| 121 | + |
| 122 | + return $jsLayout; |
| 123 | + } |
| 124 | +} |
0 commit comments