first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,276 @@
<?php
/**
* 2012-2017 Patryk Marek PrestaDev.pl
*
* Patryk Marek PrestaDev.pl - PD Price Compare Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at info@prestadev.pl.
*
* @author Patryk Marek PrestaDev.pl <info@prestadev.pl>
* @copyright 2012-2017 Patryk Marek - PrestaDev.pl
* @license License is for use in domain / or one multistore enviroment (do not modify or reuse this code or part of it) if you want any changes please contact with me at info@prestadev.pl
* @link http://prestadev.pl
* @package PD Price Compare Pro - PrestaShop 1.5.x and 1.6.x Module
* @version 1.5.0
* @date 10-06-2015
*/
require_once dirname(__FILE__).'/../../models/GoogleMerchantCenterProModelDictionary.php';
class AdminGoogleMerchantCenterProDictionaryController extends AdminController
{
public $module = null;
public $module_name = 'pdgooglemerchantcenterpro';
public function __construct()
{
$this->table = 'pdgooglemerchantcenterpro_dictionary';
$this->className = 'GoogleMerchantCenterProModelDictionary';
$this->lang = false;
$this->bootstrap = true;
if (Module::isInstalled($this->module_name)) {
$this->module = Module::getInstanceByName($this->module_name);
}
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->allow_export = true;
$this->id_lang = Configuration::get('PS_LANG_DEFAULT');
$this->ps_ver_16 = (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.6', '=')) ? true : false;
$this->ps_ver_15 = (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.5', '=')) ? true : false;
$this->context = Context::getContext();
$this->default_form_language = $this->context->language->id;
parent::__construct();
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
),
'enableSelection' => array('text' => $this->l('Enable selection')),
'disableSelection' => array('text' => $this->l('Disable selection'))
);
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
$this->fields_list = array(
'id_pdgooglemerchantcenterpro_dictionary' => array(
'title' => $this->l('ID'),
'align' => 'center',
'filter' => false,
'width' => 25
),
'active' => array(
'title' => $this->l('Active'),
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'filter' => false,
'orderby' => false,
'width' => 25
),
'source_word' => array(
'title' => $this->l('Source word / phrase'),
'width' => 100
),
'destination_word' => array(
'title' => $this->l('Destination word / phrase'),
'width' => 100
),
'date_add' => array(
'title' => $this->l('Date add'),
'align' => 'right',
'width' => 'auto',
'filter' => false,
'type' => 'datetime',
),
'date_upd' => array(
'title' => $this->l('Date updated'),
'align' => 'right',
'width' => 'auto',
'filter' => false,
'type' => 'datetime'
),
);
}
/**
* Function used to render the list to display for this controller
*/
public function renderList()
{
$this->displayInformation('&nbsp;<b>'.$this->l('How do I use dictionary and what it is for?').'</b>
<br />
<ul>
<li>'.$this->l('Some quick brief: Google don\'t like some words in product names or product description and you can replace them on the fly for empty string or some other word.').'<br /></li>
<li>'.$this->l('To add new entry click in top right corrner button "Add new dictionary entry" and type source word or phrase and destination word or phrase and click save.').'<br /></li>
</ul>');
// init and render the first list
return parent::renderList();
}
public function initPageHeaderToolbar()
{
if (empty($this->display)) {
$this->page_header_toolbar_btn['new_configuration'] = array(
'href' => self::$currentIndex.'&addpdgooglemerchantcenterpro_dictionary&token='.$this->token,
'desc' => $this->l('Add new dictionary entry', null, null, false),
'icon' => 'process-icon-new'
);
}
parent::initPageHeaderToolbar();
}
public function renderForm()
{
if (!($obj = $this->loadObject(true))) {
return;
}
// Switch or radio for ps 1.5 compatibility
$switch = version_compare(_PS_VERSION_, '1.6.0', '>=') ? 'switch' : 'radio';
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Dictionary add / edit'),
'icon' => 'icon-user'
),
'input' => array(
array(
'type' => $switch,
'label' => $this->l('Active'),
'name' => 'active',
'class' => 't',
'is_bool' => true,
'desc' => $this->l('Set if replacement should be active'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Source word / phrase'),
'name' => 'source_word',
),
array(
'type' => 'text',
'label' => $this->l('Destination word / phrase'),
'name' => 'destination_word',
),
)
);
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
'icon' => 'process-icon-save',
'class' => 'btn btn-default pull-right'
);
if (!($obj = $this->loadObject(true))) {
return;
}
return parent::renderForm();
}
public function postProcess()
{
//Tools::clearSmartyCache();
return parent::postProcess();
}
public function processAdd()
{
if (Tools::isSubmit('submitAddpdgooglemerchantcenterpro_dictionary')) {
if (!Tools::getValue('source_word') || Tools::getValue('source_word') == '') {
$this->errors[] = $this->l('You need to specify source word / phrase.');
}
if (!Tools::getValue('destination_word') || Tools::getValue('destination_word') == '') {
$this->errors[] = $this->l('You need to specify destination word / phrase for which source word / phrase will be replaced.');
}
$object = new $this->className();
$object->active = Tools::getValue('active');
$object->source_word = Tools::getValue('source_word');
$object->destination_word = Tools::getValue('destination_word');
$object->date_add = date('Y-m-d H:i:s');
$object->date_upd = '0000-00-00 00:00:00';
if (!$object->add()) {
$this->errors[] = Tools::displayError('An error occurred while creating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
}
$this->errors = array_unique($this->errors);
if (!empty($this->errors)) {
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';
return false;
}
}
}
public function processUpdate()
{
if (Tools::isSubmit('submitAddpdgooglemerchantcenterpro_dictionary') && Tools::isSubmit('id_pdgooglemerchantcenterpro_dictionary')) {
if (!Tools::getValue('source_word') || Tools::getValue('source_word') == '') {
$this->errors[] = $this->l('You need to specify source word / phrase.');
}
if (!Tools::getValue('destination_word') || Tools::getValue('destination_word') == '') {
$this->errors[] = $this->l('You need to specify destination word / phrase for which source word / phrase will be replaced.');
}
$id_pdgooglemerchantcenterpro_dictionary = (int)Tools::getValue('id_pdgooglemerchantcenterpro_dictionary');
$object = new $this->className($id_pdgooglemerchantcenterpro_dictionary);
$object->active = Tools::getValue('active');
$object->source_word = Tools::getValue('source_word');
$object->destination_word = Tools::getValue('destination_word');
$object->date_upd = date('Y-m-d H:i:s');
if (!$object->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating an object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
}
}
$this->errors = array_unique($this->errors);
if (!empty($this->errors)) {
// if we have errors, we stay on the form instead of going back to the list
$this->display = 'edit';
return false;
}
}
}

View File

@@ -0,0 +1,346 @@
<?php
/**
* 2012-2015 Patryk Marek PrestaDev.pl
*
* Patryk Marek PrestaDev.pl - PD Google Merchant Center Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at info@prestadev.pl.
*
* @author Patryk Marek PrestaDev.pl <info@prestadev.pl>
* @copyright 2012-2015 Patryk Marek - PrestaDev.pl
* @license License is for use in domain / or one multistore enviroment (do not modify or reuse this code or part of it) if you want any changes please contact with me at info@prestadev.pl
* @link http://prestadev.pl
* @package PD Google Merchant Center Pro - PrestaShop 1.5.x and 1.6.x Module
* @version 2.2.0
* @date 04-03-2016
*/
require_once dirname(__FILE__).'/../../models/GoogleMerchantCenterProModelTaxonomy.php';
class AdminGoogleMerchantCenterProTaxonomyController extends AdminController
{
public $module = null;
public $module_name = 'pdgooglemerchantcenterpro';
public function __construct()
{
$this->table = 'pdgooglemerchantcenterpro_taxonomy';
$this->className = 'GoogleMerchantCenterProModelTaxonomy';
$this->lang = false;
$this->bootstrap = true;
$this->context = Context::getContext();
$this->list_simple_header = true;
$this->list_no_link = true;
if (Module::isInstalled($this->module_name)) {
$this->module = Module::getInstanceByName($this->module_name);
}
$this->ps_ver_17 = (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.7', '=')) ? true : false;
$this->ps_ver_16 = (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.6', '=')) ? true : false;
$this->ps_ver_15 = (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.5', '=')) ? true : false;
parent::__construct();
$this->fields_list = array(
'id_pdgooglemerchantcenterpro_taxonomy' => array(
'title' => $this->l('ID'),
'align' => 'center',
'filter' => false,
'width' => 25
),
'taxonomy_lang' => array(
'title' => $this->l('Google iso code'),
'width' => 60
),
'languages' => array(
'title' => $this->l('Concerned languages'),
'width' => 140
),
'currencies' => array(
'title' => $this->l('Concerned currencies'),
'width' => 140
),
'countries' => array(
'title' => $this->l('Concerned countries'),
'width' => 140
),
'imported' => array(
'title' => $this->l('Imported'),
'align' => 'center',
'callback' => 'printImportedIcon',
'type' => 'bool',
'filter' => false,
'orderby' => false,
'width' => 25
),
'import' => array(
'title' => $this->l('Import / update'),
'align' => 'text-center',
'callback' => 'printImportIcon',
'orderby' => false,
'search' => false,
'remove_onclick' => true,
'width' => 25
),
'date_add' => array(
'title' => $this->l('Date import / update'),
'align' => 'right',
'width' => 'auto',
'filter' => false,
'type' => 'datetime',
),
);
}
public function setMedia($isNewTheme = false)
{
parent::setMedia();
$this->addJqueryPlugin(array('autocomplete'));
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
$languages_array = $this->module->languagesIsoTranslation;
$countries_array = $this->module->countriesIsoTranslation;
foreach ($this->_list as $k => $list) {
if (count(explode(',', $this->_list[$k]['languages'])) > 1) {
$languages_row_arr = explode(',', $this->_list[$k]['languages']);
$string = '';
foreach ($languages_row_arr as &$l) {
$l = trim($l);
$string .= $languages_array[$l].', ';
}
$this->_list[$k]['languages'] = rtrim($string, ', ');
$string = '';
} else {
$this->_list[$k]['languages'] = $languages_array[$list['languages']];
}
if (count(explode(',', $this->_list[$k]['countries'])) > 1) {
$countries_row_arr = explode(',', $this->_list[$k]['countries']);
$string = '';
foreach ($countries_row_arr as &$c) {
$c = trim($c);
$string .= $countries_array[$c].', ';
}
$this->_list[$k]['countries'] = rtrim($string, ', ');
$string = '';
} else {
$this->_list[$k]['countries'] = $countries_array[$list['countries']];
}
}
//dump($this->_list);
//die();
}
/**
* Function used to render the list to display for this controller
*/
public function renderList()
{
$this->addRowAction('Mapcategories');
$this->displayInformation('&nbsp;<b>'.$this->l('How do I import Google taxonomy / product categories and map them to shop categories?').'</b>
<br />
<ul>
<li>'.$this->l('Some quick brief: Each country has its own taxonomy / product categories in Google Merchant Center').'<br /></li>
<li>'.$this->l('If You want to use shop category products to Google products category mapping first You need to download corect taxonomy data').'<br /></li>
<li>'.$this->l('Please click "Import / update" button to download Google taxonomy / product category for your country / language / currency, or import all of them').'<br /></li>
<li>'.$this->l('Final step is to map shop categories to Gogole categories by clicking "Map categories" button and next to each shop category start typing category name in input field, autocomplete function will bring up results which you can assign to shop category').'<br /></li>
</ul>');
// init and render the first list
return parent::renderList();
}
public function displayMapCategoriesLink($token, $id, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_edit.tpl');
$tpl->assign(array(
'href' => self::$currentIndex.'&id_pdgooglemerchantcenterpro_taxonomy='.$id.'&map_categories'.$this->table.'&token='.($token != null ? $token : $this->token),
'action' => $this->l('Map categories'),
'id' => $id
));
return $tpl->fetch();
}
public function printImportIcon($id_pdgooglemerchantcenterpro_taxonomy, $tr)
{
$id = $tr['id_pdgooglemerchantcenterpro_taxonomy'];
$link = $this->context->link->getAdminLink('AdminGoogleMerchantCenterProTaxonomy').'&id_pdgooglemerchantcenterpro_taxonomy='.$id.'&download_google_taxonomy';
if ($this->ps_ver_16 || $this->ps_ver_17) {
$button = '<a class="btn btn-default" href="'.$link.'"><i class="icon-circle-arrow-up"></i></a>';
} else {
$button = '<a href="'.$link.'"><img src="../img/admin/manufacturers.gif" /></a>';
}
return $button;
}
public function printImportedIcon($id_pdgooglemerchantcenterpro_taxonomy, $tr)
{
$imported = $tr['imported'];
if ($this->ps_ver_16) {
if ($imported) {
$button = '<span title="'.$this->l('Enabled').'" class="list-action-enable action-enabled"><i class="icon-check"></i></span>';
} else {
$button = '<span title="'.$this->l('Disabled').'" class="list-action-enable action-disabled"><i class="icon-remove"></i></span>';
}
} else {
if ($imported) {
$button = '<aspan><img src="../img/admin/enabled.gif" /></span>';
} else {
$button = '<aspan><img src="../img/admin/disabled.gif" /></span>';
}
}
return $button;
}
/**
* List actions
*/
public function initProcess()
{
parent::initProcess();
if (Tools::isSubmit('download_google_taxonomy')) {
$id_pdgooglemerchantcenterpro_taxonomy = (int)Tools::getValue('id_pdgooglemerchantcenterpro_taxonomy');
$object = new $this->className($id_pdgooglemerchantcenterpro_taxonomy);
$imported = $this->module->importTaxonomyData($object->taxonomy_lang);
if ($imported) {
$object->imported = 1;
$object->date_add = date('Y-m-d H:i:s');
$object->update();
}
}
}
public function postProcess()
{
if (Tools::getIsset('map_categoriespdgooglemerchantcenterpro_taxonomy')) {
$this->renderForm();
}
if (Tools::isSubmit('searchTaxonomyCategory')) {
$query = Tools::getValue('q', false);
$id_pdgooglemerchantcenterpro_taxonomy = (int)Tools::getValue('id_pdgooglemerchantcenterpro_taxonomy');
$object = new $this->className($id_pdgooglemerchantcenterpro_taxonomy);
$taxonomy_lang = $object->taxonomy_lang;
if (ob_get_level() && ob_get_length() > 0) {
ob_end_clean();
}
echo $this->autoCompleteSearch($query, $taxonomy_lang);
die();
}
if (Tools::isSubmit('submitSaveCategoriesMapping')) {
$id_pdgooglemerchantcenterpro_taxonomy = (int)Tools::getValue('id_pdgooglemerchantcenterpro_taxonomy');
$object = new $this->className($id_pdgooglemerchantcenterpro_taxonomy);
$taxonomy_lang = $object->taxonomy_lang;
$catsmappingarr = Tools::getValue('catsmappingarr');
if (!count($catsmappingarr)) {
$this->errors[] = $this->l('Please map categories first before save.');
}
$this->module->updateMapGoogleCategories2ShopCategories($catsmappingarr, $taxonomy_lang);
$this->displayConfirmation($this->l('Shop categories to Google categories mappings was saved sucesfully.'));
}
//parent::postProcess();
}
public function autoCompleteSearch($query, $taxonomy_lang)
{
if (!$query || $query == '' || Tools::strlen($query) < 1) {
die();
}
$words = explode(' ', $query);
$output = '';
$sql = 'SELECT `value`
FROM `'._DB_PREFIX_.'pdgooglemerchantcenterpro_taxonomy_data`
WHERE lang = "'.pSQL($taxonomy_lang).'"';
foreach ($words as $w) {
$sql .= ' AND value LIKE \'%'.pSQL($w).'%\'';
}
$items = Db::getInstance()->ExecuteS($sql);
if ($items) {
foreach ($items as $item) {
$output .= trim($item['value'])."\n";
}
}
return trim($output);
}
public function renderForm()
{
$id_pdgooglemerchantcenterpro_taxonomy = (int)Tools::getValue('id_pdgooglemerchantcenterpro_taxonomy');
$object = new $this->className($id_pdgooglemerchantcenterpro_taxonomy);
$taxonomy_lang = $object->taxonomy_lang;
$categories = $this->module->generateCategoryPath($this->context->language->id, $this->context->shop->id);
foreach ($categories as &$c) {
$gct = $this->module->getGoogleTaxonomyCategory((int)$c['id_category'], $taxonomy_lang);
if ($gct && is_array($gct) && sizeof($gct) && isset($gct['txt_taxonomy'])) {
$c['txt_taxonomy'] = $gct['txt_taxonomy'];
} else {
$c['txt_taxonomy'] = '';
}
}
$this->context->smarty->assign(array(
'ps_ver_16' => $this->ps_ver_16,
'ps_ver_15' => $this->ps_ver_15,
'categories' => $categories,
'taxonomy_lang' => $taxonomy_lang,
'id_pdgooglemerchantcenterpro_taxonomy' => $id_pdgooglemerchantcenterpro_taxonomy,
'post_url' => self::$currentIndex.'&saveAsociations&token='.$this->token,
'ajax_url' => $this->context->link->getAdminLink('AdminGoogleMerchantCenterProTaxonomy', true),
'token' => $this->token,
));
$this->content .= $this->context->smarty->fetch(dirname(__FILE__).'/../../views/templates/admin/categories.tpl');
}
public function displayConfirmation($string)
{
$output = '
<div class="bootstrap">
<div class="module_confirmation conf confirm alert alert-success">
<button type="button" class="close" data-dismiss="alert">&times;</button>
'.$string.'
</div>
</div>';
return $this->content .= $output;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* 2012-2015 Patryk Marek PrestaDev.pl
*
* Patryk Marek PrestaDev.pl - PD Google Merchant Center Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at info@prestadev.pl.
*
* @author Patryk Marek PrestaDev.pl <info@prestadev.pl>
* @copyright 2012-2015 Patryk Marek - PrestaDev.pl
* @license License is for use in domain / or one multistore enviroment (do not modify or reuse this code or part of it) if you want any changes please contact with me at info@prestadev.pl
* @link http://prestadev.pl
* @package PD Google Merchant Center Pro - PrestaShop 1.5.x and 1.6.x Module
* @version 2.2.0
* @date 04-03-2016
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;