update
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandCarrierPudoService Responsible for specific DPD service (carrier) management
|
||||
*/
|
||||
class DpdPolandCarrierPudoService extends DpdPolandService
|
||||
{
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'dpd_pudo.service';
|
||||
|
||||
/**
|
||||
* Installs specific DPD service (carrier)
|
||||
*
|
||||
* @return bool Carrier installed successfully
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
$id_carrier = (int)Configuration::get(DpdPolandConfiguration::CARRIER_PUDO_ID, null, $id_shop_group, $id_shop);
|
||||
$carrier = self::getCarrierByReference((int)$id_carrier);
|
||||
|
||||
if ($id_carrier && Validate::isLoadedObject($carrier))
|
||||
if (!$carrier->deleted)
|
||||
return true;
|
||||
else {
|
||||
$carrier->deleted = 0;
|
||||
return (bool)$carrier->save();
|
||||
}
|
||||
|
||||
$carrier_pudo = new DpdPolandCarrierPudoService();
|
||||
|
||||
$carrier = new Carrier();
|
||||
$carrier->name = $carrier_pudo->module_instance->l('DPD Poland Reception Point Pickup', self::FILENAME);
|
||||
$carrier->active = 1;
|
||||
$carrier->is_free = 0;
|
||||
$carrier->shipping_handling = 1;
|
||||
$carrier->shipping_external = 1;
|
||||
$carrier->shipping_method = 1;
|
||||
$carrier->max_width = 0;
|
||||
$carrier->max_height = 0;
|
||||
$carrier->max_depth = 0;
|
||||
$carrier->max_weight = 0;
|
||||
$carrier->grade = 0;
|
||||
$carrier->is_module = 1;
|
||||
$carrier->need_range = 1;
|
||||
$carrier->range_behavior = 1;
|
||||
$carrier->external_module_name = $carrier_pudo->module_instance->name;
|
||||
$carrier->url = _DPDPOLAND_TRACKING_URL_;
|
||||
|
||||
$delay = array();
|
||||
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$delay[$language['id_lang']] = $carrier_pudo->module_instance->l('DPD Poland Reception Point Pickup', self::FILENAME);
|
||||
|
||||
$carrier->delay = $delay;
|
||||
|
||||
if (!$carrier->save())
|
||||
return false;
|
||||
|
||||
$dpdpoland_carrier = new DpdPolandCarrier();
|
||||
$dpdpoland_carrier->id_carrier = (int)$carrier->id;
|
||||
$dpdpoland_carrier->id_reference = (int)$carrier->id;
|
||||
|
||||
if (!$dpdpoland_carrier->save())
|
||||
return false;
|
||||
|
||||
if (!copy(_DPDPOLAND_IMG_DIR_ . DpdPolandCarrierPudoService::IMG_DIR . '/' . _DPDPOLAND_PUDO_ID_ . '.' .
|
||||
DpdPolandCarrierPudoService::IMG_EXTENSION, _PS_SHIP_IMG_DIR_ . '/' . (int)$carrier->id . '.jpg'))
|
||||
return false;
|
||||
|
||||
$zones = Zone::getZones(false);
|
||||
foreach ($zones as $zone)
|
||||
$carrier->addZone((int)$zone["id_zone"]);
|
||||
|
||||
if (!$range_obj = $carrier->getRangeObject())
|
||||
return false;
|
||||
|
||||
$range_obj->id_carrier = (int)$carrier->id;
|
||||
$range_obj->delimiter1 = 0;
|
||||
$range_obj->delimiter2 = 1;
|
||||
|
||||
if (!$range_obj->add())
|
||||
return false;
|
||||
|
||||
if (!self::assignCustomerGroupsForCarrier($carrier))
|
||||
return false;
|
||||
|
||||
if (!Configuration::updateValue(DpdPolandConfiguration::CARRIER_PUDO_ID, (int)$carrier->id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes DPD carrier
|
||||
*
|
||||
* @return bool DPD carrier deleted successfully
|
||||
*/
|
||||
public static function delete()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
return (bool)self::deleteCarrier((int)Configuration::get(DpdPolandConfiguration::CARRIER_PUDO_ID, null, $id_shop_group, $id_shop));
|
||||
}
|
||||
}
|
||||
129
modules/dpdpoland/controllers/dpd_standard.service.php
Normal file
129
modules/dpdpoland/controllers/dpd_standard.service.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandCarrierStandardService Responsible for specific DPD service (carrier) management
|
||||
*/
|
||||
class DpdPolandCarrierStandardService extends DpdPolandService
|
||||
{
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'dpd_standard.service';
|
||||
|
||||
/**
|
||||
* Installs specific DPD service (carrier)
|
||||
*
|
||||
* @return bool Carrier installed successfully
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
$id_carrier = (int)Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_ID, null, $id_shop_group, $id_shop);
|
||||
$carrier = self::getCarrierByReference((int)$id_carrier);
|
||||
|
||||
if ($id_carrier && Validate::isLoadedObject($carrier))
|
||||
if (!$carrier->deleted)
|
||||
return true;
|
||||
else {
|
||||
$carrier->deleted = 0;
|
||||
return (bool)$carrier->save();
|
||||
}
|
||||
|
||||
$carrier_standard = new DpdPolandCarrierStandardService();
|
||||
|
||||
$carrier = new Carrier();
|
||||
$carrier->name = $carrier_standard->module_instance->l('DPD domestic shipment - Standard', self::FILENAME);
|
||||
$carrier->active = 1;
|
||||
$carrier->is_free = 0;
|
||||
$carrier->shipping_handling = 1;
|
||||
$carrier->shipping_external = 1;
|
||||
$carrier->shipping_method = 1;
|
||||
$carrier->max_width = 0;
|
||||
$carrier->max_height = 0;
|
||||
$carrier->max_depth = 0;
|
||||
$carrier->max_weight = 0;
|
||||
$carrier->grade = 0;
|
||||
$carrier->is_module = 1;
|
||||
$carrier->need_range = 1;
|
||||
$carrier->range_behavior = 1;
|
||||
$carrier->external_module_name = $carrier_standard->module_instance->name;
|
||||
$carrier->url = _DPDPOLAND_TRACKING_URL_;
|
||||
|
||||
$delay = array();
|
||||
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$delay[$language['id_lang']] = $carrier_standard->module_instance->l('DPD domestic shipment - Standard', self::FILENAME);
|
||||
|
||||
$carrier->delay = $delay;
|
||||
|
||||
if (!$carrier->save())
|
||||
return false;
|
||||
$carrier = self::getCarrierByReference((int)$carrier->id);
|
||||
$dpdpoland_carrier = new DpdPolandCarrier();
|
||||
$dpdpoland_carrier->id_carrier = (int)$carrier->id;
|
||||
$dpdpoland_carrier->id_reference = (int)$carrier->id;
|
||||
|
||||
if (!$dpdpoland_carrier->save())
|
||||
return false;
|
||||
|
||||
if (!copy(_DPDPOLAND_IMG_DIR_ . DpdPolandCarrierStandardService::IMG_DIR . '/' . _DPDPOLAND_STANDARD_ID_ . '.' .
|
||||
DpdPolandCarrierStandardService::IMG_EXTENSION, _PS_SHIP_IMG_DIR_ . '/' . (int)$carrier->id . '.jpg'))
|
||||
return false;
|
||||
|
||||
$zones = Zone::getZones(false);
|
||||
foreach ($zones as $zone)
|
||||
$carrier->addZone((int)$zone["id_zone"]);
|
||||
|
||||
if (!$range_obj = $carrier->getRangeObject())
|
||||
return false;
|
||||
|
||||
$range_obj->id_carrier = (int)$carrier->id;
|
||||
$range_obj->delimiter1 = 0;
|
||||
$range_obj->delimiter2 = 1;
|
||||
|
||||
if (!$range_obj->add())
|
||||
return false;
|
||||
|
||||
if (!self::assignCustomerGroupsForCarrier($carrier))
|
||||
return false;
|
||||
|
||||
if (!Configuration::updateValue(DpdPolandConfiguration::CARRIER_STANDARD_ID, (int)$carrier->id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes DPD carrier
|
||||
*
|
||||
* @return bool DPD carrier deleted successfully
|
||||
*/
|
||||
public static function delete()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
return (bool)self::deleteCarrier((int)Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_ID, null, $id_shop_group, $id_shop));
|
||||
}
|
||||
}
|
||||
129
modules/dpdpoland/controllers/dpd_standard_cod.service.php
Normal file
129
modules/dpdpoland/controllers/dpd_standard_cod.service.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandCarrierStandardCODService Responsible for specific DPD service (carrier) management
|
||||
*/
|
||||
class DpdPolandCarrierStandardCODService extends DpdPolandService
|
||||
{
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'dpd_standard_cod.service';
|
||||
|
||||
/**
|
||||
* Installs specific DPD service (carrier)
|
||||
*
|
||||
* @return bool Carrier installed successfully
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
$id_carrier = (int)Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_COD_ID, null, $id_shop_group, $id_shop);
|
||||
$carrier = self::getCarrierByReference((int)$id_carrier);
|
||||
|
||||
if ($id_carrier && Validate::isLoadedObject($carrier))
|
||||
if (!$carrier->deleted)
|
||||
return true;
|
||||
else {
|
||||
$carrier->deleted = 0;
|
||||
return (bool)$carrier->save();
|
||||
}
|
||||
|
||||
$carrier_standard_cod = new DpdPolandCarrierStandardCODService();
|
||||
|
||||
$carrier = new Carrier();
|
||||
$carrier->name = $carrier_standard_cod->module_instance->l('DPD domestic shipment - Standard with COD', self::FILENAME);
|
||||
$carrier->active = 1;
|
||||
$carrier->is_free = 0;
|
||||
$carrier->shipping_handling = 1;
|
||||
$carrier->shipping_external = 1;
|
||||
$carrier->shipping_method = 1;
|
||||
$carrier->max_width = 0;
|
||||
$carrier->max_height = 0;
|
||||
$carrier->max_depth = 0;
|
||||
$carrier->max_weight = 0;
|
||||
$carrier->grade = 0;
|
||||
$carrier->is_module = 1;
|
||||
$carrier->need_range = 1;
|
||||
$carrier->range_behavior = 1;
|
||||
$carrier->external_module_name = $carrier_standard_cod->module_instance->name;
|
||||
$carrier->url = _DPDPOLAND_TRACKING_URL_;
|
||||
|
||||
$delay = array();
|
||||
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$delay[$language['id_lang']] = $carrier_standard_cod->module_instance->l('DPD domestic shipment - Standard with COD', self::FILENAME);
|
||||
|
||||
$carrier->delay = $delay;
|
||||
|
||||
if (!$carrier->save())
|
||||
return false;
|
||||
|
||||
$dpdpoland_carrier = new DpdPolandCarrier();
|
||||
$dpdpoland_carrier->id_carrier = (int)$carrier->id;
|
||||
$dpdpoland_carrier->id_reference = (int)$carrier->id;
|
||||
|
||||
if (!$dpdpoland_carrier->save())
|
||||
return false;
|
||||
|
||||
if (!copy(_DPDPOLAND_IMG_DIR_ . DpdPolandCarrierStandardCODService::IMG_DIR . '/' . _DPDPOLAND_STANDARD_COD_ID_ . '.' .
|
||||
DpdPolandCarrierStandardCODService::IMG_EXTENSION, _PS_SHIP_IMG_DIR_ . '/' . (int)$carrier->id . '.jpg'))
|
||||
return false;
|
||||
|
||||
$zones = Zone::getZones(false);
|
||||
foreach ($zones as $zone)
|
||||
$carrier->addZone((int)$zone["id_zone"]);
|
||||
|
||||
if (!$range_obj = $carrier->getRangeObject())
|
||||
return false;
|
||||
|
||||
$range_obj->id_carrier = (int)$carrier->id;
|
||||
$range_obj->delimiter1 = 0;
|
||||
$range_obj->delimiter2 = 1;
|
||||
|
||||
if (!$range_obj->add())
|
||||
return false;
|
||||
|
||||
if (!self::assignCustomerGroupsForCarrier($carrier))
|
||||
return false;
|
||||
|
||||
if (!Configuration::updateValue(DpdPolandConfiguration::CARRIER_STANDARD_COD_ID, (int)$carrier->id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes DPD carrier
|
||||
*
|
||||
* @return bool DPD carrier deleted successfully
|
||||
*/
|
||||
public static function delete()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
return (bool)self::deleteCarrier((int)Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_COD_ID, null, $id_shop_group, $id_shop));
|
||||
}
|
||||
}
|
||||
131
modules/dpdpoland/controllers/dpd_swipbox.service.php
Normal file
131
modules/dpdpoland/controllers/dpd_swipbox.service.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* 2022 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
require_once(_DPDPOLAND_CONTROLLERS_DIR_.'service.php');
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandCarrierSwipBoxService Responsible for specific DPD service (carrier) management
|
||||
*/
|
||||
class DpdPolandCarrierSwipBoxService extends DpdPolandService
|
||||
{
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'dpd_swipbox.service';
|
||||
|
||||
/**
|
||||
* Installs specific DPD service (carrier)
|
||||
*
|
||||
* @return bool Carrier installed successfully
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
$id_carrier = (int)Configuration::get(DpdPolandConfiguration::CARRIER_SWIPBOX_ID, null, $id_shop_group, $id_shop);
|
||||
$carrier = self::getCarrierByReference((int)$id_carrier);
|
||||
|
||||
if ($id_carrier && Validate::isLoadedObject($carrier))
|
||||
if (!$carrier->deleted)
|
||||
return true;
|
||||
else {
|
||||
$carrier->deleted = 0;
|
||||
return (bool)$carrier->save();
|
||||
}
|
||||
|
||||
$carrier_pudo = new DpdPolandCarrierSwipBoxService();
|
||||
|
||||
$carrier = new Carrier();
|
||||
$carrier->name = $carrier_pudo->module_instance->l('DPD Poland - Swip box', self::FILENAME);
|
||||
$carrier->active = 1;
|
||||
$carrier->is_free = 0;
|
||||
$carrier->shipping_handling = 1;
|
||||
$carrier->shipping_external = 1;
|
||||
$carrier->shipping_method = 1;
|
||||
$carrier->max_width = 0;
|
||||
$carrier->max_height = 0;
|
||||
$carrier->max_depth = 0;
|
||||
$carrier->max_weight = 0;
|
||||
$carrier->grade = 0;
|
||||
$carrier->is_module = 1;
|
||||
$carrier->need_range = 1;
|
||||
$carrier->range_behavior = 1;
|
||||
$carrier->external_module_name = $carrier_pudo->module_instance->name;
|
||||
$carrier->url = _DPDPOLAND_TRACKING_URL_;
|
||||
|
||||
$delay = array();
|
||||
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$delay[$language['id_lang']] = $carrier_pudo->module_instance->l('DPD Poland - Swip box', self::FILENAME);
|
||||
|
||||
$carrier->delay = $delay;
|
||||
|
||||
if (!$carrier->save())
|
||||
return false;
|
||||
|
||||
$dpdpoland_carrier = new DpdPolandCarrier();
|
||||
$dpdpoland_carrier->id_carrier = (int)$carrier->id;
|
||||
$dpdpoland_carrier->id_reference = (int)$carrier->id;
|
||||
|
||||
if (!$dpdpoland_carrier->save())
|
||||
return false;
|
||||
|
||||
if (!copy(_DPDPOLAND_IMG_DIR_ . DpdPolandCarrierSwipBoxService::IMG_DIR . '/' . _DPDPOLAND_SWIPBOX_ID_ . '.' .
|
||||
DpdPolandCarrierSwipBoxService::IMG_EXTENSION, _PS_SHIP_IMG_DIR_ . '/' . (int)$carrier->id . '.jpg'))
|
||||
return false;
|
||||
|
||||
$zones = Zone::getZones(false);
|
||||
foreach ($zones as $zone)
|
||||
$carrier->addZone((int)$zone["id_zone"]);
|
||||
|
||||
if (!$range_obj = $carrier->getRangeObject())
|
||||
return false;
|
||||
|
||||
$range_obj->id_carrier = (int)$carrier->id;
|
||||
$range_obj->delimiter1 = 0;
|
||||
$range_obj->delimiter2 = 1;
|
||||
|
||||
if (!$range_obj->add())
|
||||
return false;
|
||||
|
||||
if (!self::assignCustomerGroupsForCarrier($carrier))
|
||||
return false;
|
||||
|
||||
if (!Configuration::updateValue(DpdPolandConfiguration::CARRIER_SWIPBOX_ID, (int)$carrier->id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes DPD carrier
|
||||
*
|
||||
* @return bool DPD carrier deleted successfully
|
||||
*/
|
||||
public static function delete()
|
||||
{
|
||||
$id_shop = Shop::getContextShopID(true);
|
||||
$id_shop_group = Shop::getContextShopGroupID(true);
|
||||
return (bool)self::deleteCarrier((int)Configuration::get(DpdPolandConfiguration::CARRIER_SWIPBOX_ID, null, $id_shop_group, $id_shop));
|
||||
}
|
||||
}
|
||||
29
modules/dpdpoland/controllers/index.php
Normal file
29
modules/dpdpoland/controllers/index.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
167
modules/dpdpoland/controllers/manifest.webservice.php
Normal file
167
modules/dpdpoland/controllers/manifest.webservice.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandManifestWS Responsible for manifest management
|
||||
*/
|
||||
class DpdPolandManifestWS extends DpdPolandWS
|
||||
{
|
||||
/**
|
||||
* Generates manifest
|
||||
*
|
||||
* @param DpdPolandManifest $manifest Manifest object
|
||||
* @param string $output_doc_format Document format
|
||||
* @param string $output_doc_page_format Document page format
|
||||
* @param string $policy Policy type
|
||||
* @return bool
|
||||
*/
|
||||
public function generate(DpdPolandManifest $manifest, $output_doc_format, $output_doc_page_format, $policy)
|
||||
{
|
||||
$package = $manifest->getPackageInstance();
|
||||
$packages = $manifest->getPackages();
|
||||
$package_number = null;
|
||||
|
||||
foreach ($packages as $id_package_ws)
|
||||
{
|
||||
$current_package = new DpdPolandPackage((int)$id_package_ws);
|
||||
|
||||
if ($package_number === null)
|
||||
$package_number = $current_package->payerNumber;
|
||||
elseif ($package_number !== $current_package->payerNumber)
|
||||
$package_number = 'null';
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'dpdServicesParamsV1' => array(
|
||||
'pickupAddress' => $package->getSenderAddress(),
|
||||
'policy' => $policy,
|
||||
'session' => array(
|
||||
'sessionId' => (int)$package->sessionId,
|
||||
'sessionType' => $package->getSessionType()
|
||||
)
|
||||
),
|
||||
'outputDocFormatV1' => $output_doc_format,
|
||||
'outputDocPageFormatV1' => $output_doc_page_format
|
||||
);
|
||||
|
||||
if ($manifest->id_manifest_ws)
|
||||
$params['dpdServicesParamsV1']['documentId'] = (int)$manifest->id_manifest_ws;
|
||||
|
||||
$result = $this->generateProtocolV2($params);
|
||||
|
||||
if (isset($result['documentData']) ||
|
||||
(isset($result['session']) && isset($result['session']['statusInfo']) && $result['session']['statusInfo']['status'] == 'OK'))
|
||||
{
|
||||
if (!$manifest->id_manifest_ws)
|
||||
$manifest->id_manifest_ws = (int)$result['documentId'];
|
||||
|
||||
if (!$manifest->getPackageIdWsByManifestIdWs($manifest->id_manifest_ws) && !$manifest->save())
|
||||
return false;
|
||||
|
||||
return $result['documentData'];
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates multiple manifests for selected packages
|
||||
*
|
||||
* @param array $package_ids Packages IDs
|
||||
* @param string $output_doc_format Document format
|
||||
* @param string $output_doc_page_format Document page format
|
||||
* @param string $policy Policy type
|
||||
* @return bool Multiple manifests generated successfully
|
||||
*/
|
||||
public function generateMultiple($package_ids, $output_doc_format = 'PDF', $output_doc_page_format = 'LBL_PRINTER', $policy = 'STOP_ON_FIRST_ERROR')
|
||||
{
|
||||
$session_type = '';
|
||||
$package_number = null;
|
||||
|
||||
foreach ($package_ids as $id_package_ws)
|
||||
{
|
||||
$package = new DpdPolandPackage((int)$id_package_ws);
|
||||
|
||||
if (!$session_type || $session_type == $package->getSessionType())
|
||||
{
|
||||
$session_type = $package->getSessionType();
|
||||
|
||||
if ($package_number === null)
|
||||
$package_number = $package->payerNumber;
|
||||
elseif ($package_number !== $package->payerNumber)
|
||||
$package_number = 'null';
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$errors[] = $this->l('Manifests of DOMESTIC shipments cannot be mixed with INTERNATIONAL shipments');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'dpdServicesParamsV1' => array(
|
||||
'pickupAddress' => $package->getSenderAddress(),
|
||||
'policy' => $policy,
|
||||
'session' => array(
|
||||
'sessionType' => $session_type,
|
||||
'packages' => array()
|
||||
)
|
||||
),
|
||||
'outputDocFormatV1' => $output_doc_format,
|
||||
'outputDocPageFormatV1' => $output_doc_page_format
|
||||
);
|
||||
|
||||
foreach ($package_ids as $id_package_ws)
|
||||
{
|
||||
$params['dpdServicesParamsV1']['session']['packages'][] = array(
|
||||
'packageId' => (int)$id_package_ws
|
||||
);
|
||||
}
|
||||
|
||||
$result = $this->generateProtocolV2($params);
|
||||
|
||||
if (isset($result['session']) && isset($result['session']['statusInfo']) && $result['session']['statusInfo']['status'] == 'OK')
|
||||
{
|
||||
foreach ($package_ids as $id_package_ws)
|
||||
{
|
||||
$manifest = new DpdPolandManifest;
|
||||
$manifest->id_manifest_ws = (int)$result['documentId'];
|
||||
$manifest->id_package_ws = (int)$id_package_ws;
|
||||
|
||||
if (!$manifest->save())
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result['documentData'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($result['session']['statusInfo']['description']))
|
||||
self::$errors[] = $result['session']['statusInfo']['description'];
|
||||
elseif (isset($result['session']['statusInfo']['status']))
|
||||
self::$errors[] = $result['session']['statusInfo']['status'];
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
201
modules/dpdpoland/controllers/manifestList.controller.php
Normal file
201
modules/dpdpoland/controllers/manifestList.controller.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandManifestListController Responsible for manifests list view and management
|
||||
*/
|
||||
class DpdPolandManifestListController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Default list sorting type
|
||||
*/
|
||||
const DEFAULT_ORDER_BY = 'date_add';
|
||||
|
||||
/**
|
||||
* Default list sorting way
|
||||
*/
|
||||
const DEFAULT_ORDER_WAY = 'desc';
|
||||
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'manifestList.controller';
|
||||
|
||||
/**
|
||||
* Prints a single manifest
|
||||
*
|
||||
* @param int|string $id_manifest_ws Manifest ID
|
||||
* @return bool Manifest printed successfully
|
||||
*/
|
||||
public function printManifest($id_manifest_ws)
|
||||
{
|
||||
if (is_array($id_manifest_ws))
|
||||
{
|
||||
if (empty($id_manifest_ws))
|
||||
return false;
|
||||
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf') &&
|
||||
!unlink(_PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf'))
|
||||
{
|
||||
$error_message = $this->l('Could not delete old PDF file. Please check module permissions');
|
||||
$error = $this->module_instance->displayError($error_message);
|
||||
|
||||
return $this->module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
foreach ($id_manifest_ws as $id)
|
||||
{
|
||||
$manifest = new DpdPolandManifest;
|
||||
$manifest->id_manifest_ws = $id;
|
||||
|
||||
if ($pdf_file_contents = $manifest->generate())
|
||||
{
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/manifest_'.(int)$id.'.pdf') &&
|
||||
!unlink(_PS_MODULE_DIR_.'dpdpoland/manifest_'.(int)$id.'.pdf'))
|
||||
{
|
||||
$error_message = $this->l('Could not delete old PDF file. Please check module permissions');
|
||||
$error = $this->module_instance->displayError($error_message);
|
||||
return $this->module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
$fp = fopen(_PS_MODULE_DIR_.'dpdpoland/manifest_'.(int)$id.'.pdf', 'a');
|
||||
|
||||
if (!$fp)
|
||||
{
|
||||
$error_message = $this->l('Could not create PDF file. Please check module folder permissions');
|
||||
$error = $this->module_instance->displayError($error_message);
|
||||
return $this->module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
fwrite($fp, $pdf_file_contents);
|
||||
fclose($fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error_message = $this->module_instance->displayError(reset(DpdPolandManifestWS::$errors));
|
||||
return $this->module_instance->outputHTML($error_message);
|
||||
}
|
||||
}
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'dpdpoland/libraries/PDFMerger/PDFMerger.php');
|
||||
|
||||
$pdf = new PDFMerger;
|
||||
|
||||
foreach ($id_manifest_ws as $id)
|
||||
{
|
||||
$manifest_pdf_path = _PS_MODULE_DIR_.'dpdpoland/manifest_'.(int)$id.'.pdf';
|
||||
$pdf->addPDF($manifest_pdf_path, 'all');
|
||||
}
|
||||
|
||||
$pdf->merge('file', _PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf');
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-type: application/pdf');
|
||||
header('Content-Disposition: attachment; filename="manifests_'.time().'.pdf"');
|
||||
readfile(_PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf');
|
||||
$this->deletePDFFiles($id_manifest_ws);
|
||||
exit;
|
||||
}
|
||||
|
||||
$manifest = new DpdPolandManifest;
|
||||
$manifest->id_manifest_ws = $id_manifest_ws;
|
||||
|
||||
if ($pdf_file_contents = $manifest->generate())
|
||||
{
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/manifest.pdf') && !unlink(_PS_MODULE_DIR_.'dpdpoland/manifest.pdf'))
|
||||
{
|
||||
$error_message = $this->l('Could not delete old PDF file. Please check module permissions');
|
||||
$error = $this->module_instance->displayError($error_message);
|
||||
return $this->module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf') && !unlink(_PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf'))
|
||||
{
|
||||
$error_message = $this->l('Could not delete old PDF file. Please check module permissions');
|
||||
$error = $this->module_instance->displayError($error_message);
|
||||
return $this->module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
$fp = fopen(_PS_MODULE_DIR_.'dpdpoland/manifest.pdf', 'a');
|
||||
if (!$fp)
|
||||
{
|
||||
$error_message = $this->l('Could not create PDF file. Please check module folder permissions');
|
||||
$error = $this->module_instance->displayError($error_message);
|
||||
return $this->module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
fwrite($fp, $pdf_file_contents);
|
||||
fclose($fp);
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'dpdpoland/libraries/PDFMerger/PDFMerger.php');
|
||||
$pdf = new PDFMerger;
|
||||
$pdf->addPDF(_PS_MODULE_DIR_.'dpdpoland/manifest.pdf', 'all');
|
||||
$pdf->merge('file', _PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf');
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-type: application/pdf');
|
||||
header('Content-Disposition: attachment; filename="manifests_'.time().'.pdf"');
|
||||
readfile(_PS_MODULE_DIR_.'dpdpoland/manifest_duplicated.pdf');
|
||||
|
||||
$this->deletePDFFiles($id_manifest_ws);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
$this->module_instance->outputHTML($this->module_instance->displayError(reset(DpdPolandManifestWS::$errors)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes generated PDF files after merging them into a single document
|
||||
*
|
||||
* @param int|string $id_manifest_ws Manifest ID
|
||||
*/
|
||||
private function deletePDFFiles($id_manifest_ws)
|
||||
{
|
||||
$manifests = array('manifest', 'manifest_duplicated');
|
||||
|
||||
if (is_array($id_manifest_ws))
|
||||
foreach ($id_manifest_ws as $id)
|
||||
$manifests[] = 'manifest_'.(int)$id;
|
||||
else
|
||||
$manifests[] = 'manifest_'.(int)$id_manifest_ws;
|
||||
|
||||
foreach ($manifests as $manifest)
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/'.$manifest.'.pdf') && is_writable(_PS_MODULE_DIR_.'dpdpoland/'.$manifest.'.pdf'))
|
||||
unlink(_PS_MODULE_DIR_.'dpdpoland/'.$manifest.'.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays manifests list content
|
||||
*
|
||||
* @return string Manifests list content in HTML
|
||||
*/
|
||||
public function getListHTML()
|
||||
{
|
||||
$keys_array = array('id_manifest_ws', 'count_parcels', 'count_orders', 'date_add');
|
||||
$this->prepareListData($keys_array, 'Manifests', new DpdPolandManifest, self::DEFAULT_ORDER_BY, self::DEFAULT_ORDER_WAY, 'manifest_list');
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.6', '<'))
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/manifest_list.tpl');
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/manifest_list_16.tpl');
|
||||
}
|
||||
}
|
||||
116
modules/dpdpoland/controllers/messages.controller.php
Normal file
116
modules/dpdpoland/controllers/messages.controller.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class DpdPolandMessagesController Responsible for flash messages management
|
||||
*/
|
||||
class DpdPolandMessagesController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Name of success message saved in cookie
|
||||
*/
|
||||
const DPD_POLAND_SUCCESS_MESSAGE = 'dpd_poland_success_message';
|
||||
|
||||
/**
|
||||
* Name of error message saved in cookie
|
||||
*/
|
||||
const DPD_POLAND_ERROR_MESSAGE = 'dpd_poland_error_message';
|
||||
|
||||
/**
|
||||
* @var Cookie Cookie object instance
|
||||
*/
|
||||
private $cookie;
|
||||
|
||||
/**
|
||||
* DpdPolandMessagesController class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->cookie = new Cookie(_DPDPOLAND_COOKIE_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves success message into Cookie
|
||||
*
|
||||
* @param string $message Success message text
|
||||
*/
|
||||
public function setSuccessMessage($message)
|
||||
{
|
||||
if (!is_array($message))
|
||||
$this->cookie->{self::DPD_POLAND_SUCCESS_MESSAGE} = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves error message into Cookie
|
||||
*
|
||||
* @param string $message Error message text
|
||||
*/
|
||||
public function setErrorMessage($message)
|
||||
{
|
||||
$old_message = $this->cookie->{self::DPD_POLAND_ERROR_MESSAGE};
|
||||
if ($old_message && Validate::isSerializedArray($old_message))
|
||||
{
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
$old_message = unserialize($old_message);
|
||||
else
|
||||
$old_message = Tools::unSerialize($old_message);
|
||||
$message = array_merge($message, $old_message);
|
||||
}
|
||||
|
||||
if (is_array($message))
|
||||
$this->context->cookie->{self::DPD_POLAND_ERROR_MESSAGE} = serialize($message);
|
||||
else
|
||||
$this->cookie->{self::DPD_POLAND_ERROR_MESSAGE} = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and returns success message
|
||||
* Removes success message from Cookie
|
||||
*
|
||||
* @return string Success message
|
||||
*/
|
||||
public function getSuccessMessage()
|
||||
{
|
||||
$message = $this->cookie->{self::DPD_POLAND_SUCCESS_MESSAGE};
|
||||
$this->cookie->__unset(self::DPD_POLAND_SUCCESS_MESSAGE);
|
||||
return $message ? $message : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and returns error message
|
||||
* Removes error message from Cookie
|
||||
*
|
||||
* @return array|string Error message(s)
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
$message = $this->cookie->{self::DPD_POLAND_ERROR_MESSAGE};
|
||||
if (Validate::isSerializedArray($message))
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
$message = unserialize($message);
|
||||
else
|
||||
$message = Tools::unSerialize($message);
|
||||
$this->cookie->__unset(self::DPD_POLAND_ERROR_MESSAGE);
|
||||
if (is_array($message))
|
||||
return array_unique($message);
|
||||
return $message ? array($message) : '';
|
||||
}
|
||||
}
|
||||
538
modules/dpdpoland/controllers/package.webservice.php
Normal file
538
modules/dpdpoland/controllers/package.webservice.php
Normal file
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandPackageWS Responsible for management via WebServices
|
||||
*/
|
||||
class DpdPolandPackageWS extends DpdPolandWS
|
||||
{
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'Package';
|
||||
|
||||
/**
|
||||
* @var array Sender data used for WebServices
|
||||
*/
|
||||
private $sender = array();
|
||||
|
||||
|
||||
/**
|
||||
* Collects error messages from WebServices
|
||||
*
|
||||
* @param array $response Response from WebServices
|
||||
* @param string $error_key Error code
|
||||
* @param array $errors Collected errors
|
||||
* @return array Error messages
|
||||
*/
|
||||
private function getErrorsByKey($response, $error_key, $errors = array())
|
||||
{
|
||||
if (!empty($response))
|
||||
foreach ($response as $key => $value)
|
||||
if (is_object($value) || is_array($value))
|
||||
$errors = $this->getErrorsByKey($value, $error_key, $errors);
|
||||
elseif ($key == $error_key)
|
||||
$errors[] = $value;
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates package
|
||||
*
|
||||
* @param array $package_obj Package object
|
||||
* @return bool Package created successfully
|
||||
*/
|
||||
public function create($package_obj, $payerNumber)
|
||||
{
|
||||
if ($result = $this->createRemotely($package_obj, 'THIRD_PARTY', $payerNumber)) {
|
||||
if (isset($result['Status']) && $result['Status'] == 'OK') {
|
||||
$packages = $result['Packages']['Package'];
|
||||
|
||||
$isMultiShipping = !isset($result['Packages']['Package']['PackageId']);
|
||||
if ($isMultiShipping) {
|
||||
foreach ($packages as $key => $package) {
|
||||
$package_obj[$key]->id_package_ws = (int)$package['PackageId'];
|
||||
$package_obj[$key]->sessionId = (int)$result['SessionId'];
|
||||
|
||||
if (!$package_obj[$key]->save())
|
||||
self::$errors[] = $this->l('Package was successfully created but we were unable to save its data locally');
|
||||
}
|
||||
} else {
|
||||
$package_obj[0]->id_package_ws = (int)$result['Packages']['Package']['PackageId'];
|
||||
$package_obj[0]->sessionId = (int)$result['SessionId'];
|
||||
|
||||
if (!$package_obj[0]->save())
|
||||
self::$errors[] = $this->l('Package was successfully created but we were unable to save its data locally');
|
||||
}
|
||||
return $packages;
|
||||
} else {
|
||||
if (isset($result['Packages']['InvalidFields']))
|
||||
$errors = $result['Packages']['InvalidFields'];
|
||||
elseif (isset($result['Packages']['Package']['ValidationDetails']))
|
||||
$errors = $result['Packages']['Package']['ValidationDetails'];
|
||||
elseif (isset($result['faultcode']) && isset($result['faultstring']))
|
||||
$errors = $result['faultcode'] . ' : ' . $result['faultstring'];
|
||||
else {
|
||||
$errors = array();
|
||||
|
||||
if ($error_ids = $this->getErrorsByKey($result, 'ErrorId')) {
|
||||
$language = new DpdPolandLanguage();
|
||||
|
||||
foreach ($error_ids as $id_error)
|
||||
$errors[] = $language->getTranslation($id_error);
|
||||
} elseif ($error_messages = $this->getErrorsByKey($result, 'Info')) {
|
||||
foreach ($error_messages as $message)
|
||||
$errors[] = $message;
|
||||
}
|
||||
|
||||
$errors = reset($errors);
|
||||
|
||||
if (!$errors)
|
||||
$errors = $this->module_instance->displayName . ' : ' . $this->l('Unknown error');
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
$errors = (array)$errors;
|
||||
$errors = (array_values($errors) === $errors) ? $errors : array($errors); // array must be multidimentional
|
||||
|
||||
foreach ($errors as $error) {
|
||||
if (isset($error['ValidationInfo']['Info']))
|
||||
self::$errors[] = $error['ValidationInfo']['Info'];
|
||||
elseif (isset($error['info']))
|
||||
self::$errors[] = $error['info'];
|
||||
elseif (isset($error['ValidationInfo']) && is_array($error['ValidationInfo'])) {
|
||||
$errors_formatted = reset($error['ValidationInfo']);
|
||||
|
||||
if (isset($errors_formatted['ErrorId'])) {
|
||||
$language = new DpdPolandLanguage();
|
||||
$error_message = $language->getTranslation($errors_formatted['ErrorId']);
|
||||
|
||||
if (!$error_message) {
|
||||
$error_message = isset($errors_formatted['Info']) ? $errors_formatted['Info'] :
|
||||
$this->l('Unknown error occured');
|
||||
}
|
||||
|
||||
self::$errors[] = $error_message;
|
||||
} elseif (isset($errors_formatted['Info'])) {
|
||||
self::$errors[] = $errors_formatted['Info'];
|
||||
}
|
||||
} else {
|
||||
self::$errors[] = $error;
|
||||
}
|
||||
}
|
||||
} else
|
||||
self::$errors[] = $errors;
|
||||
|
||||
DpdPolandLog::addError($errors);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates package remotely
|
||||
*
|
||||
* @param array $package_obj Package object
|
||||
* @param string $payerType Payer type
|
||||
* @return bool Package created successfully
|
||||
*/
|
||||
private function createRemotely($package_obj, $payerType, $payerNumber)
|
||||
{
|
||||
$params = array(
|
||||
'openUMLFeV9' => array('packages' => []),
|
||||
'pkgNumsGenerationPolicyV1' => 'STOP_ON_FIRST_ERROR',
|
||||
'langCode' => 'PL'
|
||||
);
|
||||
foreach ($package_obj as $item) {
|
||||
$receiver = $this->prepareReceiverAddress($item);
|
||||
if (!$receiver)
|
||||
return false;
|
||||
|
||||
$package = [
|
||||
'parcels' => $item->parcels,
|
||||
'payerType' => $payerType,
|
||||
'thirdPartyFID' => $payerNumber,
|
||||
'receiver' => $receiver,
|
||||
'ref1' => $item->ref1,
|
||||
'ref2' => $item->ref2,
|
||||
'ref3' => _DPDPOLAND_REFERENCE3_,
|
||||
'reference' => null,
|
||||
'sender' => $this->prepareSenderAddress($item->id_sender_address),
|
||||
'services' => $this->prepareServicesData($item),
|
||||
];
|
||||
array_push($params['openUMLFeV9']['packages'], $package);
|
||||
}
|
||||
|
||||
return $this->generatePackagesNumbersV8($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats receiver address and prepares it to be used via WebServices
|
||||
*
|
||||
* @param DpdPolandPackage $package_obj Package object
|
||||
* @return array|bool
|
||||
*/
|
||||
private function prepareReceiverAddress(DpdPolandPackage $package_obj)
|
||||
{
|
||||
$address = new Address((int)$package_obj->id_address_delivery);
|
||||
|
||||
if (Validate::isLoadedObject($address)) {
|
||||
$customer = new Customer((int)$address->id_customer);
|
||||
|
||||
if (Validate::isLoadedObject($customer)) {
|
||||
return array(
|
||||
'address' => $address->address1 . ' ' . $address->address2,
|
||||
'city' => $address->city,
|
||||
'company' => $address->company,
|
||||
'countryCode' => Country::getIsoById((int)$address->id_country),
|
||||
'email' => isset($address->other) && !empty(trim($address->other)) ? $address->other : $customer->email,
|
||||
'fid' => null,
|
||||
'name' => $address->firstname . ' ' . $address->lastname,
|
||||
'phone' => isset($address->phone) && !empty(trim($address->phone)) ? $address->phone : $address->phone_mobile,
|
||||
'postalCode' => DpdPoland::convertPostcode($address->postcode)
|
||||
);
|
||||
} else {
|
||||
self::$errors[] = $this->l('Customer does not exists');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
self::$errors[] = $this->l('Receiver address does not exists');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats sender address and prepares it to be used via WebServices
|
||||
*
|
||||
* @param null|int $id_sender_address Address ID
|
||||
*/
|
||||
private function prepareSenderAddress($id_sender_address = null)
|
||||
{
|
||||
$sender_address = new DpdPolandSenderAddress((int)$id_sender_address);
|
||||
|
||||
return array(
|
||||
'address' => $sender_address->address,
|
||||
'city' => $sender_address->city,
|
||||
'company' => $sender_address->company,
|
||||
'countryCode' => DpdPoland::POLAND_ISO_CODE,
|
||||
'email' => $sender_address->email,
|
||||
'name' => $sender_address->name,
|
||||
'phone' => $sender_address->phone,
|
||||
'postalCode' => DpdPoland::convertPostcode($sender_address->postcode)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats data and prepares it to be used via WebServices
|
||||
*
|
||||
* @param DpdPolandPackage $package_obj Package object
|
||||
*/
|
||||
private function prepareServicesData(DpdPolandPackage $package_obj)
|
||||
{
|
||||
$services = array();
|
||||
if ($package_obj->cod_amount !== null || $package_obj->sessionType == 'domestic_with_cod' || $package_obj->sessionType == 'pudo_cod') {
|
||||
if ($package_obj->cod_amount !== null) {
|
||||
$services['cod'] = array(
|
||||
'amount' => $package_obj->cod_amount,
|
||||
'currency' => _DPDPOLAND_CURRENCY_ISO_
|
||||
);
|
||||
} else {
|
||||
$services['cod'] = array(
|
||||
'amount' => 0,
|
||||
'currency' => _DPDPOLAND_CURRENCY_ISO_
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($package_obj->declaredValue_amount !== null) {
|
||||
$services['declaredValue'] = array(
|
||||
'amount' => $package_obj->declaredValue_amount,
|
||||
'currency' => _DPDPOLAND_CURRENCY_ISO_
|
||||
);
|
||||
}
|
||||
|
||||
if ($package_obj->cud) {
|
||||
$services['cud'] = 1;
|
||||
}
|
||||
|
||||
if ($package_obj->rod) {
|
||||
$services['rod'] = 1;
|
||||
}
|
||||
|
||||
if ($package_obj->dpde) {
|
||||
$services['dpdExpress'] = 1;
|
||||
}
|
||||
|
||||
if ($package_obj->dpdnd) {
|
||||
$services['guarantee'] = array('type' => 'DPDNEXTDAY');
|
||||
}
|
||||
|
||||
if ($package_obj->dpdtoday) {
|
||||
$services['guarantee'] = array('type' => 'DPDTODAY');
|
||||
}
|
||||
|
||||
if ($package_obj->dpdfood) {
|
||||
$services['dpdFood'] = array('limitDate' => $package_obj->dpdfood_limit_date);
|
||||
}
|
||||
|
||||
if ($package_obj->dpdsaturday) {
|
||||
$services['guarantee'] = array('type' => 'SATURDAY');
|
||||
}
|
||||
|
||||
if ($package_obj->dpdlq) {
|
||||
$services['dpdLQ'] = 1;
|
||||
}
|
||||
|
||||
if ($package_obj->duty) {
|
||||
$services['duty'] = array(
|
||||
'amount' => $package_obj->duty_amount,
|
||||
'currency' => $package_obj->duty_currency
|
||||
);
|
||||
}
|
||||
|
||||
// DPD PUDO SERVICE DATA PREPARATION
|
||||
$order = new Order($package_obj->id_order);
|
||||
|
||||
// Check if order has pudo service as carrier
|
||||
if ($package_obj->sessionType == 'pudo' || $package_obj->sessionType == 'pudo_cod') {
|
||||
// Get pudo code from pudo_cart mappings table
|
||||
$pudoCode = Db::getInstance()->getValue('
|
||||
SELECT `pudo_code`
|
||||
FROM `' . _DB_PREFIX_ . 'dpdpoland_pudo_cart`
|
||||
WHERE `id_cart` = ' . (int)$order->id_cart . '
|
||||
');
|
||||
$services['dpdPickup'] = array(
|
||||
'pudo' => $pudoCode,
|
||||
);
|
||||
}
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and returns sender address
|
||||
*
|
||||
* @param null|int $id_sender_address Sender address ID
|
||||
* @return array Sender address
|
||||
*/
|
||||
public function getSenderAddress($id_sender_address = null)
|
||||
{
|
||||
if (!$this->sender)
|
||||
return $this->prepareSenderAddress($id_sender_address);
|
||||
|
||||
return $this->sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates multiple labels for selected packages
|
||||
*
|
||||
* @param array $waybills Packages waybills
|
||||
* @param string $outputDocPageFormat Document page format
|
||||
* @param string $session_type Session type
|
||||
* @return bool Multiple labels generated successfully
|
||||
*/
|
||||
public function generateMultipleLabels($waybills, $outputDocPageFormat, $session_type, $outputLabelType)
|
||||
{
|
||||
if (!in_array($outputDocPageFormat, array(DpdPolandConfiguration::PRINTOUT_FORMAT_A4, DpdPolandConfiguration::PRINTOUT_FORMAT_LABEL)))
|
||||
$outputDocPageFormat = DpdPolandConfiguration::PRINTOUT_FORMAT_A4;
|
||||
|
||||
$this->prepareSenderAddress();
|
||||
|
||||
$session = array(
|
||||
'packages' => array(
|
||||
'parcels' => array()
|
||||
),
|
||||
'sessionType' => $session_type
|
||||
);
|
||||
|
||||
foreach ($waybills as $waybill) {
|
||||
$session['packages']['parcels'][] = array('waybill' => $waybill);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'dpdServicesParamsV1' => array(
|
||||
'policy' => 'IGNORE_ERRORS',
|
||||
'session' => $session
|
||||
),
|
||||
'outputDocFormatV1' => 'PDF',
|
||||
'outputDocPageFormatV1' => $outputDocPageFormat,
|
||||
'outputLabelType' => $outputLabelType,
|
||||
'pickupAddress' => $this->sender
|
||||
);
|
||||
|
||||
if (!$result = $this->generateSpedLabelsV4($params)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($result['session']) && $result['session']['statusInfo']['status'] == 'OK') {
|
||||
return $result['documentData'];
|
||||
} else {
|
||||
if (isset($result['session']['statusInfo']['status'])) {
|
||||
self::$errors[] = $result['session']['statusInfo']['status'];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$error = isset($result['session']['packages']['statusInfo']['description']) ?
|
||||
$result['session']['packages']['statusInfo']['description'] :
|
||||
$result['session']['statusInfo']['description'];
|
||||
self::$errors[] = $error;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates labels for package
|
||||
*
|
||||
* @param DpdPolandPackage $package Package object
|
||||
* @param string $outputDocFormat Document format
|
||||
* @param string $outputDocPageFormat Document page format
|
||||
* @param $outputLabelType
|
||||
* @param string $policy Policy type
|
||||
* @return bool Labels generated successfully
|
||||
*/
|
||||
public function generateLabels(DpdPolandPackage $package, $outputDocFormat, $outputDocPageFormat, $policy, $outputLabelType)
|
||||
{
|
||||
if (!in_array($outputDocPageFormat, array(DpdPolandConfiguration::PRINTOUT_FORMAT_A4, DpdPolandConfiguration::PRINTOUT_FORMAT_LABEL)))
|
||||
$outputDocPageFormat = DpdPolandConfiguration::PRINTOUT_FORMAT_A4;
|
||||
|
||||
$this->prepareSenderAddress();
|
||||
|
||||
$params = array(
|
||||
'dpdServicesParamsV1' => array(
|
||||
'policy' => $policy,
|
||||
'session' => array(
|
||||
'sessionId' => (int)$package->sessionId,
|
||||
'sessionType' => $package->getSessionType()
|
||||
)
|
||||
),
|
||||
'outputDocFormatV1' => $outputDocFormat,
|
||||
'outputDocPageFormatV1' => $outputDocPageFormat,
|
||||
'outputLabelType' => $outputLabelType,
|
||||
'pickupAddress' => $this->sender
|
||||
);
|
||||
|
||||
if (!$result = $this->generateSpedLabelsV4($params))
|
||||
return false;
|
||||
|
||||
if (isset($result['session']) && $result['session']['statusInfo']['status'] == 'OK') {
|
||||
$package->labels_printed = 1;
|
||||
$package->update();
|
||||
return $result['documentData'];
|
||||
} else {
|
||||
if (isset($result['session']['statusInfo']['status'])) {
|
||||
if ($result['session']['statusInfo']['status'] === "NOT_FOUND") {
|
||||
self::$errors[] = (new DpdPolandLanguage())->getTranslationByCode($result['session']['statusInfo']['status']);
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$errors[] = $result['session']['statusInfo']['status'];
|
||||
return false;
|
||||
}
|
||||
|
||||
$error = isset($result['session']['packages']['statusInfo']['description']) ?
|
||||
$result['session']['packages']['statusInfo']['description'] :
|
||||
$result['session']['statusInfo']['description'];
|
||||
self::$errors[] = $error;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates multiple labels for selected packages
|
||||
*
|
||||
* @param array $package_ids Packages IDs
|
||||
* @param string $outputDocFormat Document format
|
||||
* @param string $outputDocPageFormat Document page format
|
||||
* @param $outputLabelType
|
||||
* @param string $policy Policy type
|
||||
* @return bool Labels generated successfully
|
||||
*/
|
||||
public function generateLabelsForMultiplePackages($package_ids, $outputDocFormat, $outputDocPageFormat, $policy, $outputLabelType)
|
||||
{
|
||||
$sessionType = '';
|
||||
$packages = array();
|
||||
|
||||
foreach ($package_ids as $id_package_ws) {
|
||||
$package = new DpdPolandPackage((int)$id_package_ws);
|
||||
|
||||
if (!$sessionType || $sessionType == $package->getSessionType())
|
||||
$sessionType = $package->getSessionType();
|
||||
else {
|
||||
self::$errors[] = $this->l('Manifests of DOMESTIC shipments cannot be mixed with INTERNATIONAL shipments');
|
||||
return false;
|
||||
}
|
||||
|
||||
$packages[] = array(
|
||||
'packageId' => (int)$id_package_ws
|
||||
);
|
||||
}
|
||||
|
||||
$this->prepareSenderAddress();
|
||||
|
||||
$params = array(
|
||||
'dpdServicesParamsV1' => array(
|
||||
'policy' => $policy,
|
||||
'session' => array(
|
||||
'packages' => $packages,
|
||||
'sessionType' => $sessionType
|
||||
)
|
||||
),
|
||||
'outputDocFormatV1' => $outputDocFormat,
|
||||
'outputDocPageFormatV1' => $outputDocPageFormat,
|
||||
'outputLabelType' => $outputLabelType,
|
||||
'pickupAddress' => $this->sender
|
||||
);
|
||||
|
||||
if (!$result = $this->generateSpedLabelsV4($params))
|
||||
return false;
|
||||
|
||||
if (isset($result['session']['statusInfo']['status']) && $result['session']['statusInfo']['status'] == 'OK') {
|
||||
foreach ($packages as $id_package_ws) {
|
||||
$package = new DpdPolandPackage($id_package_ws);
|
||||
$package->labels_printed = 1;
|
||||
$package->update();
|
||||
}
|
||||
|
||||
return $result['documentData'];
|
||||
} else {
|
||||
$packages = $result['session']['statusInfo'];
|
||||
$packages = (array_values($packages) === $packages) ? $packages : array($packages); // array must be multidimentional
|
||||
|
||||
foreach ($packages as $package)
|
||||
if (isset($package['description']))
|
||||
self::$errors[] = $package['description'];
|
||||
elseif (isset($package['status']))
|
||||
self::$errors[] = $package['status'];
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
273
modules/dpdpoland/controllers/packageList.controller.php
Normal file
273
modules/dpdpoland/controllers/packageList.controller.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandPackageListController Responsible for packages list view and actions
|
||||
*/
|
||||
class DpdPolandPackageListController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Default list sorting criteria
|
||||
*/
|
||||
const DEFAULT_ORDER_BY = 'date_add';
|
||||
|
||||
/**
|
||||
* Default list sorting way
|
||||
*/
|
||||
const DEFAULT_ORDER_WAY = 'desc';
|
||||
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'packageList.controller';
|
||||
|
||||
/**
|
||||
* Prints manifests from packages list
|
||||
*
|
||||
* @param object $module_instance Module instance
|
||||
* @return bool Manifest printed successfully
|
||||
*/
|
||||
public static function printManifest($module_instance)
|
||||
{
|
||||
$cookie = Context::getContext()->cookie;
|
||||
|
||||
if (isset($cookie->dpdpoland_packages_ids))
|
||||
{
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
$package_ids = unserialize(Context::getContext()->cookie->dpdpoland_packages_ids);
|
||||
else
|
||||
$package_ids = Tools::unSerialize(Context::getContext()->cookie->dpdpoland_packages_ids);
|
||||
|
||||
unset($cookie->dpdpoland_packages_ids);
|
||||
$cookie->write();
|
||||
|
||||
$separated_packages = DpdPolandPackage::separatePackagesBySession($package_ids);
|
||||
$international_packages = $separated_packages['INTERNATIONAL'];
|
||||
$domestic_packages = $separated_packages['DOMESTIC'];
|
||||
$manifest_ids = array();
|
||||
|
||||
if ($international_packages)
|
||||
$manifest_ids[] = DpdPolandManifest::getManifestIdWsByPackageIdWs($international_packages[0]);
|
||||
|
||||
if ($domestic_packages)
|
||||
$manifest_ids[] = DpdPolandManifest::getManifestIdWsByPackageIdWs($domestic_packages[0]);
|
||||
|
||||
require_once(_DPDPOLAND_CONTROLLERS_DIR_.'manifestList.controller.php');
|
||||
|
||||
$manifest_controller = new DpdPolandManifestListController();
|
||||
|
||||
return $manifest_controller->printManifest($manifest_ids);
|
||||
}
|
||||
|
||||
if ($package_ids = Tools::getValue('PackagesBox'))
|
||||
{
|
||||
if (!DpdPolandManifest::validateSenderAddresses($package_ids))
|
||||
{
|
||||
$error_message = $module_instance->l('Manifests can not have different sender addresses', self::FILENAME);
|
||||
$error = $module_instance->displayError($error_message);
|
||||
|
||||
return $module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
$separated_packages = DpdPolandPackage::separatePackagesBySession($package_ids);
|
||||
$international_packages = $separated_packages['INTERNATIONAL'];
|
||||
$domestic_packages = $separated_packages['DOMESTIC'];
|
||||
|
||||
if ($international_packages)
|
||||
{
|
||||
$manifest = new DpdPolandManifest;
|
||||
|
||||
if (!$manifest->generateMultiple($international_packages))
|
||||
{
|
||||
$error = $module_instance->displayError(reset(DpdPolandManifestWS::$errors));
|
||||
|
||||
return $module_instance->outputHTML($error);
|
||||
}
|
||||
}
|
||||
|
||||
if ($domestic_packages)
|
||||
{
|
||||
$manifest = new DpdPolandManifest;
|
||||
|
||||
if (!$manifest->generateMultiple($domestic_packages))
|
||||
{
|
||||
$error = $module_instance->displayError(reset(DpdPolandManifestWS::$errors));
|
||||
|
||||
return $module_instance->outputHTML($error);
|
||||
}
|
||||
}
|
||||
|
||||
$cookie->dpdpoland_packages_ids = serialize($package_ids);
|
||||
$redirect_uri = $module_instance->module_url.'&menu=packages_list';
|
||||
|
||||
die(Tools::redirectAdmin($redirect_uri));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates label from packages list
|
||||
*
|
||||
* @param object $package Package object
|
||||
* @param object $module_instance Module instance
|
||||
* @param array $packages Packages IDs
|
||||
* @param string $printout_format Printout format (label, A4)
|
||||
* @param string $filename Label file name
|
||||
* @return bool Label created successfully
|
||||
*/
|
||||
private static function createLabelPDFDocument($package, $module_instance, $packages, $printout_format, $filename)
|
||||
{
|
||||
if (!$pdf_file_contents = $package->generateLabelsForMultiplePackages($packages, 'PDF', $printout_format))
|
||||
{
|
||||
$error = $module_instance->displayError(reset(DpdPolandPackageWS::$errors));
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/'.$filename) && !unlink(_PS_MODULE_DIR_.'dpdpoland/'.$filename))
|
||||
{
|
||||
$error_message = $module_instance->l('Could not delete old PDF file. Please check module folder permissions', self::FILENAME);
|
||||
$error = $module_instance->displayError($error_message);
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
$international_pdf = fopen(_PS_MODULE_DIR_.'dpdpoland/'.$filename, 'w');
|
||||
|
||||
if (!$international_pdf)
|
||||
{
|
||||
$error_message = $module_instance->l('Could not create PDF file. Please check module folder permissions', self::FILENAME);
|
||||
$error = $module_instance->displayError($error_message);
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
fwrite($international_pdf, $pdf_file_contents);
|
||||
fclose($international_pdf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints multiple label for selected packages
|
||||
*
|
||||
* @param string $printout_format Printout format (label, A4)
|
||||
* @return mixed Error messages
|
||||
*/
|
||||
public static function printLabels($printout_format)
|
||||
{
|
||||
$module_instance = Module::getinstanceByName('dpdpoland');
|
||||
|
||||
if ($package_ids = Tools::getValue('PackagesBox'))
|
||||
{
|
||||
$package = new DpdPolandPackage;
|
||||
|
||||
$separated_packages = DpdPolandPackage::separatePackagesBySession($package_ids);
|
||||
$international_packages = $separated_packages['INTERNATIONAL'];
|
||||
$domestic_packages = $separated_packages['DOMESTIC'];
|
||||
|
||||
if ($international_packages)
|
||||
{
|
||||
$result = self::createLabelPDFDocument($package, $module_instance, $international_packages, $printout_format, 'international_labels.pdf');
|
||||
|
||||
if ($result !== true)
|
||||
return $module_instance->outputHTML($result);
|
||||
}
|
||||
|
||||
if ($domestic_packages)
|
||||
{
|
||||
$result = self::createLabelPDFDocument($package, $module_instance, $domestic_packages, $printout_format, 'domestic_labels.pdf');
|
||||
|
||||
if ($result !== true)
|
||||
return $module_instance->outputHTML($result);
|
||||
}
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'dpdpoland/libraries/PDFMerger/PDFMerger.php');
|
||||
|
||||
$pdf = new PDFMerger;
|
||||
|
||||
if ($international_packages && $domestic_packages)
|
||||
{
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/labels_multisession.pdf') && !unlink(_PS_MODULE_DIR_.'dpdpoland/labels_multisession.pdf'))
|
||||
{
|
||||
$error_message = $module_instance->l('Could not delete old PDF file. Please check module folder permissions', self::FILENAME);
|
||||
$error = $module_instance->displayError($error_message);
|
||||
|
||||
return $module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
$international_pdf_path = _PS_MODULE_DIR_.'dpdpoland/international_labels.pdf';
|
||||
$domestic_pdf_path = _PS_MODULE_DIR_.'dpdpoland/domestic_labels.pdf';
|
||||
$multisession_pdf_path = _PS_MODULE_DIR_.'dpdpoland/labels_multisession.pdf';
|
||||
$pdf->addPDF($international_pdf_path, 'all')->addPDF($domestic_pdf_path, 'all')->merge('file', $multisession_pdf_path);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
header('Content-type: application/pdf');
|
||||
header('Content-Disposition: attachment; filename="labels_'.time().'.pdf"');
|
||||
|
||||
if ($international_packages && $domestic_packages)
|
||||
readfile(_PS_MODULE_DIR_.'dpdpoland/labels_multisession.pdf');
|
||||
elseif ($international_packages)
|
||||
readfile(_PS_MODULE_DIR_.'dpdpoland/international_labels.pdf');
|
||||
elseif ($domestic_packages)
|
||||
readfile(_PS_MODULE_DIR_.'dpdpoland/domestic_labels.pdf');
|
||||
else
|
||||
{
|
||||
$error_message = $module_instance->l('No labels were found', self::FILENAME);
|
||||
$error = $module_instance->displayError($error_message);
|
||||
return $module_instance->outputHTML($error);
|
||||
}
|
||||
|
||||
self::deletePDFFiles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes existing PDF files which were used to merge them onto a single document
|
||||
*/
|
||||
private static function deletePDFFiles()
|
||||
{
|
||||
$labels = array('labels_multisession', 'international_labels', 'domestic_labels');
|
||||
|
||||
foreach ($labels as $label)
|
||||
if (file_exists(_PS_MODULE_DIR_.'dpdpoland/'.$label.'.pdf') && is_writable(_PS_MODULE_DIR_.'dpdpoland/'.$label.'.pdf'))
|
||||
unlink(_PS_MODULE_DIR_.'dpdpoland/'.$label.'.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares list data to be displayed in page
|
||||
*
|
||||
* @return string Page content in HTML
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$keys_array = array('date_add', 'id_order', 'package_number', 'count_parcel', 'receiver', 'country', 'postcode', 'city', 'address', 'ref1', 'ref2', 'additional_info');
|
||||
$this->prepareListData($keys_array, 'Packages', new DpdPolandPackage, self::DEFAULT_ORDER_BY, self::DEFAULT_ORDER_WAY, 'packages_list');
|
||||
$this->context->smarty->assign('order_link', 'index.php?controller=AdminOrders&vieworder&token='.Tools::getAdminTokenLite('AdminOrders'));
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.6', '>='))
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/package_list_16.tpl');
|
||||
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/package_list.tpl');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandParcelHistoryController Responsible for parcel history list page view and actions
|
||||
*/
|
||||
class DpdPolandParcelHistoryController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Default list sorting criteria
|
||||
*/
|
||||
const DEFAULT_ORDER_BY = 'date_add';
|
||||
|
||||
/**
|
||||
* Default list sorting way
|
||||
*/
|
||||
const DEFAULT_ORDER_WAY = 'desc';
|
||||
|
||||
/**
|
||||
* @var string Tracking URL address
|
||||
*/
|
||||
private $tracking_link = 'https://tracktrace.dpd.com.pl/parcelDetails?typ=1&p1=';
|
||||
|
||||
/**
|
||||
* Prepares list data to be displayed in page
|
||||
*
|
||||
* @return string Page content in HTML
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$keys_array = array('id_order', 'id_parcel', 'receiver', 'country', 'postcode', 'city', 'address', 'date_add');
|
||||
$this->prepareListData($keys_array, 'ParcelHistories', new DpdPolandParcel(),
|
||||
self::DEFAULT_ORDER_BY, self::DEFAULT_ORDER_WAY, 'parcel_history_list');
|
||||
$this->context->smarty->assign('tracking_link', $this->tracking_link);
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.6', '<'))
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/parcel_history_list.tpl');
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/parcel_history_list_16.tpl');
|
||||
}
|
||||
}
|
||||
348
modules/dpdpoland/controllers/pickup.webservice.php
Normal file
348
modules/dpdpoland/controllers/pickup.webservice.php
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandPickup Responsible for Arrange Pickup actions management
|
||||
*/
|
||||
class DpdPolandPickup extends DpdPolandWS
|
||||
{
|
||||
/**
|
||||
* @var int Pickup ID
|
||||
*/
|
||||
public $id_pickup;
|
||||
|
||||
/**
|
||||
* @var date|string Pickup date
|
||||
*/
|
||||
public $pickupDate;
|
||||
|
||||
/**
|
||||
* @var date|string Pickup time
|
||||
*/
|
||||
public $pickupTime;
|
||||
|
||||
/**
|
||||
* @var string Order type (international, domestic)
|
||||
*/
|
||||
public $orderType;
|
||||
|
||||
/**
|
||||
* @var bool Pickup for envelope
|
||||
*/
|
||||
public $dox = false;
|
||||
|
||||
/**
|
||||
* @var int|string Documents count
|
||||
*/
|
||||
public $doxCount;
|
||||
|
||||
/**
|
||||
* @var bool Pickup for parcels
|
||||
*/
|
||||
public $parcels = false;
|
||||
|
||||
/**
|
||||
* @var int|string Parcels count
|
||||
*/
|
||||
public $parcelsCount;
|
||||
|
||||
/**
|
||||
* @var float|string Parcels weight
|
||||
*/
|
||||
public $parcelsWeight;
|
||||
|
||||
/**
|
||||
* @var float|string Parcel max weight
|
||||
*/
|
||||
public $parcelMaxWeight;
|
||||
|
||||
/**
|
||||
* @var float|string Parcel max height
|
||||
*/
|
||||
public $parcelMaxHeight;
|
||||
|
||||
/**
|
||||
* @var float|string Parcel max depth
|
||||
*/
|
||||
public $parcelMaxDepth;
|
||||
|
||||
/**
|
||||
* @var float|string Parcel max width
|
||||
*/
|
||||
public $parcelMaxWidth;
|
||||
|
||||
/**
|
||||
* @var bool Pickup for pallet
|
||||
*/
|
||||
public $pallet = false;
|
||||
|
||||
/**
|
||||
* @var int|string Pallets count
|
||||
*/
|
||||
public $palletsCount;
|
||||
|
||||
/**
|
||||
* @var float|string Pallets weight
|
||||
*/
|
||||
public $palletsWeight;
|
||||
|
||||
/**
|
||||
* @var float|string Pallet max weight
|
||||
*/
|
||||
public $palletMaxWeight;
|
||||
|
||||
/**
|
||||
* @var float|string Pallet max height
|
||||
*/
|
||||
public $palletMaxHeight;
|
||||
|
||||
public $customerName;
|
||||
|
||||
public $customerCompany;
|
||||
|
||||
public $customerPhone;
|
||||
|
||||
/**
|
||||
* Is it a standard parcel
|
||||
* Always must be true
|
||||
*/
|
||||
const STANDARD_PARCEL = true;
|
||||
|
||||
/**
|
||||
* Makes web services call to arrange a pickup
|
||||
*
|
||||
* @param string $operationType Operation type
|
||||
* @param bool $waybillsReady Are waybills ready
|
||||
* @return bool Pickup arranged successfully
|
||||
*/
|
||||
public function arrange($operationType = 'INSERT', $waybillsReady = true)
|
||||
{
|
||||
list($pickupTimeFrom, $pickupTimeTo) = explode('-', $this->pickupTime);
|
||||
|
||||
$settings = new DpdPolandConfiguration;
|
||||
|
||||
$params = array(
|
||||
'dpdPickupParamsV3' => array(
|
||||
'operationType' => $operationType,
|
||||
'orderType' => $this->orderType,
|
||||
'pickupCallSimplifiedDetails' => array(
|
||||
'packagesParams' => $this->getPackagesParams(),
|
||||
'pickupCustomer' => array(
|
||||
'customerFullName' => $this->customerName,
|
||||
'customerName' => $this->customerCompany,
|
||||
'customerPhone' => $this->customerPhone
|
||||
),
|
||||
'pickupPayer' => array(
|
||||
'payerName' => $settings->client_name,
|
||||
'payerNumber' => $settings->client_number
|
||||
),
|
||||
'pickupSender' => $this->getSenderAddress()
|
||||
),
|
||||
'pickupDate' => $this->pickupDate,
|
||||
'pickupTimeFrom' => $pickupTimeFrom,
|
||||
'pickupTimeTo' => $pickupTimeTo,
|
||||
'waybillsReady' => $waybillsReady
|
||||
)
|
||||
);
|
||||
|
||||
$result = $this->packagesPickupCallV4($params);
|
||||
|
||||
if (isset($result['statusInfo']) && isset($result['statusInfo']['errorDetails']))
|
||||
{
|
||||
$errors = $result['statusInfo']['errorDetails'];
|
||||
$errors = (array_values($errors) === $errors) ? $errors : array($errors); // array must be multidimentional
|
||||
foreach ($errors as $error)
|
||||
self::$errors[] = sprintf($this->l('Error code: %s, fields: %s'), $error['code'], $error['fields']);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($result['orderNumber']))
|
||||
{
|
||||
$this->id_pickup = (int)$result['orderNumber'];
|
||||
Configuration::updateValue('DPDPOLAND_CONFIGURATION_OK', true);
|
||||
return true;
|
||||
}
|
||||
self::$errors[] = $this->l('Order number is undefined');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted sender address
|
||||
*
|
||||
* @return array Sender address
|
||||
*/
|
||||
private function getSenderAddress()
|
||||
{
|
||||
$id_sender_address = (int)Tools::getValue('sender_address_selection');
|
||||
$sender_address = new DpdPolandSenderAddress((int)$id_sender_address);
|
||||
|
||||
return array(
|
||||
'senderAddress' => $sender_address->address,
|
||||
'senderCity' => $sender_address->city,
|
||||
'senderFullName' => $sender_address->name,
|
||||
'senderName' => $sender_address->name,
|
||||
'senderPhone' => $sender_address->phone,
|
||||
'senderPostalCode' => DpdPoland::convertPostcode($sender_address->postcode),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create array with pickup packages (envelopes, pallets or parcels) data for web services call
|
||||
*
|
||||
* @return array Formatted WebServices parameters
|
||||
*/
|
||||
private function getPackagesParams()
|
||||
{
|
||||
return array_merge(
|
||||
$this->getEnvelopesParams(),
|
||||
$this->getPalletsParams(),
|
||||
$this->getParcelsParams()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array with envelopes data prepared for web services call
|
||||
* In order to send envelopes, both conditions must be met:
|
||||
* 1. Envelopes chosen
|
||||
* 2. Envelopes count > 0
|
||||
* Otherwise envelopes count will be 0.
|
||||
* 'dox' parameter always must bet set to 0 - requirement by DPD Poland
|
||||
*
|
||||
* @return array Envelopes parameters
|
||||
*/
|
||||
private function getEnvelopesParams()
|
||||
{
|
||||
$result = array(
|
||||
'dox' => 0, // always false even if envelopes are sent
|
||||
'doxCount' => 0
|
||||
);
|
||||
|
||||
if ($this->dox && (int)$this->doxCount)
|
||||
$result['doxCount'] = (int)$this->doxCount;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array with envelopes data prepared for web services call
|
||||
* In order to send pallets, both conditions must be met:
|
||||
* 1. Pallets chosen
|
||||
* 2. Pallets count > 0
|
||||
*
|
||||
* @return array Pallets parameters
|
||||
*/
|
||||
private function getPalletsParams()
|
||||
{
|
||||
$result = array(
|
||||
'pallet' => 0,
|
||||
'palletMaxHeight' => '',
|
||||
'palletMaxWeight' => '',
|
||||
'palletsCount' => 0,
|
||||
'palletsWeight' => ''
|
||||
);
|
||||
|
||||
if ($this->pallet && (int)$this->palletsCount)
|
||||
{
|
||||
$result['pallet'] = 1;
|
||||
$result['palletMaxHeight'] = $this->palletMaxHeight;
|
||||
$result['palletMaxWeight'] = $this->palletMaxWeight;
|
||||
$result['palletsCount'] = (int)$this->palletsCount;
|
||||
$result['palletsWeight'] = $this->palletsWeight;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array with parcels data prepared for web services call
|
||||
* If envelopes or pallets are sent without parcels then parcels should have all params set to 1
|
||||
* In order to send parcels, both conditions must be met:
|
||||
* 1. Parcels chosen
|
||||
* 2. Parcels count > 0
|
||||
*
|
||||
* @return array Parcels parameters
|
||||
*/
|
||||
private function getParcelsParams()
|
||||
{
|
||||
$result = array(
|
||||
'parcelsCount' => 0,
|
||||
'standardParcel' => self::STANDARD_PARCEL, // Always must be true
|
||||
'parcelMaxDepth' => '',
|
||||
'parcelMaxHeight' => '',
|
||||
'parcelMaxWeight' => '',
|
||||
'parcelMaxWidth' => '',
|
||||
'parcelsWeight' => ''
|
||||
);
|
||||
|
||||
// If no parcels but envelopes or pallets are chosen then parcels all values should be 1
|
||||
if (!$this->parcels && ($this->dox || $this->pallet))
|
||||
{
|
||||
$result['parcelsCount'] = 1;
|
||||
$result['standardParcel'] = self::STANDARD_PARCEL; // Always must be true
|
||||
$result['parcelMaxDepth'] = 1;
|
||||
$result['parcelMaxHeight'] = 1;
|
||||
$result['parcelMaxWeight'] = 1;
|
||||
$result['parcelMaxWidth'] = 1;
|
||||
$result['parcelsWeight'] = 1;
|
||||
}
|
||||
elseif ($this->parcels && (int)$this->parcelsCount)
|
||||
{
|
||||
$result['parcelsCount'] = (int)$this->parcelsCount;
|
||||
$result['standardParcel'] = self::STANDARD_PARCEL; // Always must be true
|
||||
$result['parcelMaxDepth'] = $this->parcelMaxDepth;
|
||||
$result['parcelMaxHeight'] = $this->parcelMaxHeight;
|
||||
$result['parcelMaxWeight'] = $this->parcelMaxWeight;
|
||||
$result['parcelMaxWidth'] = $this->parcelMaxWidth;
|
||||
$result['parcelsWeight'] = $this->parcelsWeight;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available pickup time frames for a particular date
|
||||
*
|
||||
* @return bool Are any available time frames
|
||||
*/
|
||||
public function getCourierTimeframes()
|
||||
{
|
||||
$id_sender_address = (int)Tools::getValue('sender_address_selection');
|
||||
$sender_address = new DpdPolandSenderAddress((int)$id_sender_address);
|
||||
|
||||
$params = array(
|
||||
'senderPlaceV1' => array(
|
||||
'countryCode' => DpdPoland::POLAND_ISO_CODE,
|
||||
'zipCode' => DpdPoland::convertPostcode($sender_address->postcode)
|
||||
)
|
||||
);
|
||||
|
||||
$result = $this->getCourierOrderAvailabilityV1($params);
|
||||
|
||||
if (!isset($result['ranges']) && !self::$errors)
|
||||
self::$errors[] = $this->l('Cannot get TimeFrames from webservices. Please check if sender\'s postal code is typed in correctly');
|
||||
|
||||
if(isset($result['ranges']) && isset($result['ranges']['offset']))
|
||||
return array($result['ranges']);
|
||||
|
||||
return (isset($result['ranges'])) ? $result['ranges'] : false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandSenderAddressListController Responsible for
|
||||
*/
|
||||
class DpdPolandPickupHistoryListController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Default list sorting criteria
|
||||
*/
|
||||
const DEFAULT_ORDER_BY = 'order_number';
|
||||
|
||||
/**
|
||||
* Default list sorting way
|
||||
*/
|
||||
const DEFAULT_ORDER_WAY = 'desc';
|
||||
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'manifestList.controller';
|
||||
|
||||
/**
|
||||
* Prepares list data to be displayed in page
|
||||
*
|
||||
* @return string Page content in HTML
|
||||
*/
|
||||
public function getListHTML()
|
||||
{
|
||||
$keys_array = array('id_pickup_history', 'order_number', 'sender_address', 'sender_company', 'sender_name', 'sender_phone', 'pickup_date', 'pickup_time', 'type', 'envelope', 'package', 'pallet');
|
||||
$this->prepareListData($keys_array, 'PickupHistory', new DpdPolandPickupHistory, self::DEFAULT_ORDER_BY, self::DEFAULT_ORDER_WAY, 'pickup_history');
|
||||
|
||||
$this->context->smarty->assign('form_url', $this->module_instance->module_url . '&menu=pickup_history_form');
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.6', '<'))
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'admin/pickup_history_list.tpl');
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'admin/pickup_history_list_16.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save pickup
|
||||
* @param $pickup
|
||||
* @param $id_sender_address
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
public function save($pickup)
|
||||
{
|
||||
$id_sender_address = (int)Tools::getValue('sender_address_selection');
|
||||
$sender_address = new DpdPolandSenderAddress((int)$id_sender_address);
|
||||
|
||||
$pickup_history = new DpdPolandPickupHistory;
|
||||
$pickup_history->order_number = $pickup->id_pickup;
|
||||
$pickup_history->sender_address = $sender_address->alias;
|
||||
$pickup_history->sender_company = $pickup->customerCompany;
|
||||
$pickup_history->sender_name = $pickup->customerName;
|
||||
$pickup_history->sender_phone = $pickup->customerPhone;
|
||||
$pickup_history->pickup_date = $pickup->pickupDate;
|
||||
$pickup_history->pickup_time = $pickup->pickupTime;
|
||||
$pickup_history->type = $pickup->orderType;
|
||||
$pickup_history->envelope = $pickup->doxCount;
|
||||
$pickup_history->package = $pickup->parcelsCount;
|
||||
$pickup_history->package_weight_all = $pickup->parcelsWeight;
|
||||
$pickup_history->package_heaviest_weight = $pickup->parcelMaxWeight;
|
||||
$pickup_history->package_heaviest_width = $pickup->parcelMaxWidth;
|
||||
$pickup_history->package_heaviest_length = $pickup->parcelMaxDepth;
|
||||
$pickup_history->package_heaviest_height = $pickup->parcelMaxHeight;
|
||||
$pickup_history->pallet = $pickup->palletsCount;
|
||||
$pickup_history->pallet_weight = $pickup->palletsWeight;
|
||||
$pickup_history->pallet_heaviest_weight = $pickup->palletMaxWeight;
|
||||
$pickup_history->pallet_heaviest_height = $pickup->palletMaxHeight;
|
||||
$pickup_history->id_shop = (int)$this->context->shop->id;
|
||||
|
||||
$pickup_history->save();
|
||||
}
|
||||
}
|
||||
183
modules/dpdpoland/controllers/senderAddressForm.controller.php
Normal file
183
modules/dpdpoland/controllers/senderAddressForm.controller.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandSenderAddressFormController Responsible for sender address form page view and actions
|
||||
*/
|
||||
class DpdPolandSenderAddressFormController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'configuration.controller';
|
||||
|
||||
/**
|
||||
* @var int Sender address
|
||||
*/
|
||||
private $id_sender_address = 0;
|
||||
|
||||
/**
|
||||
* DpdPolandSenderAddressFormController class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if (Tools::isSubmit('editSenderAddress')) {
|
||||
$this->id_sender_address = (int)Tools::getValue('id_sender_address');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts at page actions
|
||||
*/
|
||||
public function controllerActions()
|
||||
{
|
||||
if (Tools::isSubmit('saveSenderAddress')) {
|
||||
$this->saveSenderAddress();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares form data to be displayed in page
|
||||
*
|
||||
* @return string Form data in HTML
|
||||
*/
|
||||
public function getForm()
|
||||
{
|
||||
$sender_address = new DpdPolandSenderAddress((int)$this->id_sender_address);
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'object' => $sender_address,
|
||||
'saveAction' => $this->module_instance->module_url.'&menu=sender_address_form'
|
||||
));
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.6', '>='))
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/sender_address_form_16.tpl');
|
||||
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/sender_address_form.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves sender address in database
|
||||
*/
|
||||
private function saveSenderAddress()
|
||||
{
|
||||
$id_sender_address = (int)Tools::getValue('id_sender_address');
|
||||
|
||||
$address = new DpdPolandSenderAddress((int)$id_sender_address);
|
||||
$address->alias = Tools::getValue('alias');
|
||||
$address->company = Tools::getValue('company');
|
||||
$address->name = Tools::getValue('name');
|
||||
$address->phone = Tools::getValue('phone');
|
||||
$address->postcode = Tools::getValue('postcode');
|
||||
$address->city = Tools::getValue('city');
|
||||
$address->address = Tools::getValue('address');
|
||||
$address->email = Tools::getValue('email');
|
||||
$address->id_shop = (int)$this->context->shop->id;
|
||||
|
||||
if ($this->validateSenderAddress($address)) {
|
||||
$messages_controller = new DpdPolandMessagesController();
|
||||
|
||||
if ($address->save()) {
|
||||
$messages_controller->setSuccessMessage(
|
||||
$this->module_instance->l('Address saved successfully', self::FILENAME)
|
||||
);
|
||||
} else {
|
||||
$messages_controller->setErrorMessage(
|
||||
$this->module_instance->l('Could not save address', self::FILENAME)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Tools::redirectAdmin($this->module_instance->module_url.'&menu=sender_address');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if sender address fields are valid
|
||||
*
|
||||
* @param DpdPolandSenderAddress $address Sender address object
|
||||
* @return bool Sender address is valid
|
||||
*/
|
||||
private function validateSenderAddress(DpdPolandSenderAddress $address)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
if ($address->alias === '') {
|
||||
$errors[] = $this->module_instance->l('Alias name is required', self::FILENAME);
|
||||
} elseif (!Validate::isGenericName($address->alias)) {
|
||||
$errors[] = $this->module_instance->l('Alias name is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->company === '') {
|
||||
$errors[] = $this->module_instance->l('Company name is required', self::FILENAME);
|
||||
} elseif (!Validate::isGenericName($address->company)) {
|
||||
$errors[] = $this->module_instance->l('Company name is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->name === '') {
|
||||
$errors[] = $this->module_instance->l('Name / Surname is required', self::FILENAME);
|
||||
} elseif (!Validate::isName($address->name)) {
|
||||
$errors[] = $this->module_instance->l('Name / Surname is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->phone === '') {
|
||||
$errors[] = $this->module_instance->l('Phone is required', self::FILENAME);
|
||||
} elseif (!Validate::isPhoneNumber($address->phone)) {
|
||||
$errors[] = $this->module_instance->l('Phone number is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->postcode === '') {
|
||||
$errors[] = $this->module_instance->l('Postcode is required', self::FILENAME);
|
||||
} elseif (!Validate::isPostCode($address->postcode)) {
|
||||
$errors[] = $this->module_instance->l('Postcode is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->city === '') {
|
||||
$errors[] = $this->module_instance->l('City is required', self::FILENAME);
|
||||
} elseif (!Validate::isCityName($address->city)) {
|
||||
$errors[] = $this->module_instance->l('City is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->address === '') {
|
||||
$errors[] = $this->module_instance->l('Address is required', self::FILENAME);
|
||||
} elseif (!Validate::isAddress($address->address)) {
|
||||
$errors[] = $this->module_instance->l('Address is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($address->email === '') {
|
||||
$errors[] = $this->module_instance->l('Email is required', self::FILENAME);
|
||||
} elseif (!Validate::isEmail($address->email)) {
|
||||
$errors[] = $this->module_instance->l('Email is invalid', self::FILENAME);
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
$messages_controller = new DpdPolandMessagesController();
|
||||
$messages_controller->setErrorMessage(serialize($errors));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandSenderAddressListController Responsible for
|
||||
*/
|
||||
class DpdPolandSenderAddressListController extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* Default list sorting criteria
|
||||
*/
|
||||
const DEFAULT_ORDER_BY = 'date_add';
|
||||
|
||||
/**
|
||||
* Default list sorting way
|
||||
*/
|
||||
const DEFAULT_ORDER_WAY = 'desc';
|
||||
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'manifestList.controller';
|
||||
|
||||
/**
|
||||
* Reacts at page actions
|
||||
*/
|
||||
public function controllerActions()
|
||||
{
|
||||
if (Tools::isSubmit('deleteSenderAddress')) {
|
||||
$this->deleteSenderAddress();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares list data to be displayed in page
|
||||
*
|
||||
* @return string Page content in HTML
|
||||
*/
|
||||
public function getListHTML()
|
||||
{
|
||||
$keys_array = array('id_sender_address', 'company', 'name', 'city', 'email', 'alias');
|
||||
$this->prepareListData($keys_array, 'SenderAddress', new DpdPolandSenderAddress, self::DEFAULT_ORDER_BY, self::DEFAULT_ORDER_WAY, 'sender_address');
|
||||
|
||||
$this->context->smarty->assign('form_url', $this->module_instance->module_url.'&menu=sender_address_form');
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.6', '<'))
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/sender_address_list.tpl');
|
||||
return $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_.'admin/sender_address_list_16.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes sender address
|
||||
*/
|
||||
private function deleteSenderAddress()
|
||||
{
|
||||
$id_sender_address = (int)Tools::getValue('id_sender_address');
|
||||
$sender_address = new DpdPolandSenderAddress((int)$id_sender_address);
|
||||
$messages_controller = new DpdPolandMessagesController();
|
||||
|
||||
if ($sender_address->delete()) {
|
||||
$messages_controller->setSuccessMessage(
|
||||
$this->module_instance->l('Address deleted successfully', self::FILENAME)
|
||||
);
|
||||
} else {
|
||||
$messages_controller->setErrorMessage(
|
||||
$this->module_instance->l('Could not delete address', self::FILENAME)
|
||||
);
|
||||
}
|
||||
|
||||
Tools::redirectAdmin($this->module_instance->module_url.'&menu=sender_address');
|
||||
}
|
||||
}
|
||||
146
modules/dpdpoland/controllers/service.php
Normal file
146
modules/dpdpoland/controllers/service.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandService Responsible for DPD services (carriers) management
|
||||
*/
|
||||
class DpdPolandService
|
||||
{
|
||||
/**
|
||||
* DPD carriers images directory name
|
||||
*/
|
||||
const IMG_DIR = 'DPD_services';
|
||||
|
||||
/**
|
||||
* DPD carriers images extension
|
||||
*/
|
||||
const IMG_EXTENSION = 'jpg';
|
||||
|
||||
/**
|
||||
* @var Module Module instance
|
||||
*/
|
||||
protected $module_instance;
|
||||
|
||||
/**
|
||||
* DpdPolandService class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->module_instance = Module::getInstanceByName('dpdpoland');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete existing carrier
|
||||
*
|
||||
* @param int $id_carrier ID of carrier to delete
|
||||
* @return boolean Carrier deleted successfully
|
||||
*/
|
||||
protected static function deleteCarrier($id_carrier)
|
||||
{
|
||||
if (!$id_carrier)
|
||||
return true;
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
{
|
||||
$id_carrier = (int)DpdPolandCarrier::getIdCarrierByReference((int)$id_carrier);
|
||||
$carrier = new Carrier((int)$id_carrier);
|
||||
}
|
||||
else
|
||||
$carrier = Carrier::getCarrierByReference($id_carrier);
|
||||
|
||||
if (!Validate::isLoadedObject($carrier))
|
||||
return true;
|
||||
|
||||
if ($carrier->deleted)
|
||||
return true;
|
||||
|
||||
$carrier->deleted = 1;
|
||||
|
||||
return (bool)$carrier->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns PrestaShop customer groups for carrier on PS 1.4
|
||||
*
|
||||
* @param int $id_carrier Carrier ID
|
||||
* @param array $groups Groups IDs
|
||||
* @return bool Groups successfully assigned for carrier
|
||||
*/
|
||||
protected static function setGroups14($id_carrier, $groups)
|
||||
{
|
||||
foreach ($groups as $id_group)
|
||||
if (!Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'carrier_group`
|
||||
(`id_carrier`, `id_group`)
|
||||
VALUES
|
||||
("'.(int)$id_carrier.'", "'.(int)$id_group.'")
|
||||
'))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns customer groups for carrier on PS 1.5 and PS 1.6
|
||||
*
|
||||
* @param Carrier $carrier Carrier object
|
||||
* @return bool Customer groups successfully assigned for carrier
|
||||
*/
|
||||
protected static function assignCustomerGroupsForCarrier($carrier)
|
||||
{
|
||||
$groups = array();
|
||||
|
||||
foreach (Group::getGroups((int)Context::getContext()->language->id) as $group)
|
||||
$groups[] = $group['id_group'];
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.5.5', '<'))
|
||||
{
|
||||
if (!self::setGroups14((int)$carrier->id, $groups))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (!$carrier->setGroups($groups))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns carrier according to it's reference
|
||||
*
|
||||
* @param string|int $reference Carrier reference
|
||||
* @return bool|Carrier Carrier object
|
||||
*/
|
||||
public static function getCarrierByReference($reference)
|
||||
{
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
{
|
||||
$id_carrier = (int)DpdPolandCarrier::getIdCarrierByReference($reference);
|
||||
$carrier = new Carrier((int)$id_carrier);
|
||||
}
|
||||
else
|
||||
$carrier = Carrier::getCarrierByReference((int)$reference);
|
||||
|
||||
return $carrier;
|
||||
}
|
||||
}
|
||||
295
modules/dpdpoland/controllers/webservice.php
Normal file
295
modules/dpdpoland/controllers/webservice.php
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
/**
|
||||
* 2019 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2019 DPD Polska Sp. z o.o.
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
require_once(_PS_MODULE_DIR_.'dpdpoland/dpdpoland.lang.php');
|
||||
require_once(_DPDPOLAND_CLASSES_DIR_.'Log.php');
|
||||
|
||||
/**
|
||||
* Class DpdPolandWS Responsible for WebService calls management
|
||||
*/
|
||||
class DpdPolandWS extends DpdPolandController
|
||||
{
|
||||
/**
|
||||
* @var SoapClient Instance of SoapClient class
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var array WebServices parameters
|
||||
*/
|
||||
private $params = array();
|
||||
|
||||
/**
|
||||
* @var string Last called function payload
|
||||
*/
|
||||
private $lastCalledFunctionPayload;
|
||||
|
||||
/**
|
||||
* @var string Last called function name
|
||||
*/
|
||||
private $lastCalledFunctionName;
|
||||
|
||||
/**
|
||||
* @var array Last called function arguments
|
||||
*/
|
||||
private $lastCalledFunctionArgs = array();
|
||||
|
||||
/**
|
||||
* Current file name
|
||||
*/
|
||||
const FILENAME = 'dpdpoland.ws';
|
||||
|
||||
/**
|
||||
* Debug file name setting name
|
||||
*/
|
||||
const DEBUG_FILENAME = 'DPDPOLAND_DEBUG_FILENAME';
|
||||
|
||||
/**
|
||||
* Bool Debug data should be displayed in PopUp window or logs file
|
||||
*/
|
||||
const DEBUG_POPUP = false;
|
||||
|
||||
/**
|
||||
* Debug file name symbols count
|
||||
*/
|
||||
const DEBUG_FILENAME_LENGTH = 16;
|
||||
|
||||
/**
|
||||
* DpdPolandWS class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$settings = new DpdPolandConfiguration;
|
||||
|
||||
$this->params = array(
|
||||
'authDataV1' => array(
|
||||
'login' => $settings->login,
|
||||
'masterFid' => $settings->customer_fid,
|
||||
'password' => $settings->password
|
||||
)
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
$this->client = new SoapClient($settings->ws_url, array('trace' => true));
|
||||
return $this->client;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
DpdPolandLog::addError('URL: '.$settings->ws_url.' - '.$e->getMessage());
|
||||
self::$errors[] = $e->getMessage();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function used to make a request via WebServices
|
||||
*
|
||||
* @param string $function_name Function name
|
||||
* @param array $arguments Function arguments
|
||||
* @return array|bool Response
|
||||
*/
|
||||
public function __call($function_name, $arguments)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
$this->lastCalledFunctionName = $function_name;
|
||||
$this->lastCalledFunctionArgs = $arguments;
|
||||
|
||||
if (isset($arguments[0]) && is_array($arguments[0]))
|
||||
{
|
||||
$this->params = array_merge($this->params, $arguments[0]);
|
||||
|
||||
try
|
||||
{
|
||||
if (!$result = $this->client->$function_name($this->params))
|
||||
self::$errors[] = $this->l('Could not connect to webservice server. Please check webservice URL');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
DpdPolandLog::addError('function_name: '.$function_name.' - message: '.$e->getMessage());
|
||||
self::$errors[] = $e->getMessage();
|
||||
}
|
||||
|
||||
if (isset($result->return))
|
||||
$result = $result->return;
|
||||
|
||||
if (isset($result->faultstring))
|
||||
self::$errors[] = $result->faultstring;
|
||||
|
||||
if (_DPDPOLAND_DEBUG_MODE_)
|
||||
$this->debug($result);
|
||||
|
||||
return $this->objectToArray($result);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response should be used as array
|
||||
*
|
||||
* @param object|array $response Response from WebServices
|
||||
* @return array Formatted response
|
||||
*/
|
||||
private function objectToArray($response)
|
||||
{
|
||||
if (!is_object($response) && !is_array($response))
|
||||
return $response;
|
||||
|
||||
return array_map(array($this, 'objectToArray'), (array)$response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates debug file if it is still not created
|
||||
*
|
||||
* @return string Debug file name
|
||||
*/
|
||||
private function createDebugFileIfNotExists()
|
||||
{
|
||||
if ((!$debug_filename = Configuration::get(self::DEBUG_FILENAME)) || !$this->isDebugFileName($debug_filename))
|
||||
{
|
||||
$debug_filename = Tools::passwdGen(self::DEBUG_FILENAME_LENGTH).'.html';
|
||||
Configuration::updateValue(self::DEBUG_FILENAME, $debug_filename);
|
||||
}
|
||||
|
||||
if (!file_exists(_DPDPOLAND_MODULE_DIR_.$debug_filename))
|
||||
{
|
||||
$file = fopen(_DPDPOLAND_MODULE_DIR_.$debug_filename, 'w');
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
return $debug_filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if string can be used as debug file name
|
||||
*
|
||||
* @param string $debug_filename Debug file name
|
||||
* @return bool String can be used as debug file name
|
||||
*/
|
||||
private function isDebugFileName($debug_filename)
|
||||
{
|
||||
return Tools::strlen($debug_filename) == (int)self::DEBUG_FILENAME_LENGTH + 5 && preg_match('#^[a-zA-Z0-9]+\.html$#', $debug_filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds data into debug file
|
||||
*
|
||||
* @param null $result Request / Response / Errors from / to WebsServices
|
||||
*/
|
||||
private function debug($result = null)
|
||||
{
|
||||
$debug_html = '';
|
||||
|
||||
if ($this->lastCalledFunctionName)
|
||||
{
|
||||
$debug_html .= '<h2 style="padding: 10px 0 10px 0; display: block; border-top: solid 2px #000000; border-bottom: solid 2px #000000;">
|
||||
['.date('Y-m-d H:i:s').']</h2><h2>Function \''.$this->lastCalledFunctionName.'\' params
|
||||
</h2><pre>';
|
||||
$debug_html .= print_r($this->lastCalledFunctionArgs, true);
|
||||
$debug_html .= '</pre>';
|
||||
}
|
||||
|
||||
if ($this->lastCalledFunctionPayload = (string)$this->client->__getLastRequest())
|
||||
$debug_html .= '<h2>Request</h2><pre>'.$this->displayPayload().'</pre>';
|
||||
|
||||
if ($result)
|
||||
{
|
||||
if ($err = $this->getError())
|
||||
$debug_html .= '<h2>Error</h2><pre>'.$err.'</pre>';
|
||||
else
|
||||
{
|
||||
$result = print_r($result, true);
|
||||
|
||||
$debug_html .= '<h2>Response</h2><pre>';
|
||||
$debug_html .= strip_tags($result);
|
||||
$debug_html .= '</pre>';
|
||||
}
|
||||
}
|
||||
else
|
||||
$debug_html .= '<h2>Errors</h2><pre>'.print_r(self::$errors, true).'</pre>';
|
||||
|
||||
if ($debug_html)
|
||||
{
|
||||
$debug_filename = $this->createDebugFileIfNotExists();
|
||||
|
||||
$current_content = Tools::file_get_contents(_DPDPOLAND_MODULE_DIR_.$debug_filename);
|
||||
@file_put_contents(_DPDPOLAND_MODULE_DIR_.$debug_filename, $debug_html.$current_content, LOCK_EX);
|
||||
|
||||
if (self::DEBUG_POPUP)
|
||||
{
|
||||
echo '
|
||||
<div id="_invertus_ws_console" style="display:none">
|
||||
'.$debug_html.'
|
||||
</div>
|
||||
<script language=javascript>
|
||||
_invertus_ws_console = window.open("","Invertus WS debugging console","width=680,height=600,resizable,scrollbars=yes");
|
||||
_invertus_ws_console.document.write("<HTML><TITLE>Invertus WS debugging console</TITLE><BODY bgcolor=#ffffff>");
|
||||
_invertus_ws_console.document.write(document.getElementById("_invertus_ws_console").innerHTML);
|
||||
_invertus_ws_console.document.write("</BODY></HTML>");
|
||||
_invertus_ws_console.document.close();
|
||||
document.getElementById("_invertus_ws_console").remove();
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only for debugging purposes
|
||||
*
|
||||
* @return string Last called function payload
|
||||
*/
|
||||
private function displayPayload()
|
||||
{
|
||||
$xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $this->lastCalledFunctionPayload);
|
||||
$token = strtok($xml, "\n");
|
||||
$result = '';
|
||||
$pad = 0;
|
||||
$matches = array();
|
||||
while ($token !== false)
|
||||
{
|
||||
if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches))
|
||||
$indent = 0;
|
||||
elseif (preg_match('/^<\/\w/', $token, $matches))
|
||||
{
|
||||
$pad -= 4;
|
||||
$indent = 0;
|
||||
}
|
||||
elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches))
|
||||
$indent = 4;
|
||||
else
|
||||
$indent = 0;
|
||||
|
||||
$line = str_pad($token, Tools::strlen($token) + $pad, ' ', STR_PAD_LEFT);
|
||||
$result .= $line."\n";
|
||||
$token = strtok("\n");
|
||||
$pad += $indent;
|
||||
}
|
||||
|
||||
return htmlentities($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user