|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * GiaPhuGroup Co., Ltd. |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the GiaPhuGroup.com license that is |
| 8 | + * available through the world-wide-web at this URL: |
| 9 | + * https://www.giaphugroup.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 PHPCuong |
| 17 | + * @package PHPCuong_CustomerAddressAutocomplete |
| 18 | + * @copyright Copyright (c) 2018-2019 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/) |
| 19 | + * @license https://www.giaphugroup.com/LICENSE.txt |
| 20 | + */ |
| 21 | + |
| 22 | +namespace PHPCuong\CustomerAddressAutocomplete\Block\Address; |
| 23 | + |
| 24 | +class Autocomplete extends \Magento\Framework\View\Element\Template |
| 25 | +{ |
| 26 | + /** |
| 27 | + * @var \PHPCuong\CustomerAddressAutocomplete\Helper\Data |
| 28 | + */ |
| 29 | + protected $addressAutocompleteHelperData; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \Magento\Framework\Locale\ResolverInterface |
| 33 | + */ |
| 34 | + protected $_localeResolver; |
| 35 | + |
| 36 | + /** |
| 37 | + * @param \Magento\Framework\View\Element\Template\Context $context |
| 38 | + * @param \PHPCuong\CustomerAddressAutocomplete\Helper\Data $addressAutocompleteHelperData |
| 39 | + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver |
| 40 | + */ |
| 41 | + public function __construct( |
| 42 | + \Magento\Framework\View\Element\Template\Context $context, |
| 43 | + \PHPCuong\CustomerAddressAutocomplete\Helper\Data $addressAutocompleteHelperData, |
| 44 | + \Magento\Framework\Locale\ResolverInterface $localeResolver |
| 45 | + ) { |
| 46 | + $this->addressAutocompleteHelperData = $addressAutocompleteHelperData; |
| 47 | + $this->_localeResolver = $localeResolver; |
| 48 | + parent::__construct($context); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Retrieve the address autocomplete status |
| 53 | + * |
| 54 | + * @return boolean |
| 55 | + */ |
| 56 | + public function showAddressAutocomplete() |
| 57 | + { |
| 58 | + $moduleName = $this->getRequest()->getModuleName(); |
| 59 | + $controllerName = $this->getRequest()->getControllerName(); |
| 60 | + $actionName = $this->getRequest()->getActionName(); |
| 61 | + $currentPage = $moduleName.'_'.$controllerName.'_'.$actionName; |
| 62 | + $array = [ |
| 63 | + 'customer_account_create', |
| 64 | + 'customer_address_edit', |
| 65 | + 'customer_address_new', |
| 66 | + 'customer_address_form', |
| 67 | + 'checkout_index_index' |
| 68 | + ]; |
| 69 | + if (in_array($currentPage, $array) |
| 70 | + && $this->addressAutocompleteHelperData->getAddressAutocompleteStatus() |
| 71 | + ) { |
| 72 | + return true; |
| 73 | + } |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Check if the current page is the checkout page |
| 79 | + * |
| 80 | + * @return boolean |
| 81 | + */ |
| 82 | + public function isCheckoutPage() |
| 83 | + { |
| 84 | + $moduleName = $this->getRequest()->getModuleName(); |
| 85 | + $controllerName = $this->getRequest()->getControllerName(); |
| 86 | + $actionName = $this->getRequest()->getActionName(); |
| 87 | + $currentPage = $moduleName.'_'.$controllerName.'_'.$actionName; |
| 88 | + $array = [ |
| 89 | + 'checkout_index_index' |
| 90 | + ]; |
| 91 | + if (in_array($currentPage, $array)) { |
| 92 | + return true; |
| 93 | + } |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Retrieve the API Key |
| 99 | + * |
| 100 | + * @return string |
| 101 | + */ |
| 102 | + public function getApiKey() |
| 103 | + { |
| 104 | + return $this->addressAutocompleteHelperData->getApiKey(); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Retrieve the locate |
| 109 | + * |
| 110 | + * @return string |
| 111 | + */ |
| 112 | + public function getLocate() |
| 113 | + { |
| 114 | + return $this->_localeResolver->getLocale(); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Retrieve the countries code allowed |
| 119 | + * |
| 120 | + * @return string |
| 121 | + */ |
| 122 | + public function getCountriesAllowed() |
| 123 | + { |
| 124 | + return $this->addressAutocompleteHelperData->getCountriesAllowed(); |
| 125 | + } |
| 126 | +} |
0 commit comments