Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,141 @@
<?php
/**
* 2007-2019 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-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PaypalPPBTlib;
abstract class AbstractMethod
{
/** @var string module name */
public $name = 'paypal';
// Force les classes filles à définir cette méthode
/** @var string payment method */
protected $payment_method;
/** @var array An array of transaction information : method, currency, transaction_id, payment_status, payment_method, id_payment, capture, payment_tool, date_transaction. */
protected $transaction_detail = array();
/** @return string*/
protected function getPaymentMethod()
{
if ((int)\Configuration::get('PAYPAL_SANDBOX')) {
return $this->payment_method . ' - SANDBOX';
} else {
return $this->payment_method;
}
}
/**
* Init payment method
* @return string|array
*/
abstract public function init();
/**
* Validate payment
* @return Exception
*/
abstract public function validation();
/**
* Capture authorized transaction
* @param $orderPayPal PaypalOrder object
* @return array|Exception
*/
abstract public function confirmCapture($orderPayPal);
/**
* Refund settled transaction
* @param $orderPayPal PaypalOrder object
* @return mixed
*/
abstract public function refund($orderPayPal);
/**
* Update configuration (postProcess)
* @param $params array
* @return mixed
*/
abstract public function setConfig($params);
/**
* Generate getContent
* @param Paypal $module
* @return mixed
*/
abstract public function getConfig(\Paypal $module);
/**
* Void authorized transaction (cancel payment)
* @param $orderPayPal PaypalOrder object
* @return mixed
*/
abstract public function void($orderPayPal);
/**
* @param $params array hookActionOrderSlipAdd parameters
* @return mixed
*/
abstract public function partialRefund($params);
/**
* @param string $method method alias like BT, EC, PPP
* @return stdClass Method class
*/
public static function load($method)
{
if (preg_match('/^[a-zA-Z0-9_-]+$/', $method) && file_exists(_PS_MODULE_DIR_.'paypal/classes/Method'.$method.'.php')) {
include_once _PS_MODULE_DIR_.'paypal/classes/Method'.$method.'.php';
$method_class = 'Method'.$method;
return new $method_class();
}
}
/**
* Get Transaction details for order
* @return array
*/
public function getDetailsTransaction()
{
return $this->transaction_detail;
}
/**
* Get Transaction details for order
* @param object $transaction
* @return array
*/
abstract function setDetailsTransaction($transaction);
/**
* Get link to transaction
* @param string $id_transaction
* @param bool $sandbox mode (sandbox/live)
* @return string
*/
abstract public function getLinkToTransaction($id_transaction, $sandbox);
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* 2007-2019 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-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PaypalPPBTlib;
use \ModuleFrontController;
use Symfony\Component\HttpFoundation\JsonResponse;
use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerHandler;
abstract class CommonAbstarctModuleFrontController extends ModuleFrontController
{
/** @var string module name */
public $name = 'paypal';
/** @var array Contain ajax response. */
public $jsonValues;
/** @var array POST and GET values defined in init function */
public $values;
/** @var string Contain redirect URL.. */
public $redirectUrl;
/** @var array An array of error information : error_msg, error_code, msg_long. */
public $errors;
/** @var array An array of transaction information : method, currency, transaction_id, payment_status, payment_method, id_payment, capture, payment_tool, date_transaction. */
public $transaction_detail = array();
/**
* @see ModuleFrontController::run
*/
public function run()
{
$this->init();
if ($this->checkAccess()) {
// postProcess handles ajaxProcess
$this->postProcess();
}
if (empty($this->errors) == false) {
$message = '';
if (isset($this->errors['error_code'])) {
$message .= 'Error code: ' . $this->errors['error_code'] . '.';
}
if (isset($this->errors['error_msg']) && $this->errors['error_msg']) {
$message .= 'Short message: ' . $this->errors['error_msg'] . '.';
}
if (isset($this->errors['msg_long']) && $this->errors['msg_long']) {
$message .= 'Long message: ' . $this->errors['msg_long'] . '.';
}
ProcessLoggerHandler::openLogger();
ProcessLoggerHandler::logError(
$message,
null,
isset($this->transaction_detail['payment_tool']) && $this->transaction_detail['payment_tool'] ? $this->transaction_detail['payment_tool'] : 'Paypal',
\Context::getContext()->cart->id,
\Context::getContext()->shop->id,
isset($this->transaction_detail['transaction_id']) ? $this->transaction_detail['transaction_id'] : null,
(int)\Configuration::get('PAYPAL_SANDBOX'),
isset($this->transaction_detail['date_transaction']) ? $this->transaction_detail['date_transaction'] : null
);
ProcessLoggerHandler::closeLogger();
}
if (!empty($this->redirectUrl)) {
\Tools::redirect($this->redirectUrl);
}
if (!empty($this->jsonValues)) {
$response = new JsonResponse($this->jsonValues);
return $response->send();
}
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Db;
class DbSchema
{
/**
* @var PaypalPPBTlib\Db\ObjectModelDefinition
*/
protected $def;
/**
* Table (internal) ID
*
* @var string
*/
protected $id;
/**
* Register PaypalPPBTlib\Db\ObjectModelDefinition and table (internal) ID
* @param PaypalPPBTlib\Db\ObjectModelDefinition $def
* @param string $id
*/
public function __construct($def, $id)
{
$this->def = $def;
$this->id = $id;
}
/**
* Map table properties
* @param PaypalPPBTlib\Db\DbTable $table
* @return PaypalPPBTlib\Db\DbTable
*/
public function map($table)
{
return $table
->setName($this->def->getName($this->id))
->setEngine($this->def->getEngine($this->id))
->setCharset($this->def->getCharset($this->id))
->setCollation($this->def->getCollation($this->id))
->setColumns($this->def->getColumns($this->id))
->setKeyPrimary($this->def->getKeyPrimary($this->id))
->setKeysSimple($this->def->getKeysSimple($this->id))
->setKeysUnique($this->def->getKeysUnique($this->id))
->setKeysFulltext($this->def->getKeysFulltext($this->id))
// @todo: fix foreign key with lang table not InnoDb
//->setKeysForeign($this->def->getKeysForeign($this->id))
;
}
}

View File

@@ -0,0 +1,387 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Db;
use \Tools;
class DbTable
{
/**
* Key identifiers.
*
* @var int
*/
const PRIMARY = 1;
const FOREIGN = 2;
const UNIQUE = 3;
const FULLTEXT = 4;
/** @var Db */
protected $db;
/** @var string */
protected $name;
/** @var string */
protected $engine;
/** @var string */
protected $charset;
/** @var string */
protected $collation;
/** @var array */
protected $columns;
/** @var array */
protected $schema;
/** @var array */
protected $keys;
/**
* Register Db
* @param Db $db
*/
public function __construct($db)
{
$this->db = $db;
}
/**
* Hydrate properties
* @param PaypalPPBTlib\Db\DbSchema $schema
* @return PaypalPPBTlib\Db\DbTable
*/
public function hydrate($schema)
{
$this->schema = $schema;
return $schema->map($this);
}
/**
* Create table
* @return bool
*/
public function create()
{
$tableExists = $this->db->executeS("SHOW TABLES LIKE '$this->name'");
if ($tableExists == false) {
$keys = array();
foreach ($this->keys as $modelDef) {
if (strpos($modelDef, 'FOREIGN KEY') === 0) {
continue;
}
$keys[] = $modelDef;
}
$result = $this->db->execute("CREATE TABLE IF NOT EXISTS `$this->name` (".
implode(', ', array_merge($this->columns, $keys)).
") ENGINE=$this->engine CHARSET=$this->charset COLLATE=$this->collation;");
if ($result == true) {
$this->alterKeys();
}
return $result;
}
// table exists
$alter = $this->alterFields();
if (!empty($alter)) {
return $this->db->execute($alter);
}
$this->alterKeys();
return true;
}
/**
* Alter table fields
* @return string
*/
private function alterFields()
{
$describe = $this->db->executeS("SHOW COLUMNS FROM `$this->name`");
foreach ($describe as $key => $col) {
$describe[$key]['modelDef'] = '`'.$col['Field'].'` '.Tools::strtoupper($col['Type']).' ';
if ('NO' === $col['Null']) {
$describe[$key]['modelDef'] .= 'NOT NULL ';
}
if (false === empty($col['Extra'])) {
$describe[$key]['modelDef'] .= Tools::strtoupper($col['Extra']);
}
}
$alterToSkip = array();
$alterToExecute = array();
$alters = array();
foreach ($this->columns as $key => $column) {
foreach ($describe as $col) {
if (trim($column) === trim($col['modelDef'])) {
$alterToSkip[$key] = true;
} elseif (false !== strpos($column, '`' . $col['Field'] . '`')) {
$alterToExecute[$key] = 'MODIFY';
$alters[$key] = "ALTER TABLE `$this->name` MODIFY $column;";
}
}
if (empty($alterToExecute[$key]) && empty($alterToSkip[$key])) {
$alterToExecute[$key]['action'] = 'ADD '.$column;
$alters[$key] = "ALTER TABLE `$this->name` ADD $column;";
}
}
return implode("\r\n", $alters);
}
/**
* Alter table keys
* @return string
*/
private function alterKeys()
{
$describe = $this->db->executeS("SHOW KEYS FROM `$this->name`");
foreach ($describe as $k => $key) {
if ($key['Key_name'] != 'PRIMARY') {
try {
$this->db->execute("ALTER TABLE `$this->name` DROP KEY `".$key['Key_name']."`; ");
} catch (\Exception $e) {
continue;
}
}
}
if (version_compare(_PS_VERSION_, '1.7', '>')) {
$i = 0;
foreach ($this->keys as $modelDef) {
if (strpos($modelDef, 'FOREIGN KEY') === 0) {
$i++;
try {
$this->db->execute("ALTER TABLE `$this->name` DROP FOREIGN KEY `".$this->name . "_ibfk_$i`;");
} catch (\Exception $e) {
continue;
}
}
}
}
foreach ($this->keys as $modelDef) {
if (strpos($modelDef, 'PRIMARY KEY') === 0) {
continue;
}
try {
if (strpos($modelDef, 'FOREIGN KEY') === 0 && version_compare(_PS_VERSION_, '1.7', '<')) {
continue;
}
$this->db->execute("ALTER TABLE `$this->name` ADD ".$modelDef.";");
} catch (\Exception $e) {
continue;
}
}
return true;
}
/**
* Drop table
* @return bool
*/
public function drop()
{
return $this->db->execute("DROP TABLE IF EXISTS `$this->name`;");
}
/**
* @param string $name
* @return PaypalPPBTlib\Db\DbTable
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @param string $engine
* @return PaypalPPBTlib\Db\DbTable
*/
public function setEngine($engine)
{
$this->engine = $engine;
return $this;
}
/**
* @param string $charset
* @return PaypalPPBTlib\Db\DbTable
*/
public function setCharset($charset)
{
$this->charset = $charset;
return $this;
}
/**
* @param string $collation
* @return PaypalPPBTlib\Db\DbTable
*/
public function setCollation($collation)
{
$this->collation = $collation;
return $this;
}
/**
* @param array $columns
* @return PaypalPPBTlib\Db\DbTable
*/
public function setColumns($columns)
{
$this->columns = $columns;
return $this;
}
/**
* @param array $columns
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeyPrimary($columns)
{
return $this->setKey($columns, static::PRIMARY);
}
/**
* @param array $keys
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeysForeign($keys)
{
foreach ($keys as $columns) {
$this->setKeyForeign($columns);
}
return $this;
}
/**
* @param array $columns
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeyForeign($columns)
{
return $this->setKey($columns, static::FOREIGN);
}
/**
* @param array $keys
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeysUnique($keys)
{
return $this->setKeyUnique(array_keys($keys));
}
/**
* @param array $columns
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeyUnique($columns)
{
return $this->setKey($columns, static::UNIQUE);
}
/**
* @param array $keys
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeysFulltext($keys)
{
return $this->setKeyFulltext(array_keys($keys));
}
/**
* @param array $columns
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeyFulltext($columns)
{
return $this->setKey($columns, static::FULLTEXT);
}
/**
* @param array $keys
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeysSimple($keys)
{
return $this->setKeySimple(array_keys($keys));
}
/**
* @param array $columns
* @return PaypalPPBTlib\Db\DbTable
*/
public function setKeySimple($columns)
{
return $this->setKey($columns);
}
/**
* @param array $columns
* @param int|null $type
* @return PaypalPPBTlib\Db\DbTable
*/
protected function setKey($columns, $type = null)
{
// Empty columns may be returned by `array_filter`s.
if (empty($columns)) {
return $this;
}
$name = implode('_', $columns);
$columns = implode('`, `', $columns);
switch ($type) {
case static::PRIMARY:
$this->keys[] = "PRIMARY KEY (`$columns`)";
break;
case static::FOREIGN:
list($table, $columns) = explode('.', $name);
$this->keys[] = "FOREIGN KEY (`$columns`) REFERENCES $table (`$columns`)
ON UPDATE CASCADE ON DELETE CASCADE";
break;
case static::UNIQUE:
$this->keys[] = "UNIQUE KEY (`$columns`)";
break;
case static::FULLTEXT:
$this->keys[] = "FULLTEXT KEY (`$columns`)";
break;
default:
$this->keys[] = "KEY (`$columns`)";
break;
}
return $this;
}
}

View File

@@ -0,0 +1,284 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Db;
use PaypalPPBTlib\Db\ObjectModelDefinition;
use PaypalPPBTlib\Db\DbTableDefinitionRelation;
use \ObjectModel;
class DbTableDefinitionModel
{
/**
* Internal ID.
*/
const ID = 'm';
/**
* @var PaypalPPBTlib\Db\ObjectModelDefinition
*/
protected $def;
/**
* Register PaypalPPBTlib\Db\ObjectModelDefinition
* @param PaypalPPBTlib\Db\ObjectModelDefinition $def
*/
public function __construct($def)
{
$this->def = $def;
}
/**
* @return string
*/
public function getName()
{
return ObjectModelDefinition::DB_PREFIX . $this->def->get('table');
}
/**
* @return string
*/
public function getPrimary()
{
return $this->def->get('primary');
}
/**
* @return string
*/
public function getEngine()
{
return !empty($this->def->get('engine')) ? $this->def->get('engine') : ObjectModelDefinition::ENGINE;
}
/**
* @return string
*/
public function getCharset()
{
return !empty($this->def->get('charset')) ?
$this->def->get('charset') : ObjectModelDefinition::CHARSET;
}
/**
* @return string
*/
public function getCollation()
{
return !empty($this->def->get('collation')) ?
$this->def->get('collation') : ObjectModelDefinition::COLLATION;
}
/**
* @return array
*/
public function getColumns()
{
return $this->def->getColumnsFromFields(
$this->getFields()
);
}
/**
* @return array
*/
public function getKeyPrimary()
{
return array(
$this->getPrimary()
);
}
/**
* @return array
*/
public function getKeysForeign()
{
$ids = $this->def->getIdsSingleRelations();
$relations = $this->def->getRelations($ids);
return array_map(function (DbTableDefinitionRelation $relation) {
return array("{$relation->getName()}.{$relation->getPrimary()}");
}, $relations);
}
/**
* @return array
*/
public function getKeysSimple()
{
return array_filter(
$this->getFieldsCommon(),
array(
$this->def,
'isFieldSimpleKey'
)
);
}
/**
* @return array
*/
public function getKeysUnique()
{
return array_filter(
$this->getFieldsCommon(),
array(
$this->def,
'isFieldUniqueKey'
)
);
}
/**
* @return array
*/
public function getKeysFulltext()
{
return array_filter(
$this->getFieldsCommon(),
array(
$this->def,
'isFieldFulltextKey'
)
);
}
/**
* @param string $relation
* @return bool
*/
public function has($relation)
{
switch ($relation) {
case DbTableDefinitionRelation::ID_LANG:
return $this->def->get('multilang');
case DbTableDefinitionRelation::ID_SHOP:
return $this->def->get('multishop');
default:
return isset($this->def->get('associations')[$relation]);
}
}
/**
* @param string $relation
* @return bool
*/
public function hasMany($relation)
{
return $this->has($relation)
&& ObjectModel::HAS_MANY === $this->def->getRelation($relation)->getType();
}
/**
* @param string $relation
* @return bool
*/
public function hasSingle($relation)
{
return $this->has($relation)
&& ObjectModel::HAS_ONE === $this->def->getRelation($relation)->getType();
}
/**
* @return array
*/
protected function getFields()
{
return array_merge(
$this->getFieldPrimary(),
$this->getFieldsCommon()
);
}
/**
* @return array
*/
protected function getFieldPrimary()
{
return array(
$this->getPrimary() => ObjectModelDefinition::PRIMARY_KEY_FIELD
);
}
/**
* @return array
*/
protected function getFieldsCommon()
{
return array_filter(
$this->def->get('fields'),
array(
$this,
'hasField'
)
);
}
/**
* Wether or not this table has a given field
* @param array $field
* @return bool
*/
protected function hasField($field)
{
return !$this->isFieldMultilang($field)
&& !$this->isFieldMultishop($field)
|| $this->isFieldMultishopShared($field);
}
/**
* Wether or not given field is multilang
* @param array $field
* @return bool
*/
protected function isFieldMultilang($field)
{
return !empty($field['lang']);
}
/**
* Wether or not given field is multishop
* @param array $field
* @return bool
*/
protected function isFieldMultishop($field)
{
return !empty($field['shop']);
}
/**
* Wether or not given multishop field is shared with this table
* @param array $field
* @return bool
*/
protected function isFieldMultishopShared($field)
{
return !empty($field['shop'])
&& 'both' === $field['shop'];
}
}

View File

@@ -0,0 +1,385 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Db;
use PaypalPPBTlib\Db\ObjectModelDefinition;
use PaypalPPBTlib\Db\DbTableDefinitionRelation;
use \ObjectModel;
class DbTableDefinitionRelation
{
/**
* Internal IDs.
*/
const ID_LANG = 'l';
const ID_SHOP = 's';
/**
* Internal table ID.
*
* @var string
*/
protected $id;
/**
* @var paypalObjectModelDefinition
*/
protected $def;
/**
* Register paypalObjectModelDefinition and the internal ID
* @param paypalObjectModelDefinition $def
* @param string $id
*/
public function __construct($def, $id)
{
$this->id = $id;
$this->def = $def;
}
/**
* Get key value from paypalObjectModel::$definition['associations'][$this->id]
* @param string $key
* @return array|null
*/
public function get($key)
{
switch ($key) {
case 'fields':
return isset($this->def->get('associations')[$this->id][$key]) ?
$this->def->get('associations')[$this->id][$key] : array();
default:
return isset($this->def->get('associations')[$this->id][$key]) ?
$this->def->get('associations')[$this->id][$key] : null;
}
}
/**
* @return string
*/
public function getName()
{
switch ($this->id) {
case static::ID_LANG:
return $this->def->getModel()->getName().'_lang';
case static::ID_SHOP:
return $this->def->getModel()->getName().'_shop';
default:
return ObjectModelDefinition::DB_PREFIX.$this->get('association');
}
}
/**
* @return string
*/
public function getPrimary()
{
switch ($this->id) {
case static::ID_LANG:
return 'id_lang';
case static::ID_SHOP:
return 'id_shop';
default:
return (string)$this->get('field');
}
}
/**
* @return string
*/
public function getEngine()
{
return !empty($this->get('engine')) ? (string)$this->get('engine') : ObjectModelDefinition::ENGINE;
}
/**
* @return string
*/
public function getCharset()
{
return !empty($this->get('charset')) ? (string)$this->get('charset') : ObjectModelDefinition::CHARSET;
}
/**
* @return string
*/
public function getCollation()
{
return !empty($this->get('collation')) ?
(string)$this->get('collation') : ObjectModelDefinition::COLLATION;
}
/**
* @return array
*/
public function getColumns()
{
return $this->def->getColumnsFromFields(
$this->getFields()
);
}
/**
* @return array
*/
public function getKeyPrimary()
{
$primary = array(
$this->def->getModel()->getPrimary(),
$this->getPrimary(),
);
if ($this->hasMany('shop')) {
$primary[] = 'id_shop';
}
if ($this->hasMany('lang')) {
$primary[] = 'id_lang';
}
return $primary;
}
/**
* @return array
*/
public function getKeysForeign()
{
$model_table_1 = $this->def->getModel()->getName();
$model_primary_1 = $this->def->getModel()->getPrimary();
$model_table_2 = $this->getForeignTable();
$model_primary_2 = $this->getPrimary();
$foreign = array(
array("$model_table_1.$model_primary_1"),
array("$model_table_2.$model_primary_2"),
);
if ($this->hasMany('shop')) {
$foreign[] = array(_DB_PREFIX_.'shop.id_shop');
}
if ($this->hasMany('lang')) {
$foreign[] = array(_DB_PREFIX_.'lang.id_lang');
}
return $foreign;
}
/**
* @return array
*/
public function getKeysSimple()
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
case DbTableDefinitionRelation::ID_SHOP:
return array();
default:
return array_filter(
$this->get('fields'),
array(
$this->def,
'isFieldSimpleKey'
)
);
}
}
/**
* @return array
*/
public function getKeysUnique()
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
case DbTableDefinitionRelation::ID_SHOP:
return array();
default:
return array_filter(
$this->getFieldsCommon(),
array(
$this->def,
'isFieldUniqueKey'
)
);
}
}
/**
* @return array
*/
public function getKeysFulltext()
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
case DbTableDefinitionRelation::ID_SHOP:
return array();
default:
return array_filter(
$this->getFieldsCommon(),
array(
$this->def,
'isFieldFulltextKey'
)
);
}
}
/**
* @return int
*/
public function getType()
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
case DbTableDefinitionRelation::ID_SHOP:
return ObjectModel::HAS_MANY;
default:
return (int)$this->get('type');
}
}
/**
* Get relation fields
* @return array
*/
protected function getFields()
{
return array_merge(
$this->getFieldsPrimary(),
$this->getFieldsCommon()
);
}
/**
* Get relation primary fields
* @return array
*/
protected function getFieldsPrimary()
{
$fields = array(
$this->def->getModel()->getPrimary() => ObjectModelDefinition::KEY_FIELD,
$this->getPrimary() => ObjectModelDefinition::KEY_FIELD,
);
if ($this->hasMany('shop')) {
$fields['id_shop'] = ObjectModelDefinition::KEY_FIELD;
}
if ($this->hasMany('lang')) {
$fields['id_lang'] = ObjectModelDefinition::KEY_FIELD;
}
return $fields;
}
/**
* Get relation common fields
* @return array
*/
protected function getFieldsCommon()
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
case DbTableDefinitionRelation::ID_SHOP:
return array_filter(
$this->def->get('fields'),
array(
$this,
'hasField'
),
ARRAY_FILTER_USE_BOTH
);
default:
return $this->get('fields');
}
}
/**
* Get relation foreign table
* @return string
*/
protected function getForeignTable()
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
return _DB_PREFIX_ . 'lang';
case DbTableDefinitionRelation::ID_SHOP:
return _DB_PREFIX_ . 'shop';
default:
return _DB_PREFIX_ . $this->getForeignModelTableName();
}
}
/**
* Get table name of foreign relation model
* @return string
*/
protected function getForeignModelTableName()
{
/** @var \ObjectModel $class */
$class = $this->get('object');
$classDefinition = $class::$definition; //static definition \ObjectModel named $class
return $classDefinition['table'];
}
/**
* Wether or not this table has a 'OneToMany' relation
* @param string $relation
* @return bool
*/
protected function hasMany($relation)
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
return !empty($this->def->get("multilang_$relation"));
default:
return !empty($this->get("multi$relation"));
}
}
/**
* Wether or not this table has a given field
* @param array $field
* @param string $name
* @return bool
*/
protected function hasField($field, $name)
{
switch ($this->id) {
case DbTableDefinitionRelation::ID_LANG:
return !empty($field['lang']);
case DbTableDefinitionRelation::ID_SHOP:
return !empty($field['shop']);
default:
return isset($this->get('fields')[$name]);
}
}
}

View File

@@ -0,0 +1,504 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Db;
use PaypalPPBTlib\Db\DbTableDefinitionModel;
use PaypalPPBTlib\Db\DbTableDefinitionRelation;
use PaypalPPBTlib\Db\DbSchema;
use \ObjectModel;
use \Tools;
class ObjectModelDefinition
{
/**
* Defaults.
*/
const CHARSET = 'utf8';
const COLLATION = 'DEFAULT';
const ENGINE = _MYSQL_ENGINE_;
const DB_PREFIX = _DB_PREFIX_;
/**
* Primary key field description.
*/
const PRIMARY_KEY_FIELD = array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedId',
'required' => true,
'primary' => true,
);
/**
* (Simple) Key field description.
*/
const KEY_FIELD = array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedId',
'required' => true,
);
/**
* ObjectModel::$definition.
*
* @var array
*/
protected $def;
/**
* @var DbTableDefinitionModel
*/
protected $model;
/**
* @var array of PaypalPPBTlib\Db\DbTableDefinitionRelation
*/
protected $relations;
/**
* Register ObjectModel::$definition as a collection data source
* @param array $def
*/
public function __construct($def)
{
$this->def = $def;
// Prestashop doesn't define shop association when fetching definition.
if ($this->get('multishop')) {
$this->def['associations'][DbTableDefinitionRelation::ID_SHOP] = array(
'type' => ObjectModel::HAS_MANY,
'field' => $this->get('primary'),
);
}
}
/**
* @param string $key
* @return array|bool|mixed|null
*/
public function get($key)
{
switch ($key) {
case 'table':
case 'primary':
return $this->def[$key];
case 'fields':
case 'associations':
return isset($this->def[$key]) ? $this->def[$key] : array();
case 'multilang':
case 'multilang_shop':
case 'multishop':
return isset($this->def[$key]) ? $this->def[$key] : false;
default:
return isset($this->def[$key]) ? $this->def[$key] : null;
}
}
/**
* @return array
*/
public function getSchemas()
{
return array_map(
array(
$this,
'getSchema'
),
$this->getIds()
);
}
/**
* @param string $id
* @return PaypalPPBTlib\Db\DbSchema
*/
public function getSchema($id)
{
return new DbSchema($this, $id);
}
/**
* @return DbTableDefinitionModel
*/
public function getModel()
{
return isset($this->model) ? $this->model : $this->model = new DbTableDefinitionModel($this);
}
/**
* @param array $ids
* @return array
*/
public function getRelations($ids)
{
return array_map(
array(
$this,
'getRelation'
),
$ids
);
}
/**
* @param string $id
* @return PaypalPPBTlib\Db\DbTableDefinitionRelation
*/
public function getRelation($id)
{
return isset($this->relations[$id]) ?
$this->relations[$id] : $this->relations[$id] = new DbTableDefinitionRelation($this, $id);
}
/**
* @return array
*/
public function getIds()
{
return array_unique(array_merge(
array($this->getIdModel()),
$this->getIdsMultiRelations()
));
}
/**
* @return string
*/
public function getIdModel()
{
return DbTableDefinitionModel::ID;
}
/**
* @param int|null $type
* @return array
*/
public function getIdsRelations($type = null)
{
switch ($type) {
// OneToOne and ManyToOne.
case ObjectModel::HAS_ONE:
return array_filter(
$this->getIdsRelations(),
array(
$this->getModel(),
'hasSingle'
)
);
// ManyToMany.
case ObjectModel::HAS_MANY:
return array_filter(
$this->getIdsRelations(),
array(
$this->getModel(),
'hasMany'
)
);
// All potential relations.
default:
return array_merge(
array(
DbTableDefinitionRelation::ID_LANG,
DbTableDefinitionRelation::ID_SHOP
),
array_keys($this->get('associations'))
);
}
}
/**
* @return array
*/
public function getIdsMultiRelations()
{
return $this->getIdsRelations(ObjectModel::HAS_MANY);
}
/**
* @return array
*/
public function getIdsSingleRelations()
{
return $this->getIdsRelations(ObjectModel::HAS_ONE);
}
/**
* @return array
*/
public function getNames()
{
return array_map(
array(
$this,
'getName'
),
$this->getIds()
);
}
/**
* @param string $id
* @return string
*/
public function getName($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getName();
default:
return $this->getRelation($id)->getName();
}
}
/**
* @param string $id
* @return string
*/
public function getEngine($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getEngine();
default:
return $this->getRelation($id)->getEngine();
}
}
/**
* @param string $id
* @return string
*/
public function getCharset($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getCharset();
default:
return $this->getRelation($id)->getCharset();
}
}
/**
* @param string $id
* @return string
*/
public function getCollation($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getCollation();
default:
return $this->getRelation($id)->getCollation();
}
}
/**
* @param string $id
* @return array
*/
public function getColumns($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getColumns();
default:
return $this->getRelation($id)->getColumns();
}
}
/**
* @param array $fields
* @return array
*/
public function getColumnsFromFields($fields)
{
return array_map(
array(
$this,
'getColumnFromField'
),
array_keys($fields),
$fields
);
}
/**
* @param string $name
* @param array $constraints
* @return string
* @throws \PrestaShopException
*/
public function getColumnFromField($name, $constraints)
{
$description = "`$name` ";
if (empty($constraints['values'])) {
switch ($constraints['type']) {
case ObjectModel::TYPE_BOOL:
$description .= 'TINYINT(1) UNSIGNED';
break;
case ObjectModel::TYPE_DATE:
$description .= 'DATETIME';
break;
case ObjectModel::TYPE_FLOAT:
$description .= 'DECIMAL'.(
isset($constraints['size'], $constraints['scale'])
? "({$constraints['size']},{$constraints['scale']})"
: ''
);
break;
case ObjectModel::TYPE_HTML:
case ObjectModel::TYPE_SQL:
$length = isset($constraints['size']) ? $constraints['size'] : null;
$length = isset($length['max']) ? $length['max'] : $length;
$description .= $length ? "TEXT($length)" : 'TEXT';
break;
case ObjectModel::TYPE_INT:
$description .= 'INT(10)'.(
!empty($constraints['validate'])
&& strpos(Tools::strtolower($constraints['validate']), 'unsigned')
? ' UNSIGNED'
: ' SIGNED'
);
break;
case ObjectModel::TYPE_STRING:
$length = isset($constraints['size']) ? $constraints['size'] : 255;
$length = isset($length['max']) ? $length['max'] : $length;
$description .= "VARCHAR($length)";
break;
default:
throw new \PrestaShopException("Missing type constraint definition for field $name");
}
}
if (!empty($constraints['values'])) {
$description .= " ENUM('".implode("','", $constraints['values'])."')";
}
if (empty($constraints['allow_null']) || isset($constraints['default']) || !empty($constraints['required'])) {
$description .= ' NOT NULL';
}
if (isset($constraints['default'])) {
$description .= " DEFAULT '".addslashes($constraints['default'])."'";
}
if (!empty($constraints['primary'])) {
$description .= ' AUTO_INCREMENT';
}
return $description;
}
/**
* @param string $id
* @return array
*/
public function getKeyPrimary($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getKeyPrimary();
default:
return $this->getRelation($id)->getKeyPrimary();
}
}
/**
* @param string $id
* @return array
*/
public function getKeysForeign($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getKeysForeign();
default:
return $this->getRelation($id)->getKeysForeign();
}
}
/**
* @param string $id
* @return array
*/
public function getKeysSimple($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getKeysSimple();
default:
return $this->getRelation($id)->getKeysSimple();
}
}
/**
* @param string $id
* @return array
*/
public function getKeysUnique($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getKeysUnique();
default:
return $this->getRelation($id)->getKeysUnique();
}
}
/**
* @param string $id
* @return array
*/
public function getKeysFulltext($id)
{
switch ($id) {
case DbTableDefinitionModel::ID:
return $this->getModel()->getKeysFulltext();
default:
return $this->getRelation($id)->getKeysFulltext();
}
}
/**
* @param array $field
* @return bool
*/
public function isFieldSimpleKey($field)
{
return !empty($field['key']);
}
/**
* @param array $field
* @return bool
*/
public function isFieldUniqueKey($field)
{
return !empty($field['unique']);
}
/**
* @param array $field
* @return bool
*/
public function isFieldFulltextKey($field)
{
return !empty($field['fulltext']);
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Db;
use PaypalPPBTlib\Db\ObjectModelDefinition;
use PaypalPPBTlib\Db\DbTableDefinitionModel;
use PaypalPPBTlib\Db\DbTableDefinitionRelation;
use PaypalPPBTlib\Db\DbSchema;
use PaypalPPBTlib\Db\DbTable;
class ObjectModelExtension
{
/**
* @var \ObjectModel
*/
protected $om;
/**
* @var Db
*/
protected $db;
/**
* Register ObjectModel and Db
* @param \ObjectModel $om
* @param Db $db
*/
public function __construct($om, $db)
{
$this->om = $om;
$this->db = $db;
}
/**
* @return bool
*/
public function install()
{
$schemas = $this->getObjectModelDefinition()->getSchemas();
return $this->createTables($schemas);
}
/**
* @return bool
*/
public function uninstall()
{
$names = $this->getObjectModelDefinition()->getNames();
return $this->dropTables(array_reverse($names));
}
/**
* @return PaypalPPBTlib\Db\ObjectModelDefinition (as an array collection object)
*/
protected function getObjectModelDefinition()
{
return new ObjectModelDefinition($this->om->getDefinition($this->om));
}
/**
* @param array $schemas
* @return bool
*/
protected function createTables($schemas)
{
return array_product(array_map(array($this, 'createTable'), $schemas));
}
/**
* @param PaypalPPBTlib\Db\DbSchema $schema
* @return bool
*/
protected function createTable($schema)
{
return (new DbTable($this->db))->hydrate($schema)->create();
}
/**
* @param array $names
* @return bool
*/
protected function dropTables(array $names)
{
return array_product(array_map(array($this, 'dropTable'), $names));
}
/**
* @param string $name
* @return bool
*/
protected function dropTable($name)
{
return (new DbTable($this->db))->setName($name)->drop();
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,57 @@
<?php
/**
* 2007-2019 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-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PaypalPPBTlib\Extensions;
abstract class AbstractModuleExtension
{
//region Fields
public $name;
public $module;
public $objectModels = array();
public $hooks = array();
public $extensionAdminControllers = array();
public $controllers = array();
public $cronTasks = array(); //TODO
//endregion
/**
* @param Module $module
*/
public function setModule($module)
{
$this->module = $module;
return $this;
}
}

View File

@@ -0,0 +1,146 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Extensions\ProcessLogger\Classes;
use \ObjectModel;
class ProcessLoggerObjectModel extends ObjectModel
{
/** @var string log */
public $log;
/* @var int id_order*/
public $id_order;
/* @var int id_cart*/
public $id_cart;
/* @var int id_shop*/
public $id_shop;
/* @var string id_transaction*/
public $id_transaction;
/* @var string status*/
public $status;
/* @var bool sandbox*/
public $sandbox;
/* @var string tools*/
public $tools;
/* @var string creation date*/
public $date_add;
/* @var string date of transaction*/
public $date_transaction;
/**
* @see \ObjectModel::$definition
*/
public static $definition = array(
'table' => 'paypal_processlogger',
'primary' => 'id_paypal_processlogger',
'fields' => array(
'id_order' => array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedId',
'size' => 11,
),
'id_cart' => array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedId',
'size' => 11,
),
'id_shop' => array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedId',
'size' => 11,
),
'id_transaction' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isGenericName',
'size' => 50,
),
'log' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isGenericName',
'size' => 1000,
),
'status' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isGenericName',
'size' => 20,
),
'sandbox' => array(
'type' => ObjectModel::TYPE_BOOL,
'validate' => 'isBool'
),
'tools' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isGenericName',
'size' => 50,
),
'date_add' => array(
'type' => ObjectModel::TYPE_DATE,
'validate' => 'isDate',
),
'date_transaction' => array(
'type' => ObjectModel::TYPE_DATE,
'validate' => 'isDate',
),
),
);
public function getLinkToTransaction()
{
throw new \Exception('Need to define the method ' . __FUNCTION__);
}
public function getDateTransaction()
{
if ($this->date_transaction == '0000-00-00 00:00:00') {
return '';
}
$datetime1 = new \DateTime($this->date_transaction);
$datetime2 = new \DateTime($this->date_add);
$diff = $datetime2->getOffset() / 3600;
$interval = $datetime2->diff($datetime1);
if ($interval->invert == 1) {
$diff -= (int)$interval->format('%h');
} else {
$diff += (int)$interval->format('%h');
}
if ($diff == 0) {
$diff = 'GMT';
}
$dateTimeZone = new \DateTimeZone($diff);
$date = new \DateTime($this->date_transaction, $dateTimeZone);
return $date->format('Y-m-d H:i:s T');
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,357 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Extensions\ProcessLogger\Controllers\Admin;
use PaypalPPBTlib\Extensions\ProcessLogger\Classes\ProcessLoggerObjectModel;
use \Db;
use \Tools;
use \Configuration;
class AdminProcessLoggerController extends \ModuleAdminController
{
/** @var bool $bootstrap Active bootstrap for Prestashop 1.6 */
public $bootstrap = true;
/** @var \Module Instance of your module automatically set by ModuleAdminController */
public $module;
/** @var string Associated object class name */
public $className = 'PaypalPPBTlib\Extensions\ProcessLogger\Classes\ProcessLoggerObjectModel';
/** @var string Associated table name */
public $table = 'paypal_processlogger';
/** @var string|false Object identifier inside the associated table */
public $identifier = 'id_paypal_processlogger';
/** @var string Default ORDER BY clause when $_orderBy is not defined */
protected $_defaultOrderBy = 'id_paypal_processlogger';
/** @var string Default ORDER WAY clause when $_orderWay is not defined */
protected $_defaultOrderWay = 'DESC';
/** @var bool List content lines are clickable if true */
protected $list_no_link = true;
public $multishop_context = 0;
/**
* @see AdminController::__construct()
*/
public function __construct()
{
parent::__construct();
$this->addRowAction('delete');
$this->bulk_actions = array(
'delete' => array(
'text' => $this->module->l('Delete selected', 'AdminProcessLoggerController'),
'confirm' => $this->module->l(
'Would you like to delete the selected items?',
'AdminProcessLoggerController'
),
)
);
$this->fields_list = array(
'id_paypal_processlogger' => array(
'title' => $this->module->l('ID', 'AdminProcessLoggerController'),
'align' => 'center',
'class' => 'fixed-width-xs',
'search' => true,
),
'sandbox' => array(
'title' => $this->module->l('Mode', 'AdminProcessLoggerController'),
'type' => 'select',
'list' => array(1 => 'Sandbox', 0 => 'Live'),
'filter_key' => 'a!sandbox',
'filter_type' => 'int',
'callback' => 'getMode',
),
'tools' => array(
'title' => $this->module->l('Payment tools', 'AdminProcessLoggerController'),
),
'id_cart' => array(
'title' => $this->module->l('ID cart', 'AdminProcessLoggerController'),
'callback' => 'getCartLink',
),
'id_order' => array(
'title' => $this->module->l('ID order', 'AdminProcessLoggerController'),
'callback' => 'getOrderLink',
),
'id_transaction' => array(
'title' => $this->module->l('Transaction ID', 'AdminProcessLoggerController'),
'callback' => 'getLinkToTransaction',
),
'status' => array(
'title' => $this->module->l('Level', 'AdminProcessLoggerController'),
'callback' => 'getLevel'
),
'log' => array(
'title' => $this->module->l('Message (AIP PayPal/Braintree response)', 'AdminProcessLoggerController'),
),
'id_shop' => array(
'title' => $this->module->l('Shop ID', 'AdminProcessLoggerController'),
),
'date_add' => array(
'title' => $this->module->l('Date', 'AdminProcessLoggerController'),
),
'date_transaction' => array(
'title' => $this->module->l('Transaction date', 'AdminProcessLoggerController'),
'callback' => 'getDateTransaction',
),
);
$this->fields_options = array(
'processLogger' => array(
'image' => '../img/admin/cog.gif',
'title' => $this->module->l('Process Logger Settings', 'AdminProcessLoggerController'),
'description' => $this->module->l(
'Here you can change the default configuration for this Process Logger',
'AdminProcessLoggerController'
),
'info' => \Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'paypal/views/templates/admin/_partials/helperOptionInfo.tpl'),
'fields' => array(
'PAYPAL_EXTLOGS_ERASING_DISABLED' => array(
'title' => $this->module->l(
'Disable auto erasing',
'AdminProcessLoggerController'
),
'hint' => $this->module->l(
'If disabled, logs will be automatically erased after the delay',
'AdminProcessLoggerController'
),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
),
'PAYPAL_EXTLOGS_ERASING_DAYSMAX' => array(
'title' => $this->module->l(
'Auto erasing delay (in days)',
'AdminProcessLoggerController'
),
'hint' => $this->module->l(
'Choose the number of days you want to keep logs in database',
'AdminProcessLoggerController'
),
'validation' => 'isInt',
'cast' => 'intval',
'type' => 'text',
'defaultValue' => 90,
),
),
'submit' => array(
'title' => $this->module->l('Save', 'AdminProcessLoggerController'),
'name' => 'submitSaveConf'),
),
);
}
/**
* @param $echo string Value of field
* @param $tr array All data of the row
* @return string
*/
public function getObjectId($echo, $tr)
{
unset($tr);
return empty($echo) ? '' : $echo;
}
public function getDateTransaction($date_transaction, $tr)
{
if ((int)$tr['id_paypal_processlogger'] == false) {
return '';
}
$collectionLogs = new \PrestaShopCollection($this->className);
$collectionLogs->where('id_paypal_processlogger', '=', (int)$tr['id_paypal_processlogger']);
$log = $collectionLogs->getFirst();
if (\Validate::isLoadedObject($log) == false) {
return '';
}
return $log->getDateTransaction();
}
public function getLinkToTransaction($id_transaction, $tr)
{
if ($id_transaction == false || (int)$tr['id_paypal_processlogger'] == false) {
return '';
}
$collectionLogs = new \PrestaShopCollection($this->className);
$collectionLogs->where('id_paypal_processlogger', '=', (int)$tr['id_paypal_processlogger']);
$log = $collectionLogs->getFirst();
if (\Validate::isLoadedObject($log) == false) {
return '';
}
$link = $log->getLinkToTransaction();
return '<a href="' . $link . '" target="_blank">' . $log->id_transaction . '</a>';
}
public function getCartLink($id_cart)
{
if ((int)$id_cart) {
$link = \Context::getContext()->link->getAdminLink('AdminCarts', true, array(), array('id_cart' => (int)$id_cart, 'viewcart' => 1));
return '<a href="' . $link . '" target="_blank">' . $id_cart . '</a>';
}
}
public function getOrderLink($id_order)
{
if ((int)$id_order) {
$link = \Context::getContext()->link->getAdminLink('AdminOrders', true, array(), array('id_order' => (int)$id_order, 'vieworder' => 1));
return '<a href="' . $link . '" target="_blank">' . $id_order . '</a>';
}
}
/**
* @param $sandbox int Value of field
* @param $tr array All data of the row
* @return string
*/
public function getMode($sandbox, $tr)
{
unset($tr);
if ((int)$sandbox) {
return 'Sandbox';
} else {
return 'Live';
}
}
/**
* @param $echo string Value of field
* @param $tr array All data of the row
* @return string
*/
public function getLevel($echo, $tr)
{
unset($tr);
switch (strtolower($echo)) {
case 'info':
$echo = '<span class="badge badge-info">'.$echo.'</span>';
break;
case 'success':
$echo = '<span class="badge badge-success">'.$echo.'</span>';
break;
case 'error':
$echo = '<span class="badge badge-danger">'.$echo.'</span>';
break;
}
return $echo;
}
/**
* @see AdminController::initPageHeaderToolbar()
*/
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
// Remove the help icon of the toolbar which no useful for us
$this->context->smarty->clearAssign('help_link');
}
/**
* @see AdminController::initToolbar()
*/
public function initToolbar()
{
parent::initToolbar();
// Remove the add new item button
unset($this->toolbar_btn['new']);
$this->toolbar_btn['delete'] = array(
'short' => 'Erase',
'desc' => $this->module->l('Erase all'),
'js' => 'if (confirm(\''.
$this->module->l('Are you sure?', 'AdminProcessLoggerController').
'\')) document.location = \''.self::$currentIndex.'&amp;token='.$this->token.'&amp;action=erase\';'
);
}
/**
* Delete all logs
*
* @return bool
*/
public function processErase()
{
$result = Db::getInstance()->delete($this->table);
if ($result) {
$this->confirmations[] = $this->module->l('All logs has been erased', 'AdminProcessLoggerController');
}
return $result;
}
public function postProcess()
{
if (Tools::isSubmit('submitSaveConf')) {
return $this->saveConfiguration();
}
return parent::postProcess();
}
public function saveConfiguration()
{
$shops = \Shop::getShops();
foreach ($shops as $shop) {
$extlogs_erasing_daysmax = \Tools::getValue('PAYPAL_EXTLOGS_ERASING_DAYSMAX');
$extlogs_erasing_disabled = \Tools::getValue('PAYPAL_EXTLOGS_ERASING_DISABLED');
Configuration::updateValue(
'PAYPAL_EXTLOGS_ERASING_DISABLED',
($extlogs_erasing_disabled ? true : false),
false,
null,
$shop['id_shop']
);
if (!is_numeric($extlogs_erasing_daysmax)) {
$this->errors[] = $this->module->l(
'You must specify a valid \"Auto erasing delay (in days)\" number.',
'AdminProcessLoggerController'
);
} else {
\Configuration::updateValue(
'PAYPAL_EXTLOGS_ERASING_DAYSMAX',
$extlogs_erasing_daysmax,
false,
null,
$shop['id_shop']
);
$this->confirmations[] = $this->module->l(
'Log parameters are successfully updated!',
'AdminProcessLoggerController'
);
}
}
return true;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,101 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Extensions\ProcessLogger;
use PaypalPPBTlib\Extensions\AbstractModuleExtension;
use PaypalPPBTlib\Extensions\ProcessLogger\Controllers\Admin\AdminProcessLoggerController;
use PaypalPPBTlib\Extensions\ProcessLogger\Classes\ProcessLoggerObjectModel;
/**
* @import 'paypal/views/templates/hook/tableLogs.tpl'
*/
class ProcessLoggerExtension extends AbstractModuleExtension
{
public $name = 'process_logger';
public $extensionAdminControllers = array(
array(
'name' => array(
'en' => 'Logger',
'fr' => 'Logger',
),
'class_name' => 'AdminPaypalProcessLogger',
'parent_class_name' => 'AdminParentPaypalConfiguration',
'visible' => true,
),
);
public $objectModels = array(
ProcessLoggerObjectModel::class
);
public function hookDisplayAdminOrderContentOrder($params)
{
/** @var $order \Order*/
$order = $params['order'];
if ($order->module != 'paypal') {
return;
}
if (isset($params['class_logger']) && is_subclass_of($params['class_logger'], ProcessLoggerObjectModel::class)) {
$class_logger = $params['class_logger'];
} else {
$class_logger = ProcessLoggerObjectModel::class;
}
$collectionLogs = new \PrestaShopCollection($class_logger);
$collectionLogs->where('id_order', '=', $params['order']->id);
\Context::getContext()->smarty->assign('logs', $collectionLogs->getResults());
return \Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'paypal/views/templates/hook/displayAdminOrderContentOrder.tpl');
}
public function hookDisplayAdminOrderTabOrder($params)
{
/** @var $order \Order*/
$order = $params['order'];
if ($order->module != 'paypal') {
return;
}
return \Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'paypal/views/templates/hook/displayAdminOrderTabOrder.tpl');
}
public function hookDisplayAdminCartsView($params)
{
/** @var $cart Cart */
$cart = $params['cart'];
$order = new \Order((int)\Order::getIdByCartId($cart->id));
if ($order->module != 'paypal') {
return;
}
if (isset($params['class_logger']) && is_subclass_of($params['class_logger'], ProcessLoggerObjectModel::class)) {
$class_logger = $params['class_logger'];
} else {
$class_logger = ProcessLoggerObjectModel::class;
}
$collectionLogs = new \PrestaShopCollection($class_logger);
$collectionLogs->where('id_cart', '=', $params['cart']->id);
\Context::getContext()->smarty->assign('logs', $collectionLogs->getResults());
return \Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'paypal/views/templates/hook/displayAdminCartsView.tpl');
}
}

View File

@@ -0,0 +1,301 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Extensions\ProcessLogger;
use \Db;
use \Configuration;
use \Hook;
class ProcessLoggerHandler
{
/**
* @var array logs
*/
private static $logs = array();
/**
* open logger
*/
public static function openLogger()
{
self::autoErasingLogs();
}
/**
* close logger
*/
public static function closeLogger()
{
self::saveLogsInDb();
}
/**
* @param string $msg (Log message)
* @param string|null $id_transaction
* @param int|null $id_order
* @param int|null $id_cart
* @param int|null $id_shop
* @param string|null $tools (Cards, paypal, google ...)
* @param bool|null $sandbox (Sandbox/Live)
* @param string $date_transaction date of transaction
* @param string|null status (info or error)
*/
public static function addLog(
$msg,
$id_transaction = null,
$id_order = null,
$id_cart = null,
$id_shop = null,
$tools = null,
$sandbox = null,
$date_transaction = null,
$status = null
)
{
self::$logs[] = array(
'id_order' => (int)$id_order,
'id_cart' => (int)$id_cart,
'id_shop' => (int)$id_shop,
'id_transaction' => pSQL($id_transaction),
'log' => pSQL($msg),
'status' => pSQL($status),
'sandbox' => (int)$sandbox,
'tools' => pSQL($tools),
'date_add' => date("Y-m-d H:i:s"),
'date_transaction' => pSQL($date_transaction)
);
if (100 === count(self::$logs)) {
self::saveLogsInDb();
}
}
/**
* @param string $msg (Log message)
* @param string|null $id_transaction
* @param int|null $id_order
* @param int|null $id_cart
* @param int|null $id_shop
* @param string|null $tools (Cards, paypal, google ...)
* @param bool|null $sandbox (Sandbox/Live)
* @param string $date_transaction date of transaction
*/
public static function logInfo(
$msg,
$id_transaction = null,
$id_order = null,
$id_cart = null,
$id_shop = null,
$tools = null,
$sandbox = null,
$date_transaction = null
)
{
self::addLog(
$msg,
$id_transaction,
$id_order,
$id_cart,
$id_shop,
$tools,
$sandbox,
$date_transaction,
$status = 'Info'
);
}
/**
* @param string $msg (Log message)
* @param string|null $id_transaction
* @param int|null $id_order
* @param int|null $id_cart
* @param int|null $id_shop
* @param string|null $tools (Cards, paypal, google ...)
* @param bool|null $sandbox (Sandbox/Live)
* @param string $date_transaction date of transaction
*/
public static function logError(
$msg,
$id_transaction = null,
$id_order = null,
$id_cart = null,
$id_shop = null,
$tools = null,
$sandbox = null,
$date_transaction = null
)
{
self::addLog(
$msg,
$id_transaction,
$id_order,
$id_cart,
$id_shop,
$tools,
$sandbox,
$date_transaction,
$status = 'Error'
);
}
/**
* @return bool
*/
public static function saveLogsInDb()
{
$result = true;
if (false === empty(self::$logs) && self::getSkippingHooksResult()) {
Hook::exec(
'actionProcessLoggerSave',
array(
'logs' => &self::$logs,
),
null,
true
);
Hook::exec(
'actionPaypalProcessLoggerSave',
array(
'logs' => &self::$logs,
),
null,
true
);
$result = Db::getInstance()->insert(
'paypal_processlogger',
self::$logs
);
if ($result) {
self::$logs = array();
}
}
return $result;
}
/**
* @return bool
*/
public static function autoErasingLogs()
{
if (self::isAutoErasingEnabled()) {
return Db::getInstance()->delete(
'paypal_processlogger',
sprintf(
'date_add <= NOW() - INTERVAL %d DAY AND id_order = 0',
self::getAutoErasingDelayInDays()
)
);
}
return true;
}
/**
* @return bool
*/
public static function isAutoErasingEnabled()
{
return false === (bool)Configuration::get('PAYPAL_EXTLOGS_ERASING_DISABLED');
}
/**
* @return int
*/
public static function getAutoErasingDelayInDays()
{
$numberOfDays = Configuration::get('PAYPAL_EXTLOGS_ERASING_DAYSMAX');
if (empty($numberOfDays) || false === is_numeric($numberOfDays)) {
return 5;
}
return (int)$numberOfDays;
}
/**
* Executes the hooks used to skip a ProcessLogger save. This will return
* false if any module hooked to either 'actionSkipProcessLoggerSave' or
* 'actionSkipPaypalProcessLoggerSave' returns false (weak comparison)
*
* @return bool
*/
protected static function getSkippingHooksResult() {
if (Hook::getIdByName('actionSkipProcessLoggerSave')) {
$hookProcessLoggerReturnArray = Hook::exec(
'actionSkipProcessLoggerSave',
array(
'logs' => self::$logs,
),
null,
true
);
if (!is_array($hookProcessLoggerReturnArray)) {
return false;
}
if (!empty($hookProcessLoggerReturnArray)) {
$hookReturn = array_reduce($hookProcessLoggerReturnArray, function($and, $hookReturn) {
return $and && (bool)$hookReturn;
});
if (!$hookReturn) {
return false;
}
}
}
if (Hook::getIdByName('actionSkipPaypalProcessLoggerSave')) {
$hookModuleProcessLoggerReturnArray = Hook::exec(
'actionSkipPaypalProcessLoggerSave',
array(
'logs' => self::$logs,
),
null,
true
);
if (!is_array($hookModuleProcessLoggerReturnArray)) {
return false;
}
if (!empty($hookModuleProcessLoggerReturnArray)) {
$hookReturn = array_reduce($hookModuleProcessLoggerReturnArray, function($and, $hookReturn) {
return $and && (bool)$hookReturn;
});
if (!$hookReturn) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,392 @@
<?php
/**
* 2007-2019 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-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PaypalPPBTlib\Install;
use \Configuration;
use \Db;
use \DbQuery;
use \Language;
use \Tab;
use \Tools;
use PaypalPPBTlib\Db\ObjectModelExtension;
abstract class AbstractInstaller
{
//region Fields
/**
* @var \Paypal
*/
protected $module;
/**
* @var array
*/
protected $hooks;
/**
* @var array
*/
protected $adminControllers;
/**
* @var array
*/
protected $objectModels;
//endregion
public function __construct($module)
{
$this->module = $module;
}
/**
* Get hooks used in module/extension
* @return array
*/
abstract public function getHooks();
/**
* Get admin controllers used in module/extension
* @return array
*/
abstract public function getAdminControllers();
/**
* Get object models used in module/extension
* @return array
*/
abstract public function getObjectModels();
/**
* @param \Paypal $module
* @return $this
*/
public function setModule($module)
{
$this->module = $module;
return $this;
}
/**
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function install()
{
$result = $this->registerHooks();
$result &= $this->installObjectModels();
$result &= $this->installAdminControllers();
return $result;
}
/**
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function uninstall()
{
$result = $this->uninstallObjectModels();
$result &= $this->uninstallModuleAdminControllers();
return $result;
}
//TODO
/**
* Used only if merchant choose to keep data on modal in Prestashop 1.6
*
* @param Paypal $module
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function reset($module)
{
$this->module = $module;
$result = $this->clearHookUsed();
$result &= $this->installObjectModels();
$result &= $this->uninstallModuleAdminControllers();
$result &= $this->installAdminControllers();
return $result;
}
/**
* Register hooks used by our module
* @return bool
*/
public function registerHooks()
{
if (empty($this->getHooks())) {
return true;
}
return array_product(array_map(array($this->module, 'registerHook'), $this->getHooks()));
}
//TODO
/**
* Clear hooks used by our module
*
* @return bool
* @throws \PrestaShopException
*/
public function clearHookUsed()
{
$result = true;
$hooksUsed = $this->getHooksUsed();
if (empty($hooksUsed) && empty($this->getHooks())) {
// Both are empty, no need to continue process
return $result;
}
if (false === is_array($this->getHooks())) {
// If $module->hooks is not defined or is not an array
$this->hooks = array();
}
foreach ($this->getHooks() as $hook) {
if (false === in_array($hook, $hooksUsed, true)) {
// If hook is not registered, do it
$result &= $this->module->registerHook($hook);
}
}
foreach ($hooksUsed as $hookUsed) {
if (false === in_array($hookUsed, $this->getHooks(), true)) {
// If hook is registered by module but is not used anymore
$result &= $this->module->unregisterHook($hookUsed);
$result &= $this->module->unregisterExceptions($hookUsed);
}
}
return $result;
}
/**
* Retrieve hooks used by our module
*
* @return array
* @throws \PrestaShopDatabaseException
*/
public function getHooksUsed()
{
$query = new DbQuery();
$query->select('h.name');
$query->from('hook', 'h');
$query->innerJoin('hook_module', 'hm', 'hm.id_hook = h.id_hook');
$query->where('hm.id_module = ' . (int)$this->module->id);
$query->groupBy('h.name');
$results = Db::getInstance()->executeS($query);
if (empty($results)) {
return array();
}
return array_column($results, 'name');
}
/**
* Add Tabs for our ModuleAdminController
*
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function installAdminControllers()
{
$result = true;
if (empty($this->getAdminControllers())) {
// If module has no ModuleAdminController to install
return $result;
}
foreach ($this->getAdminControllers() as $tabData) {
if (Tab::getIdFromClassName($tabData['class_name'])) {
$result &= true;
continue;
}
$parentClassName = $tabData['parent_class_name'];
if ($parentClassName == 'ShopParameters' && version_compare(_PS_VERSION_, '1.7', '<')) {
$parentClassName = 'AdminPreferences';
}
/** 3 levels available on 1.7+ */
$defaultTabLevel1 = array('SELL', 'IMPROVE', 'CONFIGURE', 'DEFAULT');
if (in_array($parentClassName, $defaultTabLevel1) && version_compare(_PS_VERSION_, '1.7', '<')) {
continue;
}
if ($tabData['class_name'] == 'paypal' && version_compare(_PS_VERSION_, '1.7', '<')) {
$parentClassName = 'AdminParentModulesSf';
$tabData['parent_class_name'] = 'AdminParentModulesSf';
$tabData['visible'] = true;
}
$tab = new Tab();
$parentId = (int)Tab::getIdFromClassName($parentClassName);
if (!empty($parentId)) {
$tab->id_parent = $parentId;
}
$tab->class_name = $tabData['class_name'];
$tab->module = $this->module->name;
foreach (Language::getLanguages(false) as $language) {
if (empty($tabData['name'][$language['iso_code']])) {
$tab->name[$language['id_lang']] = $tabData['name']['en'];
} else {
$tab->name[$language['id_lang']] = $tabData['name'][$language['iso_code']];
}
}
$tab->active = true;
if (isset($tabData['visible'])) {
$tab->active = $tabData['visible'];
}
if (isset($tabData['icon']) && property_exists('Tab', 'icon')) {
$tab->icon = $tabData['icon']; // For Prestashop 1.7
}
$result &= (bool)$tab->add();
}
return $result;
}
/**
* Delete Tabs of our ModuleAdminController
*
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function uninstallModuleAdminControllers()
{
$query = new DbQuery();
$query->select('*');
$query->from('tab');
$query->where('module = \''.pSQL($this->module->name).'\'');
$tabs = Db::getInstance()->executeS($query);
if (empty($tabs)) {
return true;
}
$result = true;
foreach ($tabs as $tabData) {
$tab = new Tab((int)$tabData['id_tab']);
$result &= (bool)$tab->delete();
}
return $result;
}
/**
* Install all our \ObjectModel
*
* @return bool
*/
public function installObjectModels()
{
if (empty($this->getObjectModels())) {
return true;
}
return array_product(array_map(array($this, 'installObjectModel'), $this->getObjectModels()));
}
/**
* Install model
*
* @param string $objectModelClassName
* @return bool
* @throws \Exception
*/
public function installObjectModel($objectModelClassName)
{
if (!class_exists($objectModelClassName)) {
throw new \Exception('Installer error : ModelObject "' . $objectModelClassName . '" not found');
}
/** @var \ObjectModel $objectModel */
$objectModel = new $objectModelClassName();
$objectModelExtended = new ObjectModelExtension(
$objectModel,
Db::getInstance()
);
return $objectModelExtended->install();
}
/**
* Uninstall models
*
* @return bool
*/
public function uninstallObjectModels()
{
if (empty($this->getObjectModels())) {
return true;
}
return array_product(array_map(array($this, 'uninstallObjectModel'), $this->getObjectModels()));
}
/**
* Uninstall model
*
* @param string $objectModelClassName
* @return bool
* @throws \Exception
*/
public function uninstallObjectModel($objectModelClassName)
{
if (!class_exists($objectModelClassName)) {
throw new \Exception('Installer error : ModelObject "' . $objectModelClassName . '" not found');
}
/** @var \ObjectModel $objectModel */
$objectModel = new $objectModelClassName();
$objectModelExtended = new ObjectModelExtension(
$objectModel,
Db::getInstance()
);
return $objectModelExtended->uninstall();
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* 2007-2019 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-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PaypalPPBTlib\Install;
use \Module;
use \Db;
use \DbQuery;
use \PrestaShopDatabaseException;
use \PrestaShopException;
use \Tab;
use \Language;
use PaypalPPBTlib\Db\ObjectModelExtension;
use PaypalPPBTlib\Extensions\AbstractModuleExtension;
class ExtensionInstaller extends AbstractInstaller
{
//region Fields
/**
* @var AbstractModuleExtension
*/
protected $extension;
//endregion
public function __construct($module, $extension = null)
{
parent::__construct($module);
$this->extension = $extension;
}
//region Get-Set
/**
* @return array
* @throws PrestaShopException
*/
public function getHooks()
{
if ($this->extension == null) {
throw new PrestaShopException('Extension is null, can\'t get extension\'s hooks');
}
return $this->extension->hooks;
}
/**
* @return array
* @throws PrestaShopException
*/
public function getAdminControllers()
{
if ($this->extension == null) {
throw new PrestaShopException('Extension is null, can\'t get extension\'s admin controllers');
}
return $this->extension->extensionAdminControllers;
}
/**
* @return array
* @throws PrestaShopException
*/
public function getObjectModels()
{
if ($this->extension == null) {
throw new PrestaShopException('Extension is null, can\'t get extension\'s object models');
}
return $this->extension->objectModels;
}
/**
* @return AbstractModuleExtension
*/
public function getExtension()
{
return $this->extension;
}
/**
* @param AbstractModuleExtension $extension
* @return ExtensionInstaller
*/
public function setExtension($extension)
{
$this->extension = $extension;
return $this;
}
//endregion
}

View File

@@ -0,0 +1,270 @@
<?php
/**
* 2007-2019 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-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PaypalPPBTlib\Install;
use \Configuration;
use \Db;
use \DbQuery;
use \Language;
use \OrderState;
use \Tools;
use PaypalPPBTlib\Install\AbstractInstaller;
use PaypalPPBTlib\Install\ExtensionInstaller;
class ModuleInstaller extends AbstractInstaller
{
/**
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function install()
{
$result = parent::install();
$result &= $this->registerOrderStates();
$result &= $this->installExtensions();
return $result;
}
/**
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function uninstall()
{
$result = parent::uninstall();
$result &= $this->uninstallConfiguration();
$result &= $this->unregisterOrderStates();
$result &= $this->uninstallExtensions();
return $result;
}
/**
* @return bool
* @throws \Exception
*/
public function checkPhpVersion()
{
if (empty($this->module->php_version_required)) {
return true;
}
$phpVersion = Tools::checkPhpVersion();
if (Tools::version_compare($phpVersion, $this->module->php_version_required, '<')) {
throw new \Exception(sprintf(
'[%s] This module requires at least PHP %s or newer versions.',
$this->module->name,
$this->module->php_version_required
));
}
return true;
}
/**
* Uninstall Configuration (with or without language management)
*
* @return bool
* @throws \PrestaShopDatabaseException
*/
public function uninstallConfiguration()
{
$query = new DbQuery();
$query->select('name');
$query->from('configuration');
$query->where('name LIKE \'' . pSQL(Tools::strtoupper($this->module->name)) . '_%\'');
$results = Db::getInstance()->executeS($query);
if (empty($results)) {
return true;
}
$configurationKeys = array_column($results, 'name');
$result = true;
foreach ($configurationKeys as $configurationKey) {
$result &= Configuration::deleteByName($configurationKey);
}
return $result;
}
/**
* Register Order State : create new order state for this module
*
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function registerOrderStates()
{
if (empty($this->module->orderStates)) {
return true;
}
$result = true;
foreach ($this->module->orderStates as $configurationName => $orderStateParams) {
$orderState = new OrderState();
foreach ($orderStateParams as $key => $value) {
if ($key !== 'name' && property_exists($orderState, $key)) {
$orderState->$key = $value;
}
if ($key === 'name') {
foreach (Language::getLanguages(false) as $language) {
if (empty($value[$language['iso_code']])) {
$orderState->name[$language['id_lang']] = $value['en'];
} else {
$orderState->name[$language['id_lang']] = $value[$language['iso_code']];
}
}
}
}
$orderState->module_name = $this->module->name;
$result &= (bool)$orderState->save();
Configuration::updateValue($configurationName, $orderState->id);
}
return $result;
}
/**
* Unregister Order State : mark them as deleted
*
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function unregisterOrderStates()
{
if (empty($this->module->orderStates)) {
return true;
}
$query = new DbQuery();
$query->select('id_order_state');
$query->from('order_state');
$query->where('module_name = \'' . pSQL($this->module->name) . '\'');
$orderStateData = Db::getInstance()->executeS($query);
if (empty($orderStateData)) {
return true;
}
$result = true;
foreach ($orderStateData as $data) {
$query = new DbQuery();
$query->select('1');
$query->from('orders');
$query->where('current_state = ' . $data['id_order_state']);
$isUsed = (bool)Db::getInstance()->getValue($query);
$orderState = new OrderState($data['id_order_state']);
if ($isUsed) {
$orderState->deleted = true;
$result &= (bool)$orderState->save();
} else {
$result &= (bool)$orderState->delete();
}
}
return $result;
}
//region Install/Uninstall Extensions
public function installExtensions()
{
if (!isset($this->module->extensions) || empty($this->module->extensions)) {
return true;
}
return array_product(array_map(array($this, 'installExtension'), $this->module->extensions));
}
/**
* @param $extensionName
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function installExtension($extensionName)
{
$extension = new $extensionName($this->module);
$extensionInstaller = new ExtensionInstaller($this->module, $extension);
return $extensionInstaller->install();
}
public function uninstallExtensions()
{
if (!isset($this->module->extensions) || empty($this->module->extensions)) {
return true;
}
return array_product(array_map(array($this, 'uninstallExtension'), $this->module->extensions));
}
/**
* @param $extensionName
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function uninstallExtension($extensionName)
{
$extension = new $extensionName($this->module);
$extensionInstaller = new ExtensionInstaller($this->module, $extension);
return $extensionInstaller->uninstall();
}
//endregion
//region Getters
public function getHooks()
{
return $this->module->hooks;
}
public function getAdminControllers()
{
return $this->module->moduleAdminControllers;
}
public function getObjectModels()
{
return $this->module->objectModels;
}
//endregion
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,144 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommerce
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommerce is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommerce
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommerce est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
* @version develop
*/
namespace PaypalPPBTlib\Module;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
use \ReflectionClass;
use \Tools;
use PaypalPPBTlib\Install\ModuleInstaller;
use PaypalPPBTlib\Extensions\AbstractModuleExtension;
class PaymentModule extends \PaymentModule
{
/**
* Install Module
*
* @return bool
* @throws \PrestaShopException
*/
public function install()
{
$installer = new ModuleInstaller($this);
$isPhpVersionCompliant = false;
try {
$isPhpVersionCompliant = $installer->checkPhpVersion();
} catch (\Exception $e) {
$this->_errors[] = Tools::displayError($e->getMessage());
}
return $isPhpVersionCompliant && parent::install() && $installer->install();
}
/**
* Uninstall Module
*
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function uninstall()
{
$installer = new ModuleInstaller($this);
return parent::uninstall() && $installer->uninstall();
}
/**
* TODO
* Reset Module only if merchant choose to keep data on modal
*
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function reset()
{
$installer = new ModuleInstaller($this);
return $installer->reset($this);
}
public function handleExtensionsHook($hookName, $params)
{
if (!isset($this->extensions) || empty($this->extensions)) {
return false;
}
$result = false;
foreach ($this->extensions as $extension) {
/** @var AbstractModuleExtension $extension */
$extension = new $extension();
$extension->setModule($this);
if (is_callable(array($extension, $hookName))) {
$hookResult = $extension->{$hookName}($params);
if ($result === false) {
$result = $hookResult;
} elseif (is_array($hookResult) && $result !== false) {
$result = array_merge($result, $hookResult);
} else {
$result .= $hookResult;
}
}
}
return $result;
}
/**
* Handle module widget call
* @param $action
* @param $method
* @param $hookName
* @param $configuration
* @return bool
* @throws \ReflectionException
*/
public function handleWidget($action, $method, $hookName, $configuration)
{
if (!isset($this->extensions) || empty($this->extensions)) {
return false;
}
foreach ($this->extensions as $extension) {
/** @var AbstractModuleExtension $extension */
$extension = new $extension();
if (!($extension instanceof WidgetInterface)) {
continue;
}
$extensionClass = (new ReflectionClass($extension))->getShortName();
if ($extensionClass != $action) {
continue;
}
$extension->setModule($this);
if (is_callable(array($extension, $method))) {
return $extension->{$method}($hookName, $configuration);
}
}
return false;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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;