2017-08-29 10:46:12 +02:00

610 lines
28 KiB
PHP

<?php
/**
* Module Ekomi - Main file
*
* @category Advertising and Marketing
* @author Web in Color <addons@webincolor.fr>
* @copyright 2013 WebInColor
* @version 2.8
* @link http://www.webincolor.fr/
* @since File available since Release 1.0
*/
if (!defined('_PS_VERSION_'))
exit;
class Ekomi extends Module
{
private $_html = '';
private $_postErrors = array();
public $_ekomi_object;
public $id_lang;
public $iso_lang;
function __construct()
{
$this->name = 'ekomi';
$this->tab = 'advertising_marketing';
$this->author = 'Web In Color';
$this->version = '2.8';
$this->need_instance = 0;
$this->module_key = '0fbd74e72a982dfbb3ee49f3ccec117a';
parent::__construct();
$this->displayName = $this->l('eKomi');
$this->description = $this->l('Adds an eKomi block, Ekomi product reviews');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
if (self::isInstalled($this->name))
{
$this->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$this->iso_lang = pSQL(Language::getIsoById($this->id_lang));
/* Check Mail Directory */
if (!is_dir('../modules/'.$this->name.'/mails/'.$this->iso_lang.'/'))
$this->warning .= $this->l('directory').' "'.$this->iso_lang.'" does not exist '.'../modules/'.$this->name.'/mails/'.$this->iso_lang.'/';
}
if($this->getVersion() > 1.4)
$this->default_hook = 'displayFooter';
else
$this->default_hook = 'footer';
//including Ekomi Class
$path = dirname(__FILE__);
if (strpos(__FILE__, 'Module.php') !== false)
$path .= '/../modules/'.$this->name;
if($this->getVersion() > 1.4)
include_once($path.'/lib/ekomi_class.php');
else
include_once($path.'/lib/ekomi_class_backward.php');
/* Backward compatibility */
if (_PS_VERSION_ < '1.5' AND _PS_VERSION_ >= '1.4')
require(_PS_MODULE_DIR_.$this->name.'/backward_compatibility/backward.php');
// Retrocompatibility
$this->initContext();
}
// Retrocompatibility 1.4/1.5
private function initContext()
{
if(!$this->context->shop->id)
$this->context->shop->id = 1;
}
public function install()
{
include(dirname(__FILE__).'/sql/install.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
if($this->getVersion() > 1.4)
return (parent::install() AND $this->registerHook('displayFooter') AND $this->registerHook('displayHeader') AND $this->registerHook('actionOrderStatusUpdate') AND $this->registerHook('displayProductTab') AND $this->registerHook('displayProductTabContent'));
else
return (parent::install() AND $this->registerHook('footer') AND $this->registerHook('header') AND $this->registerHook('updateOrderStatus') AND $this->registerHook('productTab') AND $this->registerHook('productTabContent'));
}
public function uninstall()
{
include(dirname(__FILE__).'/sql/uninstall.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
if (!parent::uninstall())
return false;
return true;
}
public function getVersion(){
if(_PS_VERSION_ > 1.3 AND _PS_VERSION_ <= 1.4) return 1.4;
if(_PS_VERSION_ > 1.4 AND _PS_VERSION_ >= 1.6) return 1.5;
return 1.3;
}
public function fetchTemplate($path, $name, $extension = false)
{
return $this->display(__FILE__,$path.$name.'.'.($extension ? $extension : 'tpl'));
}
public function getContent()
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
if(!Validate::isLoadedObject($ekomiObj))
Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'ekomi`(`id_ekomi`,`id_shop`,`display_block`,`display_reviews`,`picto`,`sending`,`range`,`hook`,`id_state`) VALUES (\'\','.$this->context->shop->id.',0,0,\'1-star-yellow\',0,0,\''.$this->default_hook.'\',5);');
if($this->getVersion() > 1.4)
$this->_html = '<link type="text/css" rel="stylesheet" href="' . $this->_path . 'css/admin.css" />';
else
$this->_html = '<link type="text/css" rel="stylesheet" href="' . $this->_path . 'css/admin_backward.css" />';
$this->_html .= '<div class="toolbar-placeholder"><div class="toolbarBox toolbarHead"><div class="pageTitle"><h3> <span id="current_obj" style="font-weight: normal;"> <span class="breadcrumb item-0 "><img src="' . $this->_path . 'img/logo_webincolor_L260.png" width="260" height="70"/>'.$this->l('Expertise e-commerce Prestashop').'</span> </span></h3><span class="readme"><img src="' . $this->_path . 'img/PDF.png" width="32" height="32"/><a href="http://www.webincolor.fr/addons_prestashop/' . $this->l('ekomi_en.pdf').'" target="_blank">'.$this->l('Download the documentation').'</a></span></div></div><div class="leadin"></div></div>';
if($this->getVersion() <= 1.4)
$this->_html .= '<script type="text/javascript" src="' . $this->_path .'js/toolbar.js"></script>';
if(!extension_loaded('soap'))
$this->_html .= $this->displayError($this->l('php-soap extension is not loaded. Thank you to contact your network administrator.'));
if (Tools::isSubmit('submitEkomi'))
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
$ekomiObj->copyFromPost();
$ekomiObj->update();
if($this->getVersion() > 1.4)
{
if ($this->isRegisteredInHook('displayFooter'))
$this->unregisterHook('displayFooter');
if ($this->isRegisteredInHook('displayLeftColumn'))
$this->unregisterHook('displayLeftColumn');
if ($this->isRegisteredInHook('displayRightColumn'))
$this->unregisterHook('displayRightColumn');
}
else
{
if ($this->isRegisteredInHook('footer'))
$this->unregisterHook('footer');
if ($this->isRegisteredInHook('leftColumn'))
$this->unregisterHook('leftColumn');
if ($this->isRegisteredInHook('rightColumn'))
$this->unregisterHook('rightColumn');
}
$this->registerHook(Tools::getValue('hook'));
$this->_html .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';
}
return $this->_html.$this->displayForm();
}
public function displayForm()
{
$states = OrderState::getOrderStates($this->context->language->id);
$languages = Language::getLanguages(false);
$divLangName = 'apiId¤apiKey¤apiScript';
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
$this->_html = '
<script type="text/javascript">id_language = Number('.$this->id_lang.');</script>
<form action="'.htmlentities($_SERVER['REQUEST_URI']).'" method="post" id="ekomi-wrapper">
<fieldset>
<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Ekomi settings').'</legend>
<div class="warn">'.$this->l('Please fill the form with the data that eKomi gives you.').'</div>
<label for="api_id">'.$this->l('API ID').'&nbsp;&nbsp;</label>
<div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .='<div id="apiId_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').';float: left;">
<input id="api_id_'.$language['id_lang'].'" type="text" name="api_id_'.$language['id_lang'].'" value="'.(isset($ekomiObj->api_id[$language['id_lang']]) ? $ekomiObj->api_id[$language['id_lang']] : '').'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $this->id_lang, $divLangName, 'apiId', true);
$this->_html .= '</div><p class="clear"></p>
<label for="api_key">'.$this->l('API KEY').'</label>
<div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '<div id="apiKey_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').';float: left;">
<input id="api_key_'.$language['id_lang'].'" type="text" name="api_key_'.$language['id_lang'].'" value="'.(isset($ekomiObj->api_key[$language['id_lang']]) ? $ekomiObj->api_key[$language['id_lang']] : '').'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $this->id_lang, $divLangName, 'apiKey', true);
$this->_html .= '</div><p class="clear"></p>
<label for="ekomi_script">'.$this->l('eKomi script').'</label>
<div class="margin-form">';
foreach ($languages as $language)
{
$this->_html .= '<div id="apiScript_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').';float: left;">
<textarea id="api_script_'.$language['id_lang'].'" name="api_script_'.$language['id_lang'].'" cols="100" rows="10">'.stripslashes(html_entity_decode((isset($ekomiObj->api_script[$language['id_lang']]) ? $ekomiObj->api_script[$language['id_lang']] : ''))).'</textarea>
</div>';
}
$this->_html .= $this->displayFlags($languages, $this->id_lang, $divLangName, 'apiScript', true);
$this->_html .= '</div><p class="clear"></p>
<div class="warn" style="position: absolute;left: 700px;margin-top: 100px; width:300px;">'.$this->l('Do not forget to log in to your eKomi interface to configure your email type as well as the time of sending of this email.').'</div>
<label>'.$this->l('Display block').'</label>
<div class="margin-form">
<input type="radio" name="display_block" id="display_block_on" value="1" '.($ekomiObj->display_block ? 'checked="checked"' : '').' />
<label class="t" for="display_block_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="display_block" id="display_block_off" value="0" '.(!$ekomiObj->display_block ? 'checked="checked"' : '').' />
<label class="t" for="display_block_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p class="clear">'.$this->l('Show or don\'t show the block (orders will be sent to eKomi whether you choose to hide or display the block).').'</p>
</div>
<label>'.$this->l('Display rich snippet on product page').'</label>
<div class="margin-form">
<input type="radio" name="display_richsnippet" id="display_richsnippet_on" value="1" '.($ekomiObj->display_richsnippet ? 'checked="checked"' : '').' />
<label class="t" for="display_richsnippet_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="display_richsnippet" id="display_richsnippet_off" value="0" '.(!$ekomiObj->display_richsnippet ? 'checked="checked"' : '').' />
<label class="t" for="display_richsnippet_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p class="clear">'.$this->l('Show rich snippet block on product page.').'</p>
</div>
<label>'.$this->l('Display reviews on product page').'</label>
<div class="margin-form">
<input type="radio" name="display_reviews" id="display_reviews_on" value="1" '.($ekomiObj->display_reviews ? 'checked="checked"' : '').' />
<label class="t" for="display_reviews_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="display_reviews" id="ekomi_display_reviews_off" value="0" '.(!$ekomiObj->display_reviews ? 'checked="checked"' : '').' />
<label class="t" for="display_reviews_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p class="clear">'.$this->l('Show product reviews on product page.').'</p>
</div>
<label>'.$this->l('Limit reviews by period').'</label>
<div class="margin-form">
<select name="range">
<option value="" '.(!$ekomiObj->range ? 'selected=selected' : '').'>'.$this->l('All').'</option>
<option value="1m" '.($ekomiObj->range == '1m' ? 'selected=selected' : '').'>'.$this->l('1 month').'</option>
<option value="3m" '.($ekomiObj->range == '3m' ? 'selected=selected' : '').'>'.$this->l('3 months').'</option>
<option value="6m" '.($ekomiObj->range == '6m' ? 'selected=selected' : '').'>'.$this->l('6 months').'</option>
<option value="1y" '.($ekomiObj->range == '1y' ? 'selected=selected' : '').'>'.$this->l('1 year').'</option>
</select>
<p class="clear">'.$this->l('Select the display period of the reviews').'</p>
</div>
<label>'.$this->l('Ask your customers to note the store and products').'</label>
<div class="margin-form">
<input type="radio" name="sending" id="sending_on" value="1" '.($ekomiObj->sending ? 'checked="checked"' : '').' />
<label class="t" for="sending_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
<input type="radio" name="sending" id="sending_off" value="0" '.(!$ekomiObj->sending ? 'checked="checked"' : '').' />
<label class="t" for="sending_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p class="clear">'.$this->l('If you disable this option, only the rating of the store will be required.').'</p>
</div>
<label>'.$this->l('Pictogram to chose for rating').'</label>
<div class="margin-form">
<select style="float: left;" id="ekomiPicto" name="picto">
<option value="1-star-yellow" '.($ekomiObj->picto == '1-star-yellow' ? 'selected="selected"' : '').'>1-star-yellow</option>
<option value="2-star-green" '.($ekomiObj->picto == '2-star-green' ? 'selected="selected"' : '').'>2-star-green</option>
<option value="3-star-blue" '.($ekomiObj->picto == '3-star-blue' ? 'selected="selected"' : '').'>3-star-blue</option>
<option value="4-thumbs-yellow" '.($ekomiObj->picto == '4-thumbs-yellow' ? 'selected="selected"' : '').'>4-thumbs-yellow</option>
<option value="5-thumbs-green" '.($ekomiObj->picto == '5-thumbs-green' ? 'selected="selected"' : '').'>5-thumbs-green</option>
<option value="6-thumbs-blue" '.($ekomiObj->picto == '6-thumbs-blue' ? 'selected="selected"' : '').'>6-thumbs-blue</option>
</select>
<span id="ekomiPicto1-star-yellow" style="float: left; margin-left: 15px; margin-bottom: 10px; display: '.((!$ekomiObj->picto OR $ekomiObj->picto == '1-star-yellow') ? 'inline' : 'none').'">
<img src="'.$this->_path.'img/picto/1-star-yellow/picto.gif" alt="1-star-yellow" title="1-star-yellow" />
</span>
<span id="ekomiPicto2-star-green" style="float: left; margin-left: 15px; margin-bottom: 10px; display: '.(($ekomiObj->picto AND $ekomiObj->picto == '2-star-green') ? 'inline' : 'none').'">
<img src="'.$this->_path.'img/picto/2-star-green/picto.gif" alt="2-star-green" title="2-star-green" />
</span>
<span id="ekomiPicto3-star-blue" style="float: left; margin-left: 15px; margin-bottom: 10px; display: '.(($ekomiObj->picto AND $ekomiObj->picto == '3-star-blue') ? 'inline' : 'none').'">
<img src="'.$this->_path.'img/picto/3-star-blue/picto.gif" alt="3-star-blue" title="3-star-blue" />
</span>
<span id="ekomiPicto4-thumbs-yellow" style="float: left; margin-left: 15px; margin-bottom: 10px; display: '.(($ekomiObj->picto AND $ekomiObj->picto == '4-thumbs-yellow') ? 'inline' : 'none').'">
<img src="'.$this->_path.'img/picto/4-thumbs-yellow/picto.gif" alt="4-thumbs-yellow" title="4-thumbs-yellow" />
</span>
<span id="ekomiPicto5-thumbs-green" style="float: left; margin-left: 15px; margin-bottom: 10px; display: '.(($ekomiObj->picto AND $ekomiObj->picto == '5-thumbs-green') ? 'inline' : 'none').'">
<img src="'.$this->_path.'img/picto/5-thumbs-green/picto.gif" alt="5-thumbs-green" title="5-thumbs-green" />
</span>
<span id="ekomiPicto6-thumbs-blue" style="float: left; margin-left: 15px; margin-bottom: 10px; display: '.(($ekomiObj->picto AND $ekomiObj->picto == '6-thumbs-blue') ? 'inline' : 'none').'">
<img src="'.$this->_path.'img/picto/6-thumbs-blue/picto.gif" alt="6-thumbs-blue" title="6-thumbs-blue" />
</span>
<br class="clear" />
</div>
<label>'.$this->l('Select the status ').'</label>
<div class="margin-form">
<select name="id_state">';
foreach ($states AS $state)
$this->_html .= '<option value="'.$state['id_order_state'].'" '.(($ekomiObj->id_state == $state['id_order_state'] OR (!$ekomiObj->id_state AND $state['id_order_state'] == 5))?'selected=selected':'').'>'.$state['name'].'</option>';
$this->_html .= '</select>
<p class="clear">'.$this->l('Select the status to which we send the ratting request to the customer').'</p>
</div>
<label>'.$this->l('Where would you appear this block?').'</label>
<div class="margin-form">
<select name="hook">
<option value="'.(($this->getVersion() > 1.4) ? 'displayFooter' : 'footer').'" '.(($ekomiObj->hook == 'footer' OR $ekomiObj->hook == 'displayFooter') ? 'selected=selected' : '').'>'.$this->l('In footer').'</option>
<option value="'.(($this->getVersion() > 1.4) ? 'displayLeftColumn' : 'leftColumn').'" '.(($ekomiObj->hook == 'leftColumn' OR $ekomiObj->hook == 'displayLeftColumn') ? 'selected=selected' : '').'>'.$this->l('Left Column').'</option>
<option value="'.(($this->getVersion() > 1.4) ? 'displayRightColumn' : 'rightColumn').'" '.(($ekomiObj->hook == 'rightColumn' OR $ekomiObj->hook == 'displayRightColumn') ? 'selected=selected' : '').'>'.$this->l('Right Column').'</option>
</select>
</div>
<div class="hint" style="display:block;margin-bottom:20px;">'.$this->l('You must configure the following cron every 6 hours:').'<ul><li>';
if (_PS_VERSION_ >= 1.4)
$this->_html .= '<a href="'.Tools::getShopDomain(true).str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_order_email.php?token='.Tools::getAdminToken('eKomi').'">'.Tools::getShopDomain(true).str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_order_email.php?token='.Tools::getAdminToken('eKomi').'</a></li><li><a href="'.Tools::getShopDomain(true).str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_product_feedback.php?token='.Tools::getAdminToken('eKomi').'">'.Tools::getShopDomain(true).str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_product_feedback.php?token='.Tools::getAdminToken('eKomi').'</a>';
else
$this->_html .= '<a href="'.$_SERVER['HTTP_REFERER'].str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_order_email.php?token='.Tools::getAdminToken('eKomi').'">'.$_SERVER['HTTP_REFERER'].str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_order_email.php?token='.Tools::getAdminToken('eKomi').'</a></li><li><a href="'.$_SERVER['HTTP_REFERER'].str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_product_feedback.php?token='.Tools::getAdminToken('eKomi').'">'.$_SERVER['HTTP_REFERER'].str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $this->_path).'tools/ekomi_product_feedback.php?token='.Tools::getAdminToken('eKomi').'</a>';
$this->_html .= '</li></ul>
'.$this->l('If you have a problem thank you to contact your network administrator.').'
<br/><b>'.$this->l('You haven\'t network administrator, eKomi team helps you set up your Cron Job. Thank you contact the technical team eKomi.').'</b>
</div>
<center class="submit"><input type="submit" name="submitEkomi" value="'.$this->l('Save').'" class="button" /></center>
</fieldset>
</form>';
$this->_html .= '<script type="text/javascript">
$("#ekomiPicto").bind($.browser.msie ? \'click\' : \'change\', function (event)
{
$("#ekomiPicto option").each(function (i)
{
if ($(this).attr(\'selected\')) {
$("#ekomiPicto" + $(this).val()).css(\'display\', \'inline\');
}
else {
$("#ekomiPicto" + $(this).val()).css(\'display\', \'none\');
}
});
});
</script>';
$this->_html .= '<iframe src="http://www.webincolor.fr/addons_prestashop.html" width="670" height="430" border="0"></iframe>';
return $this->_html;
}
public function hookHeader($params)
{
if (version_compare(_PS_VERSION_,'1.5','<'))
{
Tools::addCSS(($this->_path).'css/jquery.star-rating.css', 'all');
Tools::addCSS(($this->_path).'css/module.css', 'all');
}
else
{
$this->context->controller->addCSS(($this->_path).'css/jquery.star-rating.css', 'all');
$this->context->controller->addCSS(($this->_path).'css/module.css', 'all');
}
$this->context->smarty->assign(array(
'version' => version_compare(_PS_VERSION_, '1.4.1'),
'pathJS' => $this->_path.'js/',
));
return $this->fetchTemplate('/views/templates/hooks/', 'header');
}
public function hookDisplayHeader($params)
{
return $this->hookHeader($params);
}
public function hookFooter($params)
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
if(Validate::isLoadedObject($ekomiObj))
{
if($ekomiObj->display_richsnippet)
{
if(Tools::getValue('id_product'))
{
$product = new Product(Tools::getValue('id_product'),true,$this->context->language->id);
if(Validate::isLoadedObject($product))
{
//We retrieve rating
$this->context->smarty->assign(array(
'product' => $product,
'rating' => $ekomiObj->getRating($product->id,$this->context->language->id),
'count' => $ekomiObj->getCount(Tools::getValue('id_product'),$this->context->language->id),
'currencySign' => $this->context->currency->sign,
'currencyIso' => $this->context->currency->iso_code,
'pathStar' => $this->_path.'img/picto/'.$ekomiObj->picto.'/picto.gif',
));
}
}
else
$this->context->smarty->assign(array(
'display_reviews' => false,
));
}
else
$this->context->smarty->assign(array(
'display_reviews' => false,
));
if ($ekomiObj->display_block AND $ekomiObj->api_script[$this->context->language->id])
{
$this->context->smarty->assign(array(
'badge' => stripslashes(html_entity_decode($ekomiObj->api_script[$this->context->language->id])).'<br clear="left" /><br />',
));
}
return $this->fetchTemplate('/views/templates/hooks/', 'badge');
}
else
return false;
}
public function hookDisplayFooter($params)
{
return $this->hookFooter($params);
}
public function hookLeftColumn($params)
{
return $this->hookFooter($params);
}
public function hookDisplayLeftColumn($params)
{
return $this->hookFooter($params);
}
public function hookRightColumn($params)
{
return $this->hookFooter($params);
}
public function hookDisplayRightColumn($params)
{
return $this->hookFooter($params);
}
public function hookUpdateOrderStatus($params)
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
$orderState = $params['newOrderStatus'];
if($ekomiObj->id_state)
{
if($ekomiObj->id_state == $orderState->id)
{
/* We send Product to update database Ekomi product*/
$order = new Order($params['id_order']);
$products = $order->getProducts();
foreach ($products as $product)
$ekomiObj->send_product($product,$order->id_lang, $this->context->link);
$ekomiData = $ekomiObj->send_order($params['id_order'],$order->id_lang);
if(isset($ekomiData['link']))
{
//We insert order data to sending email via cronjob
$ekomiObj->putEmailData($order->id,$order->id_customer,$ekomiData['link'],$order->id_lang);
}
}
}
return true;
}
public function hookActionOrderStatusUpdate($params)
{
return $this->hookUpdateOrderStatus($params);
}
public function hookProductTab($params)
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
if($ekomiObj->display_reviews)
{
$this->context->smarty->assign(array(
'count' => $ekomiObj->getCount(Tools::getValue('id_product'),$this->context->language->id),
));
return $this->fetchTemplate('/views/templates/hooks/', 'tab');
}
else
return false;
}
public function hookDisplayProductTab($params)
{
return $this->hookProductTab($params);
}
public function hookProductTabContent($params)
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
if($ekomiObj->display_reviews)
{
/* Get product reviews*/
$reviews = $ekomiObj->getReviews(Tools::getValue('id_product'),$this->context->language->id);
$rating = $ekomiObj->getRating(Tools::getValue('id_product'),$this->context->language->id);
$this->context->smarty->assign(array(
'pathEkomi' => $this->_path,
));
if($reviews)
{
$this->context->smarty->assign(array(
'eReviews' => $reviews,
'rating' => $rating,
'pathStar' => $this->_path.'img/picto/'.$ekomiObj->picto.'/picto.gif',
));
}
return $this->fetchTemplate('/views/templates/hooks/', 'productcomment');
}
else
return false;
}
public function hookDisplayProductTabContent($params)
{
return $this->hookProductTabContent($params);
}
public function cronSendEmail()
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
foreach($ekomiObj->api_id as $key=>$value)
{
if (!file_exists(dirname(__FILE__.'/'.Language::getIsoById((int)$key).'/')))
di('error sending email, template does not exist');
$ekomiSettings = $ekomiObj->send_settings_request($key);
if($ekomiSettings['done'])
{
$subject = utf8_encode($ekomiSettings['mail_subject']);
/* We retrieve all order to send an ekomi email */
$orders = $ekomiObj->getOrders($ekomiSettings['mail_delay'], $key);
if($orders)
{
foreach($orders as $order)
{
$customer = new Customer((int)$order['id_customer']);
$notSending = Db::getInstance()->ExecuteS('SELECT `id_customer` FROM `'._DB_PREFIX_.'ekomi_unsubscribe` WHERE `id_customer` = '.(int)$customer->id.';');
if (!preg_match("/amazon/i", $customer->email) AND !preg_match("/ebay/i", $customer->email) AND !isset($notSending[0]['id_customer']))
{
/* HTML email */
$htmlContent = str_replace('{nachname}', $customer->lastname, utf8_encode($ekomiSettings['mail_html']));
$htmlContent = str_replace('{vorname}', $customer->firstname.' ', $htmlContent);
$htmlContent = str_replace('{ekomilink}', '<a href="'.$order['ekomi_link'].'">'.$order['ekomi_link'].'</a>', $htmlContent);
/* TXT email */
$plainContent = str_replace('{nachname}', $customer->lastname, utf8_encode($ekomiSettings['mail_plain']));
$plainContent = str_replace('{vorname}', $customer->firstname.' ', $htmlContent);
$plainContent = str_replace('{ekomilink}', $order['ekomi_link'], $htmlContent);
if($order['ekomi_link'])
{
/* Email generation */
if (version_compare(_PS_VERSION_,'1.5','<'))
{
$templateVars = array(
'{htmlContent}' => $htmlContent,
'{plainContent}' => $plainContent,
'{idcustomer}' => md5($customer->id),
'{url}' => 'http://'.$_SERVER['HTTP_HOST'].'/modules/ekomi/ekomi-unsubscribe-backward.php',
);
}
else
{
$templateVars = array(
'{htmlContent}' => $htmlContent,
'{plainContent}' => $plainContent,
'{idcustomer}' => md5($customer->id),
'{url}' => 'http://'.$_SERVER['HTTP_HOST'].'/module/ekomi/unsubscribe',
);
}
/* Email sending */
if (!Mail::Send((int)$key, 'ekomi', $subject, $templateVars, $customer->email, NULL, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), NULL, NULL, dirname(__FILE__).'/mails/'))
die('error to sending email');
/* We update database ekomi order send email field */
$orders = $ekomiObj->updateSendEmailOrder($order['id_order'],$order['id']);
echo 'Email sent to order '.$order['id'].'<br/>';
}
}
else
continue;
}
}
}
}
return true;
}
public function cronProductFeedBack()
{
$ekomiObj = EkomiObject::getByIdShop($this->context->shop->id);
$ekomiObj->check_product_feedback();
return true;
}
}