Merge branch 'ticket-12272-TrustedShops' into develop

This commit is contained in:
Marion Muszynski 2017-02-03 17:06:45 +01:00
commit 878608ec79
16 changed files with 934 additions and 0 deletions

View File

@ -152,6 +152,9 @@ class Parcel {
if($this->product_type == 'BOM') {
$this->product_type = 'DOM';
}
if($so_data['cecountry'] == 'ES' && $this->product_type == 'DOM') {
$this->product_type = 'DOS';
}
if(!in_array($so_data['cecountry'], array('ES', 'BE', 'AD', 'MC', 'FR', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$this->product_type = 'DOS';
}

View File

@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7233 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;

View File

@ -0,0 +1,161 @@
<?php
class ReviewCollectorReview
{
public $reviewCollectorRequest;
private $id_lang;
const CHOSEN_VARIANT = 'CUSTOMER_SERVICE';
/**
* ReviewCollectorReview constructor.
* @param $order (can be an order object or an order id array)
* @param $id_lang
*/
public function __construct($order, $id_lang)
{
$this->reviewCollectorRequest = new ReviewCollectorRequest();
$this->id_lang = $id_lang;
if(is_array($order) && count($order) > 0){
foreach ($order as $order_id){
$current_processed_order = new Order((int)$order_id);
if (Validate::isLoadedObject($current_processed_order)) {
$this->addItem($current_processed_order);
}
}
}else{
if (Validate::isLoadedObject($order)) {
$this->addItem($order);
}
}
}
private function addItem($order){
$days = Configuration::get('TRUSTED_SHOP_DAYS');
$reviewCollectorReviewItem = new ReviewCollectorReviewItem();
$review_sent_date = new DateTime();
$review_sent_date->add(new DateInterval('P'.$days.'D')); //we add days
$reviewCollectorReviewItem->reminderDate = $review_sent_date->format("Y-m-d");
$reviewCollectorReviewItem->template = new ReviewCollectorReviewTemplate(self::CHOSEN_VARIANT, FALSE);
$reviewCollectorReviewItem->order = new ReviewCollectorReviewOrder($order, $this->id_lang);
$customer = new Customer((int)$order->id_customer);
$reviewCollectorReviewItem->consumer = new ReviewCollectorReviewConsumer($customer->firstname, $customer->lastname, $customer->email);
$this->reviewCollectorRequest->reviewCollectorReviewRequests[] = $reviewCollectorReviewItem;
}
public function generateRequest()
{
return json_encode($this);
}
}
class ReviewCollectorRequest{
public $reviewCollectorReviewRequests;
public function __construct()
{
$this->reviewCollectorReviewRequests = array();
}
}
class ReviewCollectorReviewItem
{
public $reminderDate;
public $template;
public $order;
public $consumer;
}
class ReviewCollectorReviewTemplate
{
public $variant; //The template variant might be either 'BEST_PRACTICE', 'CREATING_TRUST' or 'CUSTOMER_SERVICE'.
public $includeWidget = FALSE;
public function __construct($variant, $includeWidget)
{
$this->variant = $variant;
$this->includeWidget = $includeWidget;
}
}
class ReviewCollectorReviewOrder
{
const CURRENCY_NAME = 'EUR';
public $orderDate;
public $orderReference;
public $products;
public $currency;
public $estimatedDeliveryDate;
public function __construct(Order $order, $id_lang)
{
$order_date = new DateTime($order->date_add);
$this->orderDate = $order_date->format('Y-m-d');;
$this->orderReference = "".$order->id;
$this->currency = self::CURRENCY_NAME;
$estimated_delivery_date = new DateTime();
$estimated_delivery_date->add(new DateInterval('P8D')); //we add 8 days
$this->estimatedDeliveryDate = $estimated_delivery_date->format('Y-m-d');
$this->products = array();
foreach ($order->getProducts() as $row) {
$product = new ReviewCollectorReviewOrderProduct();
$presta_product = new Product((int)$row['product_id'], FALSE, $id_lang);
$link = new Link();
$product->name = $row['product_name'];
$product->sku = $row['product_supplier_reference'];
$product->gtin = $row['product_ean13'];
$product->mpn = $row['product_reference'];
$product->brand = ($presta_product->manufacturer_name ? $presta_product->manufacturer_name : "");
$product->imageUrl = $link->getImageLink(Tools::link_rewrite($presta_product->name),
$presta_product->id . '-' . Product::getCover($presta_product->id)['id_image'],
'large');
$product->uuid = "".$presta_product->id;
$product->url = $link->getProductLink($presta_product->id);
$this->products[] = $product;
}
}
}
class ReviewCollectorReviewOrderProduct
{
public $sku;
public $name;
public $gtin;
public $mpn;
public $brand;
public $imageUrl;
public $uuid;
public $url;
}
class ReviewCollectorReviewConsumer
{
public $firstname;
public $lastname;
public $contact;
public function __construct($firstname, $lastname, $email)
{
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->contact = new ReviewCollectorReviewConsumerContact($email);
}
}
class ReviewCollectorReviewConsumerContact
{
public $email;
public function __construct($email)
{
$this->email = $email;
}
}

View File

@ -0,0 +1,46 @@
<?php
class ReviewIndicatorCollector
{
private $id_lang;
public function __construct($id_lang)
{
$this->id_lang = $id_lang;
}
public function getResults()
{
$returnedArray = array();
$tsId = Configuration::get('TRUSTED_SHOP_' . strtoupper(Language::getIsoById((int)$this->id_lang)) . '_ID');
try{
if (FALSE === ($jsonResult = TrustedShopsCache::getReviewIndicatorCache($tsId))) {
$jsonResult = $this->getApiResult($tsId);
TrustedShopsCache::setReviewIndicatorCache($tsId, $jsonResult);
}
$jsonObject = json_decode($jsonResult,true);
$returnedArray['result'] = $jsonObject['response']['data']['shop']['qualityIndicators']['reviewIndicator']['overallMark'];
$returnedArray['count'] = $jsonObject['response']['data']['shop']['qualityIndicators']['reviewIndicator']['activeReviewCount'];
$returnedArray['shop_name'] = $jsonObject['response']['data']['shop']['name'];
}catch(Exception $ex){
Logger::AddLog("file ReviewIndicatorCollector.php - " .$ex->getMessage(), 4, '0000001', 'User', '0');
}
return $returnedArray;
}
private function getApiResult($ts_id)
{
$apiUrl = 'http://api.trustedshops.com/rest/public/v2/shops/' . $ts_id . '/quality/reviews.json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
$returnedJson = curl_exec($ch);
curl_close($ch);
return $returnedJson;
}
}

View File

@ -0,0 +1,173 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6626 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TrustedShopsAPI
{
/**
* Saved errors messages.
* @var array
*/
public $errors = array();
/**
* Saved logs messages.
* @var array
*/
public $logs = array();
/**
* API Response.
* @var array
*/
public $response;
const TRUSTED_SHOP_STATUS_OK = "SUCCESS";
const TRUSTED_SHOP_API_URL = "api.trustedshops.com/rest";
const TRUSTED_SHOP_REVIEW_COLLECTOR_PATH = "/restricted/v2/shops/{tsId}/reviewcollector";
const TRUSTED_SHOP_TOKEN = "{tsId}";
const TRUSTED_SHOP_CODE_OK = 200;
const TS_CALL_REVIEW_COLLECTOR = 'review_collector';
private $url = "";
private $tsid;
private $tsuser;
private $tspassword;
/**
* DOC : https://api.trustedshops.com/documentation/restricted/#!/review_collector/submitReviewCollectorRequest
* POST /restricted/v2/shops/{tsId}/reviewcollector
*/
public function __construct($options=array())
{
if(count($options)!=3){
$this->errors[] = 'Missing parameters';
$this->errors[] = 'Expecting $opt = array(';
$this->errors[] = ' \'tsid\' => "ID",';
$this->errors[] = ' \'tsuser\' => "USER",';
$this->errors[] = ' \'tspassword\' => "PASSWORD",';
$this->errors[] = ');';
}
$this->url = self::TRUSTED_SHOP_API_URL;
$options_keys = array_keys($options);
if(in_array('tsid',$options_keys)){
$this->tsid = $options['tsid'];
}else{
$this->errors[] = 'Missing parameter tsid';
}
if(in_array('tsuser',$options_keys)){
$this->tsuser = $options['tsuser'];
}else{
$this->errors[] = 'Missing parameter tsuser';
}
if(in_array('tspassword',$options_keys)){
$this->tspassword = $options['tspassword'];
}else{
$this->errors[] = 'Missing parameter tspassword';
}
$this->response = FALSE;
}
public function requestAPI($call, $order, $id_lang)
{
$this->response = FALSE;
if ($call == self::TS_CALL_REVIEW_COLLECTOR) {
$this->url .= str_replace(self::TRUSTED_SHOP_TOKEN, $this->tsid, self::TRUSTED_SHOP_REVIEW_COLLECTOR_PATH);
$reviewCollectorReview = new ReviewCollectorReview($order, $id_lang);
$this->response = $this->createGetRequest($reviewCollectorReview->generateRequest());
$this->response = json_decode($this->response)->response;
} else {
$this->errors[] = 'Connect failed with CURL method';
}
if(count($this->errors) > 0){
if(is_array($order) && count($order) > 0) {
Logger::AddLog("file TrustedShopsAPI.php - " .implode("-", $this->errors), 4, '0000001', 'Order', implode("-", $order));
}else{
Logger::AddLog("file TrustedShopsAPI.php - " .implode("-", $this->errors), 4, '0000001', 'Order', '0');
}
}else{
if (is_object($this->response)
&& $this->response->status == self::TRUSTED_SHOP_STATUS_OK
&& $this->response->code == self::TRUSTED_SHOP_CODE_OK )
{
return true;
}else{
if(is_array($order) && count($order) > 0) {
Logger::AddLog("file TrustedShopsAPI.php - " .implode("-", $this->errors), 4, '0000001', 'Order', implode("-", $order));
}else{
Logger::AddLog("file TrustedShopsAPI.php - " .implode("-", $this->errors), 4, '0000001', 'Order', '0');
}
}
}
}
private function createGetRequest($json_content)
{
$ch = @curl_init();
if (!$ch) {
$this->errors[] = 'Connect failed with CURL method';
} else {
$this->logs[] = 'Connect with CURL method successful';
$this->logs[] = '<b>' . 'Sending this params:' . '</b>';
$this->logs[] = $json_content;
$this->logs[] = $this->url;
@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
@curl_setopt($ch, CURLOPT_URL, 'https://' . $this->url);
@curl_setopt($ch, CURLOPT_POST, TRUE);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $json_content);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
@curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
@curl_setopt($ch, CURLOPT_HEADER, FALSE);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
@curl_setopt($ch, CURLOPT_TIMEOUT, 60);
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
@curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
@curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
@curl_setopt($ch, CURLOPT_USERPWD, $this->tsuser.":".$this->tspassword);
$result = @curl_exec($ch);
if (!$result) {
$this->errors[] = 'Send with CURL method failed ! Error:' . ' ' . curl_error($ch);
} else {
$this->logs[] = 'Send with CURL method successful';
}
@curl_close($ch);
return $result;
}
}
}

View File

@ -0,0 +1,22 @@
<?php
class TrustedShopsCache{
const CONTROLLER_NAME = 'TrustedShopsCache';
const TTL = 86400; //2 days
public static function getReviewIndicatorCache($tsId)
{
if(class_exists('CacheRedis')){
return CacheRedis::getInstance()->get($tsId, self::CONTROLLER_NAME);
}
}
public static function setReviewIndicatorCache($ts_id, $content)
{
if(class_exists('CacheRedis')){
return CacheRedis::getInstance()->set($ts_id,self::CONTROLLER_NAME,$content,self::TTL);
}
}
}

View File

@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7233 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;

BIN
modules/trustedshopsbbb/logo.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

View File

@ -0,0 +1,71 @@
<?php
class TrustedShopBbbAsync extends ObjectModel
{
public $id_order;
public $processed;
public $date_add;
public $date_upd;
protected $fieldsValidate = array(
'id_order' => 'isUnsignedId',
'processed' => 'isBool',
'date_add' => 'isDate',
'date_upd' => 'isDate',
);
public function getFields()
{
parent::validateFields();
$fields['id_order'] = (int)$this->id_order;
$fields['processed'] = (int)$this->processed;
$fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd);
return $fields;
}
protected $table = 'trustedshop_bbb_async';
protected $identifier = 'id_trustedshop_bbb_async';
/**
* Get Order To Process
* @return Array Order to process
*/
public static function getOrderToProcess()
{
return Db::getInstance()->ExecuteS('
SELECT tba.`id_order`, o.`id_lang`, l.`iso_code`
FROM `' . _DB_PREFIX_ . 'trustedshop_bbb_async` tba
JOIN `' . _DB_PREFIX_ . 'orders` o ON o.`id_order` = tba.`id_order`
JOIN `' . _DB_PREFIX_ . 'lang` l ON o.`id_lang` = l.`id_lang`
WHERE tba.`processed` = 0;
');
}
public static function saveOrUpdate($id_order, $processed = NULL)
{
$trustedShopBbbAsync = NULL;
if ($id_trustedshop_bbb_async = Db::getInstance()->getValue('
SELECT tba.`id_trustedshop_bbb_async`
FROM `' . _DB_PREFIX_ . 'trustedshop_bbb_async` tba
WHERE tba.`id_order` = ' . (int)$id_order)
) {
$trustedShopBbbAsync = new TrustedShopBbbAsync((int)$id_trustedshop_bbb_async);
} else {
$trustedShopBbbAsync = new TrustedShopBbbAsync();
$trustedShopBbbAsync->id_order = (int)$id_order;
}
if (isset($trustedShopBbbAsync)) {
if (isset($processed)) {
$trustedShopBbbAsync->processed = $processed;
}
$trustedShopBbbAsync->save();
}
}
}

View File

@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7233 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;

View File

@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7233 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;

View File

@ -0,0 +1,51 @@
<?php
// $_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
// $_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['HTTP_HOST'] = 'bebeboutik.local';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_PORT'] = 80;
global $protocol_content;
//include('../../../config/settings.inc.php');
include('../../../config/config.inc.php');
define('_PS_BASE_URL_', Tools::getShopDomain(true));
$protocol_content = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
include(dirname(__FILE__) . '/../trustedshopsbbb.php');
$module_instance = new trustedshopsbbb();
if ($module_instance->active) {
$orders = array();
//We create 2 arrays containing the orders id related to each language
$orders["fr"] = array();
//$orders["es"] = array();
foreach (TrustedShopBbbAsync::getOrderToProcess() as $orderToProcess){
/* @Todo add ES when api key for ES */
if ($orderToProcess['id_order'] != 0 && in_array($orderToProcess['iso_code'], array('fr'), TRUE)) {
$orders[$orderToProcess['iso_code']][] = (int)$orderToProcess['id_order'];
}
}
//we treat each locale
foreach ($orders as $orderKey => $orderValues) {
$opt = array(
'tsid' => Configuration::get('TRUSTED_SHOP_' . strtoupper($orderKey) . '_ID'),
'tsuser' => Configuration::get('TRUSTED_SHOP_USER'),
'tspassword' => Configuration::get('TRUSTED_SHOP_PASSWORD'),
);
$trustedShopsAPI = new TrustedShopsAPI($opt);
$id_code = Language::getIdByIso($orderKey);
$tmpOrderValues = $orderValues;
if($trustedShopsAPI->requestAPI(TrustedShopsAPI::TS_CALL_REVIEW_COLLECTOR, $orderValues, $id_code))
{
foreach ($tmpOrderValues as $updatedOrderId){
TrustedShopBbbAsync::saveOrUpdate($updatedOrderId,true);
}
}
}
}

View File

@ -0,0 +1,187 @@
<?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;
}
// 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 = '<h2>Trusted Shop Configuration</h2>';
if (Tools::isSubmit('submitTrustedShop') AND ($tsfrid = Tools::getValue('trusted_shop_fr_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 .= '
<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>
<!--label>' . $this->l('Your TSID ES') . '</label>
<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'))) . '" />
</div-->
<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']);
/* @Todo add ES when api key for ES */
if (in_array(strtoupper(Language::getIsoById($order->id_lang)), array("FR"), true)) {
TrustedShopBbbAsync::saveOrUpdate((int)$order->id);
}
}
}
public function hookFooter($params){
global $smarty, $cookie;
$resultArray = array();
/* @Todo add ES when api key for ES */
if (in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR"), true)) {
$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'],
));
return $this->display(__FILE__, 'views/rich_snippets.tpl');
}else{
return false;
}
}
public function hookOrderConfirmation($params)
{
global $smarty, $cookie;
/* @Todo add ES when api key for ES */
if (false && in_array(strtoupper(Language::getIsoById($cookie->id_lang)), array("FR"), 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;
}
}
}

View File

@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7233 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;

View File

@ -0,0 +1,15 @@
<script type="application/ld+json">
{literal}
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
"name": "{/literal}{$shopName}{literal}",
"aggregateRating" : {
"@type": "AggregateRating",
"ratingValue" : "{/literal}{$result}{literal}",
"bestRating" : "{/literal}{$max}{literal}",
"ratingCount" : "{/literal}{$count}{literal}"
}
}
{/literal}
</script>

View File

@ -0,0 +1,25 @@
<div id="customCheckoutDiv"></div>
<script type="text/javascript">
{literal}(function () {
var _tsid = '{/literal}{$tsId}{literal}';
_tsConfig = {
'yOffset': '0', /* offset from page bottom /
'variant': 'custom_reviews', / text, default, small, reviews, custom, custom_reviews /
'customElementId': 'trustedshop', / required for variants custom and custom_reviews /
'trustcardDirection': '', / for custom variants: topRight, topLeft, bottomRight, bottomLeft /
'customBadgeWidth': '', / for custom variants: 40 - 90 (in pixels) /
'customBadgeHeight': '70', / for custom variants: 40 - 90 (in pixels) /
'disableResponsive': 'false', / deactivate responsive behaviour /
'disableTrustbadge': 'false', / deactivate trustbadge */
'customCheckoutElementId': 'customCheckoutDiv'
};
var _ts = document.createElement('script');
_ts.type = 'text/javascript';
_ts.charset = 'utf-8';
_ts.async = true;
_ts.src = '//widgets.trustedshops.com/js/' + _tsid + '.js';
var __ts = document.getElementsByTagName('script')[0];
__ts.parentNode.insertBefore(_ts, __ts);
})();
{/literal}
</script>