Skip to content

Commit

Permalink
Перешёл на подсказки 17.12
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Feb 27, 2018
1 parent af4fb8b commit 4dcee7c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Инструкция по установке

1. Скачать [архив с модулем](https://github.com/hflabs/suggestions-prestashop/archive/1.5.2.zip)
1. Скачать [архив с модулем](https://github.com/hflabs/suggestions-prestashop/archive/1.6.zip)
2. В админ-панели PrestaShop перейти на вкладку *Модули > Модули* (Modules > Modules). Нажать на кнопку *Добавить новый модуль* (Add a new module) в правой верхней панели.
2. Нажать на кнопку *Выбрать файл* (Choose a file) и выберать архив модуля на компьютере. Нажать на кнопку *Загрузить этот модуль* (Upload this module).
3. Нажать на кнопку *Установить* (Install):
69 changes: 5 additions & 64 deletions suggestions_prestashop.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
class suggestions_prestashop extends Module
{

private $available_urls = array('free'=>'https://dadata.ru/api/v2','paid'=>'http://suggestions.dadata.ru/suggestions/api/4_1/rs/');
private $valid_fields = array('id_state','id_country');

public function __construct()
{
$this->name = 'suggestions_prestashop';
$this->tab = 'checkout';
$this->version = '1.5.2';
$this->version = '1.6.0';
$this->author = 'Yuri Denisov';
$this->need_instance = 0;
$this->bootstrap = true;
Expand All @@ -58,12 +57,10 @@ public function install()
!$this->registerHook('displayHeader') ||
!$this->registerHook('createAccountTop') ||
!Configuration::updateValue('DADATA_SUGGESTIONS_TOKEN','') ||
!Configuration::updateValue('DADATA_SUGGESTIONS_COUNT',10) ||
!Configuration::updateValue('DADATA_SUGGESTIONS_COUNT',5) ||
!Configuration::updateValue('DADATA_SUGGESTIONS_HIDE',true) ||
!Configuration::updateValue('DADATA_SUGGESTIONS_URL','free') ||
!Configuration::updateValue('DADATA_SUGGESTIONS_FIO',true) ||
!Configuration::updateValue('DADATA_SUGGESTIONS_ADDRESS',true) ||
!Configuration::updateValue('DADATA_SUGGESTIONS_TRIG_SEL_SPC',true) ||
!Configuration::updateValue('DADATA_SUGGESTIONS_REGION_FIELD','id_state'))
return false;
return true;
Expand All @@ -75,10 +72,8 @@ public function uninstall()
!Configuration::deleteByName('DADATA_SUGGESTIONS_TOKEN') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_COUNT') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_HIDE') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_URL') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_FIO') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_ADDRESS') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_TRIG_SEL_SPC') ||
!Configuration::deleteByName('DADATA_SUGGESTIONS_REGION_FIELD'))
return false;
return true;
Expand All @@ -91,10 +86,8 @@ protected function wrapScriptOnLoad() {
$output .= 'dadataSuggestions.configuration.suggest_fio= "'.$this->context->customer->firstname.' '.$this->context->customer->lastname.'";';
$output .= 'dadataSuggestions.configuration.suggest_fio_label= "'.$this->l('Full Name').'";';
$output .= 'dadataSuggestions.configuration.suggest_address_label= "'.$this->l('Full Address').'";';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_URL= "'.$this->available_urls[strval(Configuration::get('DADATA_SUGGESTIONS_URL'))].'";';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_TOKEN= "'.strval(Configuration::get('DADATA_SUGGESTIONS_TOKEN')).'";';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_TRIG_SEL_SPC= '.(Configuration::get('DADATA_SUGGESTIONS_TRIG_SEL_SPC')==1?'true':'false').';';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_COUNT= '.(Configuration::get('DADATA_SUGGESTIONS_COUNT')>0?strval(Configuration::get('DADATA_SUGGESTIONS_COUNT')):'10').';';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_COUNT= '.(Configuration::get('DADATA_SUGGESTIONS_COUNT')>0?strval(Configuration::get('DADATA_SUGGESTIONS_COUNT')):'5').';';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_REGION_FIELD= "'.strval(Configuration::get('DADATA_SUGGESTIONS_REGION_FIELD')).'";';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_FIO= '.(Configuration::get('DADATA_SUGGESTIONS_FIO')==1?'true':'false').';';
$output .= 'dadataSuggestions.configuration.DADATA_SUGGESTIONS_ADDRESS= '.(Configuration::get('DADATA_SUGGESTIONS_ADDRESS')==1?'true':'false').';';
Expand All @@ -112,8 +105,6 @@ public function getContent()
if (Tools::isSubmit('submit' . $this->name)) {
$dadata_token = strval(Tools::getValue('DADATA_SUGGESTIONS_TOKEN'));
$dadata_count = strval(Tools::getValue('DADATA_SUGGESTIONS_COUNT'));
$dadata_trig_sel_spc = strval(Tools::getValue('DADATA_SUGGESTIONS_TRIG_SEL_SPC'));
$dadata_url = strval(Tools::getValue('DADATA_SUGGESTIONS_URL'));
$dadata_fio = strval(Tools::getValue('DADATA_SUGGESTIONS_FIO'));
$dadata_address = strval(Tools::getValue('DADATA_SUGGESTIONS_ADDRESS'));
$dadata_region_field = strval(Tools::getValue('DADATA_SUGGESTIONS_REGION_FIELD'));
Expand All @@ -122,14 +113,10 @@ public function getContent()
|| !Validate::isSha1($dadata_token)
)
$output .= $this->displayError($this->l('Invalid').' '.$this->l('DaData.ru API Token'));
elseif (!Validate::isBool($dadata_trig_sel_spc))
$output .= $this->displayError($this->l('Invalid auto correct selection'));
elseif (!Validate::isBool($dadata_fio))
$output .= $this->displayError($this->l('Invalid hide selection'));
elseif (!Validate::isBool($dadata_address))
$output .= $this->displayError($this->l('Invalid hide selection'));
elseif (!array_key_exists($dadata_url,$this->available_urls))
$output .= $this->displayError($this->l('Invalid url selection'));
elseif (!in_array($dadata_region_field,$this->valid_fields))
$output .= $this->displayError($this->l('Invalid field name'));
elseif (!$dadata_count
Expand All @@ -142,8 +129,6 @@ public function getContent()
else {
Configuration::updateValue('DADATA_SUGGESTIONS_TOKEN', $dadata_token);
Configuration::updateValue('DADATA_SUGGESTIONS_COUNT', $dadata_count);
Configuration::updateValue('DADATA_SUGGESTIONS_TRIG_SEL_SPC', $dadata_trig_sel_spc);
Configuration::updateValue('DADATA_SUGGESTIONS_URL', $dadata_url);
Configuration::updateValue('DADATA_SUGGESTIONS_FIO', $dadata_fio);
Configuration::updateValue('DADATA_SUGGESTIONS_ADDRESS', $dadata_address);
Configuration::updateValue('DADATA_SUGGESTIONS_REGION_FIELD', $dadata_region_field);
Expand Down Expand Up @@ -179,27 +164,6 @@ public function displayForm()
'size' => 5,
'required' => true
),
array(
'type' => 'radio',
'label' => $this->l('Automatic correction on input'),
'name' => 'DADATA_SUGGESTIONS_TRIG_SEL_SPC',
'required' => true,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)

)
),
array(
'type' => 'radio',
'label' => $this->l('Disable name fields'),
Expand Down Expand Up @@ -242,27 +206,6 @@ public function displayForm()

)
),
array(
'type' => 'radio',
'label' => $this->l('Suggestions SLA'),
'name' => 'DADATA_SUGGESTIONS_URL',
'required' => true,
'class' => 't',
'is_bool' => false,
'values' => array(
array(
'id' => 'free',
'value' => 'free',
'label' => $this->l('Free')
),
array(
'id' => 'paid',
'value' => 'paid',
'label' => $this->l('Paid')
),

)
),
array(
'type' => 'radio',
'label' => $this->l('Region field id'),
Expand Down Expand Up @@ -324,10 +267,8 @@ public function displayForm()
// Load current value
$helper->fields_value['DADATA_SUGGESTIONS_TOKEN'] = Configuration::get('DADATA_SUGGESTIONS_TOKEN');
$helper->fields_value['DADATA_SUGGESTIONS_COUNT'] = Configuration::get('DADATA_SUGGESTIONS_COUNT');
$helper->fields_value['DADATA_SUGGESTIONS_URL'] = Configuration::get('DADATA_SUGGESTIONS_URL');
$helper->fields_value['DADATA_SUGGESTIONS_FIO'] = Configuration::get('DADATA_SUGGESTIONS_FIO');
$helper->fields_value['DADATA_SUGGESTIONS_ADDRESS'] = Configuration::get('DADATA_SUGGESTIONS_ADDRESS');
$helper->fields_value['DADATA_SUGGESTIONS_TRIG_SEL_SPC'] = Configuration::get('DADATA_SUGGESTIONS_TRIG_SEL_SPC');
$helper->fields_value['DADATA_SUGGESTIONS_HIDE'] = Configuration::get('DADATA_SUGGESTIONS_HIDE');
$helper->fields_value['DADATA_SUGGESTIONS_REGION_FIELD'] = Configuration::get('DADATA_SUGGESTIONS_REGION_FIELD');

Expand All @@ -336,8 +277,8 @@ public function displayForm()

public function hookDisplayHeader()
{
$this->context->controller->addCSS('https://dadata.ru/static/css/lib/suggestions-4.7.css','all');
$this->context->controller->addJs('https://dadata.ru/static/js/lib/jquery.suggestions-4.7.min.js','all');
$this->context->controller->addCSS('https://cdn.jsdelivr.net/npm/[email protected]/dist/css/suggestions.min.css','all');
$this->context->controller->addJs('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/jquery.suggestions.min.js','all');

if (Tools::version_compare(_PS_VERSION_, '1.6', '<')) {
$this->context->controller->addJs($this->_path.'views/js/suggestions_prestashop.js', 'all');
Expand Down
8 changes: 1 addition & 7 deletions views/js/suggestions_prestashop.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ var dadataSuggestions = {
],
suggest_fio_label: 'Full Name',
suggest_address_label: 'Full Address',
DADATA_SUGGESTIONS_URL: '',
DADATA_SUGGESTIONS_TOKEN: '',
DADATA_SUGGESTIONS_TRIG_SEL_SPC: true,
DADATA_SUGGESTIONS_COUNT: 10,
DADATA_SUGGESTIONS_COUNT: 5,
DADATA_SUGGESTIONS_REGION_FIELD: 'id_state',
DADATA_SUGGESTIONS_FIO: true,
DADATA_SUGGESTIONS_ADDRESS: true
Expand Down Expand Up @@ -106,9 +104,7 @@ var dadataSuggestions = {
nameEl.parent().attr("style", "display: none !important");
$("#" + value.surname).parent().attr("style", "display: none !important");
$("#" + value.suggest_field).suggestions({
serviceUrl: dadataSuggestions.configuration.DADATA_SUGGESTIONS_URL,
token: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TOKEN,
triggerSelectOnSpace: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TRIG_SEL_SPC,
count: dadataSuggestions.configuration.DADATA_SUGGESTIONS_COUNT,
type: "NAME",
onSelect: function (suggestion) {
Expand All @@ -130,9 +126,7 @@ var dadataSuggestions = {
value.region = dadataSuggestions.configuration.DADATA_SUGGESTIONS_REGION_FIELD;
}
$("#" + value.suggest_field).suggestions({
serviceUrl: dadataSuggestions.configuration.DADATA_SUGGESTIONS_URL,
token: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TOKEN,
triggerSelectOnSpace: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TRIG_SEL_SPC,
count: dadataSuggestions.configuration.DADATA_SUGGESTIONS_COUNT,
type: "ADDRESS",
onSelect: function (suggestion) {
Expand Down
8 changes: 1 addition & 7 deletions views/js/suggestions_prestashop_1.6.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ var dadataSuggestions = {
],
suggest_fio_label: 'Full Name',
suggest_address_label: 'Full Address',
DADATA_SUGGESTIONS_URL: '',
DADATA_SUGGESTIONS_TOKEN: '',
DADATA_SUGGESTIONS_TRIG_SEL_SPC: true,
DADATA_SUGGESTIONS_COUNT: 10,
DADATA_SUGGESTIONS_COUNT: 5,
DADATA_SUGGESTIONS_REGION_FIELD: 'id_state',
DADATA_SUGGESTIONS_FIO: true,
DADATA_SUGGESTIONS_ADDRESS: true
Expand Down Expand Up @@ -106,9 +104,7 @@ var dadataSuggestions = {
nameEl.parent().attr("style", "display: none !important");
$("#" + value.surname).parent().attr("style", "display: none !important");
$("#" + value.suggest_field).suggestions({
serviceUrl: dadataSuggestions.configuration.DADATA_SUGGESTIONS_URL,
token: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TOKEN,
triggerSelectOnSpace: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TRIG_SEL_SPC,
count: dadataSuggestions.configuration.DADATA_SUGGESTIONS_COUNT,
type: "NAME",
onSelect: function (suggestion) {
Expand All @@ -130,9 +126,7 @@ var dadataSuggestions = {
value.region = dadataSuggestions.configuration.DADATA_SUGGESTIONS_REGION_FIELD;
}
$("#" + value.suggest_field).suggestions({
serviceUrl: dadataSuggestions.configuration.DADATA_SUGGESTIONS_URL,
token: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TOKEN,
triggerSelectOnSpace: dadataSuggestions.configuration.DADATA_SUGGESTIONS_TRIG_SEL_SPC,
count: dadataSuggestions.configuration.DADATA_SUGGESTIONS_COUNT,
type: "ADDRESS",
onSelect: function (suggestion) {
Expand Down

0 comments on commit 4dcee7c

Please sign in to comment.