add empik module
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Empik\Marketplace\Factory\EmpikClientFactory;
|
||||
use Empik\Marketplace\API\EmpikClient;
|
||||
|
||||
class AdminEmpikActionLogController extends ModuleAdminController
|
||||
{
|
||||
/** @var EmpikClientFactory */
|
||||
private $empikClientFactory;
|
||||
|
||||
/** @var EmpikClient */
|
||||
private $empikClient;
|
||||
|
||||
/** @var int */
|
||||
protected $logLimit = 20;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
$this->table = 'empik_action';
|
||||
$this->className = 'EmpikAction';
|
||||
$this->lang = false;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->empikClientFactory = $this->module->getService('empik.marketplace.factory.empikClientFactory');
|
||||
$this->empikClient = $this->empikClientFactory->createClient();
|
||||
|
||||
$this->_select .= 'id_import AS id_import_log';
|
||||
$this->_defaultOrderWay = 'DESC';
|
||||
|
||||
$this->fields_list = [
|
||||
'id_empik_action' => [
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'class' => 'fixed-width-xs'
|
||||
],
|
||||
'action' => [
|
||||
'title' => $this->l('Action'),
|
||||
],
|
||||
'date_start' => [
|
||||
'title' => $this->l('Date start'),
|
||||
'type' => 'datetime',
|
||||
],
|
||||
'date_end' => [
|
||||
'title' => $this->l('Date end'),
|
||||
'type' => 'datetime',
|
||||
],
|
||||
'status' => [
|
||||
'title' => $this->l('Status'),
|
||||
],
|
||||
'id_import' => [
|
||||
'title' => $this->l('Import ID'),
|
||||
],
|
||||
'import_count' => [
|
||||
'title' => $this->l('Nb. products'),
|
||||
],
|
||||
'id_import_log' => [
|
||||
'title' => $this->l('Report'),
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayDownloadReportButton',
|
||||
'search' => false,
|
||||
'orderby' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
$this->toolbar_btn = [];
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$this->cleanupActionLog();
|
||||
|
||||
parent::initContent();
|
||||
|
||||
$this->updateActionLog();
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (Tools::getValue('action') === 'downloadLog') {
|
||||
$this->getExportErrorLog();
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
public function displayDownloadReportButton($val, $row)
|
||||
{
|
||||
if (!$val || $row['status'] !== 'COMPLETE') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'href' => self::$currentIndex.'&token='.$this->token. '&'.$this->identifier.'='.$row['id_empik_action'].'&action=downloadLog',
|
||||
]
|
||||
);
|
||||
|
||||
return $this->module->display($this->module->name, 'views/templates/admin/list_action_download.tpl');
|
||||
}
|
||||
|
||||
public function getExportErrorLog()
|
||||
{
|
||||
/** @var EmpikAction $obj */
|
||||
$empikAction = $this->loadObject();
|
||||
$importId = $empikAction->id_import;
|
||||
|
||||
if (!$importId) {
|
||||
$this->errors[] = $this->l('No import ID for selected action');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($empikAction->action) {
|
||||
case EmpikAction::ACTION_PRODUCT_EXPORT:
|
||||
$response = $this->empikClient->getProductImportErrorReport($importId);
|
||||
break;
|
||||
case EmpikAction::ACTION_OFFER_EXPORT:
|
||||
$response = $this->empikClient->getOfferImportErrorReport($importId);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$this->contentOutput($response, sprintf('report_%s.csv', $importId));
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->errors[] = sprintf($this->l('No error report found for import: %s'), $importId);
|
||||
}
|
||||
}
|
||||
|
||||
protected function cleanupActionLog()
|
||||
{
|
||||
$id = Db::getInstance()->getValue('SELECT MAX(id_empik_action) - '.(int)$this->logLimit.' FROM `'._DB_PREFIX_.'empik_action`');
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'empik_action` WHERE id_empik_action <= ' . (int)$id);
|
||||
}
|
||||
|
||||
protected function updateActionLog()
|
||||
{
|
||||
$this->getList(Context::getContext()->language->id);
|
||||
|
||||
$endStatuses = ['COMPLETE', 'FAILED', 'API_ERROR'];
|
||||
|
||||
foreach ($this->_list as $row) {
|
||||
|
||||
$empikAction = new EmpikAction($row['id_empik_action']);
|
||||
|
||||
if (!$empikAction->id_import || in_array($empikAction->status, $endStatuses)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($empikAction->action) {
|
||||
case EmpikAction::ACTION_PRODUCT_EXPORT:
|
||||
$response = $this->empikClient->getProductsImport($empikAction->id_import);
|
||||
$this->updateActionProductImport($response, $empikAction);
|
||||
break;
|
||||
case EmpikAction::ACTION_OFFER_EXPORT:
|
||||
$response = $this->empikClient->getOffersImport($empikAction->id_import);
|
||||
$this->updateActionOfferImport($response, $empikAction);
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $response
|
||||
* @param EmpikAction $action
|
||||
* @throws PrestaShopDatabaseException
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
protected function updateActionProductImport($response, $action)
|
||||
{
|
||||
$action->status = $response['import_status'];
|
||||
$action->import_count = $response['transform_lines_read'];
|
||||
$action->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $response
|
||||
* @param EmpikAction $action
|
||||
* @throws PrestaShopDatabaseException
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
protected function updateActionOfferImport($response, $action)
|
||||
{
|
||||
$action->status = $response['status'];
|
||||
$action->import_count = $response['lines_read'];
|
||||
$action->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param string $filename
|
||||
*/
|
||||
protected function contentOutput($content, $filename = 'error_report.csv')
|
||||
{
|
||||
ob_clean();
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
header('Content-Length: ' . strlen($content));
|
||||
echo $content;
|
||||
exit;
|
||||
}
|
||||
|
||||
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
|
||||
{
|
||||
return Translate::getModuleTranslation($this->module, $string, get_class($this), null, $addslashes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Empik\Marketplace\Adapter\ConfigurationAdapter;
|
||||
use Empik\Marketplace\Adapter\LinkAdapter;
|
||||
use Empik\Marketplace\Factory\EmpikClientFactory;
|
||||
use Empik\Marketplace\Validator\Validator;
|
||||
|
||||
class AdminEmpikConnectionController extends ModuleAdminController
|
||||
{
|
||||
const CONN_SUCCESS = 1;
|
||||
const CONN_ERROR_API = 2;
|
||||
|
||||
public $_conf = [];
|
||||
public $_error = [];
|
||||
|
||||
/** @var EmpikMarketplace */
|
||||
public $module;
|
||||
|
||||
/** @var EmpikClientFactory */
|
||||
protected $empikClientFactory;
|
||||
|
||||
/** @var LinkAdapter */
|
||||
protected $link;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->_conf[self::CONN_SUCCESS] = $this->l('Connection to API works fine.');
|
||||
$this->_error[self::CONN_ERROR_API] = $this->l('Unable to connect, check connection details and try again.');
|
||||
|
||||
$this->empikClientFactory = $this->module->getService('empik.marketplace.factory.empikClientFactory');
|
||||
$this->link = $this->module->getService('empik.marketplace.adapter.link');
|
||||
}
|
||||
|
||||
public function initProcess()
|
||||
{
|
||||
$this->display = 'edit';
|
||||
|
||||
parent::initProcess();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::getIsset('submit'.$this->controller_name)) {
|
||||
$this->handleForm();
|
||||
}
|
||||
|
||||
parent::postProcess();
|
||||
}
|
||||
|
||||
public function handleForm()
|
||||
{
|
||||
$environment = Tools::getValue('environment');
|
||||
$apiKey = Tools::getValue('api_key');
|
||||
|
||||
if (!Validator::isValidEnvironment($environment)) {
|
||||
$this->errors[] = $this->l('Invalid environment field');
|
||||
}
|
||||
|
||||
if (!Validator::isValidApiKey($apiKey)) {
|
||||
$this->errors[] = $this->l('Invalid API key field');
|
||||
}
|
||||
|
||||
if (empty($this->errors)) {
|
||||
|
||||
$result = true;
|
||||
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_ENVIRONMENT, $environment);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_API_KEY, $apiKey);
|
||||
|
||||
if ($result) {
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => 4])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->errors[] = $this->l('Error saving form.');
|
||||
}
|
||||
|
||||
public function processTestConnection()
|
||||
{
|
||||
$status = $this->getConnectionStatus();
|
||||
if ($status === self::CONN_SUCCESS) {
|
||||
$this->module->setAuthStatus();
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => self::CONN_SUCCESS])
|
||||
);
|
||||
}
|
||||
|
||||
$this->errors[] = $this->_error[self::CONN_ERROR_API];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getConnectionStatus()
|
||||
{
|
||||
try {
|
||||
$client = $this->empikClientFactory->createClient();
|
||||
$client->getAccount();
|
||||
} catch (Exception $e) {
|
||||
return self::CONN_ERROR_API;
|
||||
}
|
||||
|
||||
return self::CONN_SUCCESS;
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$controller = $this->controller_name;
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'url_test_connection' => $this->link->getAdminLink($controller, ['action' => 'testConnection'])
|
||||
]);
|
||||
|
||||
$fields = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->l('Configuration'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'name' => 'environment',
|
||||
'label' => $this->l('Environment'),
|
||||
'hint' => $this->l('Select environment'),
|
||||
'options' => [
|
||||
'query' => [
|
||||
[
|
||||
'url' => ConfigurationAdapter::ENV_TEST,
|
||||
'name' => $this->l('testing'),
|
||||
],
|
||||
[
|
||||
'url' => ConfigurationAdapter::ENV_PROD,
|
||||
'name' => $this->l('production'),
|
||||
],
|
||||
],
|
||||
'id' => 'url',
|
||||
'name' => 'name',
|
||||
],
|
||||
'class' => 'fixed-width-xxl',
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('API key'),
|
||||
'hint' => $this->l('API key'),
|
||||
'name' => 'api_key',
|
||||
],
|
||||
[
|
||||
'label' => '',
|
||||
'type' => 'html',
|
||||
'name' => 'html_data',
|
||||
'html_content' => $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/_partials/test_connection_button.tpl'
|
||||
),
|
||||
],
|
||||
[
|
||||
'label' => '',
|
||||
'type' => 'html',
|
||||
'name' => 'custom_html',
|
||||
'html_content' => $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/_partials/test_connection_footer.tpl'
|
||||
),
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$helper = new HelperForm();
|
||||
|
||||
$helper->show_toolbar = false;
|
||||
$helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
$helper->module = $this->module;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submit'.$controller;
|
||||
$helper->currentIndex = $this->link->getAdminLink($controller);
|
||||
$helper->token = Tools::getAdminTokenLite($controller);
|
||||
$helper->tpl_vars = [
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
'fields_value' => [
|
||||
'environment' => Tools::getValue('environment', Configuration::get(ConfigurationAdapter::CONF_ENVIRONMENT)),
|
||||
'api_key' => Tools::getValue('api_key', Configuration::get(ConfigurationAdapter::CONF_API_KEY))
|
||||
]
|
||||
];
|
||||
|
||||
return $helper->generateForm([$fields]);
|
||||
}
|
||||
|
||||
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
|
||||
{
|
||||
return Translate::getModuleTranslation($this->module, $string, get_class($this), null, $addslashes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
class AdminEmpikController extends ModuleAdminController
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Empik\Marketplace\Handler\CronJobsHandler;
|
||||
use Empik\Marketplace\PrestaShopContext;
|
||||
|
||||
class AdminEmpikHelpController extends ModuleAdminController
|
||||
{
|
||||
/** @var CronJobsHandler */
|
||||
protected $cronJobsHandler;
|
||||
|
||||
/** @var EmpikMarketplace */
|
||||
public $module;
|
||||
|
||||
/** @var PrestaShopContext */
|
||||
public $prestaShopContext;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->cronJobsHandler = $this->module->getService('empik.marketplace.handler.cronJobs');
|
||||
$this->prestaShopContext = $this->module->getService('empik.marketplace.prestaShopContext');
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$this->context->smarty->assign([
|
||||
'cron_jobs' => $this->cronJobsHandler->getAvailableActionsUrls(),
|
||||
'url_help' => 'https://www.empik.com/empikplace/pomoc',
|
||||
'url_docs' => 'https://www.empik.com/empikplace/integracje/prestashop/instrukcja',
|
||||
]);
|
||||
|
||||
$this->content = $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath() . '/views/templates/admin/help.tpl'
|
||||
);
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
|
||||
{
|
||||
return Translate::getModuleTranslation($this->module, $string, get_class($this), null, $addslashes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
use Empik\Marketplace\Adapter\ConfigurationAdapter;
|
||||
use Empik\Marketplace\Adapter\LinkAdapter;
|
||||
use Empik\Marketplace\Processor\ExportOfferProcessor;
|
||||
use Empik\Marketplace\Validator\Validator;
|
||||
|
||||
class AdminEmpikOffersController extends ModuleAdminController
|
||||
{
|
||||
const CONF_EXPORT_SUCCESS = 1;
|
||||
|
||||
/** @var ExportOfferProcessor */
|
||||
protected $exportOfferProcessor;
|
||||
|
||||
/** @var LinkAdapter */
|
||||
protected $link;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->_conf[self::CONF_EXPORT_SUCCESS] = $this->l('Export successful.');
|
||||
|
||||
$this->exportOfferProcessor = $this->module->getService('empik.marketplace.processor.exportOfferProcessor');
|
||||
$this->link = $this->module->getService('empik.marketplace.adapter.link');
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (Tools::getIsset('submitOrderForm')) {
|
||||
$this->handleForm();
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
public function ajaxProcessExportOffers()
|
||||
{
|
||||
$page = (int)Tools::getValue('page');
|
||||
if ($page < 0) {
|
||||
$page = 0;
|
||||
}
|
||||
|
||||
$this->exportOfferProcessor->setPage($page);
|
||||
$this->exportOfferProcessor->process();
|
||||
|
||||
$continue = !$this->exportOfferProcessor->isLastPage();
|
||||
|
||||
$this->ajaxDie(json_encode([
|
||||
'success' => !$this->exportOfferProcessor->hasErrors(),
|
||||
'errors' => $this->exportOfferProcessor->getErrors(),
|
||||
'continue' => $continue,
|
||||
'redirect' => $this->link->getAdminLink($this->controller_name, ['conf' => self::CONF_EXPORT_SUCCESS]),
|
||||
]));
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$this->display = 'edit';
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
|
||||
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/admin/empik.js');
|
||||
|
||||
Media::addJsDef([
|
||||
'empikAjaxUrl' => $this->link->getAdminLink($this->controller_name, ['ajax' => 1]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
return $this->renderOrderForm();
|
||||
}
|
||||
|
||||
public function renderOrderForm()
|
||||
{
|
||||
$controller = $this->controller_name;
|
||||
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'url_export_offers' => $this->link->getAdminLink($controller, ['action' => 'exportOffers']),
|
||||
'url_manage_price' => $this->link->getAdminLink('AdminEmpikProductsPrice'),
|
||||
]);
|
||||
|
||||
$leadTimeToShip = [];
|
||||
$leadTimeToShip[] = [
|
||||
'id' => -1,
|
||||
'name' => $this->l('- No selection -'),
|
||||
];
|
||||
for ($x = 0; $x <= 44; $x++) {
|
||||
$leadTimeToShip[] = [
|
||||
'id' => $x,
|
||||
'name' => $x,
|
||||
];
|
||||
}
|
||||
|
||||
$formFields = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->l('Offers'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Sync Empik Marketplace offers automatically'),
|
||||
'hint' => $this->l('Sync Empik Marketplace offers automatically'),
|
||||
'name' => 'sync_offers',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'sync_offers_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Yes'),
|
||||
],
|
||||
[
|
||||
'id' => 'sync_offers_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('No'),
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Sync logistic class'),
|
||||
'hint' => $this->l('Enabling this option will update logistic class for all offers'),
|
||||
'name' => 'sync_logistic_class',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'sync_logistic_class_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Yes'),
|
||||
],
|
||||
[
|
||||
'id' => 'sync_logistic_class_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('No'),
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Offer identifier'),
|
||||
'hint' => $this->l('Offer identifier'),
|
||||
'name' => 'offer_identifier',
|
||||
'options' => [
|
||||
'query' => [
|
||||
[
|
||||
'id' => 'EAN',
|
||||
'name' => $this->l('EAN'),
|
||||
],
|
||||
[
|
||||
'id' => 'SHOP_SKU',
|
||||
'name' => $this->l('SKU'),
|
||||
],
|
||||
],
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => $this->l('SKU type'),
|
||||
'hint' => $this->l('SKU type'),
|
||||
'name' => 'sku_type',
|
||||
'options' => [
|
||||
'query' => [
|
||||
[
|
||||
'id' => 'REFERENCE',
|
||||
'name' => $this->l('Reference'),
|
||||
],
|
||||
[
|
||||
'id' => 'EAN',
|
||||
'name' => $this->l('EAN'),
|
||||
],
|
||||
[
|
||||
'id' => 'ID',
|
||||
'name' => $this->l('ID'),
|
||||
],
|
||||
],
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Leadtime to ship'),
|
||||
'hint' => $this->l('Leadtime to ship'),
|
||||
'name' => 'lead_time_to_ship',
|
||||
'options' => [
|
||||
'query' => $leadTimeToShip,
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Price ratio'),
|
||||
'hint' => $this->l('Price ratio'),
|
||||
'name' => 'price_ratio',
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Add to price'),
|
||||
'hint' => $this->l('Add to price'),
|
||||
'name' => 'add_to_price',
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Reduce stock'),
|
||||
'hint' => $this->l('Reduce stock'),
|
||||
'name' => 'reduce_stock',
|
||||
],
|
||||
[
|
||||
'label' => '',
|
||||
'type' => 'html',
|
||||
'name' => 'html_data',
|
||||
'html_content' => $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/_partials/export_offers_button.tpl'
|
||||
),
|
||||
],
|
||||
[
|
||||
'label' => '',
|
||||
'type' => 'html',
|
||||
'name' => 'html_data',
|
||||
'html_content' => $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/_partials/manage_price_button.tpl'
|
||||
),
|
||||
],
|
||||
],
|
||||
'buttons' => [],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$helper = new HelperForm();
|
||||
|
||||
$helper->show_toolbar = false;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->default_form_language = $language->id;
|
||||
$helper->submit_action = 'submitOrderForm';
|
||||
$helper->currentIndex = $this->link->getAdminLink($controller);
|
||||
$helper->token = Tools::getAdminTokenLite('AdminEmpikOffers');
|
||||
$helper->tpl_vars = [
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
];
|
||||
|
||||
$helper->tpl_vars['fields_value']['sync_offers'] = Tools::getValue('sync_offers', (int)Configuration::get(ConfigurationAdapter::CONF_SYNC_OFFERS));
|
||||
$helper->tpl_vars['fields_value']['sync_logistic_class'] = Tools::getValue('sync_logistic_class', (int)Configuration::get(ConfigurationAdapter::CONF_SYNC_LOGISTIC_CLASS));
|
||||
$helper->tpl_vars['fields_value']['offer_identifier'] = Tools::getValue('offer_identifier', Configuration::get(ConfigurationAdapter::CONF_OFFER_IDENTIFIER));
|
||||
$helper->tpl_vars['fields_value']['sku_type'] = Tools::getValue('sku_type', Configuration::get(ConfigurationAdapter::CONF_SKU_TYPE));
|
||||
$helper->tpl_vars['fields_value']['lead_time_to_ship'] = Tools::getValue('lead_time_to_ship', (float)Configuration::get(ConfigurationAdapter::CONF_LEAD_TIME_TO_SHIP));
|
||||
$helper->tpl_vars['fields_value']['price_ratio'] = Tools::getValue('price_ratio', (float)Configuration::get(ConfigurationAdapter::CONF_PRICE_RATIO));
|
||||
$helper->tpl_vars['fields_value']['add_to_price'] = Tools::getValue('add_to_price', (float)Configuration::get(ConfigurationAdapter::CONF_ADD_TO_PRICE));
|
||||
$helper->tpl_vars['fields_value']['reduce_stock'] = Tools::getValue('reduce_stock', (int)Configuration::get(ConfigurationAdapter::CONF_REDUCE_STOCK));
|
||||
|
||||
return $helper->generateForm([$formFields]);
|
||||
}
|
||||
|
||||
public function handleForm()
|
||||
{
|
||||
$syncOffers = Tools::getValue('sync_offers');
|
||||
$syncLogisticClass = Tools::getValue('sync_logistic_class');
|
||||
$offerIdentifier = Tools::getValue('offer_identifier');
|
||||
$skuType = Tools::getValue('sku_type');
|
||||
$leadTimeToShip = Tools::getValue('lead_time_to_ship');
|
||||
$priceRatio = Tools::getValue('price_ratio');
|
||||
$addToPrice = Tools::getValue('add_to_price');
|
||||
$reduceStock = Tools::getValue('reduce_stock');
|
||||
|
||||
if (!is_numeric($syncOffers)) {
|
||||
$this->errors[] = $this->l('Invalid Sync offers field');
|
||||
}
|
||||
|
||||
if (!is_numeric($syncLogisticClass)) {
|
||||
$this->errors[] = $this->l('Invalid Sync logistic class field');
|
||||
}
|
||||
|
||||
if (!Validator::isOfferIdentifier($offerIdentifier)) {
|
||||
$this->errors[] = $this->l('Invalid Offer identifier field');
|
||||
}
|
||||
|
||||
if (!Validator::isSkuType($skuType)) {
|
||||
$this->errors[] = $this->l('Invalid SKU type field');
|
||||
}
|
||||
|
||||
if (!Validator::isInt($leadTimeToShip) || $leadTimeToShip < -1 || $leadTimeToShip > 44) {
|
||||
$this->errors[] = $this->l('Invalid Lead time to ship field');
|
||||
}
|
||||
|
||||
if (!Validator::isFloat($priceRatio) || $priceRatio < 0) {
|
||||
$this->errors[] = $this->l('Invalid Price ratio field');
|
||||
}
|
||||
|
||||
if (!Validator::isFloat($addToPrice) || $addToPrice < 0) {
|
||||
$this->errors[] = $this->l('Invalid Add to price field');
|
||||
}
|
||||
|
||||
if (!Validator::isInt($reduceStock) || $reduceStock < 0) {
|
||||
$this->errors[] = $this->l('Invalid Reduce stock field');
|
||||
}
|
||||
|
||||
if (empty($this->errors)) {
|
||||
|
||||
$result = true;
|
||||
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_SYNC_OFFERS, (int)$syncOffers);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_SYNC_LOGISTIC_CLASS, (int)$syncLogisticClass);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_OFFER_IDENTIFIER, $offerIdentifier);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_SKU_TYPE, $skuType);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_LEAD_TIME_TO_SHIP, $leadTimeToShip);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_PRICE_RATIO, (float)$priceRatio);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_ADD_TO_PRICE, (float)$addToPrice);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_REDUCE_STOCK, (float)$reduceStock);
|
||||
|
||||
if ($result) {
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => 4])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->errors[] = $this->l('Error saving form.');
|
||||
}
|
||||
|
||||
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
|
||||
{
|
||||
return Translate::getModuleTranslation($this->module, $string, get_class($this), null, $addslashes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
use Empik\Marketplace\Adapter\ConfigurationAdapter;
|
||||
use Empik\Marketplace\Adapter\LinkAdapter;
|
||||
use Empik\Marketplace\API\EmpikClient;
|
||||
use Empik\Marketplace\DataProvider\CarriersDataProvider;
|
||||
use Empik\Marketplace\Factory\EmpikClientFactory;
|
||||
use Empik\Marketplace\Manager\CarrierMapManager;
|
||||
use Empik\Marketplace\Validator\Validator;
|
||||
|
||||
class AdminEmpikOrdersController extends ModuleAdminController
|
||||
{
|
||||
/** @var EmpikMarketplace */
|
||||
public $module;
|
||||
|
||||
/** @var EmpikClientFactory */
|
||||
private $empikClientFactory;
|
||||
|
||||
/** @var CarrierMapManager */
|
||||
protected $carrierMapManager;
|
||||
|
||||
/** @var LinkAdapter */
|
||||
protected $link;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->bootstrap = true;
|
||||
|
||||
$this->empikClientFactory = $this->module->getService('empik.marketplace.factory.empikClientFactory');
|
||||
$this->carrierMapManager = $this->module->getService('empik.marketplace.manager.carrierMapManager');
|
||||
$this->link = $this->module->getService('empik.marketplace.adapter.link');
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (Tools::getIsset('submitOrderForm') || Tools::getIsset('submitOrderFormShipping')) {
|
||||
$this->handleForm();
|
||||
}
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$this->display = 'edit';
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function handleForm()
|
||||
{
|
||||
$result = true;
|
||||
|
||||
if (Tools::getIsset('submitOrderForm')) {
|
||||
|
||||
$importOrders = Tools::getValue('import_orders');
|
||||
$autoAcceptOrders = Tools::getValue('auto_accept_orders');
|
||||
$newOrderState = Tools::getValue('new_order_state');
|
||||
$shippedOrderState = Tools::getValue('shipped_order_state');
|
||||
|
||||
if (!Validator::isBool($importOrders)) {
|
||||
$this->errors[] = $this->l('Invalid Import orders field');
|
||||
}
|
||||
|
||||
if (!Validator::isBool($autoAcceptOrders)) {
|
||||
$this->errors[] = $this->l('Invalid Auto accept orders field');
|
||||
}
|
||||
|
||||
if (!Validator::isInt($newOrderState)) {
|
||||
$this->errors[] = $this->l('Invalid New order state field');
|
||||
}
|
||||
|
||||
if (!Validator::isInt($shippedOrderState)) {
|
||||
$this->errors[] = $this->l('Invalid Shipped order state field');
|
||||
}
|
||||
|
||||
if (empty($this->errors)) {
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_IMPORT_ORDERS, (int)$importOrders);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_AUTO_ACCEPT_ORDERS, (int)$autoAcceptOrders);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_NEW_ORDER_STATE, (int)$newOrderState);
|
||||
$result &= Configuration::updateValue(ConfigurationAdapter::CONF_SHIPPED_ORDER_STATE, (int)$shippedOrderState);
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::getIsset('submitOrderFormShipping')) {
|
||||
$result &= $this->carrierMapManager->store(Tools::getValue('carrier', []));
|
||||
}
|
||||
|
||||
if ($result && empty($this->errors)) {
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => 4])
|
||||
);
|
||||
}
|
||||
|
||||
$this->errors[] = $this->l('Error saving form.');
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
if (!$this->module->getAuthStatus()) {
|
||||
$this->errors[] = $this->l('Before starting, set up the connection');
|
||||
return false;
|
||||
}
|
||||
|
||||
return
|
||||
$this->renderOrderForm().
|
||||
$this->renderShippingMappingForm();
|
||||
}
|
||||
|
||||
public function renderOrderForm()
|
||||
{
|
||||
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
$orderStates = OrderState::getOrderStates($language->id);
|
||||
|
||||
$formFields = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->l('Orders'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Import orders from Empik Marketplace'),
|
||||
'hint' => $this->l('Import orders from Empik Marketplace'),
|
||||
'name' => 'import_orders',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'import_orders_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Yes'),
|
||||
],
|
||||
[
|
||||
'id' => 'import_orders_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('No'),
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Auto accept orders in Empik Marketplace'),
|
||||
'hint' => $this->l('Auto accept orders in Empik Marketplace'),
|
||||
'name' => 'auto_accept_orders',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'auto_accept_orders_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Yes'),
|
||||
],
|
||||
[
|
||||
'id' => 'auto_accept_orders_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('No'),
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => $this->l('New order state'),
|
||||
'hint' => $this->l('New order state'),
|
||||
'name' => 'new_order_state',
|
||||
'options' => [
|
||||
'query' => $orderStates,
|
||||
'id' => 'id_order_state',
|
||||
'name' => 'name',
|
||||
],
|
||||
'class' => 'fixed-width-xxl',
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Shipped order state'),
|
||||
'hint' => $this->l('Shipped order state'),
|
||||
'name' => 'shipped_order_state',
|
||||
'options' => [
|
||||
'query' => $orderStates,
|
||||
'id' => 'id_order_state',
|
||||
'name' => 'name',
|
||||
],
|
||||
'class' => 'fixed-width-xxl',
|
||||
],
|
||||
],
|
||||
'buttons' => [],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$helper = new HelperForm();
|
||||
|
||||
$helper->show_toolbar = false;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->default_form_language = $language->id;
|
||||
$helper->submit_action = 'submitOrderForm';
|
||||
$helper->currentIndex = $this->link->getAdminLink($this->controller_name);
|
||||
$helper->token = Tools::getAdminTokenLite('AdminEmpikOrders');
|
||||
$helper->tpl_vars = [
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
];
|
||||
|
||||
$helper->tpl_vars['fields_value']['import_orders'] = Tools::getValue('import_orders', (int)Configuration::get(ConfigurationAdapter::CONF_IMPORT_ORDERS));
|
||||
$helper->tpl_vars['fields_value']['auto_accept_orders'] = Tools::getValue('auto_accept_orders', (int)Configuration::get(ConfigurationAdapter::CONF_AUTO_ACCEPT_ORDERS));
|
||||
$helper->tpl_vars['fields_value']['new_order_state'] = Tools::getValue('new_order_state', (int)Configuration::get(ConfigurationAdapter::CONF_NEW_ORDER_STATE));
|
||||
$helper->tpl_vars['fields_value']['shipped_order_state'] = Tools::getValue('shipped_order_state', (int)Configuration::get(ConfigurationAdapter::CONF_SHIPPED_ORDER_STATE));
|
||||
|
||||
return $helper->generateForm([$formFields]);
|
||||
}
|
||||
|
||||
public function renderShippingMappingForm()
|
||||
{
|
||||
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
/** @var EmpikClient $client */
|
||||
$client = $this->empikClientFactory->createClient();
|
||||
|
||||
try {
|
||||
$responseShippingTypes = $client->getShippingTypes();
|
||||
$responseCarriers = $client->getCarriers();
|
||||
} catch (Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
$shopCarriers = (new CarriersDataProvider())->getCarriers();
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'empik_carriers' => $responseCarriers['carriers'],
|
||||
'empik_shipping_types' => $responseShippingTypes['shipping_types'],
|
||||
'shop_carriers' => $shopCarriers,
|
||||
'map' => $this->carrierMapManager->loadFromConfig(),
|
||||
]
|
||||
);
|
||||
|
||||
$formFields = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->l('Shipping'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'html',
|
||||
'label' => $this->l('Shipping mapping'),
|
||||
'name' => 'html_data',
|
||||
'html_content' => $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/_partials/shipping_table.tpl'
|
||||
),
|
||||
],
|
||||
],
|
||||
'buttons' => [],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$helper = new HelperForm();
|
||||
|
||||
$helper->show_toolbar = false;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->default_form_language = $language->id;
|
||||
$helper->submit_action = 'submitOrderFormShipping';
|
||||
$helper->currentIndex = $this->link->getAdminLink($this->controller_name);
|
||||
$helper->token = Tools::getAdminTokenLite('AdminEmpikOrders');
|
||||
$helper->tpl_vars = [
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
];
|
||||
|
||||
return $helper->generateForm([$formFields]);
|
||||
}
|
||||
|
||||
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
|
||||
{
|
||||
return Translate::getModuleTranslation($this->module, $string, get_class($this), null, $addslashes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
<?php
|
||||
|
||||
use Empik\Marketplace\Adapter\LinkAdapter;
|
||||
use Empik\Marketplace\Configuration\ExportConfiguration;
|
||||
use Empik\Marketplace\Handler\UpdateDeleteOfferHandler;
|
||||
use Empik\Marketplace\Processor\ExportProductProcessor;
|
||||
use Empik\Marketplace\Repository\ProductRepository;
|
||||
|
||||
class AdminEmpikProductsController extends ModuleAdminController
|
||||
{
|
||||
const CONF_EXPORT_SUCCESS = 1;
|
||||
const CONF_EXCLUDE_ALL_SUCCESS = 2;
|
||||
const CONF_INCLUDE_ALL_SUCCESS = 3;
|
||||
|
||||
/** @var EmpikMarketplace */
|
||||
public $module;
|
||||
|
||||
/** @var Category */
|
||||
protected $id_current_category;
|
||||
|
||||
/** @var ExportProductProcessor */
|
||||
protected $exportProductProcessor;
|
||||
|
||||
/** @var ExportConfiguration */
|
||||
protected $exportConfiguration;
|
||||
|
||||
/** @var ProductRepository */
|
||||
protected $productRepository;
|
||||
|
||||
/** @var LinkAdapter */
|
||||
protected $link;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'product';
|
||||
$this->className = 'Product';
|
||||
$this->lang = true;
|
||||
$this->bootstrap = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->_conf[self::CONF_EXPORT_SUCCESS] = $this->l('Export successful.');
|
||||
$this->_conf[self::CONF_EXCLUDE_ALL_SUCCESS] = $this->l('All products removed from export successful.');
|
||||
$this->_conf[self::CONF_INCLUDE_ALL_SUCCESS] = $this->l('All products added to export successful.');
|
||||
|
||||
$this->exportProductProcessor = $this->module->getService('empik.marketplace.processor.exportProductProcessor');
|
||||
$this->exportConfiguration = $this->module->getService('empik.marketplace.configuration.exportConfiguration');
|
||||
$this->productRepository = $this->module->getService('empik.marketplace.repository.productRepository');
|
||||
$this->link = $this->module->getService('empik.marketplace.adapter.link');
|
||||
|
||||
$langId = Context::getContext()->language->id;
|
||||
$shopId = Context::getContext()->shop->id;
|
||||
|
||||
if (Tools::getValue('reset_filter_category')) {
|
||||
$this->context->cookie->id_category_empik_products_filter = false;
|
||||
}
|
||||
|
||||
$id_category = (int)Tools::getValue('id_category');
|
||||
if (Tools::getIsset('id_category')) {
|
||||
$this->id_current_category = $id_category;
|
||||
$this->context->cookie->id_category_empik_products_filter = $id_category;
|
||||
}
|
||||
|
||||
if ($this->context->cookie->id_category_empik_products_filter) {
|
||||
$this->id_current_category = $this->context->cookie->id_category_empik_products_filter;
|
||||
}
|
||||
|
||||
if ($this->id_current_category) {
|
||||
$this->_join .= ' INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (
|
||||
cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->id_current_category.'
|
||||
)';
|
||||
}
|
||||
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'empik_product` ep ON (
|
||||
ep.id_product = a.id_product AND ep.id_product_attribute = 0
|
||||
)';
|
||||
|
||||
$this->_select .= '
|
||||
a.price AS price_tax_incl,
|
||||
sa.quantity AS quantity,
|
||||
cl.name AS category_name,
|
||||
IFNULL(ep.product_export, 0) AS product_export,
|
||||
IFNULL(ep.offer_export, 0) AS offer_export
|
||||
';
|
||||
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (
|
||||
sa.id_product = a.id_product AND
|
||||
sa.id_product_attribute = 0 '.
|
||||
StockAvailable::addSqlShopRestriction(null, null, 'sa').')';
|
||||
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (
|
||||
cl.id_category = a.id_category_default AND cl.id_lang = '.(int)$langId.' AND cl.id_shop = '.(int)$shopId.'
|
||||
)';
|
||||
|
||||
$this->fields_list = [
|
||||
'id_product' => [
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'class' => 'fixed-width-xs',
|
||||
],
|
||||
'name' => [
|
||||
'title' => $this->l('Name'),
|
||||
'filter_key' => 'b!name',
|
||||
],
|
||||
'category_name' => [
|
||||
'title' => $this->l('Category'),
|
||||
'search' => false,
|
||||
],
|
||||
'reference' => [
|
||||
'title' => $this->l('Reference'),
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'price' => [
|
||||
'title' => $this->l('Price (tax excl.)'),
|
||||
'type' => 'price',
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'price_tax_incl' => [
|
||||
'title' => $this->l('Price (tax incl.)'),
|
||||
'type' => 'price',
|
||||
'search' => false,
|
||||
'orderby' => false,
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'quantity' => [
|
||||
'title' => $this->l('Quantity'),
|
||||
'filter_key' => 'sa!quantity',
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'product_export' => [
|
||||
'title' => $this->l('Product export'),
|
||||
'product_export' => 'status',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayEnableProductButton',
|
||||
],
|
||||
'offer_export' => [
|
||||
'title' => $this->l('Offer export'),
|
||||
'offer_export' => 'status',
|
||||
'type' => 'bool',
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayEnableOfferButton',
|
||||
],
|
||||
];
|
||||
|
||||
$this->addListActions();
|
||||
}
|
||||
|
||||
protected function addListActions()
|
||||
{
|
||||
$this->addRowAction('view');
|
||||
|
||||
$this->bulk_actions = [
|
||||
'addProducts' => [
|
||||
'text' => $this->l('Add products to export'),
|
||||
'icon' => 'icon-plus',
|
||||
],
|
||||
'removeProducts' => [
|
||||
'text' => $this->l('Remove products from export'),
|
||||
'icon' => 'icon-trash',
|
||||
],
|
||||
'addOffers' => [
|
||||
'text' => $this->l('Add offers to export'),
|
||||
'icon' => 'icon-plus',
|
||||
],
|
||||
'removeOffers' => [
|
||||
'text' => $this->l('Remove offers from export'),
|
||||
'icon' => 'icon-trash',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function displayEnableProductButton($val, $row)
|
||||
{
|
||||
$id = $row['id_product'];
|
||||
$p = Tools::getValue('submitFilter' . $this->table);
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'href' => self::$currentIndex.'&token='.$this->token.'&'.$this->identifier.'='.$id.'&action='.(!$val ? 'enableProduct' : 'disableProduct').($p ? '&submitFilter' . $this->table . '=' . $p : ''),
|
||||
'action' => $this->l('Enable'),
|
||||
'enabled' => $val,
|
||||
]
|
||||
);
|
||||
|
||||
return $this->module->display($this->module->name, 'views/templates/admin/list_action_enable.tpl');
|
||||
}
|
||||
|
||||
public function displayEnableOfferButton($val, $row)
|
||||
{
|
||||
$id = $row['id_product'];
|
||||
$p = Tools::getValue('submitFilter' . $this->table);
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'href' => self::$currentIndex.'&token='.$this->token.'&'.$this->identifier.'='.$id.'&action='.(!$val ? 'enableOffer' : 'disableOffer').($p ? '&submitFilter' . $this->table . '=' . $p : ''),
|
||||
'action' => $this->l('Enable'),
|
||||
'enabled' => $val,
|
||||
]
|
||||
);
|
||||
|
||||
return $this->module->display($this->module->name, 'views/templates/admin/list_action_enable.tpl');
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
|
||||
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/admin/empik.js');
|
||||
|
||||
Media::addJsDef([
|
||||
'empikAjaxUrl' => $this->link->getAdminLink($this->controller_name, ['ajax' => 1]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
$this->toolbar_btn = [];
|
||||
}
|
||||
|
||||
public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = null)
|
||||
{
|
||||
parent::getList(
|
||||
$id_lang,
|
||||
$orderBy,
|
||||
$orderWay,
|
||||
$start,
|
||||
$limit,
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($this->_list as $i => $product) {
|
||||
$this->_list[$i]['price_tax_incl'] = Product::getPriceStatic($product['id_product']);
|
||||
}
|
||||
}
|
||||
|
||||
public function renderView()
|
||||
{
|
||||
// PS 1.6 redirect
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink(
|
||||
'AdminProducts',
|
||||
['id_product' => Tools::getValue('id_product')]
|
||||
) . '&update' . $this->table
|
||||
);
|
||||
}
|
||||
|
||||
public function ajaxProcessExportProducts()
|
||||
{
|
||||
$page = (int)Tools::getValue('page');
|
||||
if ($page < 0) {
|
||||
$page = 0;
|
||||
}
|
||||
|
||||
$this->exportProductProcessor->setPage($page);
|
||||
$this->exportProductProcessor->process();
|
||||
|
||||
$continue = !$this->exportProductProcessor->isLastPage();
|
||||
|
||||
$this->ajaxDie(json_encode([
|
||||
'success' => true,
|
||||
'continue' => $continue,
|
||||
'redirect' => $this->link->getAdminLink($this->controller_name, ['conf' => self::CONF_EXPORT_SUCCESS]),
|
||||
'errors' => $this->errors,
|
||||
]));
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
$exportConf = $this->exportConfiguration;
|
||||
$csvAbsPath = $exportConf::EXPORT_PATH;
|
||||
$csvRelPath = $exportConf::EXPORT_DIR . $exportConf::EXPORT_PRODUCT_FILENAME;
|
||||
|
||||
$this->context->smarty->assign(
|
||||
[
|
||||
'id_category' => $this->id_current_category,
|
||||
'tree' => $this->renderCategoryTree(),
|
||||
'api_authenticated' => $this->module->getAuthStatus(),
|
||||
'url_docs' => $this->link->getAdminLink('AdminEmpikHelp'),
|
||||
'url_export_products' => $this->link->getAdminLink($this->controller_name, ['action' => 'exportProducts']),
|
||||
'url_exclude_all' => $this->link->getAdminLink($this->controller_name, ['action' => 'excludeAll']),
|
||||
'url_include_all' => $this->link->getAdminLink($this->controller_name, ['action' => 'includeAll']),
|
||||
'url_products_csv' => file_exists($csvAbsPath) ? $csvRelPath : false,
|
||||
]
|
||||
);
|
||||
|
||||
$this->content .= $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/products.tpl'
|
||||
);
|
||||
$this->content .= $this->context->smarty->fetch(
|
||||
$this->module->getLocalPath().'/views/templates/admin/list_category_filter.tpl'
|
||||
);
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
protected function renderCategoryTree()
|
||||
{
|
||||
$tree = new HelperTreeCategories('product_associated_categories');
|
||||
$tree->setUseCheckBox(false)
|
||||
->setFullTree(true)
|
||||
->setRootCategory(Context::getContext()->shop->id_category);
|
||||
|
||||
if ($this->id_current_category) {
|
||||
$tree->setSelectedCategories([$this->id_current_category]);
|
||||
}
|
||||
|
||||
$tree->setInputName('category_filter');
|
||||
|
||||
return $tree->render();
|
||||
}
|
||||
|
||||
public function processEnableProduct()
|
||||
{
|
||||
$productId = Tools::getValue('id_product');
|
||||
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->product_export = 1;
|
||||
$empikProduct->save();
|
||||
|
||||
Db::getInstance()->update('empik_product', ['product_export' => 1], 'id_product = ' . (int)$productId);
|
||||
}
|
||||
|
||||
public function processDisableProduct()
|
||||
{
|
||||
$productId = Tools::getValue('id_product');
|
||||
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->product_export = 0;
|
||||
$empikProduct->save();
|
||||
|
||||
Db::getInstance()->update('empik_product', ['product_export' => 0], 'id_product = ' . (int)$productId);
|
||||
}
|
||||
|
||||
public function processEnableOffer()
|
||||
{
|
||||
$productId = Tools::getValue('id_product');
|
||||
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->offer_export = 1;
|
||||
$empikProduct->save();
|
||||
}
|
||||
|
||||
public function processDisableOffer()
|
||||
{
|
||||
$productId = Tools::getValue('id_product');
|
||||
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->offer_export = 0;
|
||||
$empikProduct->save();
|
||||
|
||||
/** @var UpdateDeleteOfferHandler $handler */
|
||||
$handler = $this->module->getService('empik.marketplace.handler.updateDeleteOfferHandler');
|
||||
|
||||
if (($result = $handler->handle([$productId]))) {
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => 4])
|
||||
);
|
||||
}
|
||||
|
||||
$this->errors = $handler->getErrors();
|
||||
}
|
||||
|
||||
public function processBulkAddProducts()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
foreach ($this->boxes as $productId) {
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->product_export = 1;
|
||||
$empikProduct->save();
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
|
||||
public function processBulkRemoveProducts()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
foreach ($this->boxes as $productId) {
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->product_export = 0;
|
||||
$empikProduct->save();
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
|
||||
public function processBulkAddOffers()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
foreach ($this->boxes as $productId) {
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->offer_export = 1;
|
||||
$empikProduct->save();
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
|
||||
public function processBulkRemoveOffers()
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
|
||||
/** @var UpdateDeleteOfferHandler $handler */
|
||||
$handler = $this->module->getService('empik.marketplace.handler.updateDeleteOfferHandler');
|
||||
|
||||
if (($result = $handler->handle($this->boxes))) {
|
||||
foreach ($this->boxes as $productId) {
|
||||
$empikProduct = \EmpikProduct::getOrCreate($productId);
|
||||
$empikProduct->offer_export = 0;
|
||||
$empikProduct->save();
|
||||
}
|
||||
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => 4])
|
||||
);
|
||||
}
|
||||
|
||||
$this->errors = $handler->getErrors();
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
|
||||
public function processExcludeAll()
|
||||
{
|
||||
Db::getInstance()->update(
|
||||
'empik_product',
|
||||
[
|
||||
'product_export' => 0,
|
||||
'offer_export' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => self::CONF_EXCLUDE_ALL_SUCCESS])
|
||||
);
|
||||
}
|
||||
|
||||
public function processIncludeAll()
|
||||
{
|
||||
$sql = 'INSERT IGNORE INTO `' . _DB_PREFIX_ . 'empik_product` (`id_product`, `id_product_attribute`, `logistic_class`, `product_export`, `offer_export`)
|
||||
SELECT `id_product`, 0, 0, 1, 1
|
||||
FROM `' . _DB_PREFIX_ . 'product`
|
||||
';
|
||||
|
||||
Db::getInstance()->execute($sql);
|
||||
|
||||
Db::getInstance()->update(
|
||||
'empik_product',
|
||||
[
|
||||
'product_export' => 1,
|
||||
'offer_export' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
Tools::redirectAdmin(
|
||||
$this->link->getAdminLink($this->controller_name, ['conf' => self::CONF_INCLUDE_ALL_SUCCESS])
|
||||
);
|
||||
}
|
||||
|
||||
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
|
||||
{
|
||||
return Translate::getModuleTranslation($this->module, $string, get_class($this), null, $addslashes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
<?php
|
||||
|
||||
use Empik\Marketplace\Adapter\LinkAdapter;
|
||||
use Empik\Marketplace\API\EmpikClient;
|
||||
use Empik\Marketplace\Factory\EmpikClientFactory;
|
||||
use Empik\Marketplace\Repository\ProductRepository;
|
||||
use Empik\Marketplace\Cache\Cache;
|
||||
use PrestaShop\PrestaShop\Adapter\CombinationDataProvider;
|
||||
|
||||
class AdminEmpikProductsPriceController extends ModuleAdminController
|
||||
{
|
||||
/** @var EmpikMarketplace */
|
||||
public $module;
|
||||
|
||||
/** @var ProductRepository */
|
||||
protected $productRepository;
|
||||
|
||||
/** @var CombinationDataProvider */
|
||||
protected $combinationDataProvider;
|
||||
|
||||
/** @var EmpikClient */
|
||||
protected $empikClient;
|
||||
|
||||
/** @var LinkAdapter */
|
||||
protected $link;
|
||||
|
||||
/** @var Cache */
|
||||
protected $cache;
|
||||
|
||||
/** @var EmpikProduct */
|
||||
protected $object;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'empik_product';
|
||||
$this->className = EmpikProduct::class;
|
||||
$this->bootstrap = true;
|
||||
parent::__construct();
|
||||
|
||||
// 1.7.0
|
||||
if (Tools::getIsset('changeDisplayOriginalPrice')) {
|
||||
$idEmpikProduct = (int)Tools::getValue('id_empik_product');
|
||||
$idProduct = Db::getInstance()->getValue('SELECT id_product FROM ' . _DB_PREFIX_ . 'empik_product
|
||||
WHERE id_empik_product = ' . (int)$idEmpikProduct);
|
||||
|
||||
if ($idProduct > 0) {
|
||||
\Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'empik_product
|
||||
SET export_original_price = IF(export_original_price=1, 0, 1)
|
||||
WHERE id_product = '.(int)$idProduct);
|
||||
}
|
||||
|
||||
Tools::redirectAdmin($this->context->link->getAdminLink('AdminEmpikProductsPrice'));
|
||||
}
|
||||
|
||||
$this->addRowAction('edit');
|
||||
|
||||
$this->productRepository = $this->module->getService('empik.marketplace.repository.productRepository');
|
||||
$this->combinationDataProvider = $this->module->getService('empik.marketplace.dataProvider.combinationDataProvider');
|
||||
$this->link = $this->module->getService('empik.marketplace.adapter.link');
|
||||
$this->cache = $this->module->getService('empik.marketplace.cache.cache');
|
||||
|
||||
/** @var EmpikClientFactory $empikClientFactory */
|
||||
$empikClientFactory = $this->module->getService('empik.marketplace.factory.empikClientFactory');
|
||||
$this->empikClient = $empikClientFactory->createClient();
|
||||
|
||||
$langId = Context::getContext()->language->id;
|
||||
$shopId = Context::getContext()->shop->id;
|
||||
|
||||
$this->_select .= 'p.reference, p.ean13, pl.name, p.price AS price_tax_incl,
|
||||
cl.name as category_name,
|
||||
IFNULL(ep.offer_price, 0) AS offer_price,
|
||||
IFNULL(ep.offer_price_reduced, 0) AS offer_price_reduced,
|
||||
CONCAT(ep.id_empik_product, "_", ep.export_original_price) as export_original_price_data
|
||||
'; // 1.7.0
|
||||
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (
|
||||
p.id_product = a.id_product AND a.id_product_attribute = 0
|
||||
)';
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'empik_product` ep ON (
|
||||
ep.id_product = a.id_product AND ep.id_product_attribute = 0
|
||||
)';
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (
|
||||
cl.id_category = p.id_category_default AND cl.id_lang = '.(int)$langId.' AND cl.id_shop = '.(int)$shopId.'
|
||||
)';
|
||||
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
pl.id_product = a.id_product AND pl.id_lang = '.(int)$langId.' AND pl.id_shop = '.(int)$shopId.'
|
||||
)';
|
||||
|
||||
$this->_where = 'AND a.id_product_attribute = 0';
|
||||
|
||||
$this->fields_list = [
|
||||
'id_product' => [
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'class' => 'fixed-width-xs',
|
||||
],
|
||||
'reference' => [
|
||||
'title' => $this->l('Reference'),
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'ean13' => [
|
||||
'title' => $this->l('EAN'),
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'name' => [
|
||||
'title' => $this->l('Name'),
|
||||
'filter_key' => 'pl!name',
|
||||
],
|
||||
'category_name' => [
|
||||
'title' => $this->l('Category'),
|
||||
'filter_key' => 'cl!name',
|
||||
],
|
||||
'price_tax_incl' => [
|
||||
'title' => $this->l('Price'),
|
||||
'type' => 'price',
|
||||
'search' => false,
|
||||
'orderby' => false,
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'offer_price' => [
|
||||
'title' => $this->l('Empik price'),
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayEmpikPriceColumn',
|
||||
'remove_onclick' => true,
|
||||
],
|
||||
'price_reduced_tax_incl' => [
|
||||
'title' => $this->l('Price reduced'),
|
||||
'type' => 'price',
|
||||
'search' => false,
|
||||
'orderby' => false,
|
||||
'class' => 'fixed-width-md',
|
||||
],
|
||||
'offer_price_reduced' => [
|
||||
'title' => $this->l('Empik price reduced'),
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'callback' => 'displayEmpikPriceReducedColumn',
|
||||
'remove_onclick' => true,
|
||||
],
|
||||
// 1.7.0
|
||||
'export_original_price_data' => [
|
||||
'title' => $this->l('Display discount'),
|
||||
'class' => 'fixed-width-md',
|
||||
'align' => 'center',
|
||||
'search' => false,
|
||||
'orderby' => false,
|
||||
'callback' => 'displayEmpikExportOriginalPriceColumn',
|
||||
'remove_onclick' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->addListActions();
|
||||
}
|
||||
|
||||
public function displayEmpikPriceColumn($val, $row)
|
||||
{
|
||||
$combinations = $this->combinationDataProvider->getCombinationsByProductId($row['id_product']);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'value' => $val,
|
||||
'id_product' => $row['id_product'],
|
||||
'combinations' => $combinations,
|
||||
]);
|
||||
|
||||
return $this->module->display($this->module->name, 'views/templates/admin/list_action_edit_price.tpl');
|
||||
}
|
||||
|
||||
public function displayEmpikPriceReducedColumn($val, $row)
|
||||
{
|
||||
$combinations = $this->combinationDataProvider->getCombinationsByProductId($row['id_product']);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'value' => $val,
|
||||
'id_product' => $row['id_product'],
|
||||
'combinations' => $combinations,
|
||||
]);
|
||||
|
||||
return $this->module->display($this->module->name, 'views/templates/admin/list_action_edit_price_reduced.tpl');
|
||||
}
|
||||
|
||||
// 1.7.0
|
||||
public function displayEmpikExportOriginalPriceColumn($val)
|
||||
{
|
||||
$data = explode('_', $val);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'displayOriginal' => (bool)$data[1],
|
||||
'urlChange' => $this->link->getAdminLink($this->controller_name, ['changeDisplayOriginalPrice' => 1, 'id_empik_product' => $data[0]]),
|
||||
]);
|
||||
|
||||
return $this->module->display($this->module->name, 'views/templates/admin/list_action_original_price.tpl');
|
||||
}
|
||||
|
||||
public function setMedia($isNewTheme = false)
|
||||
{
|
||||
parent::setMedia($isNewTheme);
|
||||
|
||||
$this->addJS(_MODULE_DIR_ . $this->module->name . '/views/js/admin/empik.js');
|
||||
|
||||
Media::addJsDef([
|
||||
'empikAjaxUrl' => $this->link->getAdminLink($this->controller_name, ['ajax' => 1]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function initToolbar()
|
||||
{
|
||||
$this->toolbar_btn = [];
|
||||
}
|
||||
|
||||
public function initProcess()
|
||||
{
|
||||
parent::initProcess();
|
||||
|
||||
if ($this->action == 'view') {
|
||||
$this->display = 'edit';
|
||||
$this->action = 'edit';
|
||||
}
|
||||
|
||||
$this->handleBulkUpdateLogisticClass();
|
||||
$this->handleBulkUpdateCondition();
|
||||
$this->handleBulkUpdateOriginalPriceOn();
|
||||
$this->handleBulkUpdateOriginalPriceOff();
|
||||
}
|
||||
|
||||
public function getList($id_lang, $orderBy = null, $orderWay = null, $start = 0, $limit = null, $id_lang_shop = null)
|
||||
{
|
||||
parent::getList(
|
||||
$id_lang,
|
||||
$orderBy,
|
||||
$orderWay,
|
||||
$start,
|
||||
$limit,
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($this->_list as $i => $product) {
|
||||
$this->_list[$i]['price_tax_incl'] = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, false);
|
||||
$this->_list[$i]['price_reduced_tax_incl'] = Product::getPriceStatic($product['id_product'], true, null, 2, null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$this->fields_form = [
|
||||
'legend' => [
|
||||
'title' => $this->l('Offer params'),
|
||||
'icon' => 'icon-gears',
|
||||
],
|
||||
'input' => [
|
||||
'name' => [
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Logistic class'),
|
||||
'name' => 'logistic_class',
|
||||
'options' => [
|
||||
'query' => $this->getLogisticClassesOptions(),
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
],
|
||||
'class' => 'fixed-width-xxl',
|
||||
],
|
||||
[
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Condition'),
|
||||
'name' => 'condition',
|
||||
'options' => [
|
||||
'query' => $this->getConditionOptions(),
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
],
|
||||
'class' => 'fixed-width-xxl',
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
],
|
||||
];
|
||||
|
||||
return parent::renderForm();
|
||||
}
|
||||
|
||||
protected function getLogisticClassesOptions()
|
||||
{
|
||||
$logisticClasses = [];
|
||||
|
||||
$response = $this->getLogisticClasses();
|
||||
|
||||
if (!empty($response['logistic_classes'])) {
|
||||
foreach ($response['logistic_classes'] as $logisticClass) {
|
||||
$logisticClasses[] = [
|
||||
'id' => $logisticClass['code'],
|
||||
'name' => $logisticClass['label'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $logisticClasses;
|
||||
}
|
||||
|
||||
protected function getConditionOptions()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'id' => 11,
|
||||
'name' => $this->l('New (code 11)')
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => $this->l('Used - very good condition')
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => $this->l('Used - good condition')
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'name' => $this->l('Used - satisfactory condition')
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'name' => $this->l('Renewed - very good condition')
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'name' => $this->l('Renewed - good condition')
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'name' => $this->l('Renewed - satisfactory condition')
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'name' => $this->l('Damaged packaging')
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function addListActions()
|
||||
{
|
||||
$this->addRowAction('view');
|
||||
|
||||
// Logistic class
|
||||
$response = $this->getLogisticClasses();
|
||||
if (!empty($response['logistic_classes'])) {
|
||||
foreach ($response['logistic_classes'] as $logisticClass) {
|
||||
$key = sprintf('logisticClass_%s', $logisticClass['code']);
|
||||
$this->bulk_actions[$key] = [
|
||||
'text' => $this->l('Logistic class:') . ' ' . $logisticClass['label'],
|
||||
'icon' => 'icon-truck',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Condition
|
||||
$conditionOptions = $this->getConditionOptions();
|
||||
foreach ($conditionOptions as $conditionOption) {
|
||||
$key = sprintf('condition_%s', $conditionOption['id']);
|
||||
$this->bulk_actions[$key] = [
|
||||
'text' => $this->l('Condition:') . ' ' . $conditionOption['name'],
|
||||
'icon' => 'icon-gears',
|
||||
];
|
||||
}
|
||||
|
||||
$key = 'original_price_on';
|
||||
$this->bulk_actions[$key] = [
|
||||
'text' => $this->l('Display discounts'),
|
||||
'icon' => 'icon-gears',
|
||||
];
|
||||
|
||||
$key = 'original_price_off';
|
||||
$this->bulk_actions[$key] = [
|
||||
'text' => $this->l('Do not display discounts'),
|
||||
'icon' => 'icon-gears',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getLogisticClasses()
|
||||
{
|
||||
try {
|
||||
return $this->cache->get('logistic_classes', function () {
|
||||
return $this->empikClient->getLogisticClasses();
|
||||
});
|
||||
} catch (Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function handleBulkUpdateLogisticClass()
|
||||
{
|
||||
$requestKeys = array_keys($_REQUEST);
|
||||
$logisticClassRequest = preg_grep('/logisticClass_(\d+)/', $requestKeys);
|
||||
if (!empty($logisticClassRequest)) {
|
||||
$logisticClassCode = preg_replace('/\D/', '', reset($logisticClassRequest));
|
||||
if (is_numeric($logisticClassCode)) {
|
||||
$this->processBulkLogisticClass($logisticClassCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleBulkUpdateCondition()
|
||||
{
|
||||
$requestKeys = array_keys($_REQUEST);
|
||||
$conditionRequest = preg_grep('/condition_(\d+)/', $requestKeys);
|
||||
if (!empty($conditionRequest)) {
|
||||
$conditionCode = preg_replace('/\D/', '', reset($conditionRequest));
|
||||
if (is_numeric($conditionCode)) {
|
||||
$this->processBulkCondition($conditionCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleBulkUpdateOriginalPriceOn()
|
||||
{
|
||||
$requestKeys = array_keys($_REQUEST);
|
||||
$request = preg_grep('/original_price_on/', $requestKeys);
|
||||
|
||||
if (!empty($request)) {
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
$this->toggleOriginalPrice(1);
|
||||
|
||||
$this->confirmations[] = $this->l('Price settings updated successfully!');
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleBulkUpdateOriginalPriceOff()
|
||||
{
|
||||
$requestKeys = array_keys($_REQUEST);
|
||||
$request = preg_grep('/original_price_off/', $requestKeys);
|
||||
|
||||
if (!empty($request)) {
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
$this->toggleOriginalPrice(0);
|
||||
$this->confirmations[] = $this->l('Price settings updated successfully!');
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function toggleOriginalPrice($value)
|
||||
{
|
||||
$idProducts = Db::getInstance()->executeS('SELECT id_product FROM ' . _DB_PREFIX_ . 'empik_product
|
||||
WHERE id_empik_product IN (' . implode(',', array_map('intval', $this->boxes)) . ')');
|
||||
|
||||
if (!empty($idProducts)) {
|
||||
foreach ($idProducts as $idProduct) {
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE ' . _DB_PREFIX_ . 'empik_product
|
||||
SET `export_original_price` = '.(int)$value.'
|
||||
WHERE id_product = ' . (int)$idProduct['id_product']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessSavePrice()
|
||||
{
|
||||
$productId = Tools::getValue('id_product');
|
||||
$productAttributeId = Tools::getValue('id_product_attribute');
|
||||
$price = Tools::getValue('price');
|
||||
|
||||
$this->productRepository->updateOfferPrice($productId, $productAttributeId, $price);
|
||||
|
||||
$this->ajaxDie(json_encode([
|
||||
'success' => true,
|
||||
'message' => $this->l('Price saved successfully!'),
|
||||
'errors' => $this->errors,
|
||||
]));
|
||||
}
|
||||
|
||||
public function ajaxProcessSaveReducedPrice()
|
||||
{
|
||||
$productId = Tools::getValue('id_product');
|
||||
$productAttributeId = Tools::getValue('id_product_attribute');
|
||||
$price = Tools::getValue('price');
|
||||
|
||||
$this->productRepository->updateOfferPriceReduced($productId, $productAttributeId, $price);
|
||||
|
||||
$this->ajaxDie(json_encode([
|
||||
'success' => true,
|
||||
'message' => $this->l('Price saved successfully!'),
|
||||
'errors' => $this->errors,
|
||||
]));
|
||||
}
|
||||
|
||||
public function processBulkLogisticClass($logisticClass)
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
Db::getInstance()->update(
|
||||
'empik_product',
|
||||
[
|
||||
'logistic_class' => (int)$logisticClass,
|
||||
],
|
||||
'id_empik_product IN (' . implode(',', array_map('intval', $this->boxes)) . ')'
|
||||
);
|
||||
|
||||
$this->confirmations[] = $this->l('Logistic class updated successfully!');
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
|
||||
public function processBulkCondition($condition)
|
||||
{
|
||||
if (is_array($this->boxes) && !empty($this->boxes)) {
|
||||
Db::getInstance()->update(
|
||||
'empik_product',
|
||||
[
|
||||
'condition' => (int)$condition,
|
||||
],
|
||||
'id_empik_product IN (' . implode(',', array_map('intval', $this->boxes)) . ')'
|
||||
);
|
||||
|
||||
$this->confirmations[] = $this->l('Condition updated successfully!');
|
||||
} else {
|
||||
$this->errors[] = $this->l('You must select at least one item');
|
||||
}
|
||||
}
|
||||
}
|
||||
11
modules/empikmarketplace/controllers/admin/index.php
Normal file
11
modules/empikmarketplace/controllers/admin/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;
|
||||
37
modules/empikmarketplace/controllers/front/cron.php
Normal file
37
modules/empikmarketplace/controllers/front/cron.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Empik\Marketplace\Exception\InvalidActionException;
|
||||
use Empik\Marketplace\Handler\CronJobsHandler;
|
||||
|
||||
class EmpikMarketplaceCronModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
/** @var EmpikMarketplace */
|
||||
public $module;
|
||||
|
||||
/** @var CronJobsHandler */
|
||||
protected $cronJobsHandler;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
$this->cronJobsHandler = $this->module->getService('empik.marketplace.handler.cronJobs');
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if ($this->cronJobsHandler->checkToken(Tools::getValue('token'))) {
|
||||
try {
|
||||
$this->cronJobsHandler->handle(Tools::getValue('action'));
|
||||
|
||||
die($this->module->l('Job complete'));
|
||||
} catch (InvalidActionException $exception) {
|
||||
die($this->module->l('Unknown action'));
|
||||
} catch (Exception $exception) {
|
||||
die(sprintf($this->module->l('Job failed: %s'), $exception->getMessage()));
|
||||
}
|
||||
} else {
|
||||
die($this->module->l('Invalid token'));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
modules/empikmarketplace/controllers/front/index.php
Normal file
11
modules/empikmarketplace/controllers/front/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;
|
||||
11
modules/empikmarketplace/controllers/index.php
Normal file
11
modules/empikmarketplace/controllers/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