name = 'inpostship'; $this->tab = 'shipping_logistics'; $this->version = '4.0.0'; $this->author = 'PrestaHelp'; $this->need_instance = 1; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Integracja InPost'); $this->description = $this->l('Nadawanie paczek nigdy nie było tak proste! Integracja z InPost za pomocą API ShipX'); $this->confirmUninstall = $this->l('Odinstalowanie modułu nie powoduje utraty żadnych danych.'); $this->debug = Configuration::get('INPOSTSHIP_DEBUG'); $this->debug_shop = Configuration::get('INPOSTSHIP_DEBUG_SHOP'); $this->template_dir = '../../../../modules/' . $this->name . '/views/templates/admin/'; if ($this->debug_shop == 1) { @ini_set('display_errors', 'on'); @error_reporting(E_ALL | E_STRICT); } } public function install() { // if (!$this->setInst()) { // return false; // } $clear = false; $ipf = Configuration::get('INPOSTSHIP_PRINT_FORMAT'); if ($ipf == 0) { $clear = true; } $this->configuration($clear); $this->createTab(); $this->installSql(); if (!parent::install() || !$this->registerHook('displayHeader') || !$this->registerHook('displayBeforeCarrier') || !$this->registerHook('displayAdminOrder') || !$this->registerHook('actionValidateOrder') || !$this->registerHook('actionCartSave') || !$this->registerHook('displayBackOfficeHeader') || !$this->registerHook('displayCustomerAccount') || !$this->registerHook('displayMyAccountBlock') || !$this->registerHook('displayAdminOrderTabShip') || !$this->registerHook('displayAdminOrderContentShip') ) { return false; } else { return true; } } public function uninstall() { if (Configuration::get('INPOSTSHIP_RESET') == 1) { $this->resetConfig(); } $this->removeTabs(); if (!parent::uninstall()) { return false; } return true; } private function setInst() { $shop = new Shop($this->context->shop->id); $auth = new AuthDS($this->name); if ($auth->makeTools($this->displayName, $this->version, $shop->getBaseURL())){ return true; } return false; } private function isActiveModule_($showLicence = null) { $shop = new Shop((int)$this->context->shop->id); $auth = new AuthDS($this->name); $licence = $auth->isActive($shop->getBaseURL()); if (empty($licence)) { $domain = AuthDS::clearDomain($shop->getBaseURL()); $licence = $auth->getStaticLicence($domain, $this->displayName, Configuration::get('INPOSTSHIP_LICENCE'), $showLicence); } return array( 'active' => $licence, 'actived' => $licence['licence']->licence ); } private function isActiveModule() { $shop = new Shop((int)$this->context->shop->id); $auth = new AuthDS($this->name, $shop->getBaseURL()); return $auth->checkLicence(); } /** * @param bool $clear_data */ private function configuration($clear_data = false) { if ($clear_data) { Configuration::updateValue('INPOSTSHIP_SANDBOX', 0); Configuration::updateValue('INPOSTSHIP_API_USER', ''); Configuration::updateValue('INPOSTSHIP_API_PASSWD', ''); Configuration::updateValue('INPOSTSHIP_API_KEY', ''); Configuration::updateValue('INPOSTSHIP_API_ORGANIZATION', ''); Configuration::updateValue('INPOSTSHIP_PRINT_FORMAT', 'PDF'); Configuration::updateValue('INPOSTSHIP_PRINT_TYPE', 'A6'); Configuration::updateValue('INPOSTSHIP_TRACK', '1'); //save track_id to default prestashop field Configuration::updateValue('INPOSTSHIP_SEND', '1'); //send track_id default prestashop email Configuration::updateValue('INPOSTSHIP_STATUS', '1'); Configuration::updateValue('INPOSTSHIP_STATUS_TYPE', '4'); Configuration::updateValue('INPOSTSHIP_DISPATCH', 'parcel_locker'); Configuration::updateValue('INPOSTSHIP_DISPATCH_POINT', '0'); Configuration::updateValue('INPOSTSHIP_COD', '0'); Configuration::updateValue('INPOSTSHIP_PACK_SIZE', 'small'); Configuration::updateValue('INPOSTSHIP_INSURANCE', '1'); Configuration::updateValue('INPOSTSHIP_TRACKING_SAVE', '1'); Configuration::updateValue('INPOSTSHIP_DELETE_DATABASE', '0'); Configuration::updateValue('INPOSTSHIP_ORDER_STATUS', 4); Configuration::updateValue('INPOSTSHIP_ORDER_STATUS_CHANGE', 0); Configuration::updateValue('INPOSTSHIP_SEND_POINT_CUSTOMER', 0); Configuration::updateValue('INPOSTSHIP_SEND_POINT_ADMIN', 0); Configuration::updateValue('INPOSTSHIP_SEND_TRACKING', 0); Configuration::updateValue('INPOSTSHIP_POSITION_BOX', 1); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_1', 1); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_2', 1); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_3', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_4', 0); Configuration::updateValue('INPOSTSHIP_CARRIER_1', 'a:1:{i:0;s:1:"0";}'); Configuration::updateValue('INPOSTSHIP_CARRIER_2', 'a:1:{i:0;s:1:"0";}'); Configuration::updateValue('INPOSTSHIP_CARRIER_3', 'a:1:{i:0;s:1:"0";}'); Configuration::updateValue('INPOSTSHIP_CARRIER_4', 'a:1:{i:0;s:1:"0";}'); Configuration::updateValue('INPOSTSHIP_CARRIER_5', 'a:1:{i:0;s:1:"0";}'); Configuration::updateValue('INPOSTSHIP_CARRIER_6', 'a:1:{i:0;s:1:"0";}'); Configuration::updateValue('INPOSTSHIP_NEAR', 3); Configuration::updateValue('INPOSTSHIP_DEBUG', 0); Configuration::updateValue('INPOSTSHIP_DEBUG_SHOP', 0); Configuration::updateValue('INPOSTSHIP_RESET', 0); Configuration::updateValue('INPOSTSHIP_MAP_TYPE', 'osm'); Configuration::updateValue('INPOSTSHIP_PL_PERPAGE', 10); Configuration::updateValue('INPOSTSHIP_WEEKPACK', 0); Configuration::updateValue('INPOSTSHIP_WEEKPACK_START_DAY', 4); Configuration::updateValue('INPOSTSHIP_WEEKPACK_END_DAY', 6); Configuration::updateValue('INPOSTSHIP_WEEKPACK_START_HOUR', '14:00'); Configuration::updateValue('INPOSTSHIP_WEEKPACK_END_HOUR', '11:00'); Configuration::updateValue('INPOSTSHIP_CHECKOUT', 'default'); Configuration::updateValue('INPOSTSHIP_MAP_BOX', 1); Configuration::updateValue('INPOSTSHIP_MAP_SHOW', 1); Configuration::updateValue('INPOSTSHIP_MAP_WIDTH', 1); Configuration::updateValue('INPOSTSHIP_GEOWIDGET', 4); } } /** * Reset module config information */ private function resetConfig() { Configuration::updateValue('INPOSTSHIP_SANDBOX', 0); Configuration::updateValue('INPOSTSHIP_API_USER', ''); Configuration::updateValue('INPOSTSHIP_API_PASSWD', ''); Configuration::updateValue('INPOSTSHIP_API_KEY', ''); Configuration::updateValue('INPOSTSHIP_API_ORGANIZATION', ''); Configuration::updateValue('INPOSTSHIP_PRINT_FORMAT', 'PDF'); Configuration::updateValue('INPOSTSHIP_PRINT_TYPE', 'A6'); Configuration::updateValue('INPOSTSHIP_TRACK', '1'); //save track_id to default prestashop field Configuration::updateValue('INPOSTSHIP_SEND', '1'); //send track_id default prestashop email Configuration::updateValue('INPOSTSHIP_STATUS', '1'); Configuration::updateValue('INPOSTSHIP_STATUS_TYPE', '4'); Configuration::updateValue('INPOSTSHIP_DISPATCH', 'parcel_locker'); Configuration::updateValue('INPOSTSHIP_DISPATCH_POINT', '0'); Configuration::updateValue('INPOSTSHIP_COD', '0'); Configuration::updateValue('INPOSTSHIP_PACK_SIZE', 'small'); Configuration::updateValue('INPOSTSHIP_INSURANCE', '1'); Configuration::updateValue('INPOSTSHIP_TRACKING_SAVE', '1'); Configuration::updateValue('INPOSTSHIP_DELETE_DATABASE', '0'); Configuration::updateValue('INPOSTSHIP_ORDER_STATUS', 4); Configuration::updateValue('INPOSTSHIP_ORDER_STATUS_CHANGE', 0); Configuration::updateValue('INPOSTSHIP_SEND_POINT_CUSTOMER', 0); Configuration::updateValue('INPOSTSHIP_SEND_POINT_ADMIN', 0); Configuration::updateValue('INPOSTSHIP_SEND_TRACKING', 0); Configuration::updateValue('INPOSTSHIP_POSITION_BOX', 1); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_1', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_2', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_3', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_4', 0); Configuration::updateValue('INPOSTSHIP_CARRIER_1', 0); Configuration::updateValue('INPOSTSHIP_CARRIER_2', 0); Configuration::updateValue('INPOSTSHIP_CARRIER_3', 0); Configuration::updateValue('INPOSTSHIP_CARRIER_4', 0); Configuration::updateValue('INPOSTSHIP_NEAR', 3); Configuration::updateValue('INPOSTSHIP_DEBUG', 0); Configuration::updateValue('INPOSTSHIP_DEBUG_SHOP', 0); Configuration::updateValue('INPOSTSHIP_RESET', 0); Configuration::updateValue('INPOSTSHIP_SENDER_NAME', ''); Configuration::updateValue('INPOSTSHIP_SENDER_COMPANY_NAME', ''); Configuration::updateValue('INPOSTSHIP_SENDER_FIRSTNAME', ''); Configuration::updateValue('INPOSTSHIP_SENDER_LASTNAME', ''); Configuration::updateValue('INPOSTSHIP_SENDER_EMAIL', ''); Configuration::updateValue('INPOSTSHIP_SENDER_PHONE', ''); Configuration::updateValue('INPOSTSHIP_SENDER_STREET', ''); Configuration::updateValue('INPOSTSHIP_SENDER_BUILDING_NR', ''); Configuration::updateValue('INPOSTSHIP_SENDER_CITY', ''); Configuration::updateValue('INPOSTSHIP_SENDER_POSTCODE', ''); Configuration::updateValue('INPOSTSHIP_API_USER', ''); Configuration::updateValue('INPOSTSHIP_API_PASSWD', ''); Configuration::updateValue('INPOSTSHIP_API_KEY', ''); Configuration::updateValue('INPOSTSHIP_SANDBOX', ''); Configuration::updateValue('INPOSTSHIP_API_ORGANIZATION', ''); Configuration::updateValue('INPOSTSHIP_ORDER_NUMBER', 1); Configuration::updateValue('INPOSTSHIP_PL_PERPAGE', 10); Configuration::updateValue('INPOSTSHIP_WEEKPACK', 0); Configuration::updateValue('INPOSTSHIP_WEEKPACK_START_DAY', 4); Configuration::updateValue('INPOSTSHIP_WEEKPACK_END_DAY', 6); Configuration::updateValue('INPOSTSHIP_WEEKPACK_START_HOUR', '14:00'); Configuration::updateValue('INPOSTSHIP_WEEKPACK_END_HOUR', '11:00'); } /** * Create PS tab */ private function createTab() { $lang = Language::getLanguages(); if (!Tab::getIdFromClassName('AdminInpostship')) { $tab = new Tab(); $tab->id_parent = 0; $tab->module = $this->name; $tab->class_name = 'AdminInpostship'; $tab->active = 1; $tab->hide_host_mode = 0; foreach ($lang as $l) { $tab->name[$l['id_lang']] = 'Inpost'; } $tab->add(); } if (!Tab::getIdFromClassName('AdminInpostshipMass')) { $tab = new Tab(); $tab->id_parent = Tab::getIdFromClassName($this->class_name_tab); $tab->module = $this->name; $tab->class_name = 'AdminInpostshipMass'; $tab->active = 1; $tab->hide_host_mode = 0; foreach ($lang as $l) { $tab->name[$l['id_lang']] = 'Nowe paczki'; } $tab->add(); } if (!Tab::getIdFromClassName('AdminInpostshipPackage')) { $tab = new Tab(); $tab->id_parent = Tab::getIdFromClassName($this->class_name_tab); $tab->module = $this->name; $tab->class_name = 'AdminInpostshipPackage'; $tab->active = 1; $tab->hide_host_mode = 0; foreach ($lang as $l) { $tab->name[$l['id_lang']] = 'Lista przesyłek'; } $tab->add(); } if (!Tab::getIdFromClassName('AdminInpostshipSettings')) { $tab = new Tab(); $tab->id_parent = Tab::getIdFromClassName($this->class_name_tab); $tab->module = $this->name; $tab->class_name = 'AdminInpostshipSettings'; $tab->active = 1; $tab->hide_host_mode = 0; foreach ($lang as $l) { $tab->name[$l['id_lang']] = 'Ustawienia'; } $tab->add(); } } /** * Remove tabs */ private function removeTabs() { if ($id_tab = Tab::getIdFromClassName('AdminInpostshipMass')) { $tab = new Tab($id_tab); $tab->delete(); } if ($id_tab = Tab::getIdFromClassName('AdminInpostshipSettings')) { $tab = new Tab($id_tab); $tab->delete(); } if ($id_tab = Tab::getIdFromClassName('AdminInpostshipPackage')) { $tab = new Tab($id_tab); $tab->delete(); } if ($id_tab = Tab::getIdFromClassName('AdminInpostship')) { $tab = new Tab($id_tab); $tab->delete(); } } private function installSql() { require_once __DIR__.'/sql/install.php'; } /** * Function deleteDatabase * this function delete all tables from db * return bool - result of db executes */ private function deleteDatabase() { if (Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'inpostship`') && Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'inpostship_cart`') && Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'inpostship_customer`') && Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'inpostship_points`')) { return true; } return false; } public function hookDisplayBackOfficeHeader() { if ($this->isActiveModule()) { if (isset($this->context->controller->module->name) && $this->context->controller->module->name == 'inpostship') { $this->context->controller->addJS('/js/jquery/jquery-1.11.0.min.js'); if (Tools::getValue('controller') == 'AdminInpostshipPackage') { // $this->context->controller->addJS('//min.gitcdn.xyz/repo/wintercounter/Protip/master/protip.min.js'); } $this->context->controller->addJS($this->_path . 'views/js/inpostship_back.js'); $this->context->controller->addCSS($this->_path . 'views/css/inpostship_back.css'); $this->context->controller->addCSS('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css'); } if ($this->context->controller->php_self == 'AdminOrders') { $this->context->controller->addJS($this->_path . 'views/js/inpostship_back.js'); $this->context->controller->addCSS($this->_path . 'views/css/inpostship_back.css'); } } } public function hookDisplayHeader() { if ($this->isActiveModule()) { $php_self = isset($this->context->controller->php_self) ? $this->context->controller->php_self : false; if (empty($php_self)) { if (isset($this->context->controller->module->name)) { $php_self = $this->context->controller->module->name; } else { $php_self = 'index'; } } if ($php_self && in_array($php_self, $this->checkouts)) { $this->context->controller->addCSS($this->_path . 'views/css/select2.min.css'); $this->context->controller->addCSS($this->_path . 'views/css/inpostship.css'); $this->context->controller->addJS($this->_path . 'views/js/select2.min.js'); if (self::ps8()) { $this->context->controller->addJS($this->_path . 'views/js/inpostship_8.js'); } else if (self::ps17()) { $this->context->controller->registerStylesheet( 'module-inpostship-style', 'https://geowidget.easypack24.net/css/easypack.css', array( 'media' => 'all', 'priority' => 200, 'server' => 'remote' ) ); $this->context->controller->registerJavascript( 'module-inpostship', 'https://geowidget.easypack24.net/js/sdk-for-javascript.js', array( 'priority' => 200, 'attribute' => 'async', 'server' => 'remote' ) ); $this->context->controller->addJS($this->_path . 'views/js/inpostship_front17.js'); } else if (self::ps15()) { $this->context->controller->addCSS('https://geowidget.easypack24.net/css/easypack.css'); $this->context->controller->addJS('https://geowidget.easypack24.net/js/sdk-for-javascript.js'); $this->context->controller->addJS($this->_path . 'views/js/inpostship_front15.js'); } else { $this->context->controller->addCSS('https://geowidget.easypack24.net/css/easypack.css'); $this->context->controller->addJS('https://geowidget.easypack24.net/js/sdk-for-javascript.js'); $this->context->controller->addJS($this->_path . 'views/js/inpostship_front.js'); } } $available_module = array('onepagecheckoutps', 'spstepcheckout', 'supercheckout', 'ets_onepagecheckout'); if (in_array(Configuration::get('INPOSTSHIP_CHECKOUT'), $available_module)) { return $this->hookDisplayWrapperTop(); } } } public function hookDisplayTop() { return $this->hookDisplayWrapperTop(); } public function hookDisplayWrapperTop() { if ($this->isActiveModule()) { $available_module = array('onepagecheckoutps', 'spstepcheckout', 'supercheckout', 'ets_onepagecheckout'); $php_self = isset($this->context->controller->php_self) ? $this->context->controller->php_self : false; if (empty($php_self)) { $php_self = $this->context->controller->module->name; } if ($php_self == 'order' || $php_self == 'chekcout' || $php_self == 'steasycheckout' || $php_self == 'onepagecheckoutps' || $php_self == 'supercheckout' || $php_self == 'ets_onepagecheckout' || in_array(Configuration::get('INPOSTSHIP_CHECKOUT'), $available_module)) { $images_url = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__ . '/modules/' . $this->name . '/views/img/'; $pointDir = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__ . 'modules/' . $this->name . '/getPoint.php'; $carrier_inpost = Carrier::getCarrierByReference(Configuration::get('INPOSTSHIP_CARRIER_1')); $carrier_inpost_cod = Carrier::getCarrierByReference(Configuration::get('INPOSTSHIP_CARRIER_2')); if (empty($carrier_inpost_cod)) { $carrier_inpost_cod = new stdClass(); $carrier_inpost_cod->id = 0; } $carrier_inpost_courier = Carrier::getCarrierByReference(Configuration::get('INPOSTSHIP_CARRIER_3')); if (empty($carrier_inpost_courier)) { $carrier_inpost_courier = new stdClass(); $carrier_inpost_courier->id = 0; } $carrier_inpost_courier_cod = Carrier::getCarrierByReference(Configuration::get('INPOSTSHIP_CARRIER_4')); if (empty($carrier_inpost_courier_cod)) { $carrier_inpost_courier_cod = new stdClass(); $carrier_inpost_courier_cod->id = 0; } $baseDirShop = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__; $selectedPoint = InpostPack::getPointByCart((int)$this->context->cart->id); $selectedPointInfo = InpostPoint::getPointInfo($selectedPoint); $selectedPointInfoText = ''; if (!empty($selectedPointInfo)) { $selectedPointInfoText = 'Wybrany paczkomat:|| ;;' . $selectedPoint . ', ' . $selectedPointInfo['point_address1'] . ', ' . $selectedPointInfo['point_address2'] . ';; ||' . $selectedPointInfo['point_desc']; } $imap = Configuration::get('INPOSTSHIP_MAP_TYPE'); $imgm = Configuration::get('INPOSTSHIP_GOOGLE_MAPS_API'); $showWeek = 0; if (Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { $datWeek = date('w'); $startWeek = Configuration::get('INPOSTSHIP_WEEKPACK_START_DAY'); $endWeek = Configuration::get('INPOSTSHIP_WEEKPACK_END_DAY'); $hourWeek = date('H:i'); $startHour = Configuration::get('INPOSTSHIP_WEEKPACK_START_HOUR'); $endHour = Configuration::get('INPOSTSHIP_WEEKPACK_END_HOUR'); if ($datWeek > $startWeek && $datWeek < $endWeek) { $showWeek = 1; } else if ($datWeek > $startWeek && $datWeek == $endWeek) { if ($hourWeek <= $endHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek < $endWeek) { if ($hourWeek >= $startHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek == $endWeek) { if ($hourWeek >= $startHour && $hourWeek <= $endHour) { $showWeek = 1; } } } $INPOSTSHIP_CARRIER_1 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_1')); $paczkomaty = '[]'; if (!empty($INPOSTSHIP_CARRIER_1)) { $paczkomaty = json_encode($INPOSTSHIP_CARRIER_1); } $INPOSTSHIP_CARRIER_2 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_2')); $paczkomaty_cod = '[]'; if (!empty($INPOSTSHIP_CARRIER_2)) { $paczkomaty_cod = json_encode($INPOSTSHIP_CARRIER_2); } $INPOSTSHIP_CARRIER_5 = (array)unserialize(Configuration::get('INPOSTSHIP_CARRIER_5')); $paczkomaty_week = '[]'; if (!empty($INPOSTSHIP_CARRIER_5)) { $paczkomaty_week = json_encode($INPOSTSHIP_CARRIER_5); } $INPOSTSHIP_CARRIER_6 = (array)unserialize(Configuration::get('INPOSTSHIP_CARRIER_6')); $paczkomaty_week_cod = '[]'; if (!empty($INPOSTSHIP_CARRIER_6)) { $paczkomaty_week_cod = json_encode($INPOSTSHIP_CARRIER_6); } $INPOSTSHIP_CARRIER_3 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_3')); $courier = '[]'; if (!empty($INPOSTSHIP_CARRIER_3)) { $courier = json_encode($INPOSTSHIP_CARRIER_3); } $INPOSTSHIP_CARRIER_4 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_4')); $courier_cod = '[]'; if (!empty($INPOSTSHIP_CARRIER_4)) { $courier_cod = json_encode($INPOSTSHIP_CARRIER_4); } $this->context->smarty->assign(array( 'points' => InpostPoint::getAllPoints(null, 0), 'cart_id' => $this->context->cart->id, 'marker_1' => urlencode($images_url . 'marker_1.png'), 'marker_2' => urlencode($images_url . 'marker_2.png'), 'paczkomaty' => $paczkomaty, 'paczkomaty_cod' => $paczkomaty_cod, 'paczkomaty_week' => $paczkomaty_week, 'paczkomaty_week_cod' => $paczkomaty_week_cod, 'courier' => $courier, 'courier_cod' => $courier_cod, 'ps17' => self::ps17(), 'pointDir' => $pointDir, 'baseDirShop' => $baseDirShop, 'box_pos' => Configuration::get('INPOSTSHIP_POSITION_BOX'), 'version' => _PS_VERSION_, 'module_dir_img' => $images_url, 'selectedPointInfo' => $selectedPointInfoText, 'testMap' => Configuration::get('INPOSTSHIP_SANDBOX'), 'imap' => $imap, 'imgm' => $imgm, 'weekPrice' => Configuration::get('INPOSTSHIP_WEEKPACK_PRICE'), 'showWeek' => $showWeek, 'isTable' => Configuration::get('INPOSTSHIP_IS_TABLE'), 'checkout' => Configuration::get('INPOSTSHIP_CHECKOUT'), )); return $this->display(__DIR__, '/views/templates/hook/header.tpl'); } } } public function hookShoppingCartExtra($params) { return $this->hookDisplayBeforeCarrier($params); } public function hookDisplayCustomerAccount() { if ($this->isActiveModule()) { $ssl = 'https://'; $url = $ssl.$this->context->shop->domain.$this->context->shop->physical_uri . 'modules/' . $this->name . '/views/img/'; $this->context->smarty->assign(array( 'moduleImgDir' => $url, )); return $this->display(__DIR__, '/views/templates/hook/myaccount.tpl'); } } public function hookDisplayMyAccountBlock() { return $this->hookDisplayCustomerAccount(); } public function hookDisplayAdminOrder($params) { if ($this->isActiveModule()) { $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); if (Tools::getIsset('print_label')) { $label = (int)Tools::getValue('print_label'); if (!empty($label) && $label > 0) { $format = Configuration::get('INPOSTSHIP_PRINT_FORMAT'); $pack = InpostPack::getInpostShipByIdPack((int)$label); $labels[] = $pack['packcode']; $content = $inpostapi->getMultiLabels((int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'), $labels, Configuration::get('INPOSTSHIP_PRINT_TYPE'), $format); $contents = $this->GetHeaders($content); ob_start(); $file_name = $pack['reference_number'].'.pdf'; $dir = __DIR__ . '/files/' . $file_name; file_put_contents($dir, $contents['http_code']); } Tools::redirectLink($_SERVER['HTTP_REFERER']); } $ioa = Configuration::get('INPOSTSHIP_ORDER_ADD'); if ($ioa == 1) { $this->InpostProcess(); } $id_order = $params['id_order']; $order = new Order($id_order); $id_cart = $order->id_cart; $customer = new Customer($order->id_customer); $address_delivery = new Address($order->id_address_delivery); $x13allegro = Configuration::get('INPOSTSHIP_INTEGRATION_X13ALLEGRO'); if (!empty($address_delivery)) { $address_delivery->phone_mobile = InpostTools::setPhoneNumber(trim(str_replace('+48', '', $address_delivery->phone_mobile))); $address_delivery->phones = !empty(trim($address_delivery->phone)) ? trim(str_replace('+48', '', $address_delivery->phone)) : trim(str_replace('+48', '', $address_delivery->phone_mobile)); $address_delivery->phones = InpostTools::setPhoneNumber(str_replace(' ', '', $address_delivery->phones)); } $identity = $order->reference; $ident = Configuration::get('INPOSTSHIP_ORDER_NUMBER'); if ($ident == 1) { $identity = $order->id; } $allegroNick = (int)Configuration::get('INPOSTSHIP_X13ALLEGRO_NICK'); $rec_mach = ''; $package = InpostPack::getInpostShipCart((int)$id_cart); $x13oinfo = null; if (!empty($package)) { $rec_mach = $package['receiver_machine']; $id_carrier = (int)$package['id_carrier']; if ($id_carrier != $order->id_carrier) { $id_carrier = (int)$order->id_carrier; } $current_pack = new Carrier((int)$id_carrier, (int)$this->context->cookie->id_lang); } else { $x13version = '6.2.1'; $x13allegroModule = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'module` WHERE `name` = "x13allegro"'); $current_pack = new Carrier((int)$order->id_carrier, (int)$this->context->cookie->id_lang); if ($x13allegro) { if ($x13allegroModule['version'] < $x13version) { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'xallegro_form` WHERE `id_order` = ' . (int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = unserialize(base64_decode($x13orderInfo['content'])); $rec_mach = $x13oinfo->postBuyFormGdAddress->postBuyFormAdrId; } } else { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'xallegro_order` WHERE `id_order` = ' . (int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = json_decode($x13orderInfo['checkout_form_content']); $rec_mach = $x13oinfo->delivery->pickupPoint->id; } } if ($allegroNick == 1) { $identity .= ' '.$x13oinfo->buyer->login; } } } $point = $inpostapi->getPointInfo($rec_mach); $pop_point = InpostPoint::getPopPointsAll(); $pok_point = InpostPoint::getPointOfType('pok'); $c1 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_1')); $c1i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1'); $c2 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_2')); $c2i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2'); $c3 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_3')); $c3i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3'); $c4 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_4')); $c4i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4'); $c5 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_5')); $c6 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_6')); $ssl = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://'; $statusesApi = $inpostapi->getStatuses(); if (isset($statusesApi['result']->items)) { $statues = $statusesApi['result']->items; } else { $statues = array(); } $packageList = InpostPack::getOrderPackageList((int)$id_order); if (!empty($packageList)) { foreach ($packageList as &$pl) { $ord = new Order($pl['id_order']); $id_cart = (int)$ord->id_cart; $inpost_cart = InpostPack::getInpostShipCart((int)$id_cart); $pl['image'] = ''; $id_carrier2 = (int)$inpost_cart['id_carrier']; if ($id_carrier2 != $ord->id_carrier) { $id_carrier2 = (int)$order->id_carrier; } $carrier2 = new Carrier((int)$id_carrier2); $cref2 = $carrier2->id; if ($c1i == 1) { if (in_array($cref2, $c1)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } } if ($c2i == 1) { if (in_array($cref2, $c2)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } } if ($c3i == 1) { if (in_array($cref2, $c3)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; } } if ($c4i == 1) { if (in_array($cref2, $c4)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; } } if (in_array($cref2, $c5)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } if (in_array($cref2, $c6)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } $pl['image'] = $image2; $dispatch = 0; if ($pl['sendtype'] == 'dispatch_order') { $dispatch = 1; } $pl['dispatch'] = $dispatch; $ship_info = array(); if ($pl['status'] != 'confirmed') { $ship_info = $inpostapi->getShipments($pl['packcode']); $ship_info = (array)$ship_info['result']; } $pl['ship_info'] = $ship_info; if ((int)$pl['dispatch_id'] > 0) { $dispatch_info = $inpostapi->getDispatchInfo((int)$pl['dispatch_id']); if (!empty($dispatch_info['error'])) { $sxerror = new InpostError(); if ($this->debug == 1) { echo "
";
                                print_r($dispatch_info);
                                echo "
"; } $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($dispatch_info) )); } else { $status = $dispatch_info['result']->status; $pl['dispatch_status'] = InpostDispatch::getDispatchStatus($status); $pl['dispatch_status_org'] = $status; } } // file with etykieta if (!empty($pl['reference_number'])) { $file_name = $pl['reference_number'] . '.pdf'; $dir = __DIR__ . '/files/' . $file_name; if (file_exists($dir)) { $pl['fileDownload'] = 'https://' . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/inpostship/files/' . $file_name; } else { $pl['fileDownload'] = ''; } } else { $pl['fileDownload'] = ''; } $current_statue = '--'; foreach ($statues as $stat) { if ($pl['status'] == $stat->name) { $current_statue = $stat->title; } } $pl['current_statue'] = $current_statue; } } $cref = $current_pack->id; $image = ''; $service = 0; $inpostCod = 0; $serviceName = ''; $paczk = 0; $allegro = 0; $week = 0; $addressAllegro = array(); $x13transactionId = $x13allegroUserId = null; if ($x13allegro && !empty($x13oinfo)) { $service = 3; if ($x13allegroModule['version'] < $x13version) { $allegroService = $x13oinfo->postBuyFormShipmentId; } else { $allegroService = $x13oinfo->delivery->method->id; } switch ($allegroService) { case 10023: $serviceName = 'Allegro Paczkomaty 24/7 InPost'; $paczk = 1; break; case 10022: $serviceName = 'Paczkomaty 24/7'; $paczk = 1; break; case 18: $serviceName = 'Allegro Kurier24 InPost pobranie '; break; case 34: $serviceName = 'Kurier InPost pobranie '; break; case '2488f7b7-5d1c-4d65-b85c-4cbcf253fd93': $serviceName = 'Allegro Paczkomaty 24/7 InPost'; $paczk = 1; $allegro = 1; break; case 'b20ef9e1-faa2-4f25-9032-adbea23e5cb9': $serviceName = 'Allegro Paczkomaty 24/7 InPost pobranie'; $paczk = 1; $inpostCod = 1; $allegro = 1; break; case '85c3ad2f-4ec1-446c-866e-63473ed10e26': $serviceName = 'Allegro Kurier24 InPost pobranie'; $inpostCod = 1; break; case '98f86f81-0018-41c5-ac83-073a56fc7021': $serviceName = 'Allegro miniKurier24 InPost pobranie'; $inpostCod = 1; break; case '999f8753-6340-48a0-8eba-46096f9749aa': $serviceName = 'Kurier InPost pobranie'; $inpostCod = 1; break; case '2653ca13-67c8-48c3-bbf8-ff9aa3f70ed3': $serviceName = 'Paczkomaty 24/7 pobranie'; $paczk = 1; $inpostCod = 1; break; case '685d8b40-2571-4111-8937-9220b1710d4c': $serviceName = 'Paczkomaty 24/7 '; $paczk = 1; break; case '9081532b-5ad3-467d-80bc-9252982e9dd8': $serviceName = 'Allegro miniKurier24 InPost'; $service = 4; $paczk = 0; break; } if ($x13allegroModule['version'] < $x13version) { $x13transactionId = $x13oinfo->postBuyFormId; $x13allegroUserId = $x13oinfo->postBuyFormBuyerId; } else { $x13transactionId = $x13oinfo->id; $x13allegroUserId = $x13oinfo->buyer->id; $addressAllegro = $x13oinfo->delivery->address; } } else { if ($c1i == 1) { if (in_array($cref, $c1)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 1; } } if ($c2i == 1) { if (in_array($cref, $c2)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 1; $inpostCod = 1; } } if ($c3i == 1) { if (in_array($cref, $c3)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; $service = 2; } } if ($c4i == 1) { if (in_array($cref, $c4)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; $service = 2; $inpostCod = 1; } } if (in_array($cref, $c5)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 5; $week = 1; } if (in_array($cref, $c6)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 6; $inpostCod = 1; $week = 1; } } $sendingMethods = $inpostapi->getSendingMethods(); $point2 = $inpostapi->getPointInfo(Configuration::get('INPOSTSHIP_SENDER_MACHINE')); $orderCarrier2 = new Carrier((int)$order->id_carrier); $orderCarrier = $orderCarrier2->id; $inpostCarrier = []; if (!empty($c1)) { $inpostCarrier = $c1; } if (!empty($c2)) { $inpostCarrier = array_merge($inpostCarrier, $c2); } if (!empty($c3)) { $inpostCarrier = array_merge($inpostCarrier, $c3); } if (!empty($c4)) { $inpostCarrier = array_merge($inpostCarrier, $c4); } if (!empty($c5)) { $inpostCarrier = array_merge($inpostCarrier, $c5); } if (!empty($c6)) { $inpostCarrier = array_merge($inpostCarrier, $c6); } $active = false; if (Configuration::get('INPOSTSHIP_SHOW_SFI') == 1) { $active = true; } if (in_array($orderCarrier, $inpostCarrier)) { $active = true; } $scv = false; if (Configuration::get('INPOSTSHIP_SHOW_COD_VALUE') == 1) { $scv = true; } if ($c2i == 1 || $c4i == 1 || !empty($c6)) { if ($orderCarrier == $c2 || $orderCarrier == $c4 || $orderCarrier == $c6) { $scv = true; } } $orderWeight = $order->getTotalWeight(); if ($orderWeight == 0) { $orderWeight = Configuration::get('INPOSTSHIP_PACKAGE_WEIGHT'); } $showWeek = 0; if (Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { $datWeek = date('w'); $startWeek = 2; $endWeek = 6; $hourWeek = date('H:i'); $startHour = '8:00'; $endHour = '13:00'; if ($datWeek > $startWeek && $datWeek < $endWeek) { $showWeek = 1; } else if ($datWeek > $startWeek && $datWeek == $endWeek) { if ($hourWeek <= $endHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek < $endWeek) { if ($hourWeek >= $startHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek == $endWeek) { if ($hourWeek >= $startHour && $hourWeek <= $endHour) { $showWeek = 1; } } } $addr = array(); $addr['postcode'] = $address_delivery->postcode; $strrets = $address_delivery->address1.(!empty($address_delivery->address2) ? ' '.$address_delivery->address2 : ''); $street = str_replace('ul. ', '', $strrets); $street = str_replace(',', '', $street); $addr['street'] = InpostTools::split_street($street); if (!InpostValidate::isPolandPostCode($address_delivery->postcode)) { $addr['postcode'] = InpostTools::setPolandPostCode($address_delivery->postcode); } $addr['city'] = $address_delivery->city; // etykiety zwrotne if ($service == 2) { } $conf = ''; if (isset($_SESSION['inpost']['conf'])) { $conf = $_SESSION['inpost']['conf']; unset($_SESSION['inpost']['conf']); } //dump($active);die; $this->context->smarty->assign(array( 'conf' => $conf, 'order' => $order, 'orderWeight' => $orderWeight, 'cart_id' => $order->id_cart, 'customer' => $customer, 'address_delivery' => $address_delivery, 'point' => $point, 'point2' => $point2, 'packtype' => $inpostapi->locker, 'insurance' => $inpostapi->insurance, 'packtype_default' => Configuration::get('INPOSTSHIP_PACK_SIZE'), 'dispatch' => Configuration::get('INPOSTSHIP_DISPATCH'), 'pop_points' => $pop_point, 'pok_points' => $pok_point, 'packageList' => $packageList, 'image' => $image, 'sendingMethods' => $sendingMethods['result']->items, 'service' => $service, 'inpostCod' => $inpostCod, 'ssbi' => Configuration::get('INPOSTSHIP_SHOW_SFI'), 'active' => $active, 'scv' => $scv, 'selPopPoint' => Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP'), 'serviceName' => $serviceName, 'paczk' => $paczk, 'x13transactionId' => $x13transactionId, 'x13allegroUserId' => $x13allegroUserId, 'price' => $this->price, 'ipi' => Configuration::get('INPOSTSHIP_PACKAGE_INSURANCE'), 'ioa' => Configuration::get('INPOSTSHIP_ORDER_ADD'), 'addressAllegro' => $addressAllegro, 'weekPack' => $package['week'], 'showWeek' => $showWeek, 'week' => $week, 'rec_mach' => $rec_mach, 'identity' => $identity, 'addr' => $addr, 'devType' => Configuration::get('INPOSTSHIP_SANDBOX'), 'dispatchUrl' => 'https://'.$this->context->shop->domain.$this->context->shop->physical_uri.'module/inpostship/Dispatch?id_pack=', 'printUrl' => 'https://'.$this->context->shop->domain.$this->context->shop->physical_uri.'module/inpostship/printLabel?id_pack=', 'pn_isset' => (int)Configuration::get('INPOSTSHIP_INTEGRATION_PRINTNODE_ISSET'), 'inpostMessage' => isset($_GET['success']) ? $_GET['success'] : '', 'inpostError' => isset($_GET['error']) ? (is_int($_GET['error']) ? $_GET['error'] : base64_decode($_GET['error'])) : '', )); if (version_compare(_PS_VERSION_, '1.6', '<')) { return $this->display(__FILE__, 'order15.tpl'); } else { if (_PS_VERSION_ >= '1.7.7.0') { return $this->display(__FILE__, 'order1770.tpl'); } else { return $this->display(__FILE__, 'order.tpl'); } } } } public function hookDisplayBeforeCarrier($params) { if ($this->isActiveModule()) { $output = ''; $images_url = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__ . '/modules/' . $this->name . '/views/img/'; $pointDir = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__ . 'modules/' . $this->name . '/getPoint.php'; $INPOSTSHIP_CARRIER_1 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_1')); $paczkomaty = '[]'; if (!empty($INPOSTSHIP_CARRIER_1)) { $paczkomaty = json_encode($INPOSTSHIP_CARRIER_1); } $INPOSTSHIP_CARRIER_2 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_2')); $paczkomaty_cod = '[]'; if (!empty($INPOSTSHIP_CARRIER_2)) { $paczkomaty_cod = json_encode($INPOSTSHIP_CARRIER_2); } $INPOSTSHIP_CARRIER_5 = (array)unserialize(Configuration::get('INPOSTSHIP_CARRIER_5')); $paczkomaty_week = '[]'; if (!empty($INPOSTSHIP_CARRIER_5)) { $paczkomaty_week = json_encode($INPOSTSHIP_CARRIER_5); } $INPOSTSHIP_CARRIER_6 = (array)unserialize(Configuration::get('INPOSTSHIP_CARRIER_6')); $paczkomaty_week_cod = '[]'; if (!empty($INPOSTSHIP_CARRIER_6)) { $paczkomaty_week_cod = json_encode($INPOSTSHIP_CARRIER_6); } $INPOSTSHIP_CARRIER_3 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_3')); $courier = '[]'; if (!empty($INPOSTSHIP_CARRIER_3)) { $courier = json_encode($INPOSTSHIP_CARRIER_3); } $INPOSTSHIP_CARRIER_4 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_4')); $courier_cod = '[]'; if (!empty($INPOSTSHIP_CARRIER_4)) { $courier_cod = json_encode($INPOSTSHIP_CARRIER_4); } /*$carrier_inpost_courier = Carrier::getCarrierByReference(Configuration::get('INPOSTSHIP_CARRIER_3')); if (empty($carrier_inpost_courier)) { $carrier_inpost_courier = new stdClass(); $carrier_inpost_courier->id = 0; }*/ /*$carrier_inpost_courier_cod = Carrier::getCarrierByReference(Configuration::get('INPOSTSHIP_CARRIER_4')); if (empty($carrier_inpost_courier_cod)) { $carrier_inpost_courier_cod = new stdClass(); $carrier_inpost_courier_cod->id = 0; }*/ $baseDirShop = (Tools::usingSecureMode() ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_) . __PS_BASE_URI__; $selectedPoint = InpostPack::getPointByCart((int)$this->context->cart->id); $selectedPointInfo = InpostPoint::getPointInfo($selectedPoint); $selectedPointInfoText = ''; if (!empty($selectedPointInfo)) { $selectedPointInfoText = 'Wybrany paczkomat:|| ;;' . $selectedPoint . ', ' . $selectedPointInfo['point_address1'] . ', ' . $selectedPointInfo['point_address2'] . ';; ||' . $selectedPointInfo['point_desc']; } $imap = Configuration::get('INPOSTSHIP_MAP_TYPE'); $imgm = Configuration::get('INPOSTSHIP_GOOGLE_MAPS_API'); $showWeek = 0; if (Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { $datWeek = date('w'); $startWeek = Configuration::get('INPOSTSHIP_WEEKPACK_START_DAY'); $endWeek = Configuration::get('INPOSTSHIP_WEEKPACK_END_DAY'); $hourWeek = date('H:i'); $startHour = Configuration::get('INPOSTSHIP_WEEKPACK_START_HOUR'); $endHour = Configuration::get('INPOSTSHIP_WEEKPACK_END_HOUR'); if ($datWeek > $startWeek && $datWeek < $endWeek) { $showWeek = 1; } else if ($datWeek > $startWeek && $datWeek == $endWeek) { if ($hourWeek <= $endHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek < $endWeek) { if ($hourWeek >= $startHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek == $endWeek) { if ($hourWeek >= $startHour && $hourWeek <= $endHour) { $showWeek = 1; } } } $pType = 0; $pTypes = Configuration::get('INPOSTSHIP_POINT_TYPE'); $pTypes = explode(',', $pTypes); foreach ($pTypes as $pT) { if ($pT == 'pop') { $pType = 1; } } $this->context->smarty->assign(array( 'points' => InpostPoint::getAllPoints(null, 0), 'cart_id' => $this->context->cart->id, 'marker_1' => urlencode($images_url . 'marker_1.png'), 'marker_2' => urlencode($images_url . 'marker_2.png'), 'paczkomaty' => $paczkomaty, 'paczkomaty_cod' => $paczkomaty_cod, 'paczkomaty_week' => $paczkomaty_week, 'paczkomaty_week_cod' => $paczkomaty_week_cod, 'courier' => $courier, 'courier_cod' => $courier_cod, 'ps17' => self::ps17(), 'pointDir' => $pointDir, 'baseDirShop' => $baseDirShop, 'box_pos' => Configuration::get('INPOSTSHIP_POSITION_BOX'), 'version' => _PS_VERSION_, 'module_dir_img' => $images_url, 'selectedPointInfo' => $selectedPointInfoText, 'testMap' => Configuration::get('INPOSTSHIP_SANDBOX'), 'imap' => $imap, 'imgm' => $imgm, 'weekPrice' => Configuration::get('INPOSTSHIP_WEEKPACK_PRICE'), 'showWeek' => $showWeek, 'isTable' => Configuration::get('INPOSTSHIP_IS_TABLE'), 'checkout' => Configuration::get('INPOSTSHIP_CHECKOUT'), 'map_box' => Configuration::get('INPOSTSHIP_MAP_BOX'), 'map_show' => Configuration::get('INPOSTSHIP_MAP_SHOW'), 'pTypes' => $pType, 'snp' => Configuration::get('INPOSTSHIP_POINT_NEAR_SHOW'), 'cnp' => Configuration::get('INPOSTSHIP_POINT_COUNT'), 'rnp' => Configuration::get('INPOSTSHIP_POINT_RADIUS'), 'imw' => Configuration::get('INPOSTSHIP_MAP_WIDTH'), 'geowidget' => (int)Configuration::get('INPOSTSHIP_GEOWIDGET'), 'geowidget_token' => Configuration::get('INPOSTSHIP_GEOV5_TOKEN'), 'sandbox' => (int)Configuration::get('INPOSTSHIP_SANDBOX'), )); $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/hook/carrier_list.tpl'); return $output; } } public function hookActionValidateOrder($params) { if ($this->isActiveModule()) { if (Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { $order = new Order((int)$params['order']->id); $id_cart = $order->id_cart; $pack = InpostPack::getInpostShipCart((int)$id_cart); if ($pack['week'] == 1) { $carrier = Carrier::getCarrierByReference((int)Configuration::get('INPOSTSHIP_CARRIER_5')); $weekPrice = Configuration::get('INPOSTSHIP_WEEKPACK_PRICE'); $weekPrice_excl = $weekPrice; if ($carrier->id_tax_rules_group > 0) { $rate = Db::getInstance()->getValue('SELECT t.`rate` FROM `tax` t LEFT JOIN `tax_rule` tr ON t.id_tax = tr.id_tax WHERE tr.id_tax_rules_group = ' . (int)$carrier->id_tax_rules_group . ' AND tr.id_country = 14'); $result = 1 + ($rate / 100); $tax = number_format($result, 2); $weekPrice_excl = $weekPrice / $tax; } $total = $order->total_paid + $weekPrice; $total_incl = $order->total_paid_tax_incl + $weekPrice; $total_excl = $order->total_paid_tax_excl + $weekPrice_excl; $total_ship = $order->total_shipping + $weekPrice; $total_ship_incl = $order->total_shipping_tax_incl + $weekPrice; $total_ship_excl = $order->total_shipping_tax_excl + $weekPrice_excl; $del_opt = str_replace($params['order']->id_carrier, $carrier->id, $params['cart']->delivery_option); $this->context->cart->id_carrier = (int)$carrier->id; $this->context->cart->delivery_option = $del_opt; $params['cart']->id_carrier = (int)$carrier->id; $params['cart']->delivery_option = $del_opt; $params['order']->id_carrier = (int)$carrier->id; $params['order']->total_paid = $total; $params['order']->total_paid_tax_incl = $total_incl; $params['order']->total_paid_tax_excl = $total_excl; $params['order']->total_shipping = $total_ship; $params['order']->total_shipping_tax_incl = $total_ship_incl; $params['order']->total_shipping_tax_excl = $total_ship_excl; Db::getInstance()->update('orders', array( 'id_carrier' => (int)$carrier->id, 'total_paid' => $total, 'total_paid_tax_incl' => $total_incl, 'total_paid_tax_excl' => $total_excl, 'total_shipping' => $total_ship, 'total_shipping_tax_incl' => $total_ship_incl, 'total_shipping_tax_excl' => $total_ship_excl ), 'id_order = ' . (int)$params['order']->id); Db::getInstance()->update('order_carrier', array( 'id_carrier' => (int)$carrier->id, 'shipping_cost_tax_excl' => $total_ship_excl, 'shipping_cost_tax_incl' => $total_ship_incl ), 'id_order = ' . (int)$params['order']->id); Db::getInstance()->update('cart', array( 'id_carrier' => (int)$carrier->id, 'delivery_option' => $del_opt ), 'id_cart = ' . (int)$order->id_cart); $this->context->cookie->id_cart = $order->id_cart; $this->context->cart = new Cart((int)$order->id_cart); } } if (Configuration::get('INPOSTSHIP_SEND_POINT_CUSTOMER') == 1 || Configuration::get('INPOSTSHIP_SEND_POINT_ADMIN') == 1) { $module = Module::getInstanceByName($this->name); $subject = $this->l('Order INPOST delivery point'); InpostPack::sendPointEmail((int)$params['order']->id, $subject, $module); } } } public function hookActionObjectOrderAddAfter($params) { if ($this->isActiveModule()) { if (Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { $order = new Order((int)$params['order']->id); $id_cart = $order->id_cart; $pack = InpostPack::getInpostShipCart((int)$id_cart); if ($pack['week'] == 1) { $carrier = Carrier::getCarrierByReference((int)Configuration::get('INPOSTSHIP_CARRIER_5')); Db::getInstance()->update('orders', array( 'id_carrier' => (int)$carrier->id ), 'id_order = ' . (int)$params['order']->id); $this->context->cookie->id_cart = $order->id_cart; $this->context->cart = new Cart((int)$order->id_cart); } } } } private function moduleInfo() { $ssl = 'http://'; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $ssl = 'https://'; } $moduleImg = $ssl.$this->context->shop->domain.$this->context->shop->physical_uri.'modules/inpostship/assets/img/'; $this->context->smarty->assign(array( 'moduleImg' => $moduleImg, 'moduleName' => $this->name, 'moduleVersion' => $this->version, 'moduleDisplayName' => $this->displayName )); } public function getContent() { $showLicence = (isset($_GET['showLicence']) ? 1 : null); $output = ''; if (!$this->isActiveModule()) { $this->postProcess(); $shop = new Shop((int)$this->context->shop->id); $this->context->smarty->assign(array( 'moduleDomain' => $shop->getBaseURL(), 'modConf' => 1, 'licenceCode' => Configuration::get('INPOSTSHIP_LICENCE'), 'licenceCodeGen' => Configuration::get('INPOSTSHIP_LICENCE_GEN'), 'licGenData' => Configuration::get('INPOSTSHIP_LICENCE_GEN_DATA'), 'showLicence' => $showLicence, )); $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/nolic.tpl'); } else { $this->postProcess(); $this->moduleInfo(); $this->context->smarty->assign(array( 'isic1' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1'), 'isic2' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2'), 'isic3' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3'), 'isic4' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4'), 'modConf' => 0, 'licenceCode' => Configuration::get('INPOSTSHIP_LICENCE'), 'licenceCodeGen' => Configuration::get('INPOSTSHIP_LICENCE_GEN'), 'licGenData' => Configuration::get('INPOSTSHIP_LICENCE_GEN_DATA'), )); if (version_compare(_PS_VERSION_, '1.6', '<')) { $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/module15.tpl'); } else { $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/module.tpl'); } } return $output; } private function postProcess() { if (Tools::getIsset('submitSaveLicenceCode')) { Configuration::updateValue('INPOSTSHIP_LICENCE', Tools::getValue('INPOSTSHIP_LICENCE')); } if (Tools::getIsset('submitSaveSettings')) { Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_1', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_2', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_3', 0); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_4', 0); $c1install = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1'); $c2install = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2'); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_1', (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_1', 0)); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_2', (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_2', 0)); if ((int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_1') == 1) { if ($c1install == 0 && (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIERS') == 1) { InpostSettings::createCarrier('INPOSTSHIP_CARRIER_1', 'InPost Paczkomaty 24'); } } if ((int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_2') == 1) { if ($c2install == 0 && (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIERS') == 1) { InpostSettings::createCarrier('INPOSTSHIP_CARRIER_2', 'InPost Paczkomaty 24 - za pobraniem'); } } $c3install = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3'); $c4install = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4'); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_3', (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_3')); Configuration::updateValue('INPOSTSHIP_INSTALL_CARRIER_4', (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_4', 0)); if ((int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_3') == 1) { if ($c3install == 0 && (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIERS') == 1) { InpostSettings::createCarrier('INPOSTSHIP_CARRIER_3', 'InPost Kurier'); } } if ((int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIER_4') == 1) { if ($c4install == 0 && (int)Tools::getValue('INPOSTSHIP_INSTALL_CARRIERS') == 1) { InpostSettings::createCarrier('INPOSTSHIP_CARRIER_4', 'InPost Kurier - za pobraniem'); } } } } public function getOrderShippingCost($shipping_cost) { return $shipping_cost; } private static function ps17() { return Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>='); } private static function ps15() { return Tools::version_compare(_PS_VERSION_, '1.6.0.0', '<='); } private static function ps8() { return Tools::version_compare(_PS_VERSION_, '8.0.0', '>='); } public function ajaxGetPoint() { $req = ''; $points_item = array(); $points_item_near = array(); $points = array(); $id_courier = (int)$_REQUEST['idCourier']; $cod = (int)$_REQUEST['cod']; $return = array(); if ($id_courier > 0) { $carrier = new Carrier((int)$id_courier, (int)$this->context->cookie->id_lang); if ((int)$carrier->id == Configuration::get('INPOSTSHIP_CARRIER_PACZKOMATY_COD') && Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2') == 1) { $cod = 0; } } $id_address = (int)$_REQUEST['idAddress']; $address = new Address((int)$id_address); $postcode = trim($address->postcode);//str_replace('-', '', trim($address->postcode)) ; $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); $nearcount = Configuration::get('INPOSTSHIP_NEAR'); $pointsNear = (array)$inpostapi->getPointNearAddress($postcode, $nearcount); $nearPointsRemove = array(); if (!empty($pointsNear)) { foreach ($pointsNear as $key => $p) { $p = (array)$p; $points_item_near[$key]['id'] = $p['name'] . ', ' . $p['address']->line1 . ', ' . $p['address']->line2; $points_item_near[$key]['text'] = $p['name'] . ', ' . $p['address']->line1 . ', ' . $p['address']->line2; $nearPointsRemove[] = $p['name']; } } if ($nearcount > 0) { $return['items'][0]['text'] = 'Paczkomaty w pobliżu Twojego adresu'; $return['items'][0]['children'] = $points_item_near; if (isset($_REQUEST['searchTerm'])) { $req = $_REQUEST['searchTerm']; $points = InpostPoint::getAllPoints($req, $cod); } else { $points = InpostPoint::getAllPoints(null, $cod); } if (!empty($points)) { foreach ($points as $key => $p) { // if (!in_array($p['point_code'], $nearPointsRemove)) { $points_item[$key]['id'] = $p['point_code'] . ', ' . $p['point_address1'] . ', ' . $p['point_address2']; $points_item[$key]['text'] = $p['point_code'] . ', ' . $p['point_address1'] . ', ' . $p['point_address2']; } } $return['items'][1]['text'] = 'Pozostałe paczkomaty'; $return['items'][1]['children'] = $points_item; } else { if (isset($_REQUEST['searchTerm'])) { $req = $_REQUEST['searchTerm']; $points = InpostPoint::getAllPoints($req, $cod); } else { $points = InpostPoint::getAllPoints(null, $cod); } if (!empty($points)) { foreach ($points as $key => $p) { $points_item[$key]['id'] = $p['point_code'] . ', ' . $p['point_address1'] . ', ' . $p['point_address2']; $points_item[$key]['text'] = $p['point_code'] . ', ' . $p['point_address1'] . ', ' . $p['point_address2']; } } $return['items'][0]['text'] = 'Paczkomaty do wyboru'; $return['items'][0]['children'] = $points_item; } return $return; } public function setAjaxCartPoint($id_cart, $point, $courier, $week) { $issetCart = InpostPack::issetCart((int)$id_cart); if (empty($issetCart)) { $return = InpostPack::setInpostShip((int)$id_cart, $point, (int)$courier, (int)$week, (int)$this->context->cookie->id_lang); } else { $return = InpostPack::updateInpostShip((int)$id_cart, $point, (int)$courier, (int)$week, (int)$this->context->cookie->id_lang); } if ($return) { return InpostPoint::getPointInfo($point); } return $return; } public function updatePoints() { set_time_limit(0); @ini_set('max_execution_time', '0'); $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); $points = $inpostapi->getPoints(); $count_points = count($points); $current_count_points = count(Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'inpostship_points ORDER BY id_point ASC')); if ($current_count_points != $count_points) { Db::getInstance()->execute('TRUNCATE TABLE '._DB_PREFIX_.'inpostship_points'); foreach ($points as $p) { $p = (array)$p; if (!InpostPoint::checkPoint($p['name'])) { $location = (array)$p['location']; $address = (array)$p['address']; $type = implode(',', (array)$p['type']); $cod_pay = (array)$p['payment_type']; $cod = 1; if (array_key_exists(0, $cod_pay)) { $cod = 0; } else { foreach ($cod_pay as $cp) { if (trim($cp) == 'Brak obsługi płatności') { $cod = 0; } } } Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'inpostship_points`(`point_code`, `point_address1`, `point_address2`, `point_lat`, `point_lng`, `point_desc`, `point_payment`, `point_cod`, `point_type`) VALUES("' . $p['name'] . '", "' . addslashes($address['line1']) . '", "' . $address['line2'] . '", "' . $location['latitude'] . '", "' . $location['longitude'] . '", "' . addslashes($p['location_description']) . '", "' . $p['payment_available'] . '", "'.(int)$cod.'", "'.$type.'")'); } } } } public function setCourier($id_cart, $courier) { $return = true; $ship = InpostPack::issetCart((int)$id_cart); if (empty($ship)) { $return = (bool)InpostPack::setInpostShipCourier((int)$id_cart, (int)$courier, (int)$this->context->cookie->id_lang); } else { $return = (bool)InpostPack::updateInpostShipCourier((int)$id_cart, (int)$courier, (int)$this->context->cookie->id_lang); } return $return; } private function InpostProcess() { if (Tools::getIsset('newReceiveMachine')) { $new = Tools::getValue('newReceiveMachine'); $id_order = Tools::getValue('id_order'); $order = new Order((int)$id_order); $id_cart = (int)$order->id_cart; InpostPack::changeReceiverMachine((int)$id_cart, $new, $order); Tools::redirectAdmin($_SERVER['HTTP_REFERER']); } if (Tools::isSubmit('submitCheckPrice')) { $inpostship = Tools::getValue('inpostship'); $receiver = array(); $sender = array(); $custom_attrib = array(); $additional_services = array(); $x13allegro = Configuration::get('INPOSTSHIP_INTEGRATION_X13ALLEGRO'); $order = new Order((int)$inpostship['id_order']); $address_delivery = new Address($order->id_address_delivery); $pack = InpostPack::getInpostShipCart((int)$inpostship['id_cart']); $parcels = array(); $pcount = 0; $owner = 0; if (isset($inpostship['sizes']) && $inpostship['sizes'] == 1) { $owner = 1; } if ($owner == 0) { $parcels[$pcount]['id'] = $inpostship['packtype'] . ' package'; $parcels[$pcount]['template'] = $inpostship['packtype']; $parcels[$pcount]['weight'] = $inpostship['packweight'] == 0 ? 2 : $inpostship['packweight']; $parcels[$pcount]['info'] = $inpostship['packtype']; $parcels[$pcount]["tracking_number"] = null; $parcels[$pcount]["is_non_standard"] = false; } else { $parcels[$pcount]['id'] = 'other package'; $parcels[$pcount]['template'] = 'other'; $parcels[$pcount]['weight'] = $inpostship['packweight'] == 0 ? 2 : $inpostship['packweight']; $parcels[$pcount]['info'] = 'other'; $parcels[$pcount]["tracking_number"] = null; $parcels[$pcount]["is_non_standard"] = false; $parcels[$pcount]['length'] = $inpostship['size1']; $parcels[$pcount]['width'] = $inpostship['size2']; $parcels[$pcount]['height'] = $inpostship['size3']; } $custom_attrib['target_point'] = $pack['receiver_machine']; $custom_attrib['sending_method'] = $inpostship['sendtype']; $service = 'inpost_locker_standard'; $id_carrier = (int)$pack['id_carrier']; if ($id_carrier != $order->id_carrier) { $id_carrier = (int)$order->id_carrier; } $carrier = new Carrier((int)$id_carrier); if (empty($inpostship['service']) || $inpostship['service'] == 0) { if ((Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3') == 1 || Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4') == 1) && (Configuration::get('INPOSTSHIP_CARRIER_3') == $carrier->id_reference || Configuration::get('INPOSTSHIP_CARRIER_4') == $carrier->id_reference)) { $service = 'inpost_courier_standard'; } if ($service == 'inpost_locker_standard') { if ($custom_attrib['target_point'] == Configuration::get('INPOSTSHIP_SENDER_MACHINE', 0) || $custom_attrib['target_point'] == Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP', 0)) { if ($inpostship['sendtype'] == 'parcel_locker') { $service = 'inpost_locker_pass_thru'; } } } } else { switch ((int)$inpostship['service']) { case 1:case 5:case 6:$service = 'inpost_locker_standard';break; case 2:$service = 'inpost_courier_standard';break; } } if ($inpostship['cod'] == 1) { $cod = 1; $cod_value = $inpostship['cod_value']; } if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_2') && Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2') == 1) { $cod = 1; $cod_value = $inpostship['cod_value']; } if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_4') && Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4') == 1) { $cod = 1; $cod_value = $inpostship['cod_value']; } if ((int)Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { if ((int)$carrier->id_reference > 0 && (int)$carrier->id_reference == (int)Configuration::get('INPOSTSHIP_CARRIER_6')) { $cod = 1; $cod_value = $inpostship['cod_value']; } } if ($x13allegro && ($inpostship['service'] == 3 || $inpostship['service'] == 4)) { if ($inpostship['service'] == 3 && $inpostship['paczk'] == 1) { $service = 'inpost_locker_allegro'; } elseif ($inpostship['service'] == 3 && $inpostship['paczk'] == 0) { $service = 'inpost_courier_allegro'; } elseif ($inpostship['service'] == 4) { $service = 'inpost_letter_allegro'; } $custom_attrib['allegro_transaction_id'] = $inpostship['x13transactionId']; $custom_attrib['allegro_user_id'] = $inpostship['x13allegroUserId']; $x13version = '6.2.1'; $rec_mach = ''; $x13allegroModule = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'module` WHERE `name` = "x13allegro"'); if ($x13allegro) { if ($x13allegroModule['version'] < $x13version) { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'xallegro_form` WHERE `id_order` = '.(int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = unserialize(base64_decode($x13orderInfo['content'])); $rec_mach = $x13oinfo->postBuyFormGdAddress->postBuyFormAdrId; } } else { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'xallegro_order` WHERE `id_order` = '.(int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = json_decode($x13orderInfo['checkout_form_content']); $rec_mach = $x13oinfo->delivery->pickupPoint->id; $address = $x13oinfo->delivery->address; $receiver['first_name'] = Tools::stripslashes($address->firstName); $receiver['last_name'] = $address->lastName; $postcode = null;//$address->zipCode; $street = str_replace('ul. ', '', $address->street); $street = str_replace(',', '', $street); $match = InpostTools::split_street($street); if (!InpostValidate::isPolandPostCode($postcode)) { $postcode = InpostTools::setPolandPostCode($postcode); } $city = $address->city; } } } if (!empty($rec_mach)) { $custom_attrib['target_point'] = $rec_mach; } } else { $receiver['first_name'] = Tools::stripslashes($address_delivery->firstname); $receiver['last_name'] = $address_delivery->lastname; $postcode = $address_delivery->postcode; $match = InpostTools::split_street(trim($address_delivery->address1.' '.$address_delivery->address2)); if (!InpostValidate::isPolandPostCode($postcode)) { $postcode = InpostTools::setPolandPostCode($postcode); } $city = $address_delivery->city; } if (empty($postcode)) { $receiver['first_name'] = Tools::stripslashes($address_delivery->firstname); $receiver['last_name'] = $address_delivery->lastname; $postcode = $address_delivery->postcode; $match = InpostTools::split_street(trim($address_delivery->address1.' '.$address_delivery->address2)); if (!InpostValidate::isPolandPostCode($postcode)) { $postcode = InpostTools::setPolandPostCode($postcode); } $city = $address_delivery->city; } $receiver['email'] = $inpostship['receiver_email']; $receiver['phone'] = $inpostship['receiver_mobile']; $receiver['address'] = array( 'street' => $match['street'], 'building_number' => $match['numberAll'], 'city' => $city, 'post_code' => $postcode, 'country_code' => 'PL' ); $sender['first_name'] = Configuration::get('INPOSTSHIP_SENDER_FIRSTNAME'); $sender['last_name'] = Configuration::get('INPOSTSHIP_SENDER_LASTNAME'); $sender['company_name'] = Configuration::get('INPOSTSHIP_SENDER_COMPANY_NAME'); $sender['phone'] = Configuration::get('INPOSTSHIP_SENDER_PHONE'); $sender['email'] = Configuration::get('INPOSTSHIP_SENDER_EMAIL'); $sender['address'] = array( 'street' => Configuration::get('INPOSTSHIP_SENDER_STREET'), 'building_number' => Configuration::get('INPOSTSHIP_SENDER_BUILDING_NR'), 'city' => Configuration::get('INPOSTSHIP_SENDER_CITY'), 'post_code' => Configuration::get('INPOSTSHIP_SENDER_POSTCODE'), 'country_code' => 'PL' ); if ($custom_attrib['sending_method'] == 'parcel_locker') { $custom_attrib['dropoff_point'] = Configuration::get('INPOSTSHIP_SENDER_MACHINE'); } else if ($custom_attrib['sending_method'] == 'pop') { $custom_attrib['dropoff_point'] = Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP'); } $insurance = array(); if ($inpostship['ins']) { $insurance['amount'] = $inpostship['ins']; $insurance['currency'] = 'PLN'; } $cods = array(); if ($cod == 1) { $cods['amount'] = $inpostship['cod_value']; $cods['currency'] = 'PLN'; } $additional_services = array(); if (isset($inpostship['email'])) { $additional_services[] = 'email'; } if (isset($inpostship['sms'])) { $additional_services[] = 'sms'; } $reference = null; if (!empty($inpostship['reference_number'])) { $reference = $inpostship['reference_number']; } $weekPack = false; if ($inpostship['showWeek'] == 1) { if ($inpostship['weekPack'] == 1) { $weekPack = 1; } } if ($inpostship['service'] == 5 || $inpostship['service'] == 6) { $weekPack = 1; } $sxerror = new InpostError(); $org_id = (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'); $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $calculate = $inpostapi->shipmentCalculate((int)$org_id, $receiver, $sender, $parcels, $custom_attrib, $cods, $insurance, $additional_services, $reference, $service, $weekPack); if (!empty($calculate['error'])) { if ($this->debug == 1) { echo "
";print_r($calculate);echo "
"; } $errorsInpost[] = $sxerror->displayErrors($calculate, 2); $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($calculate, 2), 'error' => 'Wystapił błąd przy kalkulacji ceny za przesyłkę' )); } else { $result = (array)$calculate['result'][0]; if (!isset($result['key'])) { if (isset($result['response_description'])) { $error = $result['response_description']; $this->context->smarty->assign(array( 'error' => $error )); } else { $this->price = $result['calculated_charge_amount']; $this->context->smarty->assign(array( 'conf' => 'Koszt przesyłki to ' . $this->price . ' PLN', 'price' => $this->price )); } } else { $this->context->smarty->assign(array( 'error' => $result['message'] )); } } } // end tools calculate // create package if (Tools::isSubmit('submitPackage')) { $inpostship = Tools::getValue('inpostship'); $errorsInpost = array(); $cod = 0; $cod_value = 0; $pack = InpostPack::getInpostShipCart((int)$inpostship['id_cart']); $order = new Order((int)$inpostship['id_order']); $id_carrier = (int)$pack['id_carrier']; if ($id_carrier != $order->id_carrier) { $id_carrier = (int)$order->id_carrier; } $carrier = new Carrier((int)$id_carrier, (int)$this->context->cookie->id_lang); $receiver = array(); $sender = array(); $custom_attrib = array(); $additional_services = array(); $x13allegro = Configuration::get('INPOSTSHIP_INTEGRATION_X13ALLEGRO'); if ($inpostship['cod'] == 1) { $cod = 1; $cod_value = $inpostship['cod_value']; } if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_2') && Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2') == 1) { $cod = 1; $cod_value = $inpostship['cod_value']; } if ((int)$carrier->id_reference == Configuration::get('INPOSTSHIP_CARRIER_4') && Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4') == 1) { $cod = 1; $cod_value = $inpostship['cod_value']; } if ((int)Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { if ((int)$carrier->id_reference > 0 && (int)$carrier->id_reference == (int)Configuration::get('INPOSTSHIP_CARRIER_6')) { $cod = 1; $cod_value = $inpostship['cod_value']; } } $packtype = $inpostship['packtype']; $sizes = array(); if (isset($inpostship['sizes']) && $inpostship['sizes'] == 1) { $packtype = 'other'; $sizes[] = $inpostship['size1']; $sizes[] = $inpostship['size2']; $sizes[] = $inpostship['size3']; } if (InpostPack::setInpostPackage((int)$inpostship['id_order'], $inpostship['receiver_email'], $inpostship['receiver_mobile'], $packtype, $inpostship['sendtype'], $pack['receiver_machine'], $inpostship['ins'], $cod_value, $sizes)) { $id_pack = Db::getInstance()->Insert_ID(); $address_delivery = new Address($order->id_address_delivery); $service = 'inpost_locker_standard'; $carrier = new Carrier((int)$pack['id_carrier']); $custom_attrib['target_point'] = $pack['receiver_machine']; $custom_attrib['sending_method'] = $inpostship['sendtype']; if (empty($inpostship['service']) || $inpostship['service'] == 0) { if ((Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3') == 1 || Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4') == 1) && (Configuration::get('INPOSTSHIP_CARRIER_3') == $carrier->id_reference || Configuration::get('INPOSTSHIP_CARRIER_4') == $carrier->id_reference)) { $service = 'inpost_courier_standard'; } if ($service == 'inpost_locker_standard') { if ($custom_attrib['target_point'] == Configuration::get('INPOSTSHIP_SENDER_MACHINE', 0) || $custom_attrib['target_point'] == Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP', 0)) { if ($inpostship['sendtype'] == 'parcel_locker') { $service = 'inpost_locker_pass_thru'; } } } } else { switch ((int)$inpostship['service']) { case 1:case 5:case 6:$service = 'inpost_locker_standard';break; case 2:$service = 'inpost_courier_standard';break; } } $reference = null; if (!empty($inpostship['reference_number'])) { $reference = $inpostship['reference_number']; } $allegroNick = (int)Configuration::get('INPOSTSHIP_X13ALLEGRO_NICK'); if ($x13allegro && ($inpostship['service'] == 3 || $inpostship['service'] == 4)) { if ($inpostship['service'] == 3 && $inpostship['paczk'] == 1) { $service = 'inpost_locker_allegro'; } elseif ($inpostship['service'] == 3 && $inpostship['paczk'] == 0) { $service = 'inpost_courier_allegro'; } elseif ($inpostship['service'] == 4) { $service = 'inpost_letter_allegro'; } $custom_attrib['allegro_transaction_id'] = $inpostship['x13transactionId']; $custom_attrib['allegro_user_id'] = $inpostship['x13allegroUserId']; $x13version = '6.2.1'; $rec_mach = ''; $x13allegroModule = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'module` WHERE `name` = "x13allegro"'); if ($x13allegro) { $login = ''; if ($x13allegroModule['version'] < $x13version) { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'xallegro_form` WHERE `id_order` = '.(int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = unserialize(base64_decode($x13orderInfo['content'])); $rec_mach = $x13oinfo->postBuyFormGdAddress->postBuyFormAdrId; } } else { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'xallegro_order` WHERE `id_order` = '.(int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = json_decode($x13orderInfo['checkout_form_content']); $rec_mach = $x13oinfo->delivery->pickupPoint->id; $address = $x13oinfo->delivery->address; $receiver['first_name'] = Tools::stripslashes($address->firstName); $receiver['last_name'] = $address->lastName; $postcode = null;//$address->zipCode; $street = str_replace('ul. ', '', $address->street); $street = str_replace(',', '', $street); $match = InpostTools::split_street($street); if (!InpostValidate::isPolandPostCode($postcode)) { $postcode = InpostTools::setPolandPostCode($postcode); } $city = $address->city; $login = ' '.$x13oinfo->buyer->login; } } if ($allegroNick == 1) { $reference.= $login; } } if (!empty($rec_mach)) { $custom_attrib['target_point'] = $rec_mach; } } else { $receiver['first_name'] = Tools::stripslashes($address_delivery->firstname); $receiver['last_name'] = $address_delivery->lastname; $postcode = $address_delivery->postcode; $match = InpostTools::split_street(trim($address_delivery->address1.' '.$address_delivery->address2)); if (!InpostValidate::isPolandPostCode($postcode)) { $postcode = InpostTools::setPolandPostCode($postcode); } $city = $address_delivery->city; } if (empty($postcode)) { $receiver['first_name'] = Tools::stripslashes($address_delivery->firstname); $receiver['last_name'] = $address_delivery->lastname; $postcode = $address_delivery->postcode; $match = InpostTools::split_street(trim($address_delivery->address1.' '.$address_delivery->address2)); if (!InpostValidate::isPolandPostCode($postcode)) { $postcode = InpostTools::setPolandPostCode($postcode); } $city = $address_delivery->city; } $receiver['email'] = $inpostship['receiver_email']; $receiver['phone'] = InpostValidate::reValidPhone($inpostship['receiver_mobile']); $receiver['address'] = array( 'street' => $match['street'], 'building_number' => $match['numberAll'], 'city' => $city, 'post_code' => $postcode, 'country_code' => 'PL' ); $sender['first_name'] = Configuration::get('INPOSTSHIP_SENDER_FIRSTNAME'); $sender['last_name'] = Configuration::get('INPOSTSHIP_SENDER_LASTNAME'); $sender['company_name'] = Configuration::get('INPOSTSHIP_SENDER_COMPANY_NAME'); $sender['phone'] = Configuration::get('INPOSTSHIP_SENDER_PHONE'); $sender['email'] = Configuration::get('INPOSTSHIP_SENDER_EMAIL'); $sender['address'] = array( 'street' => Configuration::get('INPOSTSHIP_SENDER_STREET'), 'building_number' => Configuration::get('INPOSTSHIP_SENDER_BUILDING_NR'), 'city' => Configuration::get('INPOSTSHIP_SENDER_CITY'), 'post_code' => Configuration::get('INPOSTSHIP_SENDER_POSTCODE'), 'country_code' => 'PL' ); // $custom_attrib['target_point'] = $pack['receiver_machine']; // $custom_attrib['sending_method'] = $inpostship['sendtype']; if ($custom_attrib['sending_method'] == 'parcel_locker') { $custom_attrib['dropoff_point'] = Configuration::get('INPOSTSHIP_SENDER_MACHINE'); } else if ($custom_attrib['sending_method'] == 'pop') { $custom_attrib['dropoff_point'] = Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP'); } $insurance = array(); if ($inpostship['ins']) { $insurance['amount'] = $inpostship['ins']; $insurance['currency'] = 'PLN'; } $cods = array(); if ($cod == 1) { $cods['amount'] = $inpostship['cod_value']; $cods['currency'] = 'PLN'; } $additional_services = array(); if (isset($inpostship['email'])) { $additional_services[] = 'email'; } if (isset($inpostship['sms'])) { $additional_services[] = 'sms'; } $parcels = array(); $pcount = 0; $owner = 0; if (isset($inpostship['sizes']) && $inpostship['sizes'] == 1) { $owner = 1; } if ($owner == 0) { $parcels[$pcount]['id'] = $inpostship['packtype'] . ' package'; $parcels[$pcount]['template'] = $inpostship['packtype']; $parcels[$pcount]['weight'] = $inpostship['packweight'] == 0 ? 2 : $inpostship['packweight']; $parcels[$pcount]['info'] = $inpostship['packtype']; $parcels[$pcount]["tracking_number"] = null; $parcels[$pcount]["is_non_standard"] = false; } else { $parcels[$pcount]['id'] = 'other package'; $parcels[$pcount]['template'] = 'other'; $parcels[$pcount]['weight'] = $inpostship['packweight'] == 0 ? 2 : $inpostship['packweight']; $parcels[$pcount]['info'] = 'other'; $parcels[$pcount]["tracking_number"] = null; $parcels[$pcount]["is_non_standard"] = false; $parcels[$pcount]['length'] = $inpostship['size1']; $parcels[$pcount]['width'] = $inpostship['size2']; $parcels[$pcount]['height'] = $inpostship['size3']; } $weekPack = false; if ($inpostship['showWeek'] == 1) { if ($inpostship['weekPack'] == 1) { $weekPack = 1; } } if ($inpostship['service'] == 5 || $inpostship['service'] == 6) { $weekPack = 1; } $sxerror = new InpostError(); $org_id = (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'); $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $packPrepare = $inpostapi->shipment((int)$org_id, $receiver, $sender, $parcels, $custom_attrib, $cods, $insurance, $additional_services, $reference, $service, false, $weekPack); // print_r($packPrepare);exit(); if (!empty($packPrepare['error'])) { if ($this->debug == 1) { echo "
";print_r($packPrepare);echo "
"; } $errorsInpost[] = $sxerror->displayErrors($packPrepare); $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($packPrepare) )); } else { InpostPack::updateInpostShipped((int)$id_pack, $packPrepare['result']->status, $packPrepare['result']->id); $id_packcode = $packPrepare['result']->id; sleep(5); $offer = $inpostapi->getShipments($id_packcode, (int)$org_id); if (!empty($offer['error'])) { if ($this->debug == 1) { echo "
";print_r($offer);echo "
"; } $errorsInpost[] = $sxerror->displayErrors($offer); $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($offer) )); } else { $oferta = $offer['result']->selected_offer; if (!empty($oferta)) { InpostPack::updateInpostOffer((int)$id_pack, $offer['result']->status, $oferta->id); } $status = $offer['result']->status; $tracking_number = $offer['result']->tracking_number; if (!empty($tracking_number)) { $module = Module::getInstanceByName($this->name); $subject = $this->l('Order tracking e-mail'); InpostPack::updateInpostBuy((int)$id_pack, (int)$inpostship['id_order'], (int)$this->context->employee->id, $status, $tracking_number, $subject, $module); if ($x13allegro) { Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'xallegro_carrier_package_info`(`id_order`, `id_operator`, `tracking_number`, `send`) '. 'VALUES('.(int)$order->id.', '.(int)$this->context->employee->id.', "'.$tracking_number.'", 1)'); } InpostPack::updateCreatedCart($order->id_cart); $_SESSION['inpost']['conf'] = 'Pomyślnie utworzono przesyłkę numer '.$tracking_number; $this->context->smarty->assign(array( 'conf' => 'Pomyślnie utworzono przesyłkę numer '.$tracking_number )); Tools::redirect($_SERVER['HTTP_REFERER']); } else { InpostPack::updateInpostBuyInfo((int)$id_pack); $this->context->smarty->assign(array( 'error' => 'Wystąpił problem z utworzeniem przesyłki' )); } } } } // end InpostPack::setInpostPackage if (count($errorsInpost) > 0) { $this->context->smarty->assign(array( 'error' => 'Wystąpiły problemy w utworzeniu przesyłki. Przejdź do sekcji WYSYŁAJ Z INPOST aby poznać szczegóły. ' )); } } // end submit submitPackage /*if (Tools::isSubmit('submitPrintLabel')) { $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $id_pack = (int)Tools::getValue('submitPrintLabel'); $pack = InpostPack::getInpostShipByIdPack((int)$id_pack); $format = Configuration::get('INPOSTSHIP_PRINT_FORMAT'); $inpost = $inpostapi->getLabel($pack['packcode'], $format, Configuration::get('INPOSTSHIP_PRINT_TYPE')); $file_name = $pack['reference_number']; ob_end_clean(); ob_start(); if ($format == 'PDF') { $file_type = 'pdf'; header('Content-Type: application/pdf'); } else { $file_type = 'epl'; header('Content-Type: application/octet-stream'); } header("Content-Disposition: attachment; filename=\"$file_name.$file_type\""); exit($inpost); } // end to print*/ if (Tools::isSubmit('submitDeletePack')) { $id_pack = (int)Tools::getValue('submitDeletePack'); if ($id_pack > 0) { InpostPack::deletePackById((int)$id_pack); } } // end delete pack if (Tools::isSubmit('submitDeleteShipping')) { $id_pack = (int)Tools::getValue('submitDeleteShipping'); if ($id_pack > 0) { $pack = InpostPack::getInpostShipByIdPack((int)$id_pack); $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $deletePack = $inpostapi->deleteShipments($pack['packcode']); if (!empty($deletePack['error'])) { if ($deletePack['result']->error == 'resource_not_found') { InpostPack::deletePackById((int)$id_pack); $this->context->smarty->assign(array( 'conf' => 'Poprawnie usunięto przesyłkę' )); } else { $this->context->smarty->assign(array( 'error' => 'Nie można usunąć przesyłki, ponieważ jej status na to nie pozwala', 'errors' => 'Nie można usunąć przesyłki, ponieważ jej status na to nie pozwala', )); } } else { InpostPack::deletePackById((int)$id_pack); $this->context->smarty->assign(array( 'conf' => 'Poprawnie usunięto przesyłkę' )); } } } // end delete pack if (Tools::isSubmit('submitOrderCourier')) { $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $id_pack = (int)Tools::getValue('submitOrderCourier'); $pack = InpostPack::getInpostShipByIdPack((int)$id_pack); $dispatch = $inpostapi->setDispatchOrder($pack['packcode'], (int)Configuration::get('INPOSTSHIP_DISPATCH_POINT'), (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION')); if (empty($dispatch['error'])) { $info = (array)$dispatch['result']; InpostPack::updateDispatchId((int)$id_pack, (int)$info['id']); } else { if ($this->debug == 1) { echo "
";print_r($dispatch);echo "
"; } $sxerror = new InpostError(); $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($dispatch) )); } } // end order courier if (Tools::isSubmit('submitDeleteDispatch')) { $id_pack = (int)Tools::getValue('submitDeleteDispatch'); $pack = InpostPack::getInpostShipByIdPack((int)$id_pack); $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $inpostapi->deleteDispatch((int)$pack['dispatch_id']); InpostPack::updateDispatchId((int)$id_pack, 0); } // end delete dispatchOrder if (Tools::isSubmit('submitReturnLabel')) { $id_pack = (int)Tools::getValue('submitReturnLabel'); $pack = InpostPack::getInpostShipByIdPack((int)$id_pack); $org_id = (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'); $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $inpostapi->getReturnLabels((int)$org_id, (int)$pack['packcode'], 'PDF'); // InpostPack::updateDispatchId((int)$id_pack, 0); } // end delete dispatchOrder if (Tools::isSubmit('submitCheckPayment')) { $id_pack = (int)Tools::getValue('submitCheckPayment'); $pack = InpostPack::getInpostShipByIdPack((int)$id_pack); $inpostship = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $searchPack = $inpostship->searchPack($pack['packcode'], (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION')); if (empty($searchPack['error'])) { $item = (array)$searchPack['result']->items[0]; if (!empty($item)) { InpostPack::updateInpostShipped((int)$id_pack, $item['status'], $pack['packcode']); $status = $item['status']; $tracking_number = $item['tracking_number']; if (!empty($tracking_number)) { $module = Module::getInstanceByName($this->name); $subject = $this->l('Order tracking e-mail'); InpostPack::updateInpostBuy((int)$id_pack, (int)$id_order, (int)$this->context->employee->id, $status, $tracking_number, $subject, $module); $_SESSION['inpost']['conf'] = 'Pomyślnie utworzono przesyłkę numer '.$tracking_number; $this->context->smarty->assign(array( 'conf' => 'Pomyślnie utworzono przesyłkę numer '.$tracking_number )); Tools::redirect($_SERVER['HTTP_REFERER']); } else { if ($item['status'] == 'offer_selected') { } } } } else { if ($this->debug == 1) { echo "
";print_r($searchPack);echo "
";die; } $sxerror = new InpostError(); $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($searchPack) )); } } // end submitCheckPayment } /** * @return bool */ public function deleteInpostPoint() { if (Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'inpostship_points`')) { return true; } return false; } public function addInpostPoint($page, $count) { $day = date('Y-m-d-h-i'); $log = 'PAGE: '.$page.' COUNT: '.$count.PHP_EOL; $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); $points = $inpostapi->getPointsPerPage($page, $count); if (!empty($points)) { $i = 0; foreach ($points as $p) { $p = (array)$p; $log .= 'POINT: '.$p['name'].PHP_EOL; // if (!InpostPoint::checkPoint($p['name'])) { $location = (array)$p['location']; $address = (array)$p['address']; $type = implode(',', (array)$p['type']); $cod_pay = (array)$p['payment_type']; $cod = 1; if (array_key_exists(0, $cod_pay)) { $cod = 0; } else { foreach ($cod_pay as $cp) { if (trim($cp) == 'Brak obsługi płatności') { $cod = 0; } } } Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'inpostship_points`(`point_code`, `point_address1`, `point_address2`, `point_lat`, `point_lng`, `point_desc`, `point_payment`, `point_cod`, `point_type`) VALUES("' . $p['name'] . '", "' . str_replace('"', "", $address['line1']) . '", "' . $address['line2'] . '", "' . $location['latitude'] . '", "' . $location['longitude'] . '", "' . addslashes($p['location_description']) . '", "' . $p['payment_available'] . '", "'.(int)$cod.'", "'.$type.'")'); $log .= 'ADD: '.$p['name'].PHP_EOL; $i++; // } } $log .= "-------------------------" . PHP_EOL; file_put_contents(__DIR__.'/log/loger/log_'.$day.'.txt', $log, FILE_APPEND); return $i;//count($points); } return 0; } public function tracking($track) { $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); $trackingInfo = $inpostapi->getTracking($track); $statues = $inpostapi->getStatuses(); if (!empty($trackingInfo['result']->tracking_details)) { $first = $trackingInfo['result']->tracking_details[0]; $current['status'] = $this->separateStatus($statues['result']->items, $first->status); $current['date'] = date('d-m-Y, H:i', strtotime($first->datetime)); $trackingInfo['current'] = $current; } else { $trackingInfo['error'] = 'error'; } return $trackingInfo; } public function trackingHistory($track) { $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); $trackingInfo = $inpostapi->getTracking($track); $statues = $inpostapi->getStatuses(); if (!empty($trackingInfo['result']->tracking_details)) { foreach ($trackingInfo['result']->tracking_details as &$td) { $td->statusPL = $this->separateStatus($statues['result']->items, $td->status); $td->date = date('d-m-Y, H:i', strtotime($td->datetime)); } } else { $trackingInfo['error'] = 'error'; } return $trackingInfo; } private function separateStatus($statuses, $state) { $return = array(); if (is_array($statuses)) { foreach ($statuses as $s) { if ($s->name == trim($state)) { $return['title'] = $s->title; $return['description'] = $s->description; return $return; } } } return $return; } public function hookDisplayAdminOrderTabShip() { if ($this->isActiveModule()) { $ioa = Configuration::get('INPOSTSHIP_ORDER_ADD'); if ($ioa == 1) { return; } $output = ''; $id_order = (int)Tools::getValue('id_order'); $this->context->smarty->assign(array( 'packCount' => count(InpostPack::getOrderPackageList((int)$id_order)) )); if (_PS_VERSION_ >= '1.7.7.0') { $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/_order/tab_177.tpl'); } else { $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/tab.tpl'); } return $output; } } public function hookDisplayAdminOrderTabLink() { return $this->hookDisplayAdminOrderTabShip(); } public function hookDisplayAdminOrderTabContent($params) { return $this->hookDisplayAdminOrderContentShip($params); } public function hookDisplayAdminOrderContentShip($params) { if ($this->isActiveModule()) { $ioa = Configuration::get('INPOSTSHIP_ORDER_ADD'); if ($ioa == 1) { return; } $output = ''; $this->InpostProcess(); $id_order = (int)Tools::getValue('id_order'); $order = new Order($id_order); $id_cart = $order->id_cart; $customer = new Customer($order->id_customer); $address_delivery = new Address($order->id_address_delivery); if (!empty($address_delivery)) { $address_delivery->phone_mobile = InpostTools::setPhoneNumber(trim(str_replace('+48', '', $address_delivery->phone_mobile))); $address_delivery->phones = !empty($address_delivery->phone) ? trim(str_replace('+48', '', $address_delivery->phone)) : trim(str_replace('+48', '', $address_delivery->phone_mobile)); $address_delivery->phones = InpostTools::setPhoneNumber(str_replace(' ', '', $address_delivery->phones)); } $x13allegro = Configuration::get('INPOSTSHIP_INTEGRATION_X13ALLEGRO'); $rec_mach = ''; $package = InpostPack::getInpostShipCart((int)$id_cart); $x13oinfo = null; if (!empty($package)) { $rec_mach = $package['receiver_machine']; $id_carrier = (int)$package['id_carrier']; if ($id_carrier != $order->id_carrier) { $id_carrier = (int)$order->id_carrier; } $current_pack = new Carrier((int)$id_carrier, (int)$this->context->cookie->id_lang); } else { $x13version = '6.2.1'; $x13allegroModule = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'module` WHERE `name` = "x13allegro"'); $current_pack = new Carrier((int)$order->id_carrier, (int)$this->context->cookie->id_lang); if ($x13allegro) { if ($x13allegroModule['version'] < $x13version) { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'xallegro_form` WHERE `id_order` = ' . (int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = unserialize(base64_decode($x13orderInfo['content'])); $rec_mach = $x13oinfo->postBuyFormGdAddress->postBuyFormAdrId; } } else { $x13orderInfo = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'xallegro_order` WHERE `id_order` = ' . (int)$order->id); if (!empty($x13orderInfo)) { $x13oinfo = json_decode($x13orderInfo['checkout_form_content']); $rec_mach = $x13oinfo->delivery->pickupPoint->id; } } } } $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX')); $point = $inpostapi->getPointInfo($rec_mach); $pop_point = InpostPoint::getPopPointsAll(); $pok_point = InpostPoint::getPointOfType('pok'); $c1 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_1')); $c1i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1'); $c2 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_2')); $c2i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2'); $c3 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_3')); $c3i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3'); $c4 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_4')); $c4i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4'); $c5 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_5')); $c6 = unserialize(Configuration::get('INPOSTSHIP_CARRIER_6')); $packageList = InpostPack::getOrderPackageList((int)$id_order); if (!empty($packageList)) { foreach ($packageList as &$pl) { $ord = new Order($pl['id_order']); $id_cart = (int)$ord->id_cart; $inpost_cart = InpostPack::getInpostShipCart((int)$id_cart); $pl['image'] = ''; $id_carrier2 = (int)$inpost_cart['id_carrier']; if ($id_carrier2 != $ord->id_carrier) { $id_carrier2 = (int)$order->id_carrier; } $carrier2 = new Carrier((int)$id_carrier2); $cref2 = $carrier2->id; if ($c1i == 1) { if (in_array($cref2, $c1)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } } if ($c2i == 1) { if (in_array($cref2, $c2)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } } if ($c3i == 1) { if (in_array($cref2, $c3)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; } } if ($c4i == 1) { if (in_array($cref2, $c4)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; } } if (in_array($cref2, $c5)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } if (in_array($cref2, $c6)) { $image2 = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; } $pl['image'] = $image2; $dispatch = 0; if ($pl['sendtype'] == 'dispatch_order') { $dispatch = 1; } $pl['dispatch'] = $dispatch; $ship_info = array(); if ($pl['status'] != 'confirmed') { $ship_info = $inpostapi->getShipments($pl['packcode']); $ship_info = (array)$ship_info['result']; } $pl['ship_info'] = $ship_info; if ((int)$pl['dispatch_id'] > 0) { $dispatch_info = $inpostapi->getDispatchInfo((int)$pl['dispatch_id']); if (!empty($dispatch_info['error'])) { $sxerror = new InpostError(); if ($this->debug == 1) { echo "
";
                                print_r($dispatch_info);
                                echo "
"; } $this->context->smarty->assign(array( 'errors' => $sxerror->displayErrors($dispatch_info) )); } else { $status = $dispatch_info['result']->status; $pl['dispatch_status'] = InpostDispatch::getDispatchStatus($status); $pl['dispatch_status_org'] = $status; } } } } $cref = $current_pack->id; $image = ''; $service = 0; $inpostCod = 0; $serviceName = ''; $paczk = 0; $addressAllegro = array(); $x13transactionId = $x13allegroUserId = null; if ($x13allegro && !empty($x13oinfo)) { $service = 3; if ($x13allegroModule['version'] < $x13version) { $allegroService = $x13oinfo->postBuyFormShipmentId; } else { $allegroService = $x13oinfo->delivery->method->id; } switch ($allegroService) { case 10023: $serviceName = 'Allegro Paczkomaty 24/7 InPost'; $paczk = 1; break; case 10022: $serviceName = 'Paczkomaty 24/7'; $paczk = 1; break; case 18: $serviceName = 'Allegro Kurier24 InPost pobranie '; break; case 34: $serviceName = 'Kurier InPost pobranie '; break; case '2488f7b7-5d1c-4d65-b85c-4cbcf253fd93': $serviceName = 'Allegro Paczkomaty 24/7 InPost'; $paczk = 1; break; case 'b20ef9e1-faa2-4f25-9032-adbea23e5cb9': $serviceName = 'Allegro Paczkomaty 24/7 InPost pobranie'; $paczk = 1; $inpostCod = 1; break; case '85c3ad2f-4ec1-446c-866e-63473ed10e26': $serviceName = 'Allegro Kurier24 InPost pobranie'; $inpostCod = 1; break; case '98f86f81-0018-41c5-ac83-073a56fc7021': $serviceName = 'Allegro miniKurier24 InPost pobranie'; $inpostCod = 1; break; case '999f8753-6340-48a0-8eba-46096f9749aa': $serviceName = 'Kurier InPost pobranie'; $inpostCod = 1; break; case '2653ca13-67c8-48c3-bbf8-ff9aa3f70ed3': $serviceName = 'Paczkomaty 24/7 pobranie'; $paczk = 1; $inpostCod = 1; break; case '685d8b40-2571-4111-8937-9220b1710d4c': $serviceName = 'Paczkomaty 24/7 '; $paczk = 1; break; case '9081532b-5ad3-467d-80bc-9252982e9dd8': $serviceName = 'Allegro miniKurier24 InPost'; $service = 4; $paczk = 0; break; } if ($x13allegroModule['version'] < $x13version) { $x13transactionId = $x13oinfo->postBuyFormId; $x13allegroUserId = $x13oinfo->postBuyFormBuyerId; } else { $x13transactionId = $x13oinfo->id; $x13allegroUserId = $x13oinfo->buyer->id; $addressAllegro = $x13oinfo->delivery->address; } } else { if ($c1i == 1) { if (in_array($cref, $c1)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 1; } } if ($c2i == 1) { if (in_array($cref, $c2)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 1; $inpostCod = 1; } } if ($c3i == 1) { if (in_array($cref, $c3)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; $service = 2; } } if ($c4i == 1) { if (in_array($cref, $c4)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg'; $service = 2; $inpostCod = 1; } } if (in_array($cref, $c5)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 5; $week = 1; } if (in_array($cref, $c6)) { $image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg'; $service = 6; $inpostCod = 1; $week = 1; } } $sendingMethods = $inpostapi->getSendingMethods(); $point2 = $inpostapi->getPointInfo(Configuration::get('INPOSTSHIP_SENDER_MACHINE')); $orderCarrier2 = new Carrier((int)$order->id_carrier); $orderCarrier = $orderCarrier2->id; $inpostCarrier = []; if (!empty($c1)) { $inpostCarrier = $c1; } if (!empty($c2)) { $inpostCarrier = array_merge($inpostCarrier, $c2); } if (!empty($c3)) { $inpostCarrier = array_merge($inpostCarrier, $c3); } if (!empty($c4)) { $inpostCarrier = array_merge($inpostCarrier, $c4); } if (!empty($c5)) { $inpostCarrier = array_merge($inpostCarrier, $c5); } if (!empty($c6)) { $inpostCarrier = array_merge($inpostCarrier, $c6); } $active = false; if (Configuration::get('INPOSTSHIP_SHOW_SFI') == 1) { $active = true; } if (in_array($orderCarrier, $inpostCarrier)) { $active = true; } $scv = false; if (Configuration::get('INPOSTSHIP_SHOW_COD_VALUE') == 1) { $scv = true; } if ($c2i == 1 || $c4i == 1) { if ($orderCarrier == $c2 || $orderCarrier == $c4) { $scv = true; } } $orderWeight = $order->getTotalWeight(); if ($orderWeight == 0) { $orderWeight = Configuration::get('INPOSTSHIP_PACKAGE_WEIGHT'); } $showWeek = 0; if (Configuration::get('INPOSTSHIP_WEEKPACK') == 1) { $datWeek = date('w'); $startWeek = 2; $endWeek = 6; $hourWeek = date('H:i'); $startHour = '8:00'; $endHour = '13:00'; if ($datWeek > $startWeek && $datWeek < $endWeek) { $showWeek = 1; } else if ($datWeek > $startWeek && $datWeek == $endWeek) { if ($hourWeek <= $endHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek < $endWeek) { if ($hourWeek >= $startHour) { $showWeek = 1; } } else if ($datWeek == $startWeek && $datWeek == $endWeek) { if ($hourWeek >= $startHour && $hourWeek <= $endHour) { $showWeek = 1; } } } $identity = $order->reference; $ident = Configuration::get('INPOSTSHIP_ORDER_NUMBER'); if ($ident == 1) { $identity = $order->id; } $addr = array(); $addr['postcode'] = $address_delivery->postcode; $strrets = $address_delivery->address1.(!empty($address_delivery->address2) ? ' '.$address_delivery->address2 : ''); $street = str_replace('ul. ', '', $strrets); $street = str_replace(',', '', $street); $addr['street'] = InpostTools::split_street($street); if (!InpostValidate::isPolandPostCode($address_delivery->postcode)) { $addr['postcode'] = InpostTools::setPolandPostCode($address_delivery->postcode); } $addr['city'] = $address_delivery->city; $this->context->smarty->assign(array( 'order' => $order, 'orderWeight' => $orderWeight, 'cart_id' => $order->id_cart, 'customer' => $customer, 'address_delivery' => $address_delivery, 'point' => $point, 'point2' => $point2, 'packtype' => $inpostapi->locker, 'insurance' => $inpostapi->insurance, 'packtype_default' => Configuration::get('INPOSTSHIP_PACK_SIZE'), 'dispatch' => Configuration::get('INPOSTSHIP_DISPATCH'), 'pop_points' => $pop_point, 'pok_points' => $pok_point, 'packageList' => $packageList, 'image' => $image, 'sendingMethods' => $sendingMethods['result']->items, 'service' => $service, 'inpostCod' => $inpostCod, 'ssbi' => Configuration::get('INPOSTSHIP_SHOW_SFI'), 'active' => $active, 'scv' => $scv, 'selPopPoint' => Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP'), 'serviceName' => $serviceName, 'paczk' => $paczk, 'x13transactionId' => $x13transactionId, 'x13allegroUserId' => $x13allegroUserId, 'price' => $this->price, 'ipi' => Configuration::get('INPOSTSHIP_PACKAGE_INSURANCE'), 'addressAllegro' => $addressAllegro, 'weekPack' => $package['week'], 'showWeek' => $showWeek, 'identity' => $identity, 'addr' => $addr )); if (_PS_VERSION_ >= '1.7.7.0') { $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/_order/tab_content_177.tpl'); } else { $output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/tab_content.tpl'); } return $output; } } public function trackPackInfo() { $allPack = InpostPack::getAllNotDeliveredPackageList(); if ($this->debug) { $allPack = InpostPack::getAllNotDeliveredPackageList(true); } if (!empty($allPack)) { $shipx = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $closeOrder = (int)Configuration::get('INPOSTSHIP_TRACKING_SETEND'); $close_state = 'delivered'; // Configuration::get('INPOSTSHIP_TRACKING_END'); foreach ($allPack as $item) { if (!empty($item['reference_number'])) { $statuePack = InpostTracking::getAllPackStates($item['id_pack']); $status = $shipx->getTracking($item['reference_number']); if ($this->debug) { print_r($statuePack); print_r($status); } if (empty($status['error'])) { $packStates = $status['result']->tracking_details; if (!empty($packStates)) { if (!empty($statuePack)) { $is_statue = array(); foreach ($statuePack as $sPack) { $is_statue[] = $sPack['state']; } if ($this->debug) { print_r($is_statue); } foreach ($packStates as $pState) { if (!in_array($pState->status, $is_statue)) { InpostTracking::addState((int)$item['id_pack'], $pState->status, $pState->datetime); if ($closeOrder == 1) { if ($pState->status == $close_state) { $history = new OrderHistory(); $history->id_order = (int)$item['id_order']; $history->changeIdOrderState((int)Configuration::get('INPOSTSHIP_TRACKING_STATUS'), (int)$item['id_order']); $history->addWithemail(true, array()); } } } } InpostPack::setCurrentStatePack((int)$item['id_pack'], $packStates[0]->status); } else { foreach ($packStates as $pState) { InpostTracking::addState((int)$item['id_pack'], $pState->status, $pState->datetime); if ($closeOrder == 1) { if ($pState->status == $close_state) { $history = new OrderHistory(); $history->id_order = (int)$item['id_order']; $history->changeIdOrderState((int)Configuration::get('INPOSTSHIP_TRACKING_STATUS'), (int)$item['id_order']); $history->addWithemail(true, array()); } } } InpostPack::setCurrentStatePack((int)$item['id_pack'], $packStates[0]->status); } } else { Db::getInstance()->update('inpostship', array( 'statue' => '--' ), 'id_pack = '.(int)$item['id_pack']); } } else { Db::getInstance()->update('inpostship', array( 'statue' => '--' ), 'id_pack = '.(int)$item['id_pack']); } } else { Db::getInstance()->update('inpostship', array( 'statue' => '--' ), 'id_pack = '.(int)$item['id_pack']); } } } } private function GetHeaders($response) { $headers = []; $xx = explode("\r\n\r\n", $response); foreach($xx as $i => $line) { if($i == 1) { $headers['http_code'] = $line; } else { $xxx2 = nl2br($line); $xxx = explode('
', $xxx2); if (!empty($xxx)) { foreach ($xxx as $x) { $hd = explode(':', $x); if (count($hd) > 1) { $headers[trim($hd[0])] = $hd[1]; if (trim($hd[0]) == 'Content-Disposition') { $file2 = explode('=', $hd[1]); $file = str_replace('"', '', $file2[1]); $headers['file'] = $file; $ext2 = explode('.', $file); $ext = $ext2[1]; switch ($ext2[1]) { case 'zip': $ext = 'zip'; break; case 'pdf': $ext = 'pdf'; break; } $headers['file_type'] = $ext; } } else { $headers['file'] = ''; $headers['file_type'] = ''; } } } $headers['head'] = $line; } } return $headers; } public function printLabel($label_id) { if ($label_id > 0) { $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $pack = InpostPack::getInpostShipByIdPack((int)$label_id); $format = Configuration::get('INPOSTSHIP_PRINT_FORMAT'); $inpost = $inpostapi->getLabel($pack['packcode'], $format, Configuration::get('INPOSTSHIP_PRINT_TYPE')); $file_name = $pack['reference_number']; // ob_end_clean(); // ob_start(); if ($format == 'PDF') { $file_type = 'pdf'; header('Content-Type: application/pdf'); } else { $file_type = 'epl'; header('Content-Type: application/octet-stream'); } header("Content-Disposition: attachment; filename=\"$file_name.$file_type\""); exit($inpost); } } public function getUserPoints($cod = 0) { $return = array(); if (isset($this->context->customer)) { $id_cart = (int)$this->context->cookie->id_cart; $cart = new Cart($id_cart); $id_address = $cart->id_address_delivery; $address = new Address($id_address); $urlAddress = $address->address1.' '.$address->postcode;//.' '.$address->city; $urlAddress = str_replace(' ', '+', $urlAddress); $url = 'https://nominatim.openstreetmap.org/?format=json&addressdetails=1&q='.$urlAddress.'&format=json&limit=1'; $return['address'] = $urlAddress; $return['url'] = $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0')); $result = curl_exec($ch); $resp = json_decode($result); $return['resp'] = $resp; $lat = $resp[0]->lat; $lon = $resp[0]->lon; $npc = (int)Configuration::get('INPOSTSHIP_POINT_COUNT', null, null, null, 6); $rnp = (int)Configuration::get('INPOSTSHIP_POINT_RADIUS', null, null, null, 10); $return['search']['lat'] = $lat; $return['search']['lon'] = $lon; $return['search']['npc'] = $npc; $return['search']['rnp1000'] = $rnp*1000; $return['search']['rnp'] = $rnp; $inpostapi = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug); $pointsNear = $inpostapi->getPointsNearAddress($lat, $lon, $npc, $rnp*1000, $cod); $points = array(); if (!empty($pointsNear)) { foreach ($pointsNear as $key => $item) { $points[$key]['name'] = $item->name; $points[$key]['desc'] = $item->location_description; $points[$key]['address'] = $item->address->line1.' '.$item->address->line2; } } $return['points'] = $points; } echo json_encode($return); exit(); } public function hookActionCartSave($params) { $id_customer = $params['cart']->id_customer; $id_cart = $params['cart']->id; $issetPoint = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'inpostship_user_point` WHERE `id_customer` = '.(int)$id_customer); if (!empty($issetPoint)) { if ($id_cart > 0) { $issetCart = InpostPack::issetCart((int)$id_cart); if (empty($issetCart)) { InpostPack::setInpostShip((int)$id_cart, $issetPoint['point'], 0, 0, (int)$this->context->cookie->id_lang); } } } } }