├── composer.json ├── logo.png ├── phalgoliaplaces-v0.4.0.zip ├── views ├── css │ ├── front.css │ └── index.php ├── templates │ ├── hook │ │ ├── footer.tpl │ │ └── index.php │ ├── admin │ │ ├── _configure │ │ │ ├── helpers │ │ │ │ ├── form │ │ │ │ │ ├── form.tpl │ │ │ │ │ └── index.php │ │ │ │ └── index.php │ │ │ └── index.php │ │ ├── index.php │ │ └── versioncheck.tpl │ ├── index.php │ └── front │ │ └── index.php ├── img │ └── index.php ├── js │ ├── index.php │ └── front.js └── index.php ├── package.json ├── LICENSE ├── Readme.md ├── index.php ├── controllers ├── front │ └── index.php ├── index.php └── admin │ └── index.php ├── init └── index.php ├── models └── index.php ├── translations └── index.php ├── .gitignore ├── Gruntfile.js └── phalgoliaplaces.php /composer.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kpodemski/phalgoliaplaces/HEAD/logo.png -------------------------------------------------------------------------------- /phalgoliaplaces-v0.4.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kpodemski/phalgoliaplaces/HEAD/phalgoliaplaces-v0.4.0.zip -------------------------------------------------------------------------------- /views/css/front.css: -------------------------------------------------------------------------------- 1 | .algolia-places { 2 | background: #f0f0f0; 3 | padding: 15px; 4 | width: 30%; 5 | display: block !important; 6 | } 7 | 8 | .algolia-places > .algolia-places { 9 | width: 100%; 10 | padding: 0; 11 | } -------------------------------------------------------------------------------- /views/templates/hook/footer.tpl: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phalgoliaplaces", 3 | "description": "", 4 | "main": "Gruntfile.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/kpodemski/phalgoliaplaces" 11 | }, 12 | "author": "Krystian Podemski", 13 | "license": "MIT", 14 | "homepage": "https://github.com/kpodemski/phalgoliaplaces#readme", 15 | "devDependencies": { 16 | "grunt": "^1.0.1", 17 | "grunt-cli": "^1.2.0", 18 | "grunt-contrib-compress": "^1.3.0" 19 | }, 20 | "options": { 21 | "moduleName": "phalgoliaplaces" 22 | } 23 | } -------------------------------------------------------------------------------- /views/templates/admin/_configure/helpers/form/form.tpl: -------------------------------------------------------------------------------- 1 | {extends file="helpers/form/form.tpl"} 2 | {block name="after"} 3 | 4 |
5 |
6 | {l s='Important informations' mod='phalgoliaplaces'} 7 |
8 |

9 | {l s='This module allows your customers quickly select address based on search results from Algolia Places.' mod='phalgoliaplaces'} 10 |

11 |

12 | {l s='The Algolia Places API enforces some rate limits, currently (June 2016) this limit is 1.000 requests per day for a one domain. You can increase this limit to 100.000 by registering a new account on https://www.algolia.com/users/sign_up/places.' mod='phalgoliaplaces'} 13 |

14 |

15 | {l s='Module developed by %s from %s' sprintf=['Krystian Podemski', 'PrestaHome']} 16 |

17 |
18 | 19 | {/block} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Krystian Podemski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # PrestaHome - Algolia Places for PrestaShop 2 | 3 | What is all about? 4 | 5 | > Algolia Places provides a fast, distributed and easy way to use address search autocomplete JavaScript library on your website. It has been designed to improve the user experience of your HTML forms. 6 | 7 | ## How to install? 8 | 9 | 1. Clone repo 10 | 2. Run `npm install` 11 | 3. Run `grunt` to build module package 12 | 4. Install module from .zip 13 | 14 | ## Changelog 15 | 16 | #### Version 0.4.0 - Date: June 27, 2016 17 | * Support for counties/states (by state name at this moment) 18 | 19 | #### Version 0.3.0 - Date: June 27, 2016 20 | * Add options to set appID & apiKey for registered/premium Algolia users 21 | 22 | #### Version 0.2.0 - Date: June 23, 2016 23 | * Replace Gulp with Grunt for package creation 24 | 25 | #### Version 0.1.0 - Date: June 23, 2016 26 | 27 | * First release 28 | 29 | ## To Do: 30 | 31 | - [x] Support for counties/states 32 | - [ ] Error reporting if needed (?) 33 | - [ ] spec/tests 34 | - [ ] Auto-updater from @firstred 35 | - [x] Support for Algolia premium users 36 | - [ ] Option for `useDeviceLocation` 37 | 38 | ## Support 39 | 40 | Please use `Issues` on GitHub 41 | 42 | ## License 43 | 44 | MIT -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/css/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/img/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/js/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/templates/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/templates/admin/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/templates/front/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /views/templates/hook/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../'); 35 | exit; -------------------------------------------------------------------------------- /controllers/front/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2015 PrestaShop SA 23 | * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; 36 | -------------------------------------------------------------------------------- /init/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2016 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; 36 | -------------------------------------------------------------------------------- /models/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2016 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; 36 | -------------------------------------------------------------------------------- /views/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2016 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; 36 | -------------------------------------------------------------------------------- /controllers/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2016 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; 36 | -------------------------------------------------------------------------------- /translations/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2016 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; 36 | -------------------------------------------------------------------------------- /views/templates/admin/_configure/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2013 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; -------------------------------------------------------------------------------- /views/templates/admin/_configure/helpers/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2013 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; -------------------------------------------------------------------------------- /views/templates/admin/_configure/helpers/form/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2013 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 28 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 29 | 30 | header("Cache-Control: no-store, no-cache, must-revalidate"); 31 | header("Cache-Control: post-check=0, pre-check=0", false); 32 | header("Pragma: no-cache"); 33 | 34 | header("Location: ../"); 35 | exit; -------------------------------------------------------------------------------- /controllers/admin/index.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2014 PrestaShop SA 23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | 27 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 28 | header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 29 | 30 | header('Cache-Control: no-store, no-cache, must-revalidate'); 31 | header('Cache-Control: post-check=0, pre-check=0', false); 32 | header('Pragma: no-cache'); 33 | 34 | header('Location: ../../../../'); 35 | exit; -------------------------------------------------------------------------------- /views/templates/admin/versioncheck.tpl: -------------------------------------------------------------------------------- 1 | {* 2 | * 2016 Michael Dekker 3 | * 4 | * NOTICE OF LICENSE 5 | * 6 | * This source file is subject to the Academic Free License (AFL 3.0) 7 | * that is bundled with this package in the file LICENSE.txt. 8 | * It is also available through the world-wide-web at this URL: 9 | * http://opensource.org/licenses/afl-3.0.php 10 | * If you did not receive a copy of the license and are unable to 11 | * obtain it through the world-wide-web, please send an email 12 | * to license@michaeldekker.com so we can send you a copy immediately. 13 | * 14 | * @author Michael Dekker 15 | * @copyright 2016 Michael Dekker 16 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 17 | *} 18 |
19 |

{l s='Check for updates' mod='phalgoliaplaces'}

20 |

21 | {l s='Check if this module needs updates' mod='phalgoliaplaces'}
22 |

23 | {if $needsUpdate} 24 |
25 | {l s='This module needs to be updated to version %s' mod='phalgoliaplaces' sprintf=[$latestVersion]} 26 |
27 | {else} 28 |
29 | {l s='This module is up to date.' mod='phalgoliaplaces'} 30 |
31 | {/if} 32 | {l s='Check for updates' mod='phalgoliaplaces'} 33 | {if $needsUpdate} 34 | {l s='Update module' mod='phalgoliaplaces'} 35 | {/if} 36 |
-------------------------------------------------------------------------------- /views/js/front.js: -------------------------------------------------------------------------------- 1 | var algoliaIsRunning = false; 2 | 3 | $(function() { 4 | setTimeout(runAlgoliaPlaces, 1500); 5 | }); 6 | 7 | $(document).ajaxComplete(function() { 8 | setTimeout(runAlgoliaPlaces, 1500); 9 | }); 10 | 11 | function runAlgoliaPlaces() { 12 | if ($('#address1').length > 0 && algoliaIsRunning == false) { 13 | 14 | var algoliaPlacesOptions = { 15 | container: $('input#address1').get(0), 16 | language: phalgoliaplaces_isoLang, 17 | type: 'address', 18 | useDeviceLocation: false, 19 | templates: { 20 | value: function(suggestion) { 21 | return suggestion.name; 22 | } 23 | }, 24 | }; 25 | 26 | if (phalgoliaplaces_appId && phalgoliaplaces_apiKey) { 27 | algoliaPlacesOptions['appId'] = phalgoliaplaces_appId; 28 | algoliaPlacesOptions['apiKey'] = phalgoliaplaces_apiKey; 29 | } 30 | 31 | var placesAutocomplete = places(algoliaPlacesOptions); 32 | 33 | placesAutocomplete.on('change', function resultSelected(e) { 34 | $('#city').val(e.suggestion.city); 35 | $('#postcode').val(e.suggestion.postcode); 36 | 37 | if (e.suggestion.countryCode != '') { 38 | $.each(countries, function(index, country) { 39 | if (country.iso_code.toLowerCase() === e.suggestion.countryCode.toLowerCase()) { 40 | $('#id_country').val(country.id_country).trigger('change'); 41 | if (country.contains_states == 1 && country.states.length > 0) { 42 | $.each(country.states, function(key, state) { 43 | if (state.name == e.suggestion.administrative) { 44 | $('#id_state').val(state.id_state).trigger('change'); 45 | } 46 | }); 47 | } 48 | } 49 | }); 50 | } 51 | }); 52 | algoliaIsRunning = true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff: 7 | .idea/workspace.xml 8 | .idea/tasks.xml 9 | .idea/dictionaries 10 | .idea/vcs.xml 11 | .idea/jsLibraryMappings.xml 12 | 13 | # Sensitive or high-churn files: 14 | .idea/dataSources.ids 15 | .idea/dataSources.xml 16 | .idea/dataSources.local.xml 17 | .idea/sqlDataSources.xml 18 | .idea/dynamic.xml 19 | .idea/uiDesigner.xml 20 | 21 | # Gradle: 22 | .idea/gradle.xml 23 | .idea/libraries 24 | 25 | # Mongo Explorer plugin: 26 | .idea/mongoSettings.xml 27 | 28 | ## File-based project format: 29 | *.iws 30 | .jscsrc 31 | .editorconfig 32 | index.php.copy 33 | 34 | ## Plugin-specific files: 35 | 36 | # IntelliJ 37 | /out/ 38 | 39 | # mpeltonen/sbt-idea plugin 40 | .idea_modules/ 41 | 42 | # JIRA plugin 43 | atlassian-ide-plugin.xml 44 | 45 | # Crashlytics plugin (for Android Studio and IntelliJ) 46 | com_crashlytics_export_strings.xml 47 | crashlytics.properties 48 | crashlytics-build.properties 49 | fabric.properties 50 | ### Composer template 51 | composer.phar 52 | composer.lock 53 | /vendor/ 54 | 55 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 56 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 57 | # composer.lock 58 | ### Node template 59 | # Logs 60 | logs 61 | *.log 62 | npm-debug.log* 63 | 64 | # Runtime data 65 | pids 66 | *.pid 67 | *.seed 68 | 69 | # Directory for instrumented libs generated by jscoverage/JSCover 70 | lib-cov 71 | 72 | # Coverage directory used by tools like istanbul 73 | coverage 74 | 75 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 76 | .grunt 77 | 78 | # node-waf configuration 79 | .lock-wscript 80 | 81 | # Compiled binary addons (http://nodejs.org/api/addons.html) 82 | build/Release 83 | 84 | # Dependency directories 85 | node_modules 86 | jspm_packages 87 | 88 | # Optional npm cache directory 89 | .npm 90 | 91 | # Optional REPL history 92 | .node_repl_history 93 | 94 | *phalgoliaplaces.zip 95 | /config.xml 96 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | var package = require('./package.json'), 3 | options = package.options, 4 | moduleName = options.moduleName, 5 | version = package.version, 6 | pattern = new RegExp(/\$this->version = '(.*?)';/i), 7 | file = grunt.file.read('./' + moduleName + '.php'); 8 | 9 | var matches = file.match(pattern); 10 | if (matches !== null && typeof matches[1] == 'string') { 11 | version = matches[1].trim(); 12 | } 13 | 14 | grunt.initConfig({ 15 | compress: { 16 | main: { 17 | options: { 18 | archive: moduleName + '-v' + version + '.zip' 19 | }, 20 | files: [ 21 | {src: ['controllers/**'], dest: moduleName + '/', filter: 'isFile'}, 22 | {src: ['classes/**'], dest: moduleName + '/', filter: 'isFile'}, 23 | {src: ['defaults/**'], dest: moduleName + '/', filter: 'isFile'}, 24 | {src: ['init/**'], dest: moduleName + '/', filter: 'isFile'}, 25 | {src: ['models/**'], dest: moduleName + '/', filter: 'isFile'}, 26 | {src: ['src/**'], dest: moduleName + '/', filter: 'isFile'}, 27 | {src: ['docs/**'], dest: moduleName + '/', filter: 'isFile'}, 28 | {src: ['override/**'], dest: moduleName + '/', filter: 'isFile'}, 29 | {src: ['logs/**'], dest: moduleName + '/', filter: 'isFile'}, 30 | {src: ['vendor/**'], dest: moduleName + '/', filter: 'isFile'}, 31 | {src: ['translations/**'], dest: moduleName + '/', filter: 'isFile'}, 32 | {src: ['upgrade/**'], dest: moduleName + '/', filter: 'isFile'}, 33 | {src: ['views/**'], dest: moduleName + '/', filter: 'isFile'}, 34 | {src: 'index.php', dest: moduleName + '/'}, 35 | {src: moduleName + '.php', dest: moduleName + '/'}, 36 | {src: 'logo.png', dest: moduleName + '/'}, 37 | {src: 'LICENSE.md', dest: moduleName + '/'}, 38 | {src: 'README.md', dest: moduleName + '/'}, 39 | {src: 'ajax.php', dest: moduleName + '/'}, 40 | // Legacy 41 | {src: ['css/**'], dest: moduleName + '/', filter: 'isFile'}, 42 | {src: ['fonts/**'], dest: moduleName + '/', filter: 'isFile'}, 43 | {src: ['js/**'], dest: moduleName + '/', filter: 'isFile'}, 44 | {src: ['img/**'], dest: moduleName + '/', filter: 'isFile'}, 45 | {src: 'readme_en.txt', dest: moduleName + '/'} 46 | ] 47 | } 48 | } 49 | }); 50 | 51 | grunt.loadNpmTasks('grunt-contrib-compress'); 52 | 53 | grunt.registerTask('default', ['compress']); 54 | }; -------------------------------------------------------------------------------- /phalgoliaplaces.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright 2007-2015 PrestaShop SA 23 | * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 24 | * International Registered Trademark & Property of PrestaShop SA 25 | */ 26 | /** 27 | * @author Krystian Podemski 28 | * @copyright (c) 2016 Krystian Podemski - www.podemski.info / www.PrestaHome.com 29 | * @license You only can use module, nothing more! 30 | */ 31 | 32 | if (!defined('_PS_VERSION_')) { 33 | exit; 34 | } 35 | 36 | class PhAlgoliaPlaces extends Module 37 | { 38 | private $options_prefix; 39 | private $fields_form = array(); 40 | private $hooksToInstall = array( 41 | 'displayHeader', 42 | ); 43 | 44 | public function __construct() 45 | { 46 | $this->name = 'phalgoliaplaces'; 47 | $this->tab = 'front_office_features'; 48 | $this->version = '0.4.0'; 49 | $this->author = 'PrestaHome'; 50 | $this->need_instance = 0; 51 | $this->is_configurable = 0; 52 | $this->ps_versions_compliancy['min'] = '1.6'; 53 | $this->ps_versions_compliancy['max'] = _PS_VERSION_; 54 | $this->secure_key = Tools::encrypt($this->name); 55 | $this->bootstrap = true; 56 | 57 | parent::__construct(); 58 | 59 | $this->displayName = $this->l('Integration with Algolia Places'); 60 | $this->description = $this->l('Algolia Places provides a fast, distributed and easy way to use address search autocomplete JavaScript library on your website. '); 61 | 62 | $this->options_prefix = $this->name.'_'; 63 | } 64 | 65 | public function install() 66 | { 67 | $this->_clearCache('*'); 68 | $this->renderConfigurationForm(); 69 | $this->batchUpdateConfigs(); 70 | 71 | // Hooks & Install 72 | return (parent::install() 73 | && $this->prepareModuleSettings() 74 | && $this->registerHook($this->hooksToInstall)); 75 | } 76 | 77 | public function prepareModuleSettings() 78 | { 79 | $sql = array(); 80 | $sql_file = _PS_MODULE_DIR_.$this->name.'/init/install_sql.php'; 81 | if (file_exists($sql_file)) { 82 | include($sql_file); 83 | foreach ($sql as $s) { 84 | if (!Db::getInstance()->Execute($s)) { 85 | die('Error while creating DB'); 86 | } 87 | } 88 | } 89 | 90 | if (file_exists(_PS_MODULE_DIR_.$this->name.'/init/my-install.php')) { 91 | include_once _PS_MODULE_DIR_.$this->name.'/init/my-install.php'; 92 | } 93 | 94 | return true; 95 | } 96 | 97 | public function uninstall() 98 | { 99 | $this->renderConfigurationForm(); 100 | $this->deleteConfigs(); 101 | $this->_clearCache('*'); 102 | 103 | if (!parent::uninstall()) { 104 | return false; 105 | } 106 | 107 | // Database 108 | $sql = array(); 109 | $sql_file = _PS_MODULE_DIR_.$this->name.'/init/uninstall_sql.php'; 110 | if (file_exists($sql_file)) { 111 | include($sql_file); 112 | foreach ($sql as $s) { 113 | if (!Db::getInstance()->Execute($s)) { 114 | die('Error while creating DB'); 115 | } 116 | } 117 | } 118 | 119 | if (file_exists(_PS_MODULE_DIR_.$this->name.'/init/my-uninstall.php')) { 120 | include_once _PS_MODULE_DIR_.$this->name.'/init/my-uninstall.php'; 121 | } 122 | 123 | return true; 124 | } 125 | 126 | public function getContent() 127 | { 128 | $this->context->controller->addjQueryPlugin(array( 129 | 'fancybox' 130 | )); 131 | 132 | if (file_exists(_PS_MODULE_DIR_.$this->name.'/views/js/admin.js')) { 133 | $this->context->controller->addJS(array( 134 | _MODULE_DIR_.$this->name.'/views/js/admin.js', 135 | )); 136 | } 137 | 138 | if (file_exists(_PS_MODULE_DIR_.$this->name.'/views/css/admin.css')) { 139 | $this->context->controller->addCSS(array( 140 | _MODULE_DIR_.$this->name.'/views/css/admin.css', 141 | )); 142 | } 143 | 144 | $this->_html = '

'.$this->displayName.'

'; 145 | 146 | if (Tools::isSubmit('save'.$this->name)) { 147 | $this->renderConfigurationForm(); 148 | $this->batchUpdateConfigs(); 149 | 150 | $this->_clearCache('*'); 151 | $this->_html .= $this->displayConfirmation($this->l('Settings updated successfully.')); 152 | 153 | } 154 | return $this->_html . $this->renderForm(); 155 | } 156 | 157 | protected function renderForm() 158 | { 159 | $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); 160 | $this->renderConfigurationForm(); 161 | 162 | $helper = new HelperForm(); 163 | $helper->module = $this; 164 | $helper->name_controller = $this->name; 165 | $helper->identifier = $this->identifier; 166 | $helper->token = Tools::getAdminTokenLite('AdminModules'); 167 | foreach (Language::getLanguages(false) as $lang) { 168 | $helper->languages[] = array( 169 | 'id_lang' => $lang['id_lang'], 170 | 'iso_code' => $lang['iso_code'], 171 | 'name' => $lang['name'], 172 | 'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0) 173 | ); 174 | } 175 | 176 | $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; 177 | $helper->default_form_language = $default_lang; 178 | $helper->allow_employee_form_lang = $default_lang; 179 | $helper->toolbar_scroll = true; 180 | $helper->title = $this->displayName; 181 | $helper->submit_action = 'save'.$this->name; 182 | $helper->toolbar_btn = array( 183 | 'save' => 184 | array( 185 | 'desc' => $this->l('Save'), 186 | 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 187 | ) 188 | ); 189 | $helper->tpl_vars = array( 190 | 'fields_value' => $this->getConfigFieldsValues(), 191 | 'languages' => $this->context->controller->getLanguages(), 192 | 'id_language' => $this->context->language->id, 193 | 'link' => $this->context->link, 194 | ); 195 | 196 | return $helper->generateForm($this->fields_form); 197 | } 198 | 199 | public function renderConfigurationForm() 200 | { 201 | if ($this->fields_form) { 202 | return; 203 | } 204 | $fields_form = array( 205 | 'form' => array( 206 | 'legend' => array( 207 | 'title' => $this->l('Settings'), 208 | 'icon' => 'icon-cogs' 209 | ), 210 | 211 | 'input' => array( 212 | array( 213 | 'type' => 'text', 214 | 'label' => $this->l('App Id:'), 215 | 'name' => $this->options_prefix.'appid', 216 | 'default' => '', 217 | 'lang' => false, 218 | ), 219 | 220 | array( 221 | 'type' => 'text', 222 | 'label' => $this->l('API key:'), 223 | 'name' => $this->options_prefix.'apikey', 224 | 'default' => '', 225 | 'lang' => false, 226 | ), 227 | ), 228 | 229 | 'submit' => array( 230 | 'title' => $this->l('Save'), 231 | 'class' => 'btn btn-default' 232 | ) 233 | ), 234 | ); 235 | 236 | $this->fields_form[] = $fields_form; 237 | } 238 | 239 | public function getConfigFieldsValues() 240 | { 241 | $id_shop = Shop::getContextShopID(true); 242 | $id_shop_group = Shop::getContextShopGroupID(true); 243 | 244 | $fields_values = array(); 245 | foreach ($this->fields_form as $k => $f) { 246 | foreach ($f['form']['input'] as $i => $input) { 247 | if (isset($input['ignore']) && $input['ignore'] == true) { 248 | continue; 249 | } 250 | 251 | if (isset($input['lang']) && $input['lang'] == true) { 252 | foreach (Language::getLanguages(false) as $lang) { 253 | $values = Tools::getValue($input['name'].'_'.$lang['id_lang'], (Configuration::hasKey($input['name'], $lang['id_lang']) ? Configuration::get($input['name'], $lang['id_lang'], (int)$id_shop_group, (int)$id_shop) : $input['default'])); 254 | $fields_values[$input['name']][$lang['id_lang']] = $values; 255 | } 256 | } else { 257 | $values = Tools::getValue($input['name'], (Configuration::hasKey($input['name'], null, (int)$id_shop_group, (int)$id_shop) ? Configuration::get($input['name']) : $input['default'])); 258 | $fields_values[$input['name']] = $values; 259 | } 260 | } 261 | } 262 | 263 | $this->assignCustomConfigs($fields_values); 264 | 265 | return $fields_values; 266 | } 267 | 268 | public function batchUpdateConfigs() 269 | { 270 | foreach ($this->fields_form as $k => $f) { 271 | foreach ($f['form']['input'] as $i => $input) { 272 | if (isset($input['ignore']) && $input['ignore'] == true) { 273 | continue; 274 | } 275 | 276 | if (isset($input['lang']) && $input['lang'] == true) { 277 | $data = array(); 278 | foreach (Language::getLanguages(false) as $lang) { 279 | $val = Tools::getValue($input['name'].'_'.$lang['id_lang'], $input['default']); 280 | $data[$lang['id_lang']] = $val; 281 | } 282 | Configuration::updateValue(trim($input['name']), $data, true); 283 | } else { 284 | $val = Tools::getValue($input['name'], $input['default']); 285 | Configuration::updateValue($input['name'], $val, true); 286 | } 287 | } 288 | } 289 | 290 | $this->batchUpdateCustomConfigs(); 291 | } 292 | 293 | public function deleteConfigs() 294 | { 295 | foreach ($this->fields_form as $k => $f) { 296 | foreach ($f['form']['input'] as $i => $input) { 297 | if (isset($input['ignore']) && $input['ignore'] == true) { 298 | continue; 299 | } 300 | Configuration::deleteByName($input['name']); 301 | } 302 | } 303 | 304 | $this->deleteCustomConfigs(); 305 | 306 | return true; 307 | } 308 | 309 | public function assignCustomConfigs(&$fields_values) 310 | { 311 | return array(); 312 | } 313 | 314 | public function batchUpdateCustomConfigs() 315 | { 316 | return true; 317 | } 318 | 319 | public function deleteCustomConfigs() 320 | { 321 | return true; 322 | } 323 | 324 | /** 325 | * Return value with every available language 326 | * @param string Value 327 | * @return array 328 | */ 329 | public static function prepareValueForLangs($value) 330 | { 331 | $output = array(); 332 | 333 | foreach (Language::getLanguages(false) as $lang) { 334 | $output[$lang['id_lang']] = $value; 335 | } 336 | 337 | return $output; 338 | } 339 | 340 | public function hookDisplayHeader($params) 341 | { 342 | $pages = array('authentication', 'address', 'order-opc'); 343 | 344 | if (isset($this->context->controller->php_self) && in_array($this->context->controller->php_self, $pages)) { 345 | Media::addJsDef( 346 | array( 347 | $this->name.'_appId' => Configuration::get($this->options_prefix.'appid'), 348 | $this->name.'_apiKey' => Configuration::get($this->options_prefix.'appkey'), 349 | $this->name.'_isoLang' => $this->context->language->iso_code, 350 | ) 351 | ); 352 | 353 | $this->context->controller->addCSS(array( 354 | _PS_MODULE_DIR_.$this->name.'/views/css/front.css', 355 | )); 356 | 357 | $this->context->controller->addJS(array( 358 | 'https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.min.js', 359 | 'https://cdn.jsdelivr.net/places.js/1/places.min.js', 360 | _PS_MODULE_DIR_.$this->name.'/views/js/front.js', 361 | )); 362 | } 363 | } 364 | } 365 | --------------------------------------------------------------------------------