Files
2025-06-24 14:14:35 +02:00

90 lines
3.6 KiB
PHP

<?php
class inpostshipmyPackageModuleFrontController extends ModuleFrontController
{
public function initContent()
{
$this->display_column_right = false;
$this->display_column_left = false;
$context = Context::getContext();
if (empty($context->customer->id)) {
Tools::redirect('index.php');
}
parent::initContent();
$this->context->smarty->tpl_vars['page']->value['body_classes']['page-customer-account'] = true;
$packageList = InpostPack::getCustomerPackage((int)$context->customer->id);
if (!empty($packageList)) {
foreach ($packageList as &$item) {
$order = new Order((int)$item['id_order']);
$item['order_reference'] = $order->reference;
}
}
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$ajaxTrackingLink = $ssl.$this->context->shop->domain.$this->context->shop->physical_uri.'modules/inpostship/ajax/tracking.php';
$ajaxTrackingHistoryLink = $ssl.$this->context->shop->domain.$this->context->shop->physical_uri.'modules/inpostship/ajax/trackingHistory.php';
$favouritePoint = 'brak';
$userPoint = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship_user_point` WHERE `id_customer` = '.(int)$context->customer->id);
if (!empty($userPoint)) {
$point = $userPoint['point'];
$inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'));
$pointInfo = $inpostapi->getPointInfo($point);
if (isset($pointInfo->name)) {
$favouritePoint = $pointInfo->name.', '.$pointInfo->address->line1.' '.$pointInfo->address->line2.', '.$pointInfo->location_description;
// $favouritePoint .= ' <img src="'.$pointInfo->image_url.'" alt="" style="width: 200px;" />';
}
}
$pType = 0;
$pTypes = COnfiguration::get('INPOSTSHIP_POINT_TYPE');
$pTypes = explode(',', $pTypes);
foreach ($pTypes as $pT) {
if ($pT == 'pop') {
$pType = 1;
}
}
$baseDirShop = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__;
$this->context->smarty->assign(array(
'packageList' => $packageList,
'ajaxTrackingLink' => $ajaxTrackingLink,
'ajaxTrackingHistoryLink' => $ajaxTrackingHistoryLink,
'favouritePoint' => $favouritePoint,
'id_customer' => $context->customer->id,
'pTypes' => $pType,
'map_box' => Configuration::get('INPOSTSHIP_MAP_BOX'),
'imap' => Configuration::get('INPOSTSHIP_MAP_TYPE'),
'imgm' => Configuration::get('INPOSTSHIP_GOOGLE_MAPS_API'),
'imw' => Configuration::get('INPOSTSHIP_MAP_WIDTH'),
'map_show' => Configuration::get('INPOSTSHIP_MAP_SHOW'),
'baseDirShop' => $baseDirShop,
));
if (self::ps17()) {
$this->setTemplate('module:inpostship/views/templates/front/mypackage.tpl');
} else {
$this->setTemplate('mypackage16.tpl');
}
}
public function setMedia()
{
$js_path = $this->module->getPathUri().'views/js/';
$css_path = $this->module->getPathUri().'views/css/';
parent::setMedia();
$this->context->controller->addJS($js_path.'front.js');
$this->context->controller->addCSS($css_path.'myaccount.css');
}
private static function ps17()
{
return Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=');
}
}