add empik module
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Empik\Marketplace\Adapter;
|
||||
|
||||
use Configuration;
|
||||
use Context;
|
||||
use Shop;
|
||||
|
||||
class ConfigurationAdapter
|
||||
{
|
||||
const CONF_ENVIRONMENT = 'EMPIK_ENVIRONMENT';
|
||||
const CONF_API_KEY = 'EMPIK_API_KEY';
|
||||
const CONF_AUTH_STATUS = 'EMPIK_AUTH_STATUS';
|
||||
const CONF_SYNC_OFFERS = 'EMPIK_SYNC_OFFERS';
|
||||
|
||||
const CONF_SYNC_LOGISTIC_CLASS = 'EMPIK_SYNC_LOGISTIC_CLASS';
|
||||
const CONF_OFFER_IDENTIFIER = 'EMPIK_OFFER_IDENTIFIER';
|
||||
const CONF_SKU_TYPE = 'EMPIK_SKU_TYPE';
|
||||
const CONF_LEAD_TIME_TO_SHIP = 'EMPIK_LEAD_TIME_TO_SHIP';
|
||||
const CONF_PRICE_RATIO = 'EMPIK_PRICE_RATIO';
|
||||
const CONF_ADD_TO_PRICE = 'EMPIK_ADD_TO_PRICE';
|
||||
const CONF_REDUCE_STOCK = 'EMPIK_REDUCE_STOCK';
|
||||
const CONF_IMPORT_ORDERS = 'EMPIK_IMPORT_ORDERS';
|
||||
const CONF_AUTO_ACCEPT_ORDERS = 'EMPIK_AUTO_ACCEPT_ORDERS';
|
||||
const CONF_NEW_ORDER_STATE = 'EMPIK_NEW_ORDER_STATE';
|
||||
const CONF_SHIPPED_ORDER_STATE = 'EMPIK_SHIPPED_ORDER_STATE';
|
||||
const CONF_CARRIER_MAP = 'EMPIK_CARRIER_MAP';
|
||||
const CONF_ID_EMPLOYEE = 'EMPIK_ID_EMPLOYEE';
|
||||
|
||||
const ENV_TEST = 'https://stg1.marketplace.empik.com';
|
||||
const ENV_PROD = 'https://marketplace.empik.com';
|
||||
|
||||
/** @var Shop */
|
||||
private $shopId;
|
||||
|
||||
public function __construct($shopId = null)
|
||||
{
|
||||
$this->shopId = $shopId ? $shopId : Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
public function get($key, $langId = null, $shopGroupId = null, $shopId = null, $default = false)
|
||||
{
|
||||
if ($shopId === null) {
|
||||
$shopId = $this->shopId;
|
||||
}
|
||||
|
||||
return Configuration::get($key, $langId, $shopGroupId, $shopId, $default);
|
||||
}
|
||||
|
||||
public function updateValue($key, $values, $html = false, $shopGroupId = null, $shopId = null)
|
||||
{
|
||||
if ($shopId === null) {
|
||||
$shopId = $this->shopId;
|
||||
}
|
||||
|
||||
return Configuration::updateValue($key, $values, $html, $shopGroupId, $shopId);
|
||||
}
|
||||
|
||||
public function deleteByName($key)
|
||||
{
|
||||
return Configuration::deleteByName($key);
|
||||
}
|
||||
}
|
||||
37
modules/empikmarketplace/src/Adapter/LinkAdapter.php
Normal file
37
modules/empikmarketplace/src/Adapter/LinkAdapter.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Empik\Marketplace\Adapter;
|
||||
|
||||
use Empik\Marketplace\PrestaShopContext;
|
||||
use Context;
|
||||
use Link;
|
||||
|
||||
class LinkAdapter
|
||||
{
|
||||
/** @var Link */
|
||||
protected $link;
|
||||
|
||||
/** @var PrestaShopContext */
|
||||
protected $prestaShopContext;
|
||||
|
||||
public function __construct(PrestaShopContext $prestaShopContext)
|
||||
{
|
||||
$this->prestaShopContext = $prestaShopContext;
|
||||
$this->link = Context::getContext()->link;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $controller
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function getAdminLink($controller, $params = [])
|
||||
{
|
||||
if ($this->prestaShopContext->is17()) {
|
||||
return $this->link->getAdminLink($controller, true, [], $params);
|
||||
} else {
|
||||
$paramsQuery = $params ? '&' . http_build_query($params) : '';
|
||||
return $this->link->getAdminLink($controller, true) . $paramsQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
modules/empikmarketplace/src/Adapter/LoggerAdapter.php
Normal file
60
modules/empikmarketplace/src/Adapter/LoggerAdapter.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Empik\Marketplace\Adapter;
|
||||
|
||||
use PrestaShopLogger;
|
||||
|
||||
class LoggerAdapter
|
||||
{
|
||||
const LOG_SEVERITY_LEVEL_INFORMATIVE = 1;
|
||||
const LOG_SEVERITY_LEVEL_WARNING = 2;
|
||||
const LOG_SEVERITY_LEVEL_ERROR = 3;
|
||||
const LOG_SEVERITY_LEVEL_MAJOR = 4;
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param int $severity
|
||||
* @return bool
|
||||
*/
|
||||
public function log($message, $severity = self::LOG_SEVERITY_LEVEL_INFORMATIVE)
|
||||
{
|
||||
return PrestaShopLogger::addLog($message, $severity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
public function logInfo($message)
|
||||
{
|
||||
return $this->log($message, self::LOG_SEVERITY_LEVEL_INFORMATIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
public function logWarning($message)
|
||||
{
|
||||
return $this->log($message, self::LOG_SEVERITY_LEVEL_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
public function logError($message)
|
||||
{
|
||||
return $this->log($message, self::LOG_SEVERITY_LEVEL_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
public function logMajor($message)
|
||||
{
|
||||
return $this->log($message, self::LOG_SEVERITY_LEVEL_MAJOR);
|
||||
}
|
||||
}
|
||||
46
modules/empikmarketplace/src/Adapter/ToolsAdapter.php
Normal file
46
modules/empikmarketplace/src/Adapter/ToolsAdapter.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Empik\Marketplace\Adapter;
|
||||
|
||||
use Tools;
|
||||
use Context;
|
||||
|
||||
class ToolsAdapter
|
||||
{
|
||||
protected $context;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
}
|
||||
|
||||
public function hash($value)
|
||||
{
|
||||
if ($this->is176()) {
|
||||
return Tools::hash($value);
|
||||
}
|
||||
|
||||
return Tools::encrypt($value);
|
||||
}
|
||||
|
||||
public function is17()
|
||||
{
|
||||
return version_compare(_PS_VERSION_, '1.7.0', '>=');
|
||||
}
|
||||
|
||||
public function is176()
|
||||
{
|
||||
return version_compare(_PS_VERSION_, '1.7.6', '>=');
|
||||
}
|
||||
|
||||
public static function is17static()
|
||||
{
|
||||
return version_compare(_PS_VERSION_, '1.7.0', '>=');
|
||||
}
|
||||
|
||||
public static function is176static()
|
||||
{
|
||||
return version_compare(_PS_VERSION_, '1.7.6', '>=');
|
||||
}
|
||||
}
|
||||
110
modules/empikmarketplace/src/Adapter/TranslateAdapter.php
Normal file
110
modules/empikmarketplace/src/Adapter/TranslateAdapter.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Empik\Marketplace\Adapter;
|
||||
|
||||
use Context;
|
||||
use Exception;
|
||||
use Module;
|
||||
use Tools;
|
||||
use Translate;
|
||||
|
||||
class TranslateAdapter
|
||||
{
|
||||
/**
|
||||
* Adapter for getting module translation for a specific locale on PS 1.6
|
||||
*
|
||||
* @param Module|string $module Module instance or name
|
||||
* @param string $originalString string to translate
|
||||
* @param string $source source of the original string
|
||||
* @param string|null $iso locale or language ISO code
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getModuleTranslation(
|
||||
$module,
|
||||
$originalString,
|
||||
$source,
|
||||
$iso = null
|
||||
) {
|
||||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||||
return Translate::getModuleTranslation($module, $originalString, $source, null, false, $iso);
|
||||
} elseif ($iso === null) {
|
||||
return Translate::getModuleTranslation($module, $originalString, $source);
|
||||
}
|
||||
|
||||
static $translations;
|
||||
static $langCache = [];
|
||||
static $translationsMerged = [];
|
||||
|
||||
$name = $module instanceof Module ? $module->name : $module;
|
||||
|
||||
if (empty($iso)) {
|
||||
$iso = Context::getContext()->language->iso_code;
|
||||
}
|
||||
|
||||
if (!isset($translationsMerged[$name][$iso])) {
|
||||
$filesByPriority = [
|
||||
// PrestaShop 1.5 translations
|
||||
_PS_MODULE_DIR_ . $name . '/translations/' . $iso . '.php',
|
||||
// PrestaShop 1.4 translations
|
||||
_PS_MODULE_DIR_ . $name . '/' . $iso . '.php',
|
||||
// Translations in theme
|
||||
_PS_THEME_DIR_ . 'modules/' . $name . '/translations/' . $iso . '.php',
|
||||
_PS_THEME_DIR_ . 'modules/' . $name . '/' . $iso . '.php',
|
||||
];
|
||||
|
||||
foreach ($filesByPriority as $file) {
|
||||
if (file_exists($file)) {
|
||||
$_MODULE = null;
|
||||
include $file;
|
||||
|
||||
if (isset($_MODULE)) {
|
||||
$translations[$iso] = isset($translations[$iso])
|
||||
? array_merge($translations[$iso], $_MODULE)
|
||||
: $_MODULE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$translationsMerged[$name][$iso] = true;
|
||||
}
|
||||
|
||||
$string = preg_replace("/\\\*'/", "\'", $originalString);
|
||||
$key = md5($string);
|
||||
|
||||
$cacheKey = $name . '|' . $string . '|' . $source . '|' . $iso;
|
||||
if (!isset($langCache[$cacheKey])) {
|
||||
if (!isset($translations[$iso])) {
|
||||
return str_replace('"', '"', $string);
|
||||
}
|
||||
|
||||
$currentKey = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $source) . '_' . $key;
|
||||
$defaultKey = Tools::strtolower('<{' . $name . '}prestashop>' . $source) . '_' . $key;
|
||||
|
||||
if ('controller' == Tools::substr($source, -10, 10)) {
|
||||
$file = Tools::substr($source, 0, -10);
|
||||
$currentKeyFile = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $file) . '_' . $key;
|
||||
$defaultKeyFile = Tools::strtolower('<{' . $name . '}prestashop>' . $file) . '_' . $key;
|
||||
}
|
||||
|
||||
if (isset($currentKeyFile) && !empty($translations[$iso][$currentKeyFile])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$currentKeyFile]);
|
||||
} elseif (isset($defaultKeyFile) && !empty($translations[$iso][$defaultKeyFile])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$defaultKeyFile]);
|
||||
} elseif (!empty($translations[$iso][$currentKey])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$currentKey]);
|
||||
} elseif (!empty($translations[$iso][$defaultKey])) {
|
||||
$ret = Tools::stripslashes($translations[$iso][$defaultKey]);
|
||||
} else {
|
||||
$ret = Tools::stripslashes($string);
|
||||
}
|
||||
|
||||
$langCache[$cacheKey] = htmlspecialchars($ret, ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
|
||||
return $langCache[$cacheKey];
|
||||
}
|
||||
}
|
||||
11
modules/empikmarketplace/src/Adapter/index.php
Normal file
11
modules/empikmarketplace/src/Adapter/index.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user