![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/Ecombricks/InventoryCatalog/Block/Product/View/Estimate/Layout/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See LICENSE.txt for license details. */ namespace Ecombricks\InventoryCatalog\Block\Product\View\Estimate\Layout; /** * Product estimate default layout processor */ class DefaultProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface { /** * Merger * * @var \Magento\Checkout\Block\Checkout\AttributeMerger */ protected $merger; /** * Country collection * * @var \Magento\Directory\Model\ResourceModel\Country\Collection */ protected $countryCollection; /** * Region collection * * @var \Magento\Directory\Model\ResourceModel\Region\Collection */ protected $regionCollection; /** * Top destination countries * * @var \Magento\Directory\Model\TopDestinationCountries */ protected $topDestinationCountries; /** * Locale format * * @var \Magento\Framework\Locale\FormatInterface */ protected $localeFormat; /** * Constructor * * @param \Magento\Checkout\Block\Checkout\AttributeMerger $merger * @param \Magento\Framework\Locale\FormatInterface $localeFormat * @param \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection * @param \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection * @param \Magento\Directory\Model\TopDestinationCountries $topDestinationCountries * @return void */ public function __construct( \Magento\Checkout\Block\Checkout\AttributeMerger $merger, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection, \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection, \Magento\Directory\Model\TopDestinationCountries $topDestinationCountries ) { $this->merger = $merger; $this->localeFormat = $localeFormat; $this->countryCollection = $countryCollection; $this->regionCollection = $regionCollection; $this->topDestinationCountries = $topDestinationCountries; } /** * Get country options * * @return array */ protected function getCountryOptions() { return $this->countryCollection ->loadByStore()->setForegroundCountries($this->topDestinationCountries->getTopDestinations()) ->toOptionArray(); } /** * Get region options * * @return array */ protected function getRegionOptions() { return $this->regionCollection ->addAllowedCountriesFilter() ->toOptionArray(); } /** * Set data provider dictionaries * * @param array &$jsLayout * @return $this */ protected function setDataProviderDictionaries(&$jsLayout) { $checkoutProvider =& $jsLayout['components']['checkoutProvider']; if (empty($checkoutProvider['dictionaries'])) { $checkoutProvider['dictionaries'] = [ 'country_id' => $this->getCountryOptions(), 'region_id' => $this->getRegionOptions(), ]; } return $this; } /** * Get address fields * * @return array */ protected function getAddressFields() { return [ 'city' => [ 'visible' => false, 'formElement' => 'input', 'label' => __('City'), 'value' => null, ], 'country_id' => [ 'visible' => true, 'formElement' => 'select', 'label' => __('Country'), 'options' => [], 'value' => null, ], 'region_id' => [ 'visible' => true, 'formElement' => 'select', 'label' => __('State/Province'), 'options' => [], 'value' => null, ], 'postcode' => [ 'visible' => true, 'formElement' => 'input', 'label' => __('Zip/Postal Code'), 'value' => null, ], ]; } /** * Merge address * * @param array &$jsLayout * @return $this */ protected function mergeAddress(&$jsLayout) { $address =& $jsLayout['components']['product-estimate']['children']['address']; if (empty($address['children'])) { return $this; } $address['children'] = $this->merger->merge($this->getAddressFields(), 'checkoutProvider', 'shippingAddress', $address['children']); $address['children']['region_id']['config']['skipValidation'] = true; return $this; } /** * Process * * @param array $jsLayout * @return array */ public function process($jsLayout) { $this->setDataProviderDictionaries($jsLayout); $this->mergeAddress($jsLayout); return $jsLayout; } }