/** * @return void */ public function prepare() { $config = $this->getData('config'); if (isset($config['options'])) { $options = []; foreach ($config['options'] as $option) { $option['url'] = $this->urlBuilder->getUrl($option['url']); $options[] = $option; } $config['options'] = $options; } $store = $this->storeManager->getStore(); $config['validationEnabled'] = $this->config->isAddressValidationEnabled($store); $hasChoice = $this->config->allowUserToChooseAddress($store); if ($hasChoice) { $instructions = $this->config->getAddressValidationInstructionsWithChoice($store); } else { $instructions = $this->config->getAddressValidationInstructionsWithOutChoice($store); } $config['instructions'] = $instructions; $config['errorInstructions'] = $this->config->getAddressValidationErrorInstructions($store); $config['countriesEnabled'] = $this->config->getAddressValidationCountriesEnabled($store); $config['baseUrl'] = $this->urlBuilder->getUrl(self::VALIDATE_ADDRESS_PATH); $this->setData('config', $config); parent::prepare(); }
/** * Overrides payment component and adds config variable to be used in the component and template * * This class takes the place of a layout config change to checkout_index_index.xml. Making the changes to the * layout this way is necessary because in the process of merging the layout files, layout overrides are * applied over existing nodes in alphabetical order by Namespace_ModuleName. So Magento_Checkout overrides * ClassyLlama_AvaTax because Magento_Checkout layout files are merged after ClassyLlama_AvaTax layout files. The * solution is to set the value of the converted object after the layout files have been merged. Additionally, * because the config fields must be accessed from PHP, the most efficient method of setting the config node values * is with PHP as the following code does. * * @param array $jsLayout * @return array */ public function process($jsLayout) { if ($this->config->isModuleEnabled()) { if ($this->config->isAddressValidationEnabled($this->storeManager->getStore())) { $userHasChoice = $this->config->allowUserToChooseAddress($this->storeManager->getStore()); if ($userHasChoice) { $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['config']['instructions'] = $this->config->getAddressValidationInstructionsWithChoice($this->storeManager->getStore()); } else { $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['config']['instructions'] = $this->config->getAddressValidationInstructionsWithoutChoice($this->storeManager->getStore()); } $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['config']['errorInstructions'] = $this->config->getAddressValidationErrorInstructions($this->storeManager->getStore()); $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['config']['choice'] = $userHasChoice; $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['component'] = self::COMPONENT_PATH; } } return $jsLayout; }
/** * @return string */ public function getErrorInstructions() { return json_encode($this->config->getAddressValidationErrorInstructions($this->_storeManager->getStore())); }