Skip to content

Commit 83774ae

Browse files
committed
initial commit
1 parent 9ed3373 commit 83774ae

File tree

13 files changed

+817
-0
lines changed

13 files changed

+817
-0
lines changed

Block/Address/Autocomplete.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
}

Helper/Data.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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\Helper;
23+
24+
class Data extends \Magento\Framework\App\Helper\AbstractHelper
25+
{
26+
const GOOGLE_API_KEY = 'phpcuong_address_autocomplete/general/api_key';
27+
const ADDRESS_AUTOCOMPLETE_STATUS = 'phpcuong_address_autocomplete/general/enable';
28+
const COUNTRIES_CODE_ALLOWED = 'general/country/allow';
29+
30+
/**
31+
* @param \Magento\Framework\App\Helper\Context $context
32+
*/
33+
public function __construct(
34+
\Magento\Framework\App\Helper\Context $context
35+
) {
36+
parent::__construct($context);
37+
}
38+
39+
/**
40+
* Retrieve the API Key
41+
*
42+
* @return string
43+
*/
44+
public function getApiKey()
45+
{
46+
$apiKey = $this->scopeConfig->getValue(
47+
self::GOOGLE_API_KEY,
48+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
49+
);
50+
if (!$apiKey) {
51+
$apiKey = 'AIzaSyAo4tEzHqBYcQQtBYYKFoZXhy3j_SX-osU';
52+
}
53+
return $apiKey;
54+
}
55+
56+
/**
57+
* Retrieve the address autocomplete status
58+
*
59+
* @return boolean
60+
*/
61+
public function getAddressAutocompleteStatus()
62+
{
63+
return $this->scopeConfig->isSetFlag(
64+
self::ADDRESS_AUTOCOMPLETE_STATUS,
65+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
66+
);
67+
}
68+
69+
/**
70+
* Retrieve the countries code allowed
71+
*
72+
* @return string
73+
*/
74+
public function getCountriesAllowed()
75+
{
76+
return $this->scopeConfig->getValue(
77+
self::COUNTRIES_CODE_ALLOWED,
78+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
79+
);
80+
}
81+
}

etc/acl.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* GiaPhuGroup Co., Ltd.
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the GiaPhuGroup.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.giaphugroup.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category PHPCuong
18+
* @package PHPCuong_CustomerAddressAutocomplete
19+
* @copyright Copyright (c) 2018-2019 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/)
20+
* @license https://www.giaphugroup.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
24+
<acl>
25+
<resources>
26+
<resource id="Magento_Backend::admin">
27+
<resource id="Magento_Backend::stores">
28+
<resource id="Magento_Backend::stores_settings">
29+
<resource id="Magento_Config::config">
30+
<resource id="PHPCuong_CustomerAddressAutocomplete::config_address_autocomplete" title="Customer Address Autocomplete" translate="title" />
31+
</resource>
32+
</resource>
33+
</resource>
34+
</resource>
35+
</resources>
36+
</acl>
37+
</config>

etc/adminhtml/menu.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* GiaPhuGroup Co., Ltd.
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the GiaPhuGroup.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.giaphugroup.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category PHPCuong
18+
* @package PHPCuong_CustomerAddressAutocomplete
19+
* @copyright Copyright (c) 2018-2019 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/)
20+
* @license https://www.giaphugroup.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
24+
<menu>
25+
<add id="PHPCuong_CustomerAddressAutocomplete::configuration" title="Configuration" module="PHPCuong_CustomerAddressAutocomplete" sortOrder="10" action="adminhtml/system_config/edit/section/phpcuong_address_autocomplete" resource="PHPCuong_CustomerAddressAutocomplete::config_address_autocomplete" parent="PHPCuong_Core::giaphugroup_menu"/>
26+
</menu>
27+
</config>

etc/adminhtml/system.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* GiaPhuGroup Co., Ltd.
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the GiaPhuGroup.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.giaphugroup.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category PHPCuong
18+
* @package PHPCuong_AddressAutocomplete
19+
* @copyright Copyright (c) 2018-2019 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/)
20+
* @license https://www.giaphugroup.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
24+
<system>
25+
<section id="phpcuong_address_autocomplete" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
26+
<label>Customer Address Autocomplete</label>
27+
<tab>phpcuong</tab>
28+
<resource>PHPCuong_CustomerAddressAutocomplete::config_address_autocomplete</resource>
29+
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
30+
<label>General Settings</label>
31+
<field id="enable" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
32+
<label>Enable</label>
33+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
34+
</field>
35+
<field id="api_key" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
36+
<label>Maps JavaScript API</label>
37+
<comment>Create API key, please &lt;a href="https://cloud.google.com/console" target="_blank"&gt;click here&lt;/a&gt;.</comment>
38+
<validate>required-entry</validate>
39+
</field>
40+
</group>
41+
</section>
42+
</system>
43+
</config>

etc/config.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* GiaPhuGroup Co., Ltd.
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the GiaPhuGroup.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.giaphugroup.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category PHPCuong
18+
* @package PHPCuong_CustomerAddressAutocomplete
19+
* @copyright Copyright (c) 2018-2019 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/)
20+
* @license https://www.giaphugroup.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
24+
<default>
25+
<phpcuong_address_autocomplete>
26+
<general>
27+
<api_key>AIzaSyAo4tEzHqBYcQQtBYYKFoZXhy3j_SX-osU</api_key>
28+
<enable>1</enable>
29+
</general>
30+
</phpcuong_address_autocomplete>
31+
</default>
32+
</config>

etc/module.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* GiaPhuGroup Co., Ltd.
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the GiaPhuGroup.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.giaphugroup.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category PHPCuong
18+
* @package PHPCuong_CustomerAddressAutocomplete
19+
* @copyright Copyright (c) 2018-2019 GiaPhuGroup Co., Ltd. All rights reserved. (http://www.giaphugroup.com/)
20+
* @license https://www.giaphugroup.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
24+
<module name="PHPCuong_CustomerAddressAutocomplete" setup_version="2.1.0" />
25+
</config>

0 commit comments

Comments
 (0)