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; } if (!Configuration::deleteByName('TRUSTED_SHOP_ES_ID')) { return FALSE; } 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 = '

Trusted Shop Configuration

'; 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'))) { Configuration::updateValue('TRUSTED_SHOP_FR_ID', trim($tsfrid)); Configuration::updateValue('TRUSTED_SHOP_ES_ID', trim($tsesid)); 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 .= '
' . $this->l('Settings updated') . '
'; } return $output.$this->displayForm((int)($cookie->id_lang)); } public function displayForm($id_lang) { $states = OrderState::getOrderStates($id_lang); $output = '
' . $this->l('Settings') . '

' . $this->l('The api call will be triggered when the order reach this status') . '

'; 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']); if (in_array(strtoupper(Language::getIsoById($order->id_lang)), array("FR","ES"), true)) { TrustedShopBbbAsync::saveOrUpdate((int)$order->id); } } } 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); } public function hookFooter($params){ 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'; 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'], 'resultArray' => $resultArray, 'tsId' => $tsId )); return $this->display(__FILE__, 'views/rich_snippets.tpl'); } else { return false; } } return $this->flushTemplateCache($cache_id); } public function hookOrderConfirmation($params) { global $smarty, $cookie; if (false && 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'); $smarty->assign(array('tsId' => $tsId,)); return $this->display(__FILE__, 'views/trust_badge_order_confirmation.tpl'); }else{ return false; } } private function isTemplateCached(&$cache_id) { global $smarty; Tools::enableCache(); $smarty->cache_lifetime = 0; 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; } }