Jump to content

Sort by date in controller (Amazon Maretplace)


roman.b

Recommended Posts

Hi,

I have a problem sorting the imported data

In spite of the fact that we have bought the author's support, they do not know what to do. For two months they could not fix what they themselves screwed up.

The problem is in AdminAmazonOrdersController.php But I do not find it myself

For comparison I have a working version and not working, maybe someone will tell me where the error lies.

 

It is about anomalies in annex.

 

Work older version:

require_once(dirname(__FILE__) . '/../../amazon.php');
require_once(dirname(__FILE__) . '/../../classes/amazon.tools.class.php');


class AdminAmazonOrdersController extends ModuleAdminController
{
public $module = 'amazon';
public $name = 'amazon';

public function __construct()
{
$this->path = _PS_MODULE_DIR_ . $this->module . '/';

$this->className = 'amazon';
$this->display = 'edit';

$this->multishop_context = Shop::CONTEXT_ALL;
$this->id_lang = (int)Context::getContext()->language->id;

$this->lang = true;
$this->deleted = false;
$this->colorOnBackground = false;

$this->url = __PS_BASE_URI__ . basename(_PS_MODULE_DIR_) . '/' . $this->name . '/';
$this->images = $this->url . 'images/';

$this->context = Context::getContext();
$this->bootstrap = true;

parent::__construct();

if (version_compare(_PS_VERSION_, '1.6', '>='))
$this->psIs16x = true;
else
$this->psIs16x = false;
}

public function renderForm()
{
$html = null;
$html .= $this->tabHeader();
$html .= $this->languageSelector();

if ($this->psIs16x)
$this->addCSS($this->url . 'css/OrdersAmazon16.css', 'screen');
else
$this->addCSS($this->url . 'css/OrdersAmazon.css', 'screen');

$this->addJS($this->url . 'js/orders.js');

$this->context->smarty->assign('path', $this->url);
$this->context->smarty->assign('images', $this->images);
$this->context->smarty->assign('selected_tab', 'import');
$this->context->smarty->assign('psIs16', $this->psIs16x);

$html .= $this->context->smarty->fetch($this->path . 'views/AdminOrdersAmazon.tpl');

return $html . $this->content . parent::renderForm();
}

public function tabHeader()
{
$this->context->smarty->assign('images', $this->images);

$amazonTokens = unserialize(base64_decode(Amazon::configurationGet('AMAZON_CRON_TOKEN')));

$tokenOrders = Tools::getAdminToken('AdminOrders' . (int)Tab::getIdFromClassName('AdminOrders') . (int)$this->context->employee->id);

$day = 86400;
$days = 7;
$startDate = date('Y-m-d', time() - ($day * $days));
$currentDate = date('Y-m-d');

$this->addJqueryUI('ui.datepicker');

$this->context->smarty->assign('tokens', $amazonTokens);
$this->context->smarty->assign('token_order', $tokenOrders);
$this->context->smarty->assign('orders_url', $this->url . 'functions/orders.php');
$this->context->smarty->assign('import_url', $this->url . 'functions/import.php');
$this->context->smarty->assign('img_loader', $this->images . 'loading.gif');
$this->context->smarty->assign('img_loader_small', $this->images . 'small-loader.gif');
$this->context->smarty->assign('current_date', $currentDate);
$this->context->smarty->assign('start_date', $startDate);
$this->context->smarty->assign('psIs16', $this->psIs16x);

$this->context->smarty->assign('id_lang', $this->id_lang);

$documentation = Amazon_Tools::documentation($this->id_lang);
$faq = Amazon_Tools::documentation($this->id_lang, 'faq');

$this->context->smarty->assign('documentation', $documentation);
$this->context->smarty->assign('faq', $faq);

return ($this->context->smarty->fetch($this->path . 'views/items/orders_header.tpl'));
}

public function languageSelector()
{
$html = null;

$europe = unserialize(base64_decode(Amazon::configurationGet('AMAZON_EUROPE')));
$actives = unserialize(base64_decode(Amazon::configurationGet('AMAZON_ACTIVE')));
$regions = unserialize(base64_decode(Amazon::configurationGet('AMAZON_REGION')));
$marketPlaceIds = unserialize(base64_decode(Amazon::configurationGet('AMAZON_MARKETPLACE_ID')));

$this->addCSS($this->url . '/css/country_selector.css', 'screen');


$marketplaces = array();

if ($europe) {
$marketplacesEuro = array();
$marketplacesNotEuro = array();

if (is_array($actives))
foreach (Amazon_Tools::languages() as $language) {
$id_lang = $language['id_lang'];

if (!isset($actives[$id_lang]) || !$actives[$id_lang]) continue;

if (!isset($regions[$id_lang]) || empty($regions[$id_lang])) continue;

if (!isset($marketPlaceIds[$id_lang])) continue;

if (Amazon_Tools::isEuropeMarketplaceId($marketPlaceIds[$id_lang]) && Amazon_Tools::isEuroMarketplaceId($marketPlaceIds[$id_lang])) {
// Euro Zone Area
//
$marketplacesEuro[$id_lang] = array();
$marketplacesEuro[$id_lang]['name'] = sprintf('www.amazon.%s', Amazon_Tools::idToDomain($id_lang));
$marketplacesEuro[$id_lang]['region'] = $regions[$id_lang];
$marketplacesEuro[$id_lang]['id_lang'] = $id_lang;
$marketplacesEuro[$id_lang]['lang'] = $language['iso_code'];
$marketplacesEuro[$id_lang]['image'] = $this->images . 'geo_flags_web2/flag_' . $regions[$id_lang] . '_64px.png';
} else {
// Outside Euro Zone Area
//
$marketplacesNotEuro[$id_lang] = array();
$marketplacesNotEuro[$id_lang]['name'] = sprintf('www.amazon.%s', Amazon_Tools::idToDomain($id_lang));
$marketplacesNotEuro[$id_lang]['region'] = $regions[$id_lang];
$marketplacesNotEuro[$id_lang]['id_lang'] = $id_lang;
$marketplacesNotEuro[$id_lang]['lang'] = $language['iso_code'];
$marketplacesNotEuro[$id_lang]['image'] = $this->images . 'geo_flags_web2/flag_' . $regions[$id_lang] . '_64px.png';
}
}

if (count($marketplacesEuro))
$europeEuroArea = true;
else
$europeEuroArea = false;

if (count($marketplacesNotEuro))
$europeNotEuroArea = true;
else
$europeNotEuroArea = false;

$this->context->smarty->assign('images', $this->images);
$this->context->smarty->assign('europeEuroArea', $europeEuroArea);
$this->context->smarty->assign('europeNotEuroArea', $europeNotEuroArea);
$this->context->smarty->assign('europe_flag', $this->images . 'geo_flags_web2/flag_eu_64px.png');
$this->context->smarty->assign('marketplacesEuro', $marketplacesEuro);
$this->context->smarty->assign('marketplacesNotEuro', $marketplacesNotEuro);

return ($this->context->smarty->fetch($this->path . 'views/items/europe_selector.tpl'));
} else {
if (is_array($actives))
foreach (Amazon_Tools::languages() as $language) {
$id_lang = $language['id_lang'];

if (!isset($actives[$id_lang]) || !$actives[$id_lang]) continue;

if (!isset($regions[$id_lang]) || empty($regions[$id_lang])) continue;

$marketplaces[$id_lang] = array();
$marketplaces[$id_lang]['name'] = sprintf('www.amazon.%s', Amazon_Tools::idToDomain($id_lang));
$marketplaces[$id_lang]['region'] = $regions[$id_lang];
$marketplaces[$id_lang]['id_lang'] = $id_lang;
$marketplaces[$id_lang]['lang'] = $language['iso_code'];
$marketplaces[$id_lang]['image'] = $this->images . 'geo_flags_web2/flag_' . $regions[$id_lang] . '_64px.png';
}
$this->context->smarty->assign('images', $this->images);
$this->context->smarty->assign('marketplaces', $marketplaces);
$this->context->smarty->assign('psIs16', $this->psIs16x);

return ($this->context->smarty->fetch($this->path . 'views/items/country_selector.tpl'));
}
}

}

Not work new version:

require_once(dirname(__FILE__).'/../../amazon.php');
require_once(dirname(__FILE__).'/../../classes/amazon.tools.class.php');

class AdminAmazonOrdersController extends ModuleAdminController
{
public $module = 'amazon';
public $name = 'amazon';

public $ps17x = false;
public $ps16x = false;

public function __construct()
{
$this->path = _PS_MODULE_DIR_.$this->module.'/';

$this->className = 'amazon';
$this->display = 'edit';

$this->id_lang = (int)Context::getContext()->language->id;

$this->lang = true;
$this->deleted = false;
$this->colorOnBackground = false;

$this->url = __PS_BASE_URI__.basename(_PS_MODULE_DIR_).'/'.$this->name.'/';
$this->images = $this->url.'views/img/';

$this->context = Context::getContext();
$this->bootstrap = true;

parent::__construct();

if (version_compare(_PS_VERSION_, '1.7', '>=')) {
$this->ps17x = true;
$this->ps16x = true;
} elseif (version_compare(_PS_VERSION_, '1.6', '>=')) {
$this->ps16x = true;
} else {
$this->ps16x = false;
}
}

public function renderForm()
{
$html = null;
$html .= $this->tabHeader();
$html .= $this->languageSelector();

if ($this->ps17x) {
$this->addCSS($this->url.'views/css/OrdersAmazon16.css', 'screen');
$this->addCSS($this->url.'views/css/OrdersAmazon17.css', 'screen');
} elseif ($this->ps16x) {
$this->addCSS($this->url.'views/css/OrdersAmazon16.css', 'screen');
} else {
$this->addCSS($this->url.'views/css/OrdersAmazon.css', 'screen');
}

$this->addJS($this->url.'views/js/orders.js');

$this->context->smarty->assign('path', $this->url);
$this->context->smarty->assign('images', $this->images);
$this->context->smarty->assign('debug', (bool)Configuration::get('AMAZON_DEBUG_MODE'));
$this->context->smarty->assign('selected_tab', 'import');
$this->context->smarty->assign('ps16x', $this->ps16x);

$alert_class = array();
$alert_class['danger'] = $this->ps16x ? 'alert alert-danger' : 'error';
$alert_class['warning'] = $this->ps16x ? 'alert alert-warning' : 'warn';
$alert_class['success'] = $this->ps16x ? 'alert alert-success' : 'conf';
$alert_class['info'] = $this->ps16x ? 'alert alert-info' : 'info';

$this->context->smarty->assign('alert_class', $alert_class);

$html .= $this->context->smarty->fetch($this->path.'views/templates/admin/AdminOrdersAmazon.tpl');

return $html.$this->content.parent::renderForm();
}

public function tabHeader()
{
$this->context->smarty->assign('images', $this->images);

$amazonTokens = unserialize(AmazonTools::decode(Configuration::get('AMAZON_CRON_TOKEN')));

$tokenOrders = Tools::getAdminToken('AdminOrders'.(int)Tab::getIdFromClassName('AdminOrders').(int)$this->context->employee->id);

$day = 86400;
$days = 2;
$startDate = date('Y-m-d', time() - ($day * $days));
$currentDate = date('Y-m-d');

$this->addJqueryUI('ui.datepicker');

if (version_compare(_PS_VERSION_, '1.5', '>=') && Shop::isFeatureActive() && in_array($this->context->shop->getContext(), array(
Shop::CONTEXT_GROUP,
Shop::CONTEXT_ALL
))
) {
$this->context->smarty->assign('shop_warning', $this->l('You are in multishop environment. To use Amazon module, you must select a target shop.'));
}
$amazon_features = Amazon::getAmazonFeatures();

$this->context->smarty->assign('context_key', AmazonContext::getKey($this->context->shop));
$this->context->smarty->assign('debug', (bool)Configuration::get('AMAZON_DEBUG_MODE'));
$this->context->smarty->assign('carriers_modules', (bool)Configuration::get('AMAZON_CARRIERS_MODULES'));
$this->context->smarty->assign('tokens', $amazonTokens);
$this->context->smarty->assign('token_order', $tokenOrders);
$this->context->smarty->assign('orders_url', $this->url.'functions/orders.php');
$this->context->smarty->assign('import_url', $this->url.'functions/import.php');
$this->context->smarty->assign('img_loader', $this->images.'loading.gif');
$this->context->smarty->assign('img_loader_small', $this->images.'small-loader.gif');
$this->context->smarty->assign('current_date', $currentDate);
$this->context->smarty->assign('fba', (bool)$amazon_features['fba']);
$this->context->smarty->assign('start_date', $startDate);
$this->context->smarty->assign('psIs16', $this->ps16x);

$alert_class = array();
$alert_class['danger'] = $this->ps16x ? 'alert alert-danger' : 'error';
$alert_class['warning'] = $this->ps16x ? 'alert alert-warning' : 'warn';
$alert_class['success'] = $this->ps16x ? 'alert alert-success' : 'conf';
$alert_class['info'] = $this->ps16x ? 'alert alert-info' : 'info';

$this->context->smarty->assign('alert_class', $alert_class);
$this->context->smarty->assign('id_lang', $this->id_lang);

$documentation = AmazonSupport::gethreflink();

$this->context->smarty->assign('documentation', $documentation);
$this->context->smarty->assign('support', AmazonSupport::gethreflink(AmazonSupport::TUTORIAL_GET_SUPPORT));

return ($this->context->smarty->fetch($this->path.'views/templates/admin/items/orders_header.tpl'));
}

public function languageSelector()
{
$html = null;
$master = unserialize(AmazonTools::decode(Configuration::get('AMAZON_MASTER')));
$amazon_features = Amazon::getAmazonFeatures();
$europe = $amazon_features['amazon_europe'] && !empty($master);

$actives = unserialize(AmazonTools::decode(Configuration::get('AMAZON_ACTIVE')));
$regions = unserialize(AmazonTools::decode(Configuration::get('AMAZON_REGION')));
$marketPlaceIds = unserialize(AmazonTools::decode(Configuration::get('AMAZON_MARKETPLACE_ID')));

$this->addCSS($this->url.'/views/css/country_selector.css', 'screen');

$marketplaces = array();

if ($europe) {
$marketplacesEuro = array();
$marketplacesNotEuro = array();

if (is_array($actives)) {
foreach (AmazonTools::languages() as $language) {
$id_lang = $language['id_lang'];

if (!isset($actives[$id_lang]) || !$actives[$id_lang]) {
continue;
}

if (!isset($regions[$id_lang]) || empty($regions[$id_lang])) {
continue;
}

if (!isset($marketPlaceIds[$id_lang])) {
continue;
}

if (AmazonTools::isEuropeMarketplaceId($marketPlaceIds[$id_lang]) && AmazonTools::isEuroMarketplaceId($marketPlaceIds[$id_lang])) {
// Euro Zone Area
//
$marketplacesEuro[$id_lang] = array();
$marketplacesEuro[$id_lang]['name'] = sprintf('www.amazon.%s', AmazonTools::idToDomain($id_lang));
$marketplacesEuro[$id_lang]['region'] = $regions[$id_lang];
$marketplacesEuro[$id_lang]['id_lang'] = $id_lang;
$marketplacesEuro[$id_lang]['lang'] = $language['iso_code'];
$marketplacesEuro[$id_lang]['image'] = $this->images.'geo_flags_web2/flag_'.$regions[$id_lang].'_64px.png';
} else {
// Outside Euro Zone Area
//
$marketplacesNotEuro[$id_lang] = array();
$marketplacesNotEuro[$id_lang]['name'] = sprintf('www.amazon.%s', AmazonTools::idToDomain($id_lang));
$marketplacesNotEuro[$id_lang]['region'] = $regions[$id_lang];
$marketplacesNotEuro[$id_lang]['id_lang'] = $id_lang;
$marketplacesNotEuro[$id_lang]['lang'] = $language['iso_code'];
$marketplacesNotEuro[$id_lang]['image'] = $this->images.'geo_flags_web2/flag_'.$regions[$id_lang].'_64px.png';
}
}
}

if (count($marketplacesEuro)) {
$europeEuroArea = true;
} else {
$europeEuroArea = false;
}

if (count($marketplacesNotEuro)) {
$europeNotEuroArea = true;
} else {
$europeNotEuroArea = false;
}

$this->context->smarty->assign('images', $this->images);
$this->context->smarty->assign('europeEuroArea', $europeEuroArea);
$this->context->smarty->assign('europeNotEuroArea', $europeNotEuroArea);
$this->context->smarty->assign('europe_flag', $this->images.'geo_flags_web2/flag_eu_64px.png');
$this->context->smarty->assign('marketplacesEuro', $marketplacesEuro);
$this->context->smarty->assign('marketplacesNotEuro', $marketplacesNotEuro);
$this->context->smarty->assign('psIs16', $this->ps16x);
$this->context->smarty->assign('show_country_selector', count($marketplacesEuro) + count($marketplacesNotEuro) > 1 ? true : false);

return ($this->context->smarty->fetch($this->path.'views/templates/admin/items/europe_selector.tpl'));
} else {
if (is_array($actives)) {
foreach (AmazonTools::languages() as $language) {
$id_lang = $language['id_lang'];

if (!isset($actives[$id_lang]) || !$actives[$id_lang]) {
continue;
}

if (!isset($regions[$id_lang]) || empty($regions[$id_lang])) {
continue;
}

$marketplaces[$id_lang] = array();
$marketplaces[$id_lang]['name'] = sprintf('www.amazon.%s', AmazonTools::idToDomain($id_lang));
$marketplaces[$id_lang]['region'] = $regions[$id_lang];
$marketplaces[$id_lang]['id_lang'] = $id_lang;
$marketplaces[$id_lang]['lang'] = $language['iso_code'];
$marketplaces[$id_lang]['image'] = $this->images.'geo_flags_web2/flag_'.$regions[$id_lang].'_64px.png';
}
}
$this->context->smarty->assign('images', $this->images);
$this->context->smarty->assign('marketplaces', $marketplaces);
$this->context->smarty->assign('psIs16', $this->ps16x);
$this->context->smarty->assign('show_country_selector', count($marketplaces) > 1 ? true : false);

return ($this->context->smarty->fetch($this->path.'views/templates/admin/items/country_selector.tpl'));
}
}
}


post-751113-0-83595100-1490102367_thumb.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...