2017-02-02 13:00:59 +01:00
|
|
|
<?php
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
|
|
exit;
|
|
|
|
include_once (_PS_MODULE_DIR_.'trustedshopsbbb/lib/ReviewCollectorReview.php');
|
|
|
|
include_once (_PS_MODULE_DIR_.'trustedshopsbbb/lib/TrustedShopsCache.php');
|
|
|
|
include_once (_PS_MODULE_DIR_.'trustedshopsbbb/lib/ReviewIndicatorCollector.php');
|
|
|
|
include_once (_PS_MODULE_DIR_.'trustedshopsbbb/lib/TrustedShopsAPI.php');
|
|
|
|
include_once(_PS_MODULE_DIR_.'trustedshopsbbb/models/TrustedshopBbbAsync.php');
|
|
|
|
|
|
|
|
class TrustedShopsBbb extends Module
|
|
|
|
{
|
|
|
|
const TS_BEST_RATING = "5.00";
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->name = 'trustedshopsbbb';
|
|
|
|
$this->tab = 'payment_security';
|
|
|
|
$this->version = '1.0';
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Trusted Shops BBB (specific)');
|
|
|
|
if ($this->id AND !Configuration::get('TRUSTED_SHOP_ID')) {
|
|
|
|
$this->warning = $this->l('You have not yet set your Trusted Shop ID');
|
|
|
|
}
|
|
|
|
$this->description = $this->l('Allows API calls when an order reach a specific order state');
|
|
|
|
$this->confirmUninstall = $this->l('Are you sure you want to delete all your settings?');
|
|
|
|
}
|
|
|
|
public function install()
|
|
|
|
{
|
|
|
|
if (!parent::install()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!$this->registerHook('updateOrderStatus') ||
|
|
|
|
!$this->registerHook('footer') ||
|
|
|
|
!$this->registerHook('orderConfirmation')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!$this->installDB()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
private function installDB()
|
|
|
|
{
|
|
|
|
$result = true;
|
|
|
|
# Add tables
|
|
|
|
$query = '
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'trustedshop_bbb_async` (
|
|
|
|
`id_trustedshop_bbb_async` INTEGER NOT NULL AUTO_INCREMENT,
|
|
|
|
`id_order` INTEGER NOT NULL,
|
|
|
|
`processed` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`date_add` DATETIME NOT NULL,
|
|
|
|
`date_upd` DATETIME NOT NULL,
|
|
|
|
PRIMARY KEY(`id_trustedshop_bbb_async`),
|
|
|
|
KEY `trustedshop_bbb_o_index` (id_order)
|
|
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8
|
|
|
|
';
|
|
|
|
$result = (Db::getInstance()->Execute($query) and $result);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
public function uninstall()
|
|
|
|
{
|
|
|
|
if (!Configuration::deleteByName('TRUSTED_SHOP_FR_ID')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-02-17 10:55:46 +01:00
|
|
|
if (!Configuration::deleteByName('TRUSTED_SHOP_ES_ID')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-02-02 13:00:59 +01:00
|
|
|
if (!Configuration::deleteByName('TRUSTED_SHOP_STATUS_WATCHED')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!Configuration::deleteByName('TRUSTED_SHOP_PASSWORD')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!Configuration::deleteByName('TRUSTED_SHOP_USER')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!Configuration::deleteByName('TRUSTED_SHOP_DAYS')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return parent::uninstall();
|
|
|
|
}
|
|
|
|
public function getContent()
|
|
|
|
{
|
|
|
|
global $cookie;
|
|
|
|
$output = '<h2>Trusted Shop Configuration</h2>';
|
2017-02-17 10:55:46 +01:00
|
|
|
if (Tools::isSubmit('submitTrustedShop') AND ($tsfrid = Tools::getValue('trusted_shop_fr_id')) AND ($tsesid = Tools::getValue('trusted_shop_es_id')) AND ($tsdays = Tools::getValue('trusted_shop_days')) AND ($tssw = Tools::getValue('status_watched_id')) AND ($tspassword = Tools::getValue('trusted_shop_password')) AND ($tsuser = Tools::getValue('trusted_shop_user'))) {
|
2017-02-02 13:00:59 +01:00
|
|
|
Configuration::updateValue('TRUSTED_SHOP_FR_ID', trim($tsfrid));
|
2017-02-17 10:23:07 +01:00
|
|
|
Configuration::updateValue('TRUSTED_SHOP_ES_ID', trim($tsesid));
|
2017-02-02 13:00:59 +01:00
|
|
|
Configuration::updateValue('TRUSTED_SHOP_STATUS_WATCHED', $tssw);
|
|
|
|
Configuration::updateValue('TRUSTED_SHOP_PASSWORD', trim($tspassword));
|
|
|
|
Configuration::updateValue('TRUSTED_SHOP_USER', trim($tsuser));
|
|
|
|
Configuration::updateValue('TRUSTED_SHOP_DAYS', trim($tsdays));
|
|
|
|
$output .= '
|
|
|
|
<div class="conf confirm">
|
|
|
|
<img src="../img/admin/ok.gif" alt="" title="" />
|
|
|
|
' . $this->l('Settings updated') . '
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
return $output.$this->displayForm((int)($cookie->id_lang));
|
|
|
|
}
|
|
|
|
public function displayForm($id_lang)
|
|
|
|
{
|
|
|
|
$states = OrderState::getOrderStates($id_lang);
|
|
|
|
$output = '
|
|
|
|
<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
|
|
|
|
<fieldset class="width2">
|
|
|
|
<legend><img src="../img/admin/cog.gif" alt="" class="middle" />' . $this->l('Settings') . '</legend>
|
|
|
|
<label>' . $this->l('Your TSID FR') . '</label>
|
|
|
|
<div class="margin-form">
|
|
|
|
<input type="text" name="trusted_shop_fr_id" value="' . Tools::safeOutput(Tools::getValue('trusted_shop_fr_id', Configuration::get('TRUSTED_SHOP_FR_ID'))) . '" />
|
|
|
|
</div>
|
2017-02-17 10:23:07 +01:00
|
|
|
<label>' . $this->l('Your TSID ES') . '</label>
|
2017-02-02 13:00:59 +01:00
|
|
|
<div class="margin-form">
|
|
|
|
<input type="text" name="trusted_shop_es_id" value="' . Tools::safeOutput(Tools::getValue('trusted_shop_es_id', Configuration::get('TRUSTED_SHOP_ES_ID'))) . '" />
|
2017-02-17 10:23:07 +01:00
|
|
|
</div>
|
2017-02-02 13:00:59 +01:00
|
|
|
<label>' . $this->l('Your user name') . '</label>
|
|
|
|
<div class="margin-form">
|
|
|
|
<input type="text" name="trusted_shop_user" value="' . Tools::safeOutput(Tools::getValue('trusted_shop_user', Configuration::get('TRUSTED_SHOP_USER'))) . '" />
|
|
|
|
</div>
|
|
|
|
<label>' . $this->l('Your Password') . '</label>
|
|
|
|
<div class="margin-form">
|
|
|
|
<input type="text" name="trusted_shop_password" value="' . Tools::safeOutput(Tools::getValue('trusted_shop_password', Configuration::get('TRUSTED_SHOP_PASSWORD'))) . '" />
|
|
|
|
</div>
|
|
|
|
<label>' . $this->l('Days') . '</label>
|
|
|
|
<div class="margin-form">
|
|
|
|
<input type="text" name="trusted_shop_days" value="' . Tools::safeOutput(Tools::getValue('trusted_shop_days', Configuration::get('TRUSTED_SHOP_DAYS'))) . '" />
|
|
|
|
</div>
|
|
|
|
<div class="margin-form">
|
|
|
|
<select name="status_watched_id">';
|
|
|
|
foreach ($states AS $state) {
|
|
|
|
$output .= '<option value="' . $state['id_order_state'] . '"' . (($state['id_order_state'] == Configuration::get('TRUSTED_SHOP_STATUS_WATCHED')) ? ' selected="selected"' : '') . '>' . stripslashes($state['name']) . '</option>';
|
|
|
|
}
|
|
|
|
$output .= '</select>
|
|
|
|
<p class="clear">' . $this->l('The api call will be triggered when the order reach this status') . '</p>
|
|
|
|
</div>
|
|
|
|
<input type="submit" name="submitTrustedShop" value="' . $this->l('Update ID') . '" class="button" />
|
|
|
|
</fieldset>
|
|
|
|
</form>';
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
public function hookUpdateOrderStatus($params)
|
|
|
|
{
|
|
|
|
if (isset($params['newOrderStatus'])
|
|
|
|
&& Validate::isUnsignedId($params['newOrderStatus']->id)
|
|
|
|
&& FALSE !== Configuration::get('TRUSTED_SHOP_STATUS_WATCHED')
|
|
|
|
&& (int)Configuration::get('TRUSTED_SHOP_STATUS_WATCHED') == (int)$params['newOrderStatus']->id
|
|
|
|
){
|
|
|
|
$order = new Order((int)$params['id_order']);
|
2017-02-17 10:23:07 +01:00
|
|
|
if (in_array(strtoupper(Language::getIsoById($order->id_lang)), array("FR","ES"), true)) {
|
2017-02-02 13:00:59 +01:00
|
|
|
TrustedShopBbbAsync::saveOrUpdate((int)$order->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-24 14:20:53 +01:00
|
|
|
public function hookLeftColumn($params){
|
|
|
|
if(_PS_MOBILE_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
global $smarty, $cookie;
|
|
|
|
|
|
|
|
if (!($file = basename(Tools::getValue('controller')))) {
|
|
|
|
$file = str_replace('.php', '', basename($_SERVER['SCRIPT_NAME']));
|
|
|
|
}
|
|
|
|
if (!in_array($file, array('order-opc', 'order', 'orderopc'))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_id = (int)$cookie->id_lang.'_trustedshopsbbb_leftcolumn';
|
|
|
|
|
|
|
|
if (!$this->isTemplateCached($cache_id)) {
|
|
|
|
$resultArray = array();
|
|
|
|
if (in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR","ES"), true)) {
|
|
|
|
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$cookie->id_lang)) . '_ID');
|
|
|
|
$reviewIndicatorCollector = new ReviewIndicatorCollector((int)($cookie->id_lang));
|
|
|
|
$resultArray = $reviewIndicatorCollector->getResults();
|
|
|
|
}
|
|
|
|
if(count($resultArray)> 0 and (int)$resultArray['count'] > 0){
|
|
|
|
$smarty->assign(array(
|
|
|
|
'shopName' => $resultArray['shop_name'],
|
|
|
|
'result' => $resultArray['result'],
|
|
|
|
'max' => self::TS_BEST_RATING,
|
|
|
|
'count' => $resultArray['count'],
|
|
|
|
'tsId' => $tsId
|
|
|
|
));
|
|
|
|
return $this->display(__FILE__, 'views/rich_snippets_2.tpl');
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->flushTemplateCache($cache_id);
|
|
|
|
}
|
2017-02-02 13:00:59 +01:00
|
|
|
public function hookFooter($params){
|
|
|
|
global $smarty, $cookie;
|
2017-02-24 14:20:53 +01:00
|
|
|
if (!($file = basename(Tools::getValue('controller')))) {
|
|
|
|
$file = str_replace('.php', '', basename($_SERVER['SCRIPT_NAME']));
|
|
|
|
}
|
|
|
|
if (in_array($file, array('order-opc', 'order', 'orderopc'))) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-17 12:24:30 +01:00
|
|
|
|
|
|
|
$cache_id = (int)$cookie->id_lang.'_trustedshopsbbb';
|
|
|
|
|
|
|
|
if (!$this->isTemplateCached($cache_id)) {
|
|
|
|
$resultArray = array();
|
|
|
|
if (in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR","ES"), true)) {
|
2017-02-17 15:02:02 +01:00
|
|
|
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$cookie->id_lang)) . '_ID');
|
2017-02-17 12:24:30 +01:00
|
|
|
$reviewIndicatorCollector = new ReviewIndicatorCollector((int)($cookie->id_lang));
|
|
|
|
$resultArray = $reviewIndicatorCollector->getResults();
|
|
|
|
}
|
|
|
|
if(count($resultArray)> 0 and (int)$resultArray['count'] > 0){
|
|
|
|
$smarty->assign(array(
|
|
|
|
'shopName' => $resultArray['shop_name'],
|
|
|
|
'result' => $resultArray['result'],
|
|
|
|
'max' => self::TS_BEST_RATING,
|
|
|
|
'count' => $resultArray['count'],
|
2017-02-17 15:02:02 +01:00
|
|
|
'resultArray' => $resultArray,
|
|
|
|
'tsId' => $tsId
|
2017-02-17 12:24:30 +01:00
|
|
|
));
|
|
|
|
return $this->display(__FILE__, 'views/rich_snippets.tpl');
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-02 13:00:59 +01:00
|
|
|
}
|
2017-02-17 12:24:30 +01:00
|
|
|
return $this->flushTemplateCache($cache_id);
|
2017-02-02 13:00:59 +01:00
|
|
|
}
|
|
|
|
public function hookOrderConfirmation($params)
|
|
|
|
{
|
|
|
|
global $smarty, $cookie;
|
2017-02-17 10:23:07 +01:00
|
|
|
if (false && in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR","ES"), true)) {
|
2017-02-02 13:00:59 +01:00
|
|
|
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$cookie->id_lang)) . '_ID');
|
|
|
|
$smarty->assign(array('tsId' => $tsId,));
|
|
|
|
return $this->display(__FILE__, 'views/trust_badge_order_confirmation.tpl');
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-02-17 12:24:30 +01:00
|
|
|
|
|
|
|
private function isTemplateCached(&$cache_id)
|
|
|
|
{
|
|
|
|
global $smarty;
|
|
|
|
|
|
|
|
Tools::enableCache();
|
2017-02-17 12:58:11 +01:00
|
|
|
$smarty->cache_lifetime = 0;
|
2017-02-17 12:24:30 +01:00
|
|
|
|
|
|
|
return $this->isCached('rich_snippets.tpl', $cache_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function flushTemplateCache($cache_id)
|
|
|
|
{
|
|
|
|
global $smarty;
|
|
|
|
|
|
|
|
$display = $this->display(__FILE__, 'views/rich_snippets.tpl', $cache_id);
|
|
|
|
Tools::restoreCacheSettings();
|
|
|
|
$smarty->cache_lifetime = -1;
|
|
|
|
return $display;
|
|
|
|
}
|
2017-02-02 13:00:59 +01:00
|
|
|
}
|