* @copyright 2014-2023 Presta-Mod.pl * @license Licecnja na jedną domenę * Presta-Mod.pl Rafał Zontek */ if (!defined('_PS_VERSION_')) { exit; } include_once dirname(__FILE__) . '/lib/api.php'; include_once dirname(__FILE__) . '/lib/shipxapi.php'; include_once dirname(__FILE__) . '/classes/PaczkomatyList.php'; include_once dirname(__FILE__) . '/classes/BaselinkerOrder.php'; class PmInpostPaczkomaty extends Module { private static $media_added_cache = false; protected $config_form = false; public $confirmations; public $errors; public $move_footer; public $sandbox; public $warnings; public $version_ps; public function __construct() { $this->author = 'Presta-Mod.pl'; $this->bootstrap = true; $this->confirmations = []; $this->errors = []; $this->move_footer = true; $this->name = 'pminpostpaczkomaty'; $this->need_instance = 0; $this->sandbox = false; $this->tab = 'shipping_logistics'; $this->version = '2.8.5'; $this->warnings = []; parent::__construct(); $this->displayName = $this->l('Inpost Paczkomaty Poland'); $this->description = $this->l('Inpost Paczkomaty Poland with new fast map'); $this->confirmUninstall = $this->l('Do you want to uninstall the module?'); $this->ps_versions_compliancy = ['min' => '1.6', 'max' => _PS_VERSION_]; if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<=')) { $this->version_ps = '1.6'; } else { $this->version_ps = '1.7'; } $this->switchSandbox(); $this->carrierAutoEnableDisable(); } public function install() { if (extension_loaded('curl') == false) { $this->_errors[] = $this->l('You have to enable the cURL extension on your server to install this module'); return false; } return parent::install() && PaczkomatyList::installSql() && PmBaselinkerOrder::installSql() && $this->registerHook('displayHeader') && $this->registerHook('actionEmailSendBefore') && $this->registerHook('displayBackOfficeHeader') && $this->registerHook('displayBeforeCarrier') && $this->registerHook('updateCarrier') && $this->registerHook('actionCarrierUpdate') && $this->registerHook('actionValidateOrder') && $this->registerHook('sendMailAlterTemplateVars') && $this->registerHook('displayFooter') && $this->registerAdminHook() && $this->createAjaxController(); } public function uninstall() { $config = $this->getConfigurationFormValues(); foreach (array_keys($config) as $key) { Configuration::deleteByName($key); } parent::uninstall(); PaczkomatyList::uninstallSql(); PmBaselinkerOrder::uninstallSql(); $this->unregisterHook('displayHeader'); $this->unregisterHook('displayBackOfficeHeader'); $this->unregisterHook('actionValidateOrder'); $this->unregisterHook('displayBeforeCarrier'); $this->unregisterHook('updateCarrier'); $this->unregisterHook('actionCarrierUpdate'); $this->unregisterHook('sendMailAlterTemplateVars') && $this->unregisterHook('displayFooter'); $this->unregisterHook('actionEmailSendBefore'); $this->unregisterAdminHook(); $this->removeAjaxController(); return true; } public function registerAdminHook() { if (Tools::version_compare(_PS_VERSION_, '1.6.0.9', '>=')) { return $this->registerHook('displayAdminOrderTabLink') && $this->registerHook('displayAdminOrderTabContent') && $this->registerHook('displayAdminOrderTabShip') && $this->registerHook('displayAdminOrderContentShip'); } else { return $this->registerHook('adminOrder'); } } public function hookDisplayAdminOrderTabLink($hook_params) { $params = []; $params['order'] = new Order($hook_params['id_order']); return $this->hookDisplayAdminOrderTabShip($params); } public function hookDisplayAdminOrderTabContent($hook_params) { $params = []; $params['order'] = new Order($hook_params['id_order']); return $this->hookDisplayAdminOrderContentShip($params); } public function unregisterAdminHook() { $this->unregisterHook('displayAdminOrderTabShip'); $this->unregisterHook('displayAdminOrderContentShip'); $this->unregisterHook('adminOrder'); } public function createAjaxController() { $tab = new Tab(); $tab->active = 1; $languages = Language::getLanguages(false); if (is_array($languages)) { foreach ($languages as $language) { $tab->name[$language['id_lang']] = $this->name; } } $tab->class_name = 'PmInpostPaczkomatyOrder'; $tab->module = $this->name; $tab->id_parent = -1; $tab->add(); $tab = new Tab(); $tab->active = 1; $languages = Language::getLanguages(false); if (is_array($languages)) { foreach ($languages as $language) { $tab->name[$language['id_lang']] = 'Inpost paczkomaty'; } } $tab->class_name = 'PmInpostPaczkomatyList'; $tab->module = $this->name; $id_parent = Tab::getIdFromClassName('AdminParentShipping'); $tab->id_parent = $id_parent; $tab->add(); $languages = Language::getLanguages(false); if (is_array($languages)) { foreach ($languages as $language) { $tab->name[$language['id_lang']] = 'Inpost paczkomaty zlecenia'; } } $tab->class_name = 'PmInpostPaczkomatyZlecenia'; $tab->module = $this->name; $id_parent = Tab::getIdFromClassName('AdminParentShipping'); $tab->id_parent = $id_parent; $tab->add(); return true; } public function removeAjaxController() { $id_parent = Tab::getIdFromClassName('PmInpostPaczkomatyOrder'); $tab = new Tab($id_parent); $tab->delete(); $id_parent = Tab::getIdFromClassName('PmInpostPaczkomatyList'); $tab = new Tab($id_parent); $tab->delete(); $id_parent = Tab::getIdFromClassName('PmInpostPaczkomatyZlecenia'); $tab = new Tab($id_parent); $tab->delete(); return true; } public function installOverrides() { if (Module::isInstalled('x13opc') || Module::isInstalled('onepagecheckout')) { if (!is_dir($this->getLocalPath() . 'override')) { return true; } $result = true; foreach (Tools::scandir($this->getLocalPath() . 'override', 'php', '', true) as $file) { if (strpos($file, 'OrderOpcController.php')) { continue; } $class = basename($file, '.php'); if (PrestaShopAutoload::getInstance()->getClassPath($class . 'Core') || Module::getModuleIdByName($class)) { $result &= $this->addOverride($class); } } return $result; } else { return parent::installOverrides(); } } public function uninstallOverrides() { if (Module::isInstalled('x13opc')) { if (!is_dir($this->getLocalPath() . 'override')) { return true; } $result = true; foreach (Tools::scandir($this->getLocalPath() . 'override', 'php', '', true) as $file) { if (strpos($file, 'OrderOpcController.php') !== false) { continue; } $class = basename($file, '.php'); if (PrestaShopAutoload::getInstance()->getClassPath($class . 'Core') || Module::getModuleIdByName($class)) { $result &= $this->removeOverride($class); } } return $result; } else { return parent::uninstallOverrides(); } } protected function renderForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitPminpostpaczkomatyModule'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigurationFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ]; return $helper->generateForm($this->getConfigurationForm()); } protected function renderFormAdmin($params) { $btn = 1; if (isset($params['order']) && $params['order'] instanceof Order) { $order = $params['order']; } else { $order = new Order($params['id_order']); } $id_cart = $order->id_cart; $paczkomatyList = PaczkomatyList::getByIdCart($id_cart); $this->addDeliveryAllegro($paczkomatyList); if (!$paczkomatyList->id) { $btn = 1; } elseif ($paczkomatyList->nr_listu == '') { $btn = 1; } elseif ($paczkomatyList->nr_listu != '' && $paczkomatyList->status != 'Opłacona') { $btn = 2; } elseif ($paczkomatyList->nr_listu != '' && $paczkomatyList->status == 'Opłacona') { $btn = 3; } $this->context->smarty->assign('btn', $btn); $helper = new HelperForm(); $helper->base_folder = _PS_ADMIN_DIR_ . '/themes/default/template/helpers/form/'; $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = $this->name . 'submit'; $helper->currentIndex = AdminController::$currentIndex . '&id_order=' . Tools::getValue('id_order') . '&vieworder'; $helper->token = Tools::getAdminTokenLite('AdminOrders'); $values = $this->getPackageDetails($params); $helper->tpl_vars = [ 'fields_value' => $values, 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ]; $form = $this->getDeliverListForm($btn); if (isset($values['warnings'])) { $form[0]['form'] = array_merge(['warning' => $values['warnings']], $form[0]['form']); } $return = $helper->generateForm($form); $return = preg_replace("//s", '', $return); return $return; } private function getEnabledOptions() { return [ [ 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled'), ], [ 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'), ], ]; } protected function getConfigurationForm() { $switch_type = 'switch'; $form = []; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Access'), 'required' => true, 'icon' => 'icon-cogs', ], 'input' => [ [ 'col' => 5, 'type' => 'hidden', 'name' => 'selected_menu', 'label' => $this->l('Selected menu'), ], [ 'col' => 5, 'type' => 'hidden', 'name' => 'PMINPOSTPACZKOMATY_GUIDE', 'label' => $this->l('Selected Guide'), ], [ 'type' => $switch_type, 'label' => $this->l('Use shipx API'), 'name' => 'PMINPOSTPACZKOMATY_SHIPX', 'is_default' => 0, 'class' => 'inpostshipx', 'hint' => $this->l('If you want to use the new API, you must have TOKEN'), 'values' => $this->getEnabledOptions(), ], [ 'col' => 3, 'type' => 'text', 'required' => true, 'name' => 'PMINPOSTPACZKOMATY_LOGIN', 'label' => $this->l('Login'), 'hint' => $this->l('Login used in https://manager.paczkomaty.pl'), ], [ 'col' => 3, 'type' => 'text', 'required' => true, 'name' => 'PMINPOSTPACZKOMATY_PASSWORD', 'label' => $this->l('Password'), 'hint' => $this->l('The password used in https://manager.paczkomaty.pl'), ], [ 'col' => 3, 'type' => 'textarea', 'required' => true, 'name' => 'PMINPOSTPACZKOMATY_TOKEN', 'label' => $this->l('Token'), 'hint' => $this->l('The token can be obtained by contacting InPost opieka@grupainteger.pl'), ], [ 'col' => 3, 'type' => 'text', 'required' => true, 'name' => 'PMINPOSTPACZKOMATY_ID', 'label' => $this->l('Id organization'), 'hint' => $this->l('The organization\'s id can be obtained by contacting InPost'), ], [ 'type' => $switch_type, 'label' => $this->l('Sandbox'), 'name' => 'PMINPOSTPACZKOMATY_SANDBOX', 'is_default' => 0, 'class' => 'inpostshipx', 'hint' => $this->l('If you want to use sandox '), 'desc' => $this->l('Option for advanced users - Default should be select No'), 'values' => $this->getEnabledOptions(), ], [ 'type' => $switch_type, 'label' => $this->l('Log'), 'name' => 'PMINPOSTPACZKOMATY_LOG', 'is_default' => 0, 'hint' => $this->l('Generate log file from all request '), 'desc' => $this->l('Option for advanced users - Default should be select No'), 'values' => $this->getEnabledOptions(), ], ], 'buttons' => [ 'save-and-stay' => [ 'title' => $this->l('Save and test connection'), 'name' => 'saveAndTest', 'type' => 'submit', 'class' => 'btn btn-default pull-right', 'icon' => 'process-icon-save', ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Sender settings'), 'required' => true, 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_COMPANY_NAME', 'label' => $this->l('Company name'), 'hint' => [ $this->l('Company name'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_FIRST_NAME', 'label' => $this->l('Firstname'), 'hint' => [ $this->l('Firstname'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_LAST_NAME', 'label' => $this->l('Lastname'), 'hint' => [ $this->l('Lastname'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_EMAIL', 'label' => $this->l('Sender e-mail'), 'prefix' => '', 'hint' => [ $this->l('Sender e-mail'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_PHONE', 'label' => $this->l('Phone'), 'prefix' => '', 'desc' => $this->l('Use mobile phone without prefix only 9 numbers (for example 123456789)'), 'hint' => [ $this->l('Phone'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_STREET', 'label' => $this->l('Street'), 'hint' => [ $this->l('Street'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_BUILDING_NUMBER', 'label' => $this->l('Bulding number'), 'hint' => [ $this->l('Bulding number'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_POST_CODE', 'label' => $this->l('Post code'), 'hint' => [ $this->l('Post code'), $this->l('- required field if you want to communicate with api'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_CITY', 'label' => $this->l('City'), 'hint' => [ $this->l('City'), $this->l('- required field if you want to communicate with api'), ], ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Package Settings Prepayment'), 'icon' => 'icon-cogs', 'required' => true, ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Default Size'), 'name' => 'PMINPOSTPACZKOMATY_SIZE_BW', 'is_default' => 0, 'hint' => [ $this->l('The default size of the parcel paid in advance.'), $this->l('You can change the size when generating the label.'), ], 'options' => [ 'query' => $this->getSizes(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Delivery method'), 'name' => 'PMINPOSTPACZKOMATY_DELIVERY_BW', 'multiple' => true, 'desc' => $this->l('To select more than one use CTRL'), 'is_default' => 0, 'hint' => [ $this->l('Delivery method for prepaid shipment.'), $this->l('If you do not see the delivery method, create it.'), $this->l('The module does not automatically create a carrier'), ], 'options' => [ 'query' => $this->getCarriers(), 'id' => 'id_carrier', 'name' => 'name', ], ], [ 'type' => 'html', 'label' => $this->l('Use button to create new delivery method'), 'name' => 'CREATE_DELIVERY_METHOD_BW', 'hint' => [ $this->l('Click on this button to create delivery method.'), ], 'html_content' => '', ], [ 'type' => $switch_type, 'label' => $this->l('Issurance'), 'name' => 'PMINPOSTPACZKOMATY_ISSURANCE_BW', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Delivery issurance'), 'values' => $this->getEnabledOptions(), ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Package Settings Cash on delivery'), 'icon' => 'icon-cogs', 'required' => true, ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Default Size'), 'hint' => [ $this->l('The default size of the parcel paid in advance.'), $this->l('You can change the size when generating the label.'), ], 'name' => 'PMINPOSTPACZKOMATY_SIZE_COD', 'is_default' => 0, 'options' => [ 'query' => $this->getSizes(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Delivery method'), 'name' => 'PMINPOSTPACZKOMATY_DELIVERY_COD', 'is_default' => 0, 'multiple' => true, 'desc' => $this->l('To select more than one use CTRL'), 'hint' => [ $this->l('Delivery method for prepaid shipment.'), $this->l('If you do not see the delivery method, create it.'), $this->l('The module does not automatically create a carrier'), ], 'options' => [ 'query' => $this->getCarriers(), 'id' => 'id_carrier', 'name' => 'name', ], ], [ 'type' => 'html', 'label' => $this->l('Use button to create new delivery method'), 'name' => 'CREATE_DELIVERY_METHOD_COD', 'hint' => [ $this->l('Click on this button to create delivery method.'), ], 'html_content' => '', ], [ 'type' => $switch_type, 'label' => $this->l('Issurance'), 'name' => 'PMINPOSTPACZKOMATY_ISSURANCE_COD', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Shipment insurance'), 'values' => $this->getEnabledOptions(), ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Parcel settings'), 'icon' => 'icon-cogs', 'required' => true, ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Method of sending'), 'name' => 'PMINPOSTPACZKOMATY_SHIPPING_METHOD', 'is_default' => 0, 'options' => [ 'query' => $this->getShippingMethod(), 'id' => 'id_option', 'name' => 'name', ], 'hint' => [ $this->l('If you want to give packages in a parcel locker - check:'), $this->l('Posting in a parcel locker,'), $this->l('if you want shipments to be picked up by InPost courier,'), $this->l('select the Pick Up Courier method. The option can be changed during generation'), $this->l('labels, in the order view'), $this->l('Giving in to POP works only with ShipX'), ], ], [ 'type' => 'text', 'label' => $this->l('Machine'), 'name' => 'PMINPOSTPACZKOMATY_MACHINE', 'is_default' => 0, 'hint' => [ $this->l('Parcel machine to send parcels, if you want send your parcels'), $this->l('by the courier - choose the delivery method - Receive by courier'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_REFERENCE', 'label' => $this->l('Reference'), 'desc' => [ $this->l('Reference code on label max 40 chars'), $this->l('{id_order} - order number, {reference} - reference code'), $this->l('{firstname} - firstname, {lastname} - lastname'), $this->l('{productsreference} - order products reference'), ], ], [ 'type' => $switch_type, 'label' => $this->l('Add COD value to reference'), 'name' => 'PMINPOSTPACZKOMATY_ADD_COD', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Shipment insurance'), 'values' => $this->getEnabledOptions(), ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_MPK', 'label' => $this->l('MPK'), 'desc' => [ $this->l('Place of costs - optional, the place of costs must be') . $this->l('be added to the organization first so that it can be assigned to the shipment.'), $this->l('Such an operation must be carried out by an InPost employee.'), ], ], [ 'type' => 'text', 'name' => 'PMINPOSTPACZKOMATY_INSC', 'label' => $this->l('Insurance value for all packages'), 'desc' => [ $this->l('If you want, you can enter a fixed amount of insurance'), $this->l('If the amount is to be charged automatically from the order, leave it blank'), ], ], [ 'type' => 'select', 'label' => $this->l('Label format'), 'name' => 'PMINPOSTPACZKOMATY_LABEL_FORMAT', 'is_default' => 0, 'options' => [ 'query' => $this->getLabelFormat(), 'id' => 'id_option', 'name' => 'name', ], 'hint' => $this->l('Label file format'), ], [ 'type' => 'select', 'label' => $this->l('Label type'), 'name' => 'PMINPOSTPACZKOMATY_LABEL_SIZE', 'is_default' => 0, 'hint' => $this->l('The size of the downloaded file'), 'options' => [ 'query' => $this->getLabelSize(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => $switch_type, 'label' => $this->l('Download PDF with multiple deliveries'), 'name' => 'PMINPOSTPACZKOMATY_DF', 'is_default' => 0, 'class' => 't', 'values' => $this->getEnabledOptions(), ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Maps settings'), 'required' => true, 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Map select'), 'name' => 'PMINPOSTPACZKOMATY_GGMAP', 'is_default' => 0, 'options' => [ 'query' => $this->getAvailableMaps(), 'id' => 'id', 'name' => 'name', ], ], [ 'type' => 'text', 'label' => $this->l('Geowidget v5 token'), 'name' => 'PMINPOSTPACZKOMATY_MAP_TOKEN', 'desc' => [ $this->l('To obtain a token, go to manager.paczkomaty.pl,'), $this->l('My account, API > Geowidget.'), ], 'is_default' => 0, ], [ 'type' => $switch_type, 'label' => $this->l('Show Select a parcel locker from the list'), 'name' => 'PMINPOSTPACZKOMATY_WPL', 'is_default' => 0, 'hint' => [ $this->l('The option works in the back-office and in the front-office'), ], 'class' => 't', 'values' => $this->getEnabledOptions(), ], [ 'type' => $switch_type, 'label' => $this->l('Disable geolocalization for openmaps'), 'name' => 'PMINPOSTPACZKOMATY_GEO', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Geolocalization wokrs only with SSL connections'), 'values' => $this->getEnabledOptions(), ], [ 'type' => $switch_type, 'label' => $this->l('Restore the last selected parcel locker'), 'name' => 'PMINPOSTPACZKOMATY_LL', 'is_default' => 0, 'class' => 't', 'values' => $this->getEnabledOptions(), ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Inpost Paczkomaty Display Settings'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Display place'), 'name' => 'PMINPOSTPACZKOMATY_DISPLAY_PLACE', 'hint' => [ $this->l('If you use a different template than the basic one,'), $this->l('try where the parcel lockers look best'), ], 'is_default' => 0, 'options' => [ 'query' => $this->getDisplayPlace(), 'id' => 'id_option', 'name' => 'name', ], ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $params = [ 'token' => Tools::substr(md5(_COOKIE_KEY_), 0, 12), ]; $cron_url = $this->context->link->getModuleLink($this->name, 'cron', $params); $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Order status'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => $switch_type, 'label' => $this->l('Change order status'), 'name' => 'PMINPOSTPACZKOMATY_OS', 'hint' => [ $this->l('Automatically change the status of the order after generating the letter,'), $this->l('attention, you will see the change only when you refresh the page'), ], 'is_default' => 0, 'class' => 't', 'values' => $this->getEnabledOptions(), ], [ 'type' => 'select', 'label' => $this->l('Order status afer send'), 'name' => 'PMINPOSTPACZKOMATY_STATUS', 'hint' => $this->l('Choose the order status'), 'is_default' => 0, 'options' => [ 'query' => $this->getOrderStatus(), 'id' => 'id_order_state', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Select statuses with available to change'), 'name' => 'PMINPOSTPACZKOMATY_STATUS_AV', 'hint' => $this->l('Choose the order status'), 'is_default' => 0, 'multiple' => true, 'options' => [ 'query' => $this->getOrderStatus(), 'id' => 'id_order_state', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Order status pickup'), 'name' => 'PMINPOSTPACZKOMATY_STATUS_PIC', 'hint' => $this->l('Choose the order status'), 'is_default' => 0, 'options' => [ 'query' => $this->getOrderStatus(), 'id' => 'id_order_state', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Order status afer delivered'), 'name' => 'PMINPOSTPACZKOMATY_STATUS_DEL', 'hint' => $this->l('Choose the order status'), 'is_default' => 0, 'options' => [ 'query' => $this->getOrderStatus(), 'id' => 'id_order_state', 'name' => 'name', ], 'desc' => [ $this->l('This function works only when you run ajax,'), $this->l('or when you click Change order state for delivered packages (Inpost Controller)'), ], ], [ 'type' => 'html', 'label' => $this->l('Link to cron'), 'name' => 'CREATE_DELIVERY_CRON_URL', 'hint' => [ $this->l('Copy this link and add to cron task'), ], 'html_content' => '
', ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Customer message settings'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => $switch_type, 'label' => $this->l('Additional order message'), 'name' => 'PMINPOSTPACZKOMATY_CM_EN', 'hint' => [ $this->l('If you want use customer message set to Yes,'), ], 'is_default' => 0, 'class' => 't', 'values' => $this->getEnabledOptions(), ], [ 'type' => 'textarea', 'label' => $this->l('Customer message'), 'name' => 'PMINPOSTPACZKOMATY_CM', 'desc' => [ $this->l('{message_title} - tytuł wiadomości - jest zdefiniowany w tłumaczeniach sklep'), $this->l('{customer} - klient'), $this->l('{order_id} - id zamówienia'), $this->l('{order_reference} - kod referencyjny zamówienia'), $this->l('{name} - numer paczkomatu'), $this->l('{address} - adres'), ], 'size' => 20, ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Order message settings'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => $switch_type, 'label' => $this->l('Additional customer message'), 'name' => 'PMINPOSTPACZKOMATY_OM_EN', 'hint' => [ $this->l('If you want use order message set to Yes,'), $this->l('This feature works with easy uploader.'), $this->l('Your customer will get message in order confirmations.'), ], 'is_default' => 0, 'class' => 't', 'values' => $this->getEnabledOptions(), ], [ 'type' => 'textarea', 'label' => $this->l('Order message'), 'name' => 'PMINPOSTPACZKOMATY_OM', 'desc' => [ $this->l('{name} - numer paczkomatu'), $this->l('{address} - adress'), $this->l('{location_description} - opis lokalizacji'), ], 'size' => 20, ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Package Settings Prepayment') . ' - ' . $this->l('End of week'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Default Size'), 'name' => 'PMINPOSTPACZKOMATY_SIZE_EOF', 'is_default' => 0, 'hint' => [ $this->l('The default size of the parcel paid in advance.'), $this->l('You can change the size when generating the label.'), ], 'options' => [ 'query' => $this->getSizes(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Delivery method'), 'name' => 'PMINPOSTPACZKOMATY_DELIVERY_EOF', 'multiple' => true, 'is_default' => 0, 'hint' => [ $this->l('Delivery method for prepaid shipment.'), $this->l('If you do not see the delivery method, create it.'), $this->l('The module does not automatically create a carrier'), ], 'options' => [ 'query' => $this->getCarriers(), 'id' => 'id_carrier', 'name' => 'name', ], ], [ 'type' => $switch_type, 'label' => $this->l('Issurance'), 'name' => 'PMINPOSTPACZKOMATY_ISSURANCE_EOF', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Delivery issurance'), 'values' => $this->getEnabledOptions(), ], [ 'type' => 'html', 'label' => $this->l('Use button to create new delivery method'), 'name' => 'CREATE_DELIVERY_METHOD_EOF', 'hint' => [ $this->l('Click on this button to create delivery method.'), ], 'html_content' => '', ], [ 'type' => $switch_type, 'label' => $this->l('Auto enable'), 'name' => 'PMINPOSTPACZKOMATY_EOF_AE', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Auto enable delivery option'), 'values' => $this->getEnabledOptions(), ], [ 'type' => 'select', 'label' => $this->l('Available from day'), 'name' => 'PMINPOSTPACZKOMATY_EOF_D', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getDays(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Available from hour'), 'name' => 'PMINPOSTPACZKOMATY_EOF_H', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getHours(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Available to day'), 'name' => 'PMINPOSTPACZKOMATY_EOF_DT', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getDays(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Available from hour'), 'name' => 'PMINPOSTPACZKOMATY_EOF_HT', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getHours(), 'id' => 'id_option', 'name' => 'name', ], ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Package Settings Cash on delivery') . ' - ' . $this->l('End of week'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'select', 'label' => $this->l('Default Size'), 'name' => 'PMINPOSTPACZKOMATY_SIZE_EOF_COD', 'is_default' => 0, 'hint' => [ $this->l('The default size of the parcel paid in advance.'), $this->l('You can change the size when generating the label.'), ], 'options' => [ 'query' => $this->getSizes(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Delivery method'), 'name' => 'PMINPOSTPACZKOMATY_DELIVERY_EOF_COD', 'multiple' => true, 'is_default' => 0, 'hint' => [ $this->l('Delivery method for prepaid shipment.'), $this->l('If you do not see the delivery method, create it.'), $this->l('The module does not automatically create a carrier'), ], 'options' => [ 'query' => $this->getCarriers(), 'id' => 'id_carrier', 'name' => 'name', ], ], [ 'type' => 'html', 'label' => $this->l('Use button to create new delivery method'), 'name' => 'CREATE_DELIVERY_METHOD_EOF_COD', 'hint' => [ $this->l('Click on this button to create delivery method.'), ], 'html_content' => '', ], [ 'type' => $switch_type, 'label' => $this->l('Issurance'), 'name' => 'PMINPOSTPACZKOMATY_ISSURANCE_EOF_COD', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Delivery issurance'), 'values' => $this->getEnabledOptions(), ], [ 'type' => $switch_type, 'label' => $this->l('Auto enable'), 'name' => 'PMINPOSTPACZKOMATY_EOF_COD_AE', 'is_default' => 0, 'class' => 't', 'hint' => $this->l('Auto enable delivery option'), 'values' => $this->getEnabledOptions(), ], [ 'type' => 'select', 'label' => $this->l('Available from day'), 'name' => 'PMINPOSTPACZKOMATY_EOF_COD_D', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getDays(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Available from hour'), 'name' => 'PMINPOSTPACZKOMATY_EOF_COD_H', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getHours(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Available to day'), 'name' => 'PMINPOSTPACZKOMATY_EOF_COD_DT', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getDays(), 'id' => 'id_option', 'name' => 'name', ], ], [ 'type' => 'select', 'label' => $this->l('Available to hour'), 'name' => 'PMINPOSTPACZKOMATY_EOF_COD_HT', 'is_default' => 0, 'hint' => [ $this->l('If you want to use this function, remember about the InPost regulations'), $this->l('Select the days of the week and the hours'), $this->l('when the customer will be able to choose the delivery option'), $this->l('The delivery method will be enabled only in this range'), ], 'options' => [ 'query' => $this->getHours(), 'id' => 'id_option', 'name' => 'name', ], ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $params = ['token' => Tools::substr(md5(_COOKIE_KEY_), 0, 12)]; $cron_url_bl = $this->context->link->getModuleLink($this->name, 'baselinker', $params); $form[] = [ 'form' => [ 'legend' => [ 'title' => $this->l('Baselinker send Parcelocker with api'), 'icon' => 'icon-cogs', ], 'input' => [ [ 'type' => 'text', 'label' => $this->l('Id order start'), 'name' => 'PMINPOSTPACZKOMATY_BL_ORDER', 'is_default' => 0, 'hint' => [ $this->l('If you are use Baselinker connected by API.'), $this->l('To send pracel locker to baselinker. Set first order'), ], ], [ 'type' => 'text', 'label' => $this->l('Baselinker token'), 'name' => 'PMINPOSTPACZKOMATY_BL_TOKEN', 'is_default' => 0, 'hint' => [ $this->l('If you are use Baselinker connected by API.'), $this->l('To send pracel locker to baselinker. Set baselinker token'), ], ], [ 'type' => 'html', 'label' => $this->l('Send orders to baselinker'), 'name' => 'CREATE_DELIVERY_CRON_URL', 'is_default' => 0, 'html_content' => '
' . $this->l('Send orders to baselinker') . '
', ], [ 'type' => 'html', 'label' => $this->l('Link to cron'), 'name' => 'CREATE_DELIVERY_CRON_URL', 'is_default' => 0, 'html_content' => '
', ], ], 'submit' => [ 'title' => $this->l('Save'), ], ], ]; $form_titles = []; foreach ($form as $form_item) { $form_titles[] = [ 'name' => $form_item['form']['legend']['title'], 'required' => isset($form_item['form']['legend']['required']) ? $form_item['form']['legend']['required'] : false, ]; } $this->context->smarty->assign('form_titles', $form_titles); return $form; } protected function getConfigurationFormValues() { $return = [ 'PMINPOSTPACZKOMATY_ADD_COD' => Configuration::get('PMINPOSTPACZKOMATY_ADD_COD'), 'PMINPOSTPACZKOMATY_BL_CRON' => Configuration::get('PMINPOSTPACZKOMATY_BL_CRON'), 'PMINPOSTPACZKOMATY_BL_ORDER' => Configuration::get('PMINPOSTPACZKOMATY_BL_ORDER'), 'PMINPOSTPACZKOMATY_BL_TOKEN' => Configuration::get('PMINPOSTPACZKOMATY_BL_TOKEN'), 'PMINPOSTPACZKOMATY_BUILDING_NUMBER' => Configuration::get('PMINPOSTPACZKOMATY_BUILDING_NUMBER'), 'PMINPOSTPACZKOMATY_CITY' => Configuration::get('PMINPOSTPACZKOMATY_CITY'), 'PMINPOSTPACZKOMATY_CM' => Configuration::get('PMINPOSTPACZKOMATY_CM'), 'PMINPOSTPACZKOMATY_CM_EN' => Configuration::get('PMINPOSTPACZKOMATY_CM_EN'), 'PMINPOSTPACZKOMATY_COMPANY_NAME' => Configuration::get('PMINPOSTPACZKOMATY_COMPANY_NAME'), 'PMINPOSTPACZKOMATY_DELIVERY_BW[]' => $this->getCarriersBw(), 'PMINPOSTPACZKOMATY_DELIVERY_COD[]' => $this->getCarriersCod(), 'PMINPOSTPACZKOMATY_DELIVERY_EOF[]' => $this->getCarriersBwEof(), 'PMINPOSTPACZKOMATY_DELIVERY_EOF_COD[]' => $this->getCarriersCodEof(), 'PMINPOSTPACZKOMATY_DELIVERY_BW' => $this->getCarriersBw(), 'PMINPOSTPACZKOMATY_DELIVERY_COD' => $this->getCarriersCod(), 'PMINPOSTPACZKOMATY_DELIVERY_EOF' => $this->getCarriersBwEof(), 'PMINPOSTPACZKOMATY_DELIVERY_EOF_COD' => $this->getCarriersCodEof(), 'PMINPOSTPACZKOMATY_DISPLAY_PLACE' => Configuration::get('PMINPOSTPACZKOMATY_DISPLAY_PLACE'), 'PMINPOSTPACZKOMATY_DF' => Configuration::get('PMINPOSTPACZKOMATY_DF'), 'PMINPOSTPACZKOMATY_EMAIL' => Configuration::get('PMINPOSTPACZKOMATY_EMAIL'), 'PMINPOSTPACZKOMATY_EOF_AE' => Configuration::get('PMINPOSTPACZKOMATY_EOF_AE'), 'PMINPOSTPACZKOMATY_EOF_COD_AE' => Configuration::get('PMINPOSTPACZKOMATY_EOF_COD_AE'), 'PMINPOSTPACZKOMATY_EOF_COD_D' => Configuration::get('PMINPOSTPACZKOMATY_EOF_COD_D'), 'PMINPOSTPACZKOMATY_EOF_COD_DT' => Configuration::get('PMINPOSTPACZKOMATY_EOF_COD_DT'), 'PMINPOSTPACZKOMATY_EOF_COD_H' => Configuration::get('PMINPOSTPACZKOMATY_EOF_COD_H'), 'PMINPOSTPACZKOMATY_EOF_COD_HT' => Configuration::get('PMINPOSTPACZKOMATY_EOF_COD_HT'), 'PMINPOSTPACZKOMATY_EOF_D' => Configuration::get('PMINPOSTPACZKOMATY_EOF_D'), 'PMINPOSTPACZKOMATY_EOF_DT' => Configuration::get('PMINPOSTPACZKOMATY_EOF_DT'), 'PMINPOSTPACZKOMATY_EOF_H' => Configuration::get('PMINPOSTPACZKOMATY_EOF_H'), 'PMINPOSTPACZKOMATY_EOF_HT' => Configuration::get('PMINPOSTPACZKOMATY_EOF_HT'), 'PMINPOSTPACZKOMATY_FIRST_NAME' => Configuration::get('PMINPOSTPACZKOMATY_FIRST_NAME'), 'PMINPOSTPACZKOMATY_GEO' => Configuration::get('PMINPOSTPACZKOMATY_GEO'), 'PMINPOSTPACZKOMATY_LL' => Configuration::get('PMINPOSTPACZKOMATY_LL'), 'PMINPOSTPACZKOMATY_GGMAP' => Configuration::get('PMINPOSTPACZKOMATY_GGMAP'), 'PMINPOSTPACZKOMATY_GUIDE' => Configuration::get('PMINPOSTPACZKOMATY_GUIDE'), 'PMINPOSTPACZKOMATY_ID' => Configuration::get('PMINPOSTPACZKOMATY_ID'), 'PMINPOSTPACZKOMATY_ISSURANCE_BW' => Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_BW'), 'PMINPOSTPACZKOMATY_ISSURANCE_COD' => Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_COD'), 'PMINPOSTPACZKOMATY_ISSURANCE_EOF' => Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_EOF'), 'PMINPOSTPACZKOMATY_ISSURANCE_EOF_COD' => Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_EOF_COD'), 'PMINPOSTPACZKOMATY_LABEL_FORMAT' => Configuration::get('PMINPOSTPACZKOMATY_LABEL_FORMAT'), 'PMINPOSTPACZKOMATY_LABEL_SIZE' => Configuration::get('PMINPOSTPACZKOMATY_LABEL_SIZE'), 'PMINPOSTPACZKOMATY_LAST_NAME' => Configuration::get('PMINPOSTPACZKOMATY_LAST_NAME'), 'PMINPOSTPACZKOMATY_LOG' => Configuration::get('PMINPOSTPACZKOMATY_LOG'), 'PMINPOSTPACZKOMATY_LOGIN' => Configuration::get('PMINPOSTPACZKOMATY_LOGIN'), 'PMINPOSTPACZKOMATY_MACHINE' => Configuration::get('PMINPOSTPACZKOMATY_MACHINE'), 'PMINPOSTPACZKOMATY_MPK' => Configuration::get('PMINPOSTPACZKOMATY_MPK'), 'PMINPOSTPACZKOMATY_INSC' => Configuration::get('PMINPOSTPACZKOMATY_INSC'), 'PMINPOSTPACZKOMATY_NAME' => Configuration::get('PMINPOSTPACZKOMATY_NAME'), 'PMINPOSTPACZKOMATY_OM' => Configuration::get('PMINPOSTPACZKOMATY_OM'), 'PMINPOSTPACZKOMATY_OM_EN' => Configuration::get('PMINPOSTPACZKOMATY_OM_EN'), 'PMINPOSTPACZKOMATY_OS' => Configuration::get('PMINPOSTPACZKOMATY_OS'), 'PMINPOSTPACZKOMATY_PASSWORD' => Configuration::get('PMINPOSTPACZKOMATY_PASSWORD'), 'PMINPOSTPACZKOMATY_PHONE' => Configuration::get('PMINPOSTPACZKOMATY_PHONE'), 'PMINPOSTPACZKOMATY_POST_CODE' => Configuration::get('PMINPOSTPACZKOMATY_POST_CODE'), 'PMINPOSTPACZKOMATY_REFERENCE' => Configuration::get('PMINPOSTPACZKOMATY_REFERENCE'), 'PMINPOSTPACZKOMATY_SANDBOX' => Configuration::get('PMINPOSTPACZKOMATY_SANDBOX'), 'PMINPOSTPACZKOMATY_SHIPPING_METHOD' => Configuration::get('PMINPOSTPACZKOMATY_SHIPPING_METHOD'), 'PMINPOSTPACZKOMATY_SHIPX' => Configuration::get('PMINPOSTPACZKOMATY_SHIPX'), 'PMINPOSTPACZKOMATY_SIZE_BW' => Configuration::get('PMINPOSTPACZKOMATY_SIZE_BW'), 'PMINPOSTPACZKOMATY_SIZE_COD' => Configuration::get('PMINPOSTPACZKOMATY_SIZE_COD'), 'PMINPOSTPACZKOMATY_SIZE_EOF' => Configuration::get('PMINPOSTPACZKOMATY_SIZE_EOF'), 'PMINPOSTPACZKOMATY_SIZE_EOF_COD' => Configuration::get('PMINPOSTPACZKOMATY_SIZE_EOF_COD'), 'PMINPOSTPACZKOMATY_STATUS' => Configuration::get('PMINPOSTPACZKOMATY_STATUS'), 'PMINPOSTPACZKOMATY_STATUS_AV[]' => explode(',', Configuration::get('PMINPOSTPACZKOMATY_STATUS_AV')), 'PMINPOSTPACZKOMATY_STATUS_AV' => explode(',', Configuration::get('PMINPOSTPACZKOMATY_STATUS_AV')), 'PMINPOSTPACZKOMATY_STATUS_DEL' => Configuration::get('PMINPOSTPACZKOMATY_STATUS_DEL'), 'PMINPOSTPACZKOMATY_STATUS_PIC' => Configuration::get('PMINPOSTPACZKOMATY_STATUS_PIC'), 'PMINPOSTPACZKOMATY_STREET' => Configuration::get('PMINPOSTPACZKOMATY_STREET'), 'PMINPOSTPACZKOMATY_TOKEN' => Configuration::get('PMINPOSTPACZKOMATY_TOKEN'), 'PMINPOSTPACZKOMATY_MAP_TOKEN' => Configuration::get('PMINPOSTPACZKOMATY_MAP_TOKEN'), 'PMINPOSTPACZKOMATY_WPL' => Configuration::get('PMINPOSTPACZKOMATY_WPL'), 'selected_menu' => Tools::getValue('selected_menu'), ]; return $return; } private function switchSandbox() { if (Configuration::get('PMINPOSTPACZKOMATY_SANDBOX')) { $this->sandbox = true; InpostApiShipx::$shipxUrl = 'https://sandbox-api-shipx-pl.easypack24.net'; InpostApi::$wsdl = 'https://sandbox-api.paczkomaty.pl/'; } else { $this->sandbox = false; } } public function validatePostFields() { $id_carrier_bw = Tools::getValue('PMINPOSTPACZKOMATY_DELIVERY_BW'); if (!is_array($id_carrier_bw)) { $this->warnings[] = $this->l('Please select delivery method tab:') . ' ' . $this->l('Delivery method'); } $requiredFields = [ 'PMINPOSTPACZKOMATY_COMPANY_NAME', 'PMINPOSTPACZKOMATY_FIRST_NAME', 'PMINPOSTPACZKOMATY_LAST_NAME', 'PMINPOSTPACZKOMATY_EMAIL', 'PMINPOSTPACZKOMATY_PHONE', 'PMINPOSTPACZKOMATY_STREET', 'PMINPOSTPACZKOMATY_BUILDING_NUMBER', 'PMINPOSTPACZKOMATY_POST_CODE', 'PMINPOSTPACZKOMATY_CITY', ]; foreach ($requiredFields as $field) { if (trim(Tools::getValue($field)) == '') { $this->warnings[] = $this->l('Please enter company details tab:') . ' ' . $this->l('Sender settings'); break; } } $id_ogranization = Tools::getValue('PMINPOSTPACZKOMATY_ID'); if (trim($id_ogranization) != '') { if (!is_numeric($id_ogranization)) { $this->warnings[] = $this->l('Id organization') . ' ' . $this->l('Should be numeric'); } } elseif (Tools::getValue('PMINPOSTPACZKOMATY_SHIPX') && trim($id_ogranization) == '') { $this->errors[] = $this->l('Please enter id organization'); } } public function removeOldValues($config) { foreach (array_keys($config) as $key) { Configuration::deleteByName($key); } } public function clearMapCache() { $dir = dirname(__FILE__) . '/cache/mapcache/'; if (is_dir($dir)) { $objects = @scandir($dir); foreach ($objects as $file) { if ($file != 'index.php' && $file != '.' && $file != '..' && file_exists($dir . $file)) { unlink($dir . $file); } } } } protected function postProcess() { $this->confirmations[] = $this->l('Settings updated.'); $this->clearMapCache(); $this->validatePostFields(); $form_values = $this->getConfigurationFormValues(); $this->removeOldValues($form_values); foreach (array_keys($form_values) as $key) { if ($key == 'PMINPOSTPACZKOMATY_PHONE') { $value = Tools::getValue($key); $value = str_replace(['-', ' ', '+48'], ['', '', ''], $value); if (Tools::strlen($value) != 9) { $this->warnings[] = $this->l('Please enter vaild phone number'); } Configuration::updateValue($key, $value); } elseif ($key == 'PMINPOSTPACZKOMATY_DELIVERY_BW[]' || $key == 'PMINPOSTPACZKOMATY_DELIVERY_BW') { $value = Tools::getValue('PMINPOSTPACZKOMATY_DELIVERY_BW'); $this->updateSelectedCarriersBw($value); } elseif ($key == 'PMINPOSTPACZKOMATY_DELIVERY_COD[]' || $key == 'PMINPOSTPACZKOMATY_DELIVERY_COD') { $value = Tools::getValue('PMINPOSTPACZKOMATY_DELIVERY_COD'); $this->updateSelectedCarriersCod($value); } elseif ($key == 'PMINPOSTPACZKOMATY_DELIVERY_EOF[]' || $key == 'PMINPOSTPACZKOMATY_DELIVERY_EOF') { $value = Tools::getValue('PMINPOSTPACZKOMATY_DELIVERY_EOF'); $this->updateSelectedCarriersBwEof($value); } elseif ($key == 'PMINPOSTPACZKOMATY_DELIVERY_EOF_COD[]' || $key == 'PMINPOSTPACZKOMATY_DELIVERY_EOF_COD') { $value = Tools::getValue('PMINPOSTPACZKOMATY_DELIVERY_EOF_COD'); $this->updateSelectedCarriersCodEof($value); } elseif ($key == 'PMINPOSTPACZKOMATY_STATUS_AV[]' || $key == 'PMINPOSTPACZKOMATY_STATUS_AV') { $value = Tools::getValue('PMINPOSTPACZKOMATY_STATUS_AV'); $this->updateSelectedStatuses($value); } else { $value = Tools::getValue($key); if ($key == 'PMINPOSTPACZKOMATY_TOKEN') { $value = trim($value); } Configuration::updateValue($key, $value); } } if (Configuration::get('PMINPOSTPACZKOMATY_LABEL_FORMAT') == 'Zpl' && !Configuration::get('PMINPOSTPACZKOMATY_SHIPX') ) { Configuration::updateValue('PMINPOSTPACZKOMATY_LABEL_FORMAT', 'Pdf'); $this->warnings[] = $this->l('Zpl format is not supported with old API, Defalt Value: Pdf'); } if (Configuration::get('PMINPOSTPACZKOMATY_SHIPX')) { $id_parent = Tab::getIdFromClassName('PmInpostPaczkomatyZlecenia'); if ($id_parent) { $tab = new Tab($id_parent); $tab->active = true; $tab->update(); } } else { $id_parent = Tab::getIdFromClassName('PmInpostPaczkomatyZlecenia'); if ($id_parent) { $tab = new Tab($id_parent); $tab->active = false; $tab->update(); } } if (Tools::getValue('PMINPOSTPACZKOMATY_EOF_AE')) { $config = Configuration::getMultiple([ 'PMINPOSTPACZKOMATY_EOF_D', 'PMINPOSTPACZKOMATY_EOF_H', 'PMINPOSTPACZKOMATY_EOF_DT', 'PMINPOSTPACZKOMATY_EOF_HT', ]); $start = $config['PMINPOSTPACZKOMATY_EOF_D'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_H']); $end = $config['PMINPOSTPACZKOMATY_EOF_DT'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_HT']); if ($start > $end) { $this->warnings[] = $this->l('End of week') . ': ' . $this->l('Please check start date and hour') . ' ' . $this->l('Option is disable'); Configuration::updateValue('PMINPOSTPACZKOMATY_EOF_AE', false); } } if (Tools::getValue('PMINPOSTPACZKOMATY_EOF_COD_AE')) { $config = Configuration::getMultiple([ 'PMINPOSTPACZKOMATY_EOF_COD_D', 'PMINPOSTPACZKOMATY_EOF_COD_H', 'PMINPOSTPACZKOMATY_EOF_COD_DT', 'PMINPOSTPACZKOMATY_EOF_COD_HT', 'PMINPOSTPACZKOMATY_EOF_COD_LAST', ]); $start = $config['PMINPOSTPACZKOMATY_EOF_COD_D'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_COD_H']); $end = $config['PMINPOSTPACZKOMATY_EOF_COD_DT'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_COD_HT']); if ($start > $end) { $this->warnings[] = $this->l('End of week') . ' ' . $this->l('Cash on delivery') . ': ' . $this->l('Please check start date and hour') . ' ' . $this->l('Option is disable'); Configuration::updateValue('PMINPOSTPACZKOMATY_EOF_COD_AE', false); } } if (Tools::isSubmit('PMINPOSTPACZKOMATY_LOG') && Tools::getValue('PMINPOSTPACZKOMATY_LOG') == 0) { if (file_exists(dirname(__FILE__) . '/log/log.txt')) { unlink(dirname(__FILE__) . '/log/log.txt'); } } if (Tools::isSubmit('CREATE_DELIVERY_METHOD')) { $this->createDeliveryMethod(); } $this->switchSandbox(); if (sizeof($this->getCarriersBw()) == 0) { $this->warnings[] = $this->l('Please chose Parcel locker delivery method'); } if (sizeof($this->getCarriersCod()) == 0) { $this->warnings[] = $this->l('Please chose Parcel locker delivery method for COD'); } if (Tools::isSubmit('saveAndTest') && Tools::getValue('PMINPOSTPACZKOMATY_SHIPX') == 1) { $api = new InpostApiShipx(); $connection = $api->checkConnections(); if ($connection === false) { $this->errors[] = $this->l('Can not connect to API'); } elseif (isset($connection['status']) && $connection['status'] == 401) { $this->errors[] = $this->l('There is some error: ') . $this->parseErrors($connection['message']); } elseif (isset($connection['count'])) { $this->confirmations[] = $this->l('Connect successfully'); if ($connection['count'] == 1) { $this->context->smarty->assign('company_informations', $connection['items'][0]); $company_name = $connection['items'][0]['name']; $company_address = $connection['items'][0]['address']; if (Configuration::get('PMINPOSTPACZKOMATY_COMPANY_NAME') == '') { Configuration::updateValue('PMINPOSTPACZKOMATY_COMPANY_NAME', $company_name); } $fields = [ 'PMINPOSTPACZKOMATY_STREET' => 'street', 'PMINPOSTPACZKOMATY_BUILDING_NUMBER' => 'building_number', 'PMINPOSTPACZKOMATY_POST_CODE' => 'post_code', 'PMINPOSTPACZKOMATY_CITY' => 'city', ]; foreach ($fields as $field => $value) { if (Configuration::get($field) == '' && isset($company_address[$value])) { Configuration::updateValue($field, $company_address[$value]); } } } } } elseif (Tools::isSubmit('saveAndTest') && Tools::getValue('PMINPOSTPACZKOMATY_SHIPX') == 0) { if (!ini_get('allow_url_fopen')) { $this->errors[] = $this->l('Test connection faild') . ' ' . $this->l('On the server enable allow_url_fopen, ask your provider how to enable the option.') . ' ' . $this->l('You can try using ShipX'); } else { $api = new InpostApi(); $result = $api->checkConnections(); if ($result) { $this->confirmations[] = $this->l('Connect successfully'); } else { $this->errors[] = $this->l('There is some error: ') . $this->l('Can not connect to API'); } } } } public function mFil($array, $array2) { $return = array_merge($array, $array2); if (function_exists('array_filter')) { $return = array_filter($return, 'strlen'); } return $return; } private function addMediaCart() { if (self::$media_added_cache === false) { $opc_module = ''; if ($this->version_ps == '1.7') { if (Module::isEnabled('supercheckout')) { $settings = unserialize(Configuration::get('VELOCITY_SUPERCHECKOUT')); if (isset($settings['enable']) && $settings['enable']) { $opc_module = 'supercheckout_17'; } } elseif (Module::isEnabled('steasycheckout')) { $opc_module = 'steasycheckout_17'; } elseif (Module::isEnabled('spstepcheckout')) { $opc_module = 'spstepcheckout_17'; } elseif (Module::isEnabled('ets_onepagecheckout') && Configuration::get('ETS_OPC_1PAGE_ENABLED')) { $opc_module = 'ets_onepagecheckout_17'; } } $this->getCustomerLastInpostMachineAndSetCurrentCart(); $def = [ 'id_pudo_carrier' => '0', 'pm_inpostpaczkomaty_carrier' => $this->mFil($this->getCarriersBw(), $this->getCarriersBwEof()), 'pm_inpostpaczkomaty_carrier_cod' => $this->mFil($this->getCarriersCod(), $this->getCarriersCodEof()), 'pm_inpostpaczkomaty_carrier_eof' => $this->mFil($this->getCarriersCodEof(), $this->getCarriersBwEof()), 'pm_inpostpaczkomaty_current_cart' => Context::getContext()->cart->id, 'pm_inpostpaczkomaty_display_place' => Configuration::get('PMINPOSTPACZKOMATY_DISPLAY_PLACE'), 'pm_inpostpaczkomaty_gcup' => $this->context->link->getModuleLink($this->name, 'ajax'), 'pm_inpostpaczkomaty_geo' => (int) Configuration::get('PMINPOSTPACZKOMATY_GEO'), 'pm_inpostpaczkomaty_label' => $this->l('Select machine'), 'pm_inpostpaczkomaty_label_weekend' => $this->l('Please select machine to your order') . ' ' . $this->l(' - only parcel lockers for weekend packages'), 'pm_inpostpaczkomaty_machine_label' => $this->l('Machine: '), 'pm_inpostpaczkomaty_modulepath' => $this->context->link->getModuleLink($this->name, 'ajax'), 'pm_inpostpaczkomaty_opc' => $opc_module, 'pm_inpostpaczkomaty_placeholder' => $this->l('Enter city, street, or machine name'), 'pm_inpostpaczkomaty_placeholder2' => $this->l('Use button to select machine'), 'pm_inpostpaczkomaty_point_url' => $this->getPointsUrl(), 'pm_inpostpaczkomaty_prestakey' => md5(_COOKIE_KEY_), 'pm_inpostpaczkomaty_ps' => $this->version_ps, 'pm_inpostpaczkomaty_sandbox' => $this->sandbox, 'pm_inpostpaczkomaty_selected' => $this->getSelectedMachine(), 'pm_inpostpaczkomaty_selected_label' => $this->l('Please select machine to your order'), 'pm_inpostpaczkomaty_token' => $this->getEncryptedToken(), 'pm_inpostpaczkomaty_v5_token' => Configuration::get('PMINPOSTPACZKOMATY_MAP_TOKEN'), 'pm_inpostpaczkomaty_wpzl' => Configuration::get('PMINPOSTPACZKOMATY_WPL'), ]; Media::addJsDef($def); self::$media_added_cache = true; } } public function isCarrierEnabled() { return (bool) (sizeof($this->getCarriersBw()) || sizeof($this->getCarriersCod()) || sizeof($this->getCarriersBwEof()) || sizeof($this->getCarriersCodEof())); } private function getSizes() { return [ ['id_option' => 'A', 'name' => $this->l('A')], ['id_option' => 'B', 'name' => $this->l('B')], ['id_option' => 'C', 'name' => $this->l('C')], ]; } private function getSizesValues() { $sizes = $this->getSizes(); $values = []; foreach ($sizes as $size) { $values[] = [ 'id' => $size['id_option'], 'value' => $size['id_option'], 'label' => $size['name'], ]; } return $values; } private function getDays() { $days = [ ['id_option' => '1', 'name' => $this->l('Monday')], ['id_option' => '2', 'name' => $this->l('Tuesday')], ['id_option' => '3', 'name' => $this->l('Wednesday')], ['id_option' => '4', 'name' => $this->l('Thursday')], ['id_option' => '5', 'name' => $this->l('Friday')], ['id_option' => '6', 'name' => $this->l('Saturday')], ['id_option' => '7', 'name' => $this->l('Sunday')], ]; return $days; } private function getHours() { $hours = []; for ($i = 0; $i <= 23; ++$i) { $calc = str_pad($i, 2, '0', STR_PAD_LEFT); $hours[] = ['id_option' => $calc . ':00', 'name' => $calc . ':00']; $hours[] = ['id_option' => $calc . ':30', 'name' => $calc . ':30']; } return $hours; } private function getLabelFormat() { $sizes = [ ['id_option' => 'Pdf', 'name' => $this->l('Pdf')], ['id_option' => 'Epl', 'name' => $this->l('Epl')], ]; if (Configuration::get('PMINPOSTPACZKOMATY_SHIPX')) { $sizes[] = ['id_option' => 'Zpl', 'name' => $this->l('Zpl')]; } return $sizes; } private function getLabelSize() { return [ ['id_option' => 'A4', 'name' => $this->l('A4')], ['id_option' => 'A6P', 'name' => $this->l('A6P')], ]; } private function getCarriers() { $carriers_list = Carrier::getCarriers(Context::getContext()->language->id); return $carriers_list; } private function getAvailableMaps() { return [ ['id' => 0, 'name' => $this->l('Open maps')], ['id' => 2, 'name' => $this->l('Geo widget v5')], ]; } private function getShippingMethod() { $shipping_method = [ [ 'id_option' => '1', 'name' => $this->l('Giving in to the machine'), 'disabled' => 'disabled', ], [ 'id_option' => '0', 'name' => $this->l('I will create a pickup order (courier) service extra paid'), ], ]; if (Configuration::get('PMINPOSTPACZKOMATY_SHIPX')) { $shipping_method = array_merge($shipping_method, [ [ 'id_option' => '2', 'name' => $this->l('Giving in to the POP'), ], ]); } return $shipping_method; } private function getDisplayPlace() { $display_place = [ [ 'id_option' => '1', 'name' => $this->l('Display after table'), ], [ 'id_option' => '2', 'name' => $this->l('Display before table'), ], [ 'id_option' => '3', 'name' => $this->l('Display after carrier description'), ], [ 'id_option' => '4', 'name' => $this->l('Display before carrier description'), ], ]; if (version_compare(_PS_VERSION_, '1.7.0', '<')) { $display_place[] = [ 'id_option' => '5', 'name' => $this->l('Display in HOOK BEFORE CARRIER'), ]; $display_place[] = [ 'id_option' => '6', 'name' => $this->l('Display in HOOK EXTRA CARRIER'), ]; } return $display_place; } private function findInArray($search_in, $term) { foreach ($search_in as $search_in_item) { if (strpos($search_in_item, mb_strtolower($term)) !== false) { return 1; } } return 0; } private function sortResult($items, $terms) { $find = []; $terms = explode(' ', str_replace('-', ' ', $terms)); foreach ($items as $items_item) { $search = [$items_item->name, $items_item->address->line1, $items_item->address->line2]; $search = array_merge($search, (array) $items_item->address_details); $search = array_map('mb_strtolower', $search); $math = 0; foreach ($terms as $terms_item) { $math += $this->findInArray($search, $terms_item); } $find[] = ['math' => $math, 'item' => $items_item]; } usort($find, function ($first_element, $second_element) { return $second_element['math'] - $first_element['math']; }); $objects = []; foreach ($find as $find_item) { $objects[] = $find_item['item']; } return $objects; } private function getPoint($point_name) { if (empty($point_name)) { return false; } if ($this->sandbox) { $result = @Tools::file_get_contents('https://sandbox-api-pl-points.easypack24.net/v1/points/' . $point_name); } else { $result = @Tools::file_get_contents('https://api-pl-points.easypack24.net/v1/points/' . $point_name); } $point = @json_decode($result); if (is_object($point)) { $address_details = [$point->address->line1, $point->address->line2]; array_filter($address_details, 'strlen'); $address = implode(', ', $address_details); return [ '{name}' => $point_name, '{address}' => trim($address), '{location_description}' => $point->location_description ]; } return false; } private function getPoints() { $get = $_GET; $terms = Tools::getValue('term'); $get['city'] = trim(mb_strtolower($get['term'])); $get['city'] = mb_convert_case($get['city'], MB_CASE_TITLE); unset($get['term'], $get['prequest'], $get['module'], $get['controller'], $get['fc']); $get2 = $get; unset($get2['city']); $params = http_build_query($get); $params = str_replace('%5B0%5D=', '%5B%5D=', $params); $params2 = http_build_query($get2); $params2 = str_replace('%5B0%5D=', '%5B%5D=', $params2); if ($this->sandbox) { $map_result = Tools::file_get_contents('https://sandbox-api-pl-points.easypack24.net/v1/points/?' . $params); } else { $map_result = Tools::file_get_contents('https://api-pl-points.easypack24.net/v1/points/?' . $params); } $result = json_decode($map_result); if (sizeof($result->items) == 0) { if ($this->sandbox) { $map_result = Tools::file_get_contents( 'https://sandbox-api-pl-points.easypack24.net/v1/points/?' . $params2 ); } else { $map_result = Tools::file_get_contents('https://api-pl-points.easypack24.net/v1/points/?' . $params2); } $result = json_decode($map_result); } foreach ($result->items as $key => $item) { if (strpos($item->name, 'POP') !== false) { unset($result->items[$key]); } } $result->items = $this->sortResult($result->items, $terms); foreach ($result->items as &$current_item) { $current_item->location_description = (string) $current_item->location_description; $current_item->opening_hours = (string) $current_item->opening_hours; $current_item->payment_point_descr = (string) $current_item->payment_point_descr; } ob_clean(); exit(json_encode($result)); } private function selectMachine() { $id_cart = (int) Tools::getValue('pm_inpostpaczkomaty_current_cart'); if (Tools::getValue('token') == $this->getEncryptedToken($id_cart)) { $paczkomatyList = PaczkomatyList::getByIdCart($id_cart); $paczkomatyList->machine = pSql(Tools::getValue('selected')); $paczkomatyList->save(); } else { exit(json_encode(['Bad token'])); } } private function getLocation() { $id_cart = Context::getContext()->cart->id; if (Tools::getValue('token') == $this->getEncryptedToken($id_cart) || Tools::getValue('token') == md5(_COOKIE_KEY_)) { foreach (array_keys($_GET) as $key) { if (!in_array($key, ['address', 'timestamp', 'ajaxSearch', 'key'])) { unset($_GET[$key]); } } ob_clean(); $address = urlencode(Tools::getValue('address')); $md5trimaddress = md5($address); if (file_exists(dirname(__FILE__) . '/cache/mapcache/' . $md5trimaddress)) { exit(Tools::file_get_contents(dirname(__FILE__) . '/cache/mapcache/' . $md5trimaddress)); } if ((int) Configuration::get('PMINPOSTPACZKOMATY_GGMAP') == 0 || (int) Configuration::get('PMINPOSTPACZKOMATY_GGMAP') == 2) { $user_agent = $_SERVER['HTTP_USER_AGENT']; $opts = ['http' => ['header' => "User-Agent: $user_agent\r\n"]]; $context = stream_context_create($opts); $map_result = Tools::file_get_contents( 'https://osm.inpost.pl/nominatim/search?q=' . $address . '&format=jsonv2', false, $context ); $result = []; $result_location = json_decode($map_result); if (isset($result_location[0])) { $lat = $result_location[0]->lat; $lon = $result_location[0]->lon; if (isset($result_location[0])) { $result['status'] = 'OK'; $result['results'][0]['geometry']['location']['lat'] = $lat; $result['results'][0]['geometry']['location']['lng'] = $lon; } $jsoncontent = json_encode($result); echo($jsoncontent); file_put_contents(dirname(__FILE__) . '/cache/mapcache/' . $md5trimaddress, $jsoncontent); exit(); } else { $result['status'] = 'Bad location'; $jsoncontent = json_encode($result); echo($jsoncontent); exit(); } } } else { $result = []; $result['status'] = 'NO'; $result['status'] = 'Bad token'; $result['error_message'] = 'Bad token'; echo json_encode($result); exit(); } } public function ajaxCall() { if (Tools::isSubmit('prequest')) { $this->getPoints(); } elseif (Tools::isSubmit('selmachine')) { $this->selectMachine(); } elseif (Tools::isSubmit('address') && Tools::isSubmit('timestamp') && Tools::isSubmit('ajaxSearch') && Tools::isSubmit('key')) { $this->getLocation(); } } private function getSelectedMachine() { $cart = Context::getContext()->cart; return PaczkomatyList::getSelectedMachine($cart->id); } public function getSelectedMachineForPayment() { $cart = Context::getContext()->cart; if ($this->isSelectedCarrierBw($cart->id_carrier) || $this->isSelectedCarrierBwEof($cart->id_carrier) || $this->isSelectedCarrierCod($cart->id_carrier) || $this->isSelectedCarrierCodEof($cart->id_carrier) ) { return $this->l('Selected machine: ') . PaczkomatyList::getSelectedMachine($cart->id); } } public function getDeliverListForm($button = 1) { $switch_type = 'switch'; $id_order = (int) Tools::getValue('id_order'); $order = new Order($id_order); $form = []; $buttons = [ 'send' => [ 'title' => $this->l('Send Parcel'), 'icon' => 'icon-save', 'class' => 'btn btn-primary pminpostbutton-ajax send', 'href' => Context::getContext()->link->getAdminLink( 'PmInpostPaczkomatyOrder' ) . '&send=1&id_order=' . $id_order, ], 'printlabel' => [ 'title' => $this->l('Print label'), 'icon' => 'icon-print', 'class' => 'btn btn-primary pminpostbutton-ajax printlabel', 'href' => Context::getContext()->link->getAdminLink( 'PmInpostPaczkomatyOrder' ) . '&printlabel=1&id_order=' . $id_order, ], 'createnew' => [ 'title' => $this->l('Create addition'), 'icon' => 'icon-file', 'class' => 'btn btn-secondary pminpostbutton-ajax createnew', 'href' => Context::getContext()->link->getAdminLink( 'PmInpostPaczkomatyOrder' ) . '&createnew=1&id_order=' . $id_order, ], 'sendandprint' => [ 'title' => $this->l('Send and Print Label'), 'icon' => 'icon-print', 'class' => 'btn btn-primary pminpostbutton-ajax sendandprint', 'href' => Context::getContext()->link->getAdminLink('PmInpostPaczkomatyOrder') . '&sendandprint=1&id_order=' . $id_order, ], ]; if ($button == 1) { $buttons['printlabel']['class'] = $buttons['printlabel']['class'] .= ' hidden'; $buttons['createnew']['class'] = $buttons['createnew']['class'] .= ' hidden'; } if ($button == 2) { $buttons['send']['class'] = $buttons['send']['class'] .= ' hidden'; $buttons['sendandprint']['class'] = $buttons['sendandprint']['class'] .= ' hidden'; } if ($button == 3) { $buttons['send']['class'] = $buttons['send']['class'] .= ' hidden'; $buttons['sendandprint']['class'] = $buttons['sendandprint']['class'] .= ' hidden'; } $this->context->smarty->assign([ 'packages' => PaczkomatyList::getPackages($order->id_cart), 'id_order' => $id_order, ]); $others = $this->context->smarty->fetch(dirname(__FILE__) . '/views/templates/admin/others.tpl'); $cod_value = (float) Configuration::get('PMINPOSTPACZKOMATY_INSC'); $ubezpieczenie_desc = ''; if ($cod_value > 0) { $ubezpieczenie_desc = $this->l('Fixed amount of insurance, You can change in configuration.'); } $form[] = [ 'form' => [ 'input' => [ [ 'type' => 'text', 'label' => $this->l('Recipient`s e-mail address'), 'name' => 'pminpostorder_email', 'class' => 'form-control', 'required' => true, 'size' => 20, ], [ 'type' => 'text', 'label' => $this->l('Mobile phone'), 'name' => 'pminpostorder_phone', 'required' => true, 'size' => 20, 'class' => 'paczkomaty_input form-control', ], [ 'type' => 'text', 'label' => $this->l('To machine InPost'), 'name' => 'pminpostorder_selected', 'is_default' => 0, 'class' => 'widget form-control', 'required' => true, ], [ 'type' => 'radio', 'label' => $this->l('Size'), 'name' => 'pminpostorder_size', 'is_default' => 0, 'br' => false, 'class' => 'btnpaczkomaty-size', 'required' => true, 'values' => $this->getSizesValues(), ], [ 'type' => 'text', 'label' => $this->l('Reference number'), 'name' => 'pminpostorder_reference', 'size' => 20, 'class' => 'paczkomaty_input form-control', ], [ 'type' => 'select', 'label' => $this->l('Giving to the machine'), 'name' => 'pminpostorder_machine', 'is_default' => 0, 'class' => 'paczkomaty_input custom-select', 'options' => ['query' => $this->getShippingMethod(), 'id' => 'id_option', 'name' => 'name'], ], [ 'type' => 'text', 'label' => $this->l('From machine InPost'), 'name' => 'pminpostorder_selected_from', 'is_default' => 0, 'class' => 'widget form-control', 'required' => true, ], [ 'type' => $switch_type, 'label' => $this->l('COD'), 'name' => 'pminpostorder_pobranie', 'is_default' => 0, 'class' => 'paczkomaty_input t machine', 'values' => $this->getEnabledOptions(), ], [ 'type' => 'text', 'label' => $this->l('COD Value'), 'name' => 'pminpostorder_pobranie_value', 'is_default' => 0, 'class' => 'paczkomaty_input t machine form-control', ], [ 'type' => $switch_type, 'label' => $this->l('Issurance'), 'name' => 'pminpostorder_ubezpieczenie', 'is_default' => 0, 'class' => 'paczkomaty_input t machine', 'values' => $this->getEnabledOptions(), ], [ 'type' => 'text', 'label' => $this->l('Isurance Value'), 'name' => 'pminpostorder_ubezpieczenie_value', 'desc' => $ubezpieczenie_desc, 'is_default' => 0, 'class' => 'paczkomaty_input t machine form-control', ], [ 'type' => $switch_type, 'label' => $this->l('End of week'), 'name' => 'pminpostorder_eof', 'is_default' => 0, 'class' => 'paczkomaty_input t machine', 'values' => $this->getEnabledOptions(), ], [ 'type' => 'html', 'label' => $this->l('Tracking numers'), 'name' => 'OTHER_PACKAGES', 'html_content' => $others, ], [ 'type' => 'select', 'label' => $this->l('Label format'), 'name' => 'pminpostorder_format', 'class' => 'custom-select', 'is_default' => 0, 'options' => ['query' => $this->getLabelFormat(), 'id' => 'id_option', 'name' => 'name', ], 'hint' => $this->l('Label file format'), ], [ 'type' => 'select', 'label' => $this->l('Label type'), 'name' => 'pminpostorder_size_l', 'class' => 'custom-select', 'is_default' => 0, 'options' => ['query' => $this->getLabelSize(), 'id' => 'id_option', 'name' => 'name'], 'hint' => $this->l('The size of the downloaded file'), ], ], 'buttons' => $buttons, ], ]; return $form; } public function isSelectedCarrierBw($id_carrier) { return in_array($id_carrier, $this->getCarriersBw()) || $this->isSelectedCarrierBwEof($id_carrier); } public function isSelectedCarrierBwEof($id_carrier) { return in_array($id_carrier, $this->getCarriersBwEof()); } private function filterResult(&$result) { $results = []; if (Module::isInstalled('onepagecheckout')) { foreach ($result as &$result_item) { if ($result_item) { $results[] = Cart::intifier($result_item . ','); $results[] = $result_item; } } $result = array_filter($results, 'strlen'); } } public function getCarriersBw() { $result = explode(',', Configuration::get('PMINPOSTPACZKOMATY_DELIVERY_BW')); $this->filterResult($result); return $result; } public function getCarriersBwEof() { $result = explode(',', Configuration::get('PMINPOSTPACZKOMATY_DELIVERY_EOF')); $this->filterResult($result); return $result; } public function isSelectedCarrierCod($id_carrier) { return in_array($id_carrier, $this->getCarriersCod()) || $this->isSelectedCarrierCodEof($id_carrier); } public function isSelectedCarrierCodEof($id_carrier) { return in_array($id_carrier, $this->getCarriersCodEof()); } public function getCarriersCod() { $result = explode(',', Configuration::get('PMINPOSTPACZKOMATY_DELIVERY_COD')); $this->filterResult($result); return $result; } public function getCarriersCodEof() { $result = explode(',', Configuration::get('PMINPOSTPACZKOMATY_DELIVERY_EOF_COD')); $this->filterResult($result); return $result; } public function replaceComma($string) { return (float) str_replace(',', '.', $string); } public function getPackageDetails($params) { $config = []; if (isset($params['order']) && $params['order'] instanceof Order) { $order = $params['order']; } else { $order = new Order($params['id_order']); } $id_cart = $order->id_cart; $customer = new Customer($order->id_customer); $address = new Address($order->id_address_delivery); $config['pminpostorder_email'] = $customer->email; $config['pminpostorder_phone'] = $address->phone_mobile; if ($config['pminpostorder_phone'] == '') { $config['pminpostorder_phone'] = $address->phone; } $config['pminpostorder_phone'] = str_replace('+48', '', $config['pminpostorder_phone']); $config['pminpostorder_phone'] = preg_replace('/\s+/', '', $config['pminpostorder_phone']); $config['pminpostorder_phone'] = $this->trimPhone($config['pminpostorder_phone']); $config['pminpostorder_firstname'] = $address->firstname; $config['pminpostorder_pobranie_value'] = (float) $order->total_paid_tax_incl; $config['pminpostorder_ubezpieczenie_value'] = (float) $order->total_paid_tax_incl; if (($cod_value = (float) Configuration::get('PMINPOSTPACZKOMATY_INSC')) > 0) { $config['pminpostorder_ubezpieczenie_value'] = $this->replaceComma($cod_value); } if ($this->isSelectedCarrierBwEof($order->id_carrier)) { $config['pminpostorder_eof'] = 1; $config['pminpostorder_pobranie'] = 0; $config['pminpostorder_size'] = Configuration::get('PMINPOSTPACZKOMATY_SIZE_EOF'); $config['pminpostorder_ubezpieczenie'] = Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_EOF'); } elseif ($this->isSelectedCarrierCodEof($order->id_carrier)) { $config['pminpostorder_eof'] = 1; $config['pminpostorder_pobranie'] = 1; $config['pminpostorder_size'] = Configuration::get('PMINPOSTPACZKOMATY_SIZE_EOF_COD'); $config['pminpostorder_ubezpieczenie'] = Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_EOF_COD'); } elseif ($this->isSelectedCarrierCod($order->id_carrier)) { $config['pminpostorder_eof'] = 0; $config['pminpostorder_pobranie'] = 1; $config['pminpostorder_size'] = Configuration::get('PMINPOSTPACZKOMATY_SIZE_COD'); $config['pminpostorder_ubezpieczenie'] = Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_COD'); } elseif ($this->isSelectedCarrierBw($order->id_carrier)) { $config['pminpostorder_eof'] = 0; $config['pminpostorder_pobranie'] = 0; $config['pminpostorder_size'] = Configuration::get('PMINPOSTPACZKOMATY_SIZE_BW'); $config['pminpostorder_ubezpieczenie'] = Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_BW'); } else { $config['pminpostorder_eof'] = 0; $config['pminpostorder_pobranie'] = 0; $config['pminpostorder_size'] = Configuration::get('PMINPOSTPACZKOMATY_SIZE_BW'); $config['pminpostorder_ubezpieczenie'] = Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_BW'); $config['warnings'] = $this->l('Warning: delivery method was not foud please check Cash on delivery value AND end of week'); } if ($order->module == 'pm_cashondelivery') { $config['pminpostorder_pobranie'] = 1; $config['pminpostorder_ubezpieczenie'] = Configuration::get('PMINPOSTPACZKOMATY_ISSURANCE_COD'); } $config['pminpostorder_selected_from'] = Configuration::get('PMINPOSTPACZKOMATY_MACHINE'); $config['pminpostorder_machine'] = Configuration::get('PMINPOSTPACZKOMATY_SHIPPING_METHOD'); if ($config['pminpostorder_machine'] == 2) { $config['pminpostorder_machine'] = false; } $config['pminpostorder_format'] = Configuration::get('PMINPOSTPACZKOMATY_LABEL_FORMAT'); $config['pminpostorder_size_l'] = Configuration::get('PMINPOSTPACZKOMATY_LABEL_SIZE'); $config['pminpostorder_reference'] = $this->genereateReference(); $sql = 'SELECT machine FROM `' . _DB_PREFIX_ . $this->name . 'list` WHERE id_cart = ' . (int) $id_cart; $selected_machine = Db::getInstance()->getValue($sql); if ($selected_machine) { $config['pminpostorder_selected'] = $selected_machine; } else { $config['pminpostorder_selected'] = ''; } $post_info_tmp = PaczkomatyList::getPostInfoByIdCart($id_cart); $post_info = @stripslashes($post_info_tmp); // Tools::stripslashes($string) { return $string; } PS 1782 if (empty($post_info)) { $post_info = @stripslashes($post_info_tmp); // Tools::stripslashes($string) { return $string; } PS 1782 } if ($post_info) { $post_info = unserialize($post_info); $config = array_merge($config, $post_info); } return $config; } public function prepareAdminHook($params, $html = 'all') { if ($this->_errors) { $messages = $this->_errors; } else { $messages = false; } $this->context->smarty->assign( [ 'form' => $this->renderFormAdmin($params), 'selectedpm' => $this->isSelected($params), 'message' => $messages, 'machine' => '', ] ); $this->context->smarty->assign('pminpostview', $html); $this->context->smarty->assign('module_dir', $this->_path); return $this->display(__FILE__, 'order.tpl'); } public function genereateReference() { $order = new Order(Tools::getValue('id_order')); $referenceGen = Configuration::get('PMINPOSTPACZKOMATY_REFERENCE'); $products_references = []; foreach ($order->getProducts() as $product) { if (trim($product['product_reference']) != '') { $products_references[] = $product['product_reference']; } } $customer = new Customer($order->id_customer); $reference = str_replace( ['{id_order}', '{reference}', '{productsreference}', '{firstname}', '{lastname}'], [$order->id, $order->reference, implode(' ', $products_references), $customer->firstname, $customer->lastname], $referenceGen ); $reference = trim(Tools::strtoupper($reference)); return Tools::strlen($reference) > 100 ? mb_substr($reference, 0, 100) . '@' : $reference; } private function isSelected($params) { if (isset($params['order']) && $params['order'] instanceof Order) { $order = $params['order']; } else { $order = new Order($params['id_order']); } $sql = ' SELECT * FROM `' . _DB_PREFIX_ . $this->name . 'list` WHERE id_cart = ' . (int) $order->id_cart; return Db::getInstance()->getRow($sql); } public function getOrderStatus($addempty = true) { $statuses = OrderState::getOrderStates(Context::getContext()->language->id); $status = [['id_order_state' => -1, 'name' => '--']]; if (!$addempty) { return $statuses; } else { return array_merge($status, $statuses); } } public function trimPhone($num) { $phone = preg_replace('/[^0-9+]/', '', $num); $phone = str_replace('+48', '', $phone); if (strpos($phone, '48') === 0) { $phone = substr($phone, 2); } return $phone; } private function parseErrors($error) { $errors = ['Token is missing or invalid.' => $this->l('Token is missing or invalid.')]; return isset($errors[$error]) ? $errors[$error] : $error; } public function getSelectedMachineForOrder($id_order) { $order = new Order($id_order); $id_cart = $order->id_cart; if ($this->isSelectedCarrierBw($order->id_carrier) || $this->isSelectedCarrierCod($order->id_carrier)) { return PaczkomatyList::getSelectedMachine($id_cart); } else { return false; } } public function hookDisplayBackOfficeHeader() { if (Tools::getValue('controller') == 'AdminOrders' || Tools::isSubmit('id_order') || Tools::getValue('module_name') == $this->name || Tools::getValue('configure') == $this->name || Tools::getValue('controller') == 'PmInpostPaczkomatyList' ) { $create_text = []; $create_text[] = $this->l('After create the delivery method you will be redirected to editing.'); $create_text[] = $this->l('Remember to set appropriate zones and price for the delivery method'); $create_text[] = ''; $create_text[] = $this->l('Next return to module configuration'); $create_text = implode('
', $create_text); Media::addJsDef( [ 'pm_inpostpaczkomaty_label_id' => $this->l('Organization id updated to %s successfully.') . ' ' . $this->l('Remember to save the configuration.'), 'pm_inpostpaczkomaty_cancel' => $this->l('Cancel'), 'pm_inpostpaczkomaty_create' => $this->l('Create delivery method'), 'pm_inpostpaczkomaty_create_text' => $create_text, 'pm_inpostpaczkomaty_gcup' => $this->context->link->getModuleLink($this->name, 'ajax'), 'pm_inpostpaczkomaty_point_url' => $this->getPointsUrl(), 'pm_inpostpaczkomaty_prestakey' => md5(_COOKIE_KEY_), 'pm_inpostpaczkomaty_wpzl' => Configuration::get('PMINPOSTPACZKOMATY_WPL'), 'psv' => $this->version_ps, ] ); if (Tools::version_compare(_PS_VERSION_, '1.6.1.7', '<=')) { $js_script = ''; $js_def = Media::getJsDef(); $this->context->smarty->assign('js_def', $js_def); foreach ($js_def as $key => $item) { $js_script .= 'var ' . $key . ' = \'' . $item . '\'' . PHP_EOL; } file_put_contents(dirname(__FILE__) . '/views/js/jsdef.js', $js_script); } $this->context->controller->addJquery(); $this->context->controller->addJqueryPlugin('growl'); $css_array = [ $this->_path . '/views/css/paczkomator-' . $this->version . '.css', $this->_path . '/views/css/admin-' . $this->version . '.css', $this->_path . '/views/css/jquery-confirm.css', ]; if (Tools::version_compare(_PS_VERSION_, '1.6.1.7', '<=')) { $scripts_array = [ $this->_path . '/views/js/jsdef.js', $this->_path . '/views/js/admin-order-' . $this->version . '.js', $this->_path . '/views/js/paczkomator-' . $this->version . '.js', $this->_path . '/views/js/jquery-confirm.js', ]; } else { $scripts_array = [ $this->_path . '/views/js/admin-order-' . $this->version . '.js', $this->_path . '/views/js/paczkomator-' . $this->version . '.js', $this->_path . '/views/js/jquery-confirm.js', ]; } if (Tools::getValue('module_name') == $this->name || Tools::getValue('configure') == $this->name) { $css_array[] = $this->_path . '/views/css/enjoyhint.css'; $scripts_array[] = $this->_path . '/views/js/kinetic.js'; $scripts_array[] = $this->_path . '/views/js/enjoyhint.js'; $scripts_array[] = $this->_path . '/views/js/guide.js'; } $this->context->controller->addCSS( $css_array ); $this->context->controller->addJS( $scripts_array ); } } public function hookDisplayFooter($params) { if (!$this->isCarrierEnabled()) { return ''; } if (!in_array($this->context->controller->php_self, ['order', 'order-opc', null])) { return ''; } if (!Module::isInstalled('onepagecheckoutps') && !Module::isEnabled('onepagecheckoutps') && !Module::isInstalled('supercheckout') && !Module::isEnabled('supercheckout') && !Module::isInstalled('thecheckout') && !Module::isEnabled('thecheckout') && !$this->move_footer ) { return ''; } if ((int) Context::getContext()->cart->id) { $this->addMediaCart(); return ''; } else { return ''; } } public function hookDisplayAdminOrderTabShip($params) { return $this->prepareAdminHook($params, 'tab'); } public function hookDisplayAdminOrderContentShip($params) { return $this->prepareAdminHook($params, 'content'); } public function hookDisplayHeader() { if (!in_array($this->context->controller->php_self, ['order', 'order-opc', null]) && Tools::getValue('controller') != 'supercheckout') { return ''; } if (!$this->isCarrierEnabled()) { return ''; } if (version_compare(_PS_VERSION_, '1.7.0', '>=') === true) { $this->addMediaCart(); $this->context->controller->addJqueryPlugin('fancybox'); $this->context->controller->registerStylesheet( 'modules-pmpaczkomaty', 'modules/' . $this->name . '/views/css/front17-' . $this->version . '.css' ); $this->context->controller->registerStylesheet( 'modules-pmpaczkomaty-con', 'modules/' . $this->name . '/views/css/css/jquery-confirm.css' ); $this->context->controller->registerJavascript( 'jquery-confim', 'modules/' . $this->name . '/views/js/jquery-confirm.js' ); if (Configuration::get('PMINPOSTPACZKOMATY_GGMAP') == '0') { // OpenMaps if ($this->sandbox) { $this->context->controller->registerJavascript( 'remote-widget', 'modules/' . $this->name . '/views/js/openmaps-sandbox-' . $this->version . '.js' ); } else { $this->context->controller->registerJavascript( 'remote-widget', 'modules/' . $this->name . '/views/js/openmaps-' . $this->version . '.js' ); } $this->context->controller->registerJavascript( 'pminpostpaczkomaty-script', 'modules/' . $this->name . '/views/js/front-' . $this->version . '.js' ); $this->context->controller->registerStylesheet( 'modules-pmpaczkomaty-ep', 'modules/' . $this->name . '/views/css/easypack-' . $this->version . '-openmaps.css' ); } elseif (Configuration::get('PMINPOSTPACZKOMATY_GGMAP') == '2') { // OpenMaps v.5 if ($this->sandbox) { $this->context->controller->registerJavascript( 'remote-widget2', 'https://sandbox-easy-geowidget-sdk.easypack24.net/inpost-geowidget.js', ['server' => 'remote'] ); } else { $this->context->controller->registerJavascript( 'remote-widget2', 'https://geowidget.inpost.pl/inpost-geowidget.js', ['server' => 'remote'] ); } $this->context->controller->registerJavascript( 'pminpostpaczkomaty-script', 'modules/' . $this->name . '/views/js/front-' . $this->version . '.v5.js' ); $this->context->controller->registerStylesheet( 'modules-pmpaczkomaty-ep2', 'https://geowidget.inpost.pl/inpost-geowidget.css', ['server' => 'remote'] ); } $this->context->controller->registerJavascript( 'pminpostpaczkomaty-paczkomator', 'modules/' . $this->name . '/views/js/paczkomator-' . $this->version . '.js' ); } else { if (Configuration::get('PMINPOSTPACZKOMATY_GGMAP') == '0') { if ($this->sandbox) { $this->context->controller->addJS($this->_path . '/views/js/openmaps-sandbox-' . $this->version . '.js'); } else { $this->context->controller->addJS($this->_path . '/views/js/openmaps-' . $this->version . '.js'); } $this->context->controller->addCSS($this->_path . '/views/css/easypack-' . $this->version . '-openmaps.css'); } elseif (Configuration::get('PMINPOSTPACZKOMATY_GGMAP') == '2') { $this->context->controller->addJS('https://geowidget.inpost.pl/inpost-geowidget.js'); $this->context->controller->addCSS('https://geowidget.inpost.pl/inpost-geowidget.css'); } $this->context->controller->addJS($this->_path . '/views/js/paczkomator-' . $this->version . '.js'); if (Configuration::get('PMINPOSTPACZKOMATY_GGMAP') != '2') { $this->context->controller->addJS($this->_path . '/views/js/front-' . $this->version . '.js'); } else { $this->context->controller->addJS($this->_path . '/views/js/front-' . $this->version . '.v5.js'); } $this->context->controller->addJS($this->_path . '/views/js/jquery-confirm.js'); $this->context->controller->addCSS($this->_path . '/views/css/front-' . $this->version . '.css'); $this->context->controller->addCSS($this->_path . '/views/css/jquery-confirm.css'); } return $this->hookDisplayFooter([]); } public function hookActionEmailSendBefore(&$params) { $template = $params['template'] == 'new_order' || $params['template'] == 'order_conf'; if (isset($params['template']) && $template && isset($params['cart']) && is_object($params['cart'])) { $order = Order::getByCartId($params['cart']->id); if ($order->id && ($this->isSelectedCarrierCod($order->id_carrier) || $this->isSelectedCarrierBw($order->id_carrier))) { $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'pminpostpaczkomatylist` WHERE id_cart = ' . (int) $order->id_cart; $row = Db::getInstance()->getRow($sql); if ($row) { $message = '
' . $this->l('Selected machine: ') .' '. $row['machine'] . ''; $point = $this->getPoint($row['machine']); if ($point && $point['{address}']) { $message .= '
' . $point['{address}']; if (isset($point['{location_description}']) && trim($point['{location_description}']) != '') { $message .= '
(' . $point['{location_description}'] . ')'; } $params['templateVars']['{machine_address}'] = $point['{address}']; } if (isset($params['templateVars']['{message}'])) { $params['templateVars']['{message}'] .= $message; } if (isset($params['templateVars']['{carrier}']) && $params['template'] == 'order_conf') { $params['templateVars']['{carrier}'] .= $message; } $params['templateVars']['{machine}'] = $row['machine']; $params['templateVars']['{machine_location_description}'] = isset($point['{location_description}']) ? '
' . $point['{location_description}'] : ''; } } } } private function updateSelectedCarriersBw($id_carrier) { if (empty($id_carrier)) { $id_carrier = []; } if (!is_array($id_carrier)) { $id_carrier = [$id_carrier]; $id_carrier = array_merge($id_carrier, $this->getCarriersBw()); } $id_carrier = array_filter($id_carrier, 'strlen'); $id_carrier = implode(',', $id_carrier); Configuration::updateValue('PMINPOSTPACZKOMATY_DELIVERY_BW', $id_carrier); } private function updateSelectedCarriersBwEof($id_carrier) { if (empty($id_carrier)) { $id_carrier = []; } if (!is_array($id_carrier)) { $id_carrier = [$id_carrier]; $id_carrier = array_merge($id_carrier, $this->getCarriersBwEof()); } $id_carrier = array_filter($id_carrier, 'strlen'); $id_carrier = implode(',', $id_carrier); Configuration::updateValue('PMINPOSTPACZKOMATY_DELIVERY_EOF', $id_carrier); } private function updateSelectedCarriersCod($id_carrier) { if (empty($id_carrier)) { $id_carrier = []; } if (!is_array($id_carrier)) { $id_carrier = [$id_carrier]; $id_carrier = array_merge($id_carrier, $this->getCarriersCod()); } $id_carrier = array_filter($id_carrier, 'strlen'); $id_carrier = implode(',', $id_carrier); Configuration::updateValue('PMINPOSTPACZKOMATY_DELIVERY_COD', $id_carrier); } private function updateSelectedCarriersCodEof($id_carrier) { if (empty($id_carrier)) { $id_carrier = []; } if (!is_array($id_carrier)) { $id_carrier = [$id_carrier]; $id_carrier = array_merge($id_carrier, $this->getCarriersCodEof()); } $id_carrier = array_filter($id_carrier, 'strlen'); $id_carrier = implode(',', $id_carrier); Configuration::updateValue('PMINPOSTPACZKOMATY_DELIVERY_EOF_COD', $id_carrier); } private function updateSelectedStatuses($statuses) { if (empty($statuses)) { $statuses = []; } if (!is_array($statuses)) { $statuses = [$statuses]; $statuses = array_merge($statuses, $this->getCarriersCodEof()); } $statuses = array_filter($statuses, 'strlen'); $statuses = implode(',', $statuses); Configuration::updateValue('PMINPOSTPACZKOMATY_STATUS_AV', $statuses); } public function hookActionCarrierUpdate($carrier) { $id_carrier = (int) $carrier['id_carrier']; $ids_carrier_bw = $this->getCarriersBw(); $ids_carrier_cod = $this->getCarriersCod(); $ids_carrier_bw_eof = $this->getCarriersBwEof(); $ids_carrier_cod_eof = $this->getCarriersCodEof(); if ($this->isSelectedCarrierBw($id_carrier)) { foreach ($ids_carrier_bw as $key => $value) { if ($value == $id_carrier) { unset($ids_carrier_bw[$key]); } } $ids_carrier_bw[] = (int) $carrier['carrier']->id; $this->updateSelectedCarriersBw($ids_carrier_bw); } if ($this->isSelectedCarrierBwEof($id_carrier)) { foreach ($ids_carrier_bw_eof as $key => $value) { if ($value == $id_carrier) { unset($ids_carrier_bw_eof[$key]); } } $ids_carrier_bw_eof[] = (int) $carrier['carrier']->id; $this->updateSelectedCarriersBwEof($ids_carrier_bw_eof); } if ($this->isSelectedCarrierCod($id_carrier)) { foreach ($ids_carrier_cod as $key => $value) { if ($value == $id_carrier) { unset($ids_carrier_cod[$key]); } } $ids_carrier_cod[] = (int) $carrier['carrier']->id; $this->updateSelectedCarriersCod($ids_carrier_cod); } if ($this->isSelectedCarrierCodEof($id_carrier)) { foreach ($ids_carrier_cod_eof as $key => $value) { if ($value == $id_carrier) { unset($ids_carrier_cod_eof[$key]); } } $ids_carrier_cod_eof[] = (int) $carrier['carrier']->id; $this->updateSelectedCarriersCodEof($ids_carrier_cod_eof); } } public function hookDisplayBeforeCarrier($params) { if (!$this->isCarrierEnabled()) { return ''; } if (Module::isInstalled('steasycheckout') && Module::isEnabled('steasycheckout')) { $this->move_footer = false; } if ($this->move_footer) { return ''; } if (!in_array($this->context->controller->php_self, ['order', 'order-opc', null])) { return ''; } if (Module::isInstalled('onepagecheckoutps') && Module::isEnabled('onepagecheckoutps') || Module::isInstalled('supercheckout') && Module::isEnabled('supercheckout') ) { return ''; } if ((int) Context::getContext()->cart->id) { $this->addMediaCart(); if (Module::isInstalled('steasycheckout') && Module::isEnabled('steasycheckout')) { return $this->context->smarty->fetch(dirname(__FILE__) . '/views/templates/front/carrier-1.7.tpl'); } else { return ''; } } else { return ''; } } public function hookAdminOrder($params) { return $this->prepareAdminHook($params); } public function displayWarning($warning) { $output = '
'; if (is_array($warning)) { $output .= '
    '; foreach ($warning as $msg) { $output .= '
  • ' . $msg . '
  • '; } $output .= '
'; } else { $output .= $warning; } $output .= '
'; return $output; } public function displayConfirmation($string) { $output = '
' . $string . '
'; return $output; } public function displayError($error) { $output = '
'; if (is_array($error)) { $output .= '
    '; foreach ($error as $msg) { $output .= '
  • ' . $msg . '
  • '; } $output .= '
'; } else { $output .= $error; } $output .= '
'; return $output; } private function additionalOrderMessage($order, $point_replace) { $id_cart = $order->id_cart; $msg = new Message(); $message = Configuration::get('PMINPOSTPACZKOMATY_OM'); if (Validate::isCleanHtml($message)) { $message = str_replace(array_keys($point_replace), array_values($point_replace), $message); $msg->message = nl2br($message); $msg->id_cart = (int) $id_cart; $msg->id_customer = (int) ($order->id_customer); $msg->id_order = (int) $order->id; $msg->private = 0; $msg->add(); $sql = ' SELECT id_customer_thread FROM `' . _DB_PREFIX_ . 'customer_thread` WHERE id_order = ' . (int) $order->id; $id_customer_thread = (int) Db::getInstance()->getValue($sql); if (!$id_customer_thread) { $customer = new Customer($order->id_customer); $customer_thread = new CustomerThread(); $customer_thread->id_customer = (int) ($order->id_customer); $customer_thread->id_lang = Context::getContext()->language->id; $customer_thread->id_shop = Context::getContext()->shop->id; $customer_thread->id_contact = 0; $customer_thread->id_order = $order->id; $customer_thread->id_product = 0; $customer_thread->status = 'open'; $customer_thread->email = $customer->email; $customer_thread->token = Tools::getToken(); $customer_thread->add(); $id_customer_thread = $customer_thread->id; } $customer_message = new CustomerMessage(); $customer_message->id_customer_thread = $id_customer_thread; $customer_message->id_employee = 0; $customer_message->message = $message; $customer_message->private = 0; $customer_message->read = 0; $customer_message->add(); } } private function additionalCustomerMessage($order, $point_replace) { $customer = new Customer($order->id_customer); $customer_email = $customer->email; if ($this->version_ps == '1.6') { $template = 'paczkomat'; } else { $template = 'paczkomat17'; } $subject = $this->l('You have chosen the parcel machine to your order'); $dir_mail = dirname(__FILE__) . '/mails/'; $template_vars = []; $template_vars['{message_title}'] = $subject; $message = Configuration::get('PMINPOSTPACZKOMATY_CM'); $point_replace['{customer}'] = trim($customer->firstname . ' ' . $customer->lastname . ' ' . $customer->company); $point_replace['{order_id}'] = $order->id; $point_replace['{order_reference}'] = $order->reference; $point_replace['{message_title}'] = $subject; $message = str_replace(array_keys($point_replace), array_values($point_replace), $message); $template_vars['{message_lang}'] = nl2br($message); $template_vars['{order_reference}'] = $order->reference; $template_vars['{firstname}'] = $customer->firstname; $template_vars['{lastname}'] = $customer->lastname; Mail::Send( $order->id_lang, $template, $subject, $template_vars, $customer_email, null, null, Configuration::get('PS_SHOP_NAME'), null, null, $dir_mail ); } public function hookActionValidateOrder($params) { if (isset($params['order'])) { $order = $params['order']; } else { return; } $machine_selected = $this->getSelectedMachineForOrder($order->id); if ($machine_selected === false) { return; } $point_replace = $this->getPoint($machine_selected); if ($point_replace && Configuration::get('PMINPOSTPACZKOMATY_OM_EN')) { // Admin message $this->additionalOrderMessage($order, $point_replace); } if ($point_replace && Configuration::get('PMINPOSTPACZKOMATY_CM_EN')) { // Customer message $this->additionalCustomerMessage($order, $point_replace); } } protected function addGroups($carrier) { $groups_ids = []; $groups = Group::getGroups(Context::getContext()->language->id); foreach ($groups as $group) { $groups_ids[] = $group['id_group']; } $carrier->setGroups($groups_ids); } protected function addRanges($carrier) { $range_weight = new RangeWeight(); $range_weight->id_carrier = $carrier->id; $range_weight->delimiter1 = '0'; $range_weight->delimiter2 = '25'; $range_weight->add(); return $range_weight->id; } protected function addZones($carrier) { $zones = Zone::getZones(); foreach ($zones as $zone) { $carrier->addZone($zone['id_zone']); } return $zones; } private function createDeliveryMethod() { $name = $this->l('Paczkomaty InPost'); $price = 15; if (Tools::getValue('CREATE_DELIVERY_METHOD') == 'cod') { $name = $this->l('Paczkomaty InPost - ') . $this->l(' Cash On Delivery'); $price = 20; } elseif (Tools::getValue('CREATE_DELIVERY_METHOD') == 'cod_eof') { $name = $this->l('Paczkomaty InPost - ') . $this->l(' Cash On Delivery') . ': ' . $this->l('End of week'); $price = 20; } elseif (Tools::getValue('CREATE_DELIVERY_METHOD') == 'prepayment_eof') { $name = trim($this->l('Paczkomaty InPost ')) . ': ' . $this->l('End of week'); $price = 15; } $carrier = new Carrier(); $carrier->name = $name; $carrier->max_width = 38; $carrier->max_height = 41; $carrier->max_depth = 64; $carrier->max_weight = 25; $carrier->url = 'https://inpost.pl/sledzenie-przesylek?number=@'; foreach (Language::getLanguages() as $lang) { $carrier->delay[$lang['id_lang']] = $this->l('48h - 72h'); } $carrier->add(); $zones = $this->addZones($carrier); $this->addGroups($carrier); $range_id = $this->addRanges($carrier); $price_list = []; foreach ($zones as $zone_item) { $price_list[] = [ 'id_range_weight' => (int) $range_id, 'id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone_item['id_zone'], 'price' => $price, ]; } if (Tools::getValue('CREATE_DELIVERY_METHOD') == 'cod') { $this->updateSelectedCarriersCod($carrier->id); } elseif (Tools::getValue('CREATE_DELIVERY_METHOD') == 'prepayment') { $this->updateSelectedCarriersBw($carrier->id); } elseif (Tools::getValue('CREATE_DELIVERY_METHOD') == 'prepayment_eof') { $this->updateSelectedCarriersBwEof($carrier->id); } elseif (Tools::getValue('CREATE_DELIVERY_METHOD') == 'cod_eof') { $this->updateSelectedCarriersCodEof($carrier->id); } Db::getInstance()->insert('delivery', $price_list); copy(dirname(__FILE__) . '/views/img/inpost-logo-normal.jpg', _PS_SHIP_IMG_DIR_ . $carrier->id . '.jpg'); Tools::redirectAdmin($this->context->link->getAdminLink('AdminCarrierWizard') . '&id_carrier=' . $carrier->id); } public function changeStates() { if (Tools::getValue('token') != Tools::substr(md5(_COOKIE_KEY_), 0, 12)) { exit('Bad token'); } $avstates = explode(',', Configuration::get('PMINPOSTPACZKOMATY_STATUS_AV')); $configshipx = Configuration::get('PMINPOSTPACZKOMATY_SHIPX'); $state = (int) Configuration::get('PMINPOSTPACZKOMATY_STATUS_DEL'); $stored = (int) Configuration::get('PMINPOSTPACZKOMATY_STATUS_PIC'); $prepared = (int) Configuration::get('PMINPOSTPACZKOMATY_STATUS'); $configchangestate = Configuration::get('PMINPOSTPACZKOMATY_OS'); if (Configuration::get('PMINPOSTPACZKOMATY_SHIPX')) { $api = InpostApiShipx::getInstance(); } else { $api = InpostApi::getInstance(); } if (sizeof($avstates) == 0) { exit($this->l('Go to the module configuration and select the statuses that can be changed.')); } if ($configchangestate) { $sql = ' SELECT current_state, nr_listu, id_order, pack_status, o.id_cart FROM `' . _DB_PREFIX_ . 'orders` o JOIN `' . _DB_PREFIX_ . $this->name . 'list` list ON list.id_cart = o.id_cart AND current_state IN (' . implode(',', $avstates) . ') AND nr_listu <> "" WHERE o.date_add >= NOW() - INTERVAL 1 MONTH AND pack_status NOT LIKE "%Dostarczona" LIMIT 200'; $result = Db::getInstance()->executeS($sql); foreach ($result as $result_item) { $api = $api; $shipping_number = $result_item['nr_listu']; $pack_status = $api->getPackStatus($shipping_number); if ($pack_status === false) { echo 'Pominięte: ' . $result_item['id_order'] . '
'; continue; } if (!$configshipx) { $data = strtotime((string) $pack_status->statusDate); $data = date('Y-m-d H:i:s', $data); $status = (string) $pack_status->status; } else { $pack_status = (json_decode($pack_status)); if (!isset($pack_status->tracking_details)) { echo 'Pominięte: ' . $result_item['id_order'] . '
'; continue; } $data = strtotime((string) $pack_status->tracking_details[0]->datetime); $data = date('Y-m-d H:i:s', $data); $status = $pack_status->status; } if (isset($pack_status->status) && $pack_status->status == '404') { echo 'Pominięte: ' . $result_item['id_order'] . '
'; continue; } $paczkomatyList = PaczkomatyList::getObjectByShippingNumber($shipping_number); if ($configchangestate && Tools::strtolower($status) == 'delivered') { $id_cart = $result_item['id_cart']; if ($state && $id_cart) { $order = new Order(Order::getOrderByCartId($id_cart)); if ($state != $order->getCurrentState()) { $order->setCurrentState($state); } } } elseif ($configchangestate && Tools::strtolower($status) == 'prepared') { $id_cart = $result_item['id_cart']; if ($state && $id_cart) { $order = new Order(Order::getOrderByCartId($id_cart)); if ($state != $order->getCurrentState() && $prepared != $order->getCurrentState()) { $order->setCurrentState($prepared); } } } elseif ($configchangestate && (strtolower($status) == 'stored' || Tools::strtolower($status) == 'intransit') || $status == 'sent_from_source_branch' || $status == 'collected_from_sender' || $status == 'adopted_at_sorting_center') { $id_cart = $result_item['id_cart']; if ($state && $id_cart) { $order = new Order(Order::getOrderByCartId($id_cart)); if ($state != $order->getCurrentState() && $stored != $order->getCurrentState()) { $order->setCurrentState($stored); } } } $status = $data . ' ' . $this->translateText($status); echo $status . ' ' . $result_item['id_order'] . '
'; if ($paczkomatyList) { $paczkomatyList->pack_status = $status; $paczkomatyList->save(); } } } } private function carrierAutoEnableDisable() { $day_of_week = date('w'); if ($day_of_week == 0) { $day_of_week = 7; } $hour = date('G'); if (Tools::strlen($hour) == 1) { $hour = '0' . $hour; } $min = date('i'); $current = $day_of_week . $hour . $min; $carriers_to_update = $this->getCarriersBwEof(); if (Configuration::get('PMINPOSTPACZKOMATY_EOF_AE') && sizeof($carriers_to_update)) { $config = Configuration::getMultiple( [ 'PMINPOSTPACZKOMATY_EOF_D', 'PMINPOSTPACZKOMATY_EOF_H', 'PMINPOSTPACZKOMATY_EOF_DT', 'PMINPOSTPACZKOMATY_EOF_HT', 'PMINPOSTPACZKOMATY_EOF_LAST', ] ); $start = $config['PMINPOSTPACZKOMATY_EOF_D'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_H']); $end = $config['PMINPOSTPACZKOMATY_EOF_DT'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_HT']); if ($start < $current && $current <= $end && $config['PMINPOSTPACZKOMATY_EOF_LAST'] == false) { Configuration::updateValue('PMINPOSTPACZKOMATY_EOF_LAST', true); $sql = ' UPDATE `' . _DB_PREFIX_ . 'carrier` SET active = 1 WHERE id_carrier IN (' . implode(',', $carriers_to_update) . ') '; Db::getInstance()->execute($sql); } elseif (!($start < $current && $current <= $end) && $config['PMINPOSTPACZKOMATY_EOF_LAST'] == true) { Configuration::updateValue('PMINPOSTPACZKOMATY_EOF_LAST', false); $sql = ' UPDATE `' . _DB_PREFIX_ . 'carrier` SET active = 0 WHERE id_carrier IN (' . implode(',', $carriers_to_update) . ') '; Db::getInstance()->execute($sql); } } $carriers_to_update = $this->getCarriersCodEof(); if (Configuration::get('PMINPOSTPACZKOMATY_EOF_COD_AE') && sizeof($carriers_to_update)) { $config = Configuration::getMultiple( [ 'PMINPOSTPACZKOMATY_EOF_COD_D', 'PMINPOSTPACZKOMATY_EOF_COD_H', 'PMINPOSTPACZKOMATY_EOF_COD_DT', 'PMINPOSTPACZKOMATY_EOF_COD_HT', 'PMINPOSTPACZKOMATY_EOF_COD_LAST', ] ); $start = $config['PMINPOSTPACZKOMATY_EOF_COD_D'] . str_replace(':', '', $config['PMINPOSTPACZKOMATY_EOF_COD_H']); $end = $config['PMINPOSTPACZKOMATY_EOF_COD_DT'] . str_replace( ':', '', $config['PMINPOSTPACZKOMATY_EOF_COD_HT'] ); if ($start < $current && $current <= $end && $config['PMINPOSTPACZKOMATY_EOF_COD_LAST'] == false) { Configuration::updateValue('PMINPOSTPACZKOMATY_EOF_COD_LAST', true); $sql = ' UPDATE `' . _DB_PREFIX_ . 'carrier` SET active = 1 WHERE id_carrier IN (' . implode(',', $carriers_to_update) . ') '; Db::getInstance()->execute($sql); } elseif (!($start < $current && $current <= $end) && $config['PMINPOSTPACZKOMATY_EOF_COD_LAST'] == true) { Configuration::updateValue('PMINPOSTPACZKOMATY_EOF_COD_LAST', false); $sql = ' UPDATE `' . _DB_PREFIX_ . 'carrier` SET active = 0 WHERE id_carrier IN (' . implode(',', $carriers_to_update) . ') '; Db::getInstance()->execute($sql); } } } public function addDeliveryAllegro(&$paczkomatyList) { if ($paczkomatyList->machine) { return; } $allegro = Module::getModuleIdByName('x13allegro'); if ($allegro) { $sql = ' SELECT * FROM `' . _DB_PREFIX_ . 'xallegro_order` WHERE id_order = ' . (int) Tools::getValue('id_order'); $row = Db::getInstance()->getRow($sql); if (!$row) { return; } $checkout = @json_decode($row['checkout_form_content']); if ($checkout && isset($checkout->delivery, $checkout->delivery->method) && isset($checkout->delivery->pickupPoint, $checkout->delivery->pickupPoint->id) ) { $method = $checkout->delivery->method->name; $pickupPoint = $checkout->delivery->pickupPoint->id; if (strpos($method, 'Paczkomaty') !== false) { $paczkomatyList->machine = (string) $pickupPoint; if (isset( $checkout->payment, $checkout->payment->type ) && $checkout->payment->type == 'CASH_ON_DELIVERY') { $paczkomatyList->post_info = serialize(['pminpostorder_pobranie' => true]); } else { $paczkomatyList->post_info = serialize(['pminpostorder_pobranie' => false]); } $paczkomatyList->save(); } } } } public function translateText(&$error) { $translate = []; $translate['_end_of_week_collection'] = $this->l(' parameter: Weekend package'); $translate['address'] = $this->l('Address'); $translate['adopted_at_sorting_center'] = $this->l('Received at the sorting plant.'); $translate['adopted_at_source_branch'] = $this->l('Accepted at the InPost branch.'); $translate['adopted_at_target_branch'] = $this->l('Accepted at the Target Branch.'); $translate['amount'] = $this->l('ammount'); $translate['Avizo'] = $this->l('Re-notification'); $translate['avizo'] = $this->l('Return to the branch.'); $translate['building_number'] = $this->l('building number'); $translate['but is'] = $this->l('but is'); $translate['canceled'] = $this->l('Label canceled.'); $translate['canceled_redirect_to_box'] = $this->l('Redirect canceled.'); $translate['Cancelled'] = $this->l('Cancelled'); $translate['Check details object for more info'] = $this->l('Check details object for more info.'); $translate['city'] = $this->l('city'); $translate['Claimed'] = $this->l('Complaint in the parcel locker'); $translate['claimed'] = $this->l('Complaint in the parcel locker'); $translate['ClaimProcessed'] = $this->l('The complaint was considered'); $translate['cod'] = $this->l('COD'); $translate['collected_from_sender'] = $this->l('Collected from sender.'); $translate['confirmed'] = $this->l('Prepared by the Sender.'); $translate['courier_avizo_in_customer_service_point'] = $this->l('Awaiting for pickup.'); $translate['created'] = $this->l('Delivery created.'); $translate['custom_attributes'] = $this->l('Package attributes'); $translate['CustomerDelivering'] = $this->l('To be shipped at a parcel locker, POP or partner network point'); $translate['CustomerSent'] = $this->l('Taken out by a courier from a parcel locker, collected by a courier from POP'); $translate['CustomerStored'] = $this->l('Placed in a parcel locker, POP or partner network point'); $translate['debt_collection'] = $this->l('Low account balance or lack of funds in InPost account.'); $translate['delay_in_delivery'] = $this->l('Possible delay in delivery.'); $translate['Delivered'] = $this->l('Delivered'); $translate['delivered'] = $this->l('delivered'); $translate['dispatched_by_sender'] = $this->l('The package is sent in a parcel locker.'); $translate['dispatched_by_sender_to_pok'] = $this->l('Shipped at the Customer Service Point.'); $translate['does_not_exist'] = $this->l('does not exist'); $translate['dropoff_point'] = $this->l('Dropoff point'); $translate['E-mail invalid'] = $this->l('E-mail invalid'); $translate['email:'] = $this->l('Email:'); $translate['end_of_week_collection: '] = $this->l('Please check '); $translate['Expired'] = $this->l('Not picked up'); $translate['insurance'] = $this->l('Shipment insurance'); $translate['InTransit'] = $this->l('On the way to the recipient'); $translate['invalid'] = $this->l('incorrect'); $translate['invalid_end_of_week_collection'] = $this->l(': End of week: No'); $translate['LabelDestroyed'] = $this->l('The label is illegible or missing'); $translate['LabelExpired'] = $this->l('Expired label'); $translate['missing'] = $this->l('missing'); $translate['Missing'] = $this->l('Missing'); $translate['No route matches'] = $this->l('No route matches'); $translate['NotDelivered'] = $this->l('Not delivered'); $translate['offer_selected'] = $this->l('Offer sellected.'); $translate['offered'] = $this->l('error has occurred, API IS set as offer mode for this token.') . ' ' . $this->l('Check the settings of the sender - if everything is set correctly. If the error will happen again') . ' ' . $this->l('send an email to InPost with the information:') . ' ' . $this->l('During generate label process API return message: Offer selected'); $translate['offers_prepared'] = $this->l('Offer prepared.'); $translate['other'] = $this->l('Other state.'); $translate['out_for_delivery'] = $this->l('Forwarded for delivery.'); $translate['out_for_delivery_to_address'] = $this->l('In transit.'); $translate['oversized'] = $this->l('Oversized.'); $translate['phone'] = $this->l('Phone'); $translate['phone: invalid'] = $this->l('Phone number is invalid'); $translate['pickup_reminder_sent'] = $this->l('Waiting package reminder.'); $translate['pickup_reminder_sent_address'] = $this->l('In transit.'); $translate['pickup_time_expired'] = $this->l('The deadline for pickup has expired.'); $translate['post_code'] = $this->l('postcode'); $translate['prepared'] = $this->l('Delivery created'); $translate['Prepared'] = $this->l('Delivery created.'); $translate['Printed'] = $this->l('Label printed'); $translate['readdressed'] = $this->l('Redirected to another address.'); $translate['ready_to_pickup'] = $this->l('Placed in a parcel locker (receiving).'); $translate['ready_to_pickup_from_branch'] = $this->l('Package unclaimed - waiting at the Branch'); $translate['ready_to_pickup_from_pok'] = $this->l('It is waiting for collection at the Parcel Service Point.'); $translate['ready_to_pickup_from_pok_registered'] = $this->l('It is waiting for collection at the Customer Service Point.'); $translate['receiver:'] = $this->l('Receiver'); $translate['Receiver:'] = $this->l('Receiver'); $translate['redirect_to_box'] = $this->l('Redirection to a parcel locker.'); $translate['rejected_by_receiver'] = $this->l('Refusal to accept.'); $translate['required'] = $this->l('required'); $translate['Resource not found.'] = $this->l('Shipment not found.'); $translate['RetunedToAgency'] = $this->l('Forwarded to the branch'); $translate['return_pickup_confirmation_to_sender'] = $this->l('Return documents have been prepared.'); $translate['returned_to_sender'] = $this->l('Return to the sender.'); $translate['ReturnedToSender'] = $this->l('Returned to the sender'); $translate['ReturnedToSortingCenter'] = $this->l('Returned to the sender'); $translate['Saturday & Sunday parcel delivery is not available.'] = $this->l('End of week') . ' ' . $this->l('The service is available from Thursday at 20:00 to Saturday 1:00 p.m.'); $translate['sender:'] = $this->l('Sender:'); $translate['Sent'] = $this->l('Admitted in the branch'); $translate['sent_from_sorting_center'] = $this->l('Sent from Sorting Office.'); $translate['sent_from_source_branch'] = $this->l('In transit.'); $translate['shipment has not been found'] = $this->l('shipment has not been found'); $translate['shipments:'] = $this->l('shipments:'); $translate['stack_in_customer_service_point'] = $this->l('Parcel stored in POP.'); $translate['stack_parcel_pickup_time_expired'] = $this->l('The deadline for collecting the stored parcel has expired.'); $translate['status should be'] = $this->l('status should be'); $translate['Stored'] = $this->l('In a parcel locker, POP or partner network point'); $translate['stored'] = $this->l('In a parcel locker, POP or partner network point'); $translate['street'] = $this->l('street'); $translate['taken_by_courier'] = $this->l('Received from the Sender.'); $translate['taken_by_courier_from_customer_service_point'] = $this->l('Returned to the sender.'); $translate['taken_by_courier_from_pok'] = $this->l('On the way to the InPost broadcasting branch.'); $translate['target_point'] = $this->l('Target point'); $translate['There are some validation error.'] = $this->l('There are some validation error'); $translate['There are some validation errors.'] = $this->l('There are some validation error'); $translate['Token is missing or invaild:'] = $this->l('Token is missing or invaild'); $translate['too_big'] = $this->l('too big'); $translate['too_small'] = $this->l('too small'); $translate['trackempty'] = $this->l('Shipment created, delivery note cannot be retrieved.'); $translate['Tracking information about'] = $this->l('Tracking information about'); $translate['undelivered'] = $this->l('Transfer of undeliverable shipments to the warehouse.'); $translate['undelivered_cod_cash_receiver'] = $this->l('Unable to deliver.'); $translate['undelivered_incomplete_address'] = $this->l('Unable to deliver.'); $translate['undelivered_lack_of_access_letterbox'] = $this->l('Unable to deliver.'); $translate['undelivered_no_mailbox'] = $this->l('Unable to deliver.'); $translate['undelivered_not_live_address'] = $this->l('Unable to deliver.'); $translate['undelivered_unknown_receiver'] = $this->l('Unable to deliver.'); $translate['undelivered_wrong_address'] = $this->l('Unable to deliver.'); $translate['unstack_from_customer_service_point'] = $this->l('On the way to the selected parcel locker.'); $translate['.,'] = $this->l(','); $translate['..'] = $this->l('.'); $error = str_replace(array_keys($translate), $translate, $error); return $error; } public function cronCallBaselinker() { if (Tools::getValue('token') != Tools::substr(md5(_COOKIE_KEY_), 0, 12)) { exit('Bad token'); } PmBaselinkerOrder::getLastOrders(15); } public function getCustomerLastInpostMachineAndSetCurrentCart() { if (!Configuration::get('PMINPOSTPACZKOMATY_LL')) { return; } $context = Context::getContext(); $id_cart = (int) $context->cart->id; $id_customer = (int) $context->customer->id; $paczkomatyList = PaczkomatyList::getByIdCart($id_cart); if ((int) $paczkomatyList->id) { return; } $sql = ' SELECT il.`machine` FROM `' . _DB_PREFIX_ . 'pminpostpaczkomatylist` il LEFT JOIN `' . _DB_PREFIX_ . 'cart` c ON (c.`id_cart` = il.`id_cart` AND c.`id_customer` = ' . (int) $id_customer . ') LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_cart` = c.`id_cart`) WHERE o.`id_customer` = ' . (int) $id_customer . ' ORDER BY o.date_add DESC '; $row = Db::getInstance()->getRow($sql); if ($row && $id_cart) { $paczkomatyList->id_cart = $id_cart; $paczkomatyList->machine = $row['machine']; $paczkomatyList->save(); } } public function hookSendMailAlterTemplateVars(&$params) { $template = $params['template']; $vars = &$params['template_vars']; $vars['{gmparcellocker}'] = ''; if (in_array($template, ['order_conf', 'new_order'])) { $cartId = $this->context->cart->id; $sql = ' SELECT id_order FROM `' . _DB_PREFIX_ . 'orders` WHERE id_cart = ' . $cartId; $id_order = Db::getInstance()->getValue($sql); $machine_selected = $this->getSelectedMachineForOrder($id_order); if ($machine_selected !== false) { $vars['{gmparcellocker}'] = $machine_selected; $vars['{selected_machine}'] = $machine_selected; } } } public function dieErrors($params) { if ($params && is_array($params)) { $result = json_encode( [ 'error' => sprintf('
%s
', print_r($params, true)), ] ); exit($result); } else { $result = json_encode( [ 'error' => $params, ] ); exit($result); } } public function getContent() { if ((int) Tools::isSubmit('submitPminpostpaczkomatyModule')) { $this->postProcess(); } $this->assignVariables(); return $this->context->smarty->fetch(dirname(__FILE__) . '/views/templates/admin/config.tpl'); } private function getOutput() { $output = ''; if (!$this->sandbox) { try { $file = file_get_contents( 'https://presta-mod.pl/auto-update/?module=' . $this->name . '&domain=' . $_SERVER['HTTP_HOST'] . '&version=' . $this->version . '&o=' . $this->getReference() ); if ($file) { $xml = simplexml_load_string($file); Context::getContext()->smarty->assign('xml', $xml); Context::getContext()->smarty->assign('version', $this->version); if (version_compare($this->version, (string) $xml->version, '<') === true) { Context::getContext()->smarty->assign('version', true); } else { Context::getContext()->smarty->assign('version', false); } $output = Context::getContext()->smarty->fetch( dirname(__FILE__) . '/views/templates/admin/admin.tpl' ); } } catch (Exception $exp) { $output = ''; } } if (sizeof($this->confirmations)) { $output .= $this->displayConfirmation(implode('
', $this->confirmations)); } if (sizeof($this->errors)) { $output .= $this->displayError(implode('
', $this->errors)); } if (sizeof($this->warnings)) { $output .= $this->displayWarning(implode('
', $this->warnings)); } return $output; } private function assignVariables() { $output = $this->getOutput(); $this->context->smarty->assign([ 'selected_menu' => Tools::getValue('selected_menu', 0), 'module_dir' => $this->_path, 'config_form' => $this->renderForm(), 'output' => $output, 'host' => $_SERVER['HTTP_HOST'], 'module_key' => '', ]); } public function getReference() { if (file_exists(dirname(__FILE__) . '/license.txt')) { return file_get_contents(dirname(__FILE__) . '/license.txt'); } else { return ''; } } private function getPointsUrl() { if ($this->sandbox) { return 'https://sandbox-api-pl-points.easypack24.net/v1/points/'; } else { return 'https://api-pl-points.easypack24.net/v1/points/'; } } public function upgradeModule269() { PmBaselinkerOrder::installSql(); return true; } public function upgradeModule268() { $tab = new Tab(); $tab->active = 1; $languages = Language::getLanguages(false); if (is_array($languages)) { foreach ($languages as $language) { $tab->name[$language['id_lang']] = 'Inpost paczkomaty zlecenia'; } } $tab->class_name = 'PmInpostPaczkomatyZlecenia'; $tab->module = 'pminpostpaczkomaty'; $id_parent = Tab::getIdFromClassName('AdminParentShipping'); $tab->id_parent = $id_parent; $tab->add(); PaczkomatyList::update268(); return true; } public function upgradeModule284() { $id_tab = Tab::getIdFromClassName('PmInpostPaczkomatyList'); $tab = new Tab($id_tab); foreach (Language::getLanguages(false) as $lang) { $tab->name[$lang['id_lang']] = 'Inpost paczkomaty'; } $tab->save(); $this->unregisterHook('backOfficeHeader'); $this->unregisterHook('header'); $this->unregisterHook('footer'); $this->registerHook('displayBackOfficeHeader'); $this->registerHook('displayHeader'); $this->registerHook('displayFooter'); return true; } public function upgradeModule285() { $files_to_remove = []; $files_to_remove[] = $this->getLocalPath() . 'override/modules/ps_emailalerts/ps_emailalerts.php'; $files_to_remove[] = $this->getLocalPath() . 'override/modules/ps_emailalerts/index.php'; $file = $this->getLocalPath() . '/../../override/modules/ps_emailalerts/ps_emailalerts.php'; $backup = $file . '-' . date('Y-m-d') . '.bak'; $backup = str_replace('.php', '', $backup); rename($file, $backup); foreach ($files_to_remove as $file) { if (file_exists($file)) { unlink($file); } } $dirs_to_remove = []; $dirs_to_remove[] = $this->getLocalPath() . 'override/modules/ps_emailalerts/'; foreach ($dirs_to_remove as $dir) { if (file_exists($dir)) { rmdir($dir); } } $this->unregisterHook('actionEmailSendBefore'); $this->registerHook('actionEmailSendBefore'); if (!class_exists('PrestaShop\Autoload\PrestashopAutoload')) { try { \PrestaShop\Autoload\PrestashopAutoload::getInstance()->generateIndex(); } catch (Exception $e) { $this->warnings[] = $e->getMessage(); } } $this->registerHook('actionEmailSendBefore'); return true; } public function getEncryptedToken() { $id_cart = $this->context->cart->id; if ($id_cart) { return Tools::encrypt($id_cart); } return ''; } }