first commit
This commit is contained in:
280
modules/dpdpoland/classes/CSV.php
Normal file
280
modules/dpdpoland/classes/CSV.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?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 DpdPolandCSV Responsible for prices import management
|
||||
*/
|
||||
class DpdPolandCSV extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Shop ID
|
||||
*/
|
||||
public $id_shop;
|
||||
|
||||
/**
|
||||
* @var datetime Date when price rule was created
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when price rule was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var int CSV rule ID
|
||||
*/
|
||||
public $id_csv;
|
||||
|
||||
/**
|
||||
* @var string Country ISO code
|
||||
*/
|
||||
public $iso_country;
|
||||
|
||||
/**
|
||||
* @var float Price from which price rule is applied
|
||||
*/
|
||||
public $price_from;
|
||||
|
||||
/**
|
||||
* @var float Price to which price rule is applied
|
||||
*/
|
||||
public $price_to;
|
||||
|
||||
/**
|
||||
* @var float Weight from which price rule is applied
|
||||
*/
|
||||
public $weight_from;
|
||||
|
||||
/**
|
||||
* @var float Weight to which price rule is applied
|
||||
*/
|
||||
public $weight_to;
|
||||
|
||||
/**
|
||||
* @var float Shipment price
|
||||
*/
|
||||
public $parcel_price;
|
||||
|
||||
/**
|
||||
* @var int DPD service (carrier) ID
|
||||
*/
|
||||
public $id_carrier;
|
||||
|
||||
/**
|
||||
* @var float Additional COD carrier price
|
||||
*/
|
||||
public $cod_price;
|
||||
|
||||
/**
|
||||
* Country column number in CSV file
|
||||
*/
|
||||
const COLUMN_COUNTRY = 0;
|
||||
|
||||
/**
|
||||
* Price From column number in CSV file
|
||||
*/
|
||||
const COLUMN_PRICE_FROM = 1;
|
||||
|
||||
/**
|
||||
* Price To column number in CSV file
|
||||
*/
|
||||
const COLUMN_PRICE_TO = 2;
|
||||
|
||||
/**
|
||||
* Weight From column number in CSV file
|
||||
*/
|
||||
const COLUMN_WEIGHT_FROM = 3;
|
||||
|
||||
/**
|
||||
* Weight To column number in CSV file
|
||||
*/
|
||||
const COLUMN_WEIGHT_TO = 4;
|
||||
|
||||
/**
|
||||
* Shipment price column number in CSV file
|
||||
*/
|
||||
const COLUMN_PARCEL_PRICE = 5;
|
||||
|
||||
/**
|
||||
* Carrier ID column number in CSV file
|
||||
*/
|
||||
const COLUMN_CARRIER = 6;
|
||||
|
||||
/**
|
||||
* COD additional price column number in CSV file
|
||||
*/
|
||||
const COLUMN_COD_PRICE = 7;
|
||||
|
||||
/**
|
||||
* File upload field name
|
||||
*/
|
||||
const CSV_FILE = 'DPD_GEOPOST_CSV_FILE';
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_PRICE_RULE_DB_,
|
||||
'primary' => 'id_csv',
|
||||
'multilang' => false,
|
||||
'multishop' => true,
|
||||
'fields' => array(
|
||||
'id_csv' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'iso_country' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'price_from' => array('type' => self::TYPE_STRING, 'validate' => 'isFloat'),
|
||||
'price_to' => array('type' => self::TYPE_STRING, 'validate' => 'isFloat'),
|
||||
'weight_from' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'weight_to' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'parcel_price' => array('type' => self::TYPE_STRING, 'validate' => 'isFloat'),
|
||||
'cod_price' => array('type' => self::TYPE_STRING, 'validate' => 'isFloat'),
|
||||
'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects data from database about price rules
|
||||
*
|
||||
* @param string|int $start From which element data should be taken
|
||||
* @param string|int $limit How many elements should be taken
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Price rules data
|
||||
*/
|
||||
public static function getAllData($start = '', $limit = '')
|
||||
{
|
||||
return DB::getInstance()->executeS('
|
||||
SELECT `id_csv`, `iso_country`, `price_from`, `price_to`, `weight_from`, `weight_to`, `parcel_price`,
|
||||
`cod_price`, `id_carrier`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PRICE_RULE_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
'.($start && $limit ? 'LIMIT '.(int)$start.', '.(int)$limit : '')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all price rules for current shop
|
||||
*
|
||||
* @return bool Price rules deleted successfully
|
||||
*/
|
||||
public static function deleteAllData()
|
||||
{
|
||||
return DB::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_._DPDPOLAND_PRICE_RULE_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects price rules data of current shop
|
||||
*
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Price rules data
|
||||
*/
|
||||
public static function getCSVData()
|
||||
{
|
||||
return DB::getInstance()->executeS('
|
||||
SELECT `iso_country`, `price_from`, `price_to`, `weight_from`, `weight_to`, `parcel_price`, `id_carrier`,
|
||||
`cod_price`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PRICE_RULE_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns carrier price according to cart products / parameters
|
||||
*
|
||||
* @param float $total_weight Sum of products weight
|
||||
* @param int $id_carrier Carrier ID
|
||||
* @param Cart $cart Cart object
|
||||
* @return bool|int|float Carrier price
|
||||
*/
|
||||
public static function getPrice($total_weight, $id_carrier, Cart $cart)
|
||||
{
|
||||
if ($id_country = (int)Tools::getValue('id_country'))
|
||||
$iso_country = Country::getIsoById($id_country);
|
||||
else
|
||||
{
|
||||
$address = new Address((int)$cart->id_address_delivery);
|
||||
$iso_country = Country::getIsoById((int)$address->id_country);
|
||||
}
|
||||
|
||||
if(!$iso_country)
|
||||
$iso_country = 'PL';
|
||||
|
||||
$cart_total_price = $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
|
||||
$id_currency_pl = Currency::getIdByIsoCode(_DPDPOLAND_CURRENCY_ISO_, (int)Context::getContext()->shop->id);
|
||||
$currency_from = new Currency((int)$cart->id_currency);
|
||||
$currency_to = new Currency((int)$id_currency_pl);
|
||||
$cart_total_price = Tools::convertPriceFull($cart_total_price, $currency_from, $currency_to);
|
||||
|
||||
$price_rules = DB::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PRICE_RULE_DB_.'`
|
||||
WHERE (`iso_country` = "'.pSQL($iso_country).'" OR `iso_country` = "*")
|
||||
AND (`weight_from` <= "'.pSQL($total_weight).'"
|
||||
AND `weight_to` >= "'.pSQL($total_weight).'"
|
||||
OR `price_from` <= "'.pSQL($cart_total_price).'"
|
||||
AND `price_to` >= "'.pSQL($cart_total_price).'")
|
||||
AND `id_carrier` = "'.(int)$id_carrier.'"
|
||||
AND `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
');
|
||||
|
||||
if (!$price_rules)
|
||||
return false;
|
||||
|
||||
$available_prices_count = count($price_rules);
|
||||
|
||||
for ($i = 0; $i < $available_prices_count; $i++)
|
||||
if ($price_rules[$i]['iso_country'] != '*' && !Country::getByIso($price_rules[$i]['iso_country'])) //if country is not deleted
|
||||
unset($price_rules[$i]);
|
||||
|
||||
if (!$price_rules)
|
||||
return false;
|
||||
|
||||
$matching_price_rule = null;
|
||||
if (is_array($price_rules)) {
|
||||
foreach ($price_rules as $price_rule) {
|
||||
if ($price_rule['price_from'] <= $cart_total_price &&
|
||||
$price_rule['price_to'] > $cart_total_price &&
|
||||
$price_rule['weight_from'] <= $total_weight &&
|
||||
$price_rule['weight_to'] > $total_weight
|
||||
) {
|
||||
$matching_price_rule = $price_rule;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null == $matching_price_rule) {
|
||||
$matching_price_rule = $price_rules[0]; //accept first matching rule
|
||||
}
|
||||
|
||||
if (!$matching_price_rule['cod_price'])
|
||||
$matching_price_rule['cod_price'] = 0; //CSV validation allows empty value of COD price
|
||||
|
||||
$price = $matching_price_rule['parcel_price'];
|
||||
|
||||
if ($id_carrier == _DPDPOLAND_STANDARD_COD_ID_)
|
||||
$price += $matching_price_rule['cod_price'];
|
||||
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
100
modules/dpdpoland/classes/Carrier.php
Normal file
100
modules/dpdpoland/classes/Carrier.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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 DpdPolandCarrier Responsible for DPD services (carriers) creation / deletion
|
||||
*/
|
||||
class DpdPolandCarrier extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int DPD carrier ID
|
||||
*/
|
||||
public $id_dpdpoland_carrier;
|
||||
|
||||
/**
|
||||
* @var int Carrier ID in DPD system
|
||||
*/
|
||||
public $id_carrier;
|
||||
|
||||
/**
|
||||
* @var int Carrier reference
|
||||
*/
|
||||
public $id_reference;
|
||||
|
||||
/**
|
||||
* @var datetime Date when carrier was created
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when carrier was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_CARRIER_DB_,
|
||||
'primary' => 'id_dpdpoland_carrier',
|
||||
'multilang_shop' => true,
|
||||
'multishop' => true,
|
||||
'fields' => array(
|
||||
'id_dpdpoland_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_reference' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns carrier reference according to it's current ID
|
||||
*
|
||||
* @param int $id_carrier Carrier ID
|
||||
* @return false|null|string Carrier reference
|
||||
*/
|
||||
public static function getReferenceByIdCarrier($id_carrier)
|
||||
{
|
||||
return DB::getInstance()->getValue('
|
||||
SELECT `id_reference`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_CARRIER_DB_.'`
|
||||
WHERE `id_carrier` = "'.(int)$id_carrier.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns carrier newest ID according to it's reference
|
||||
*
|
||||
* @param int $id_reference Carrier reference
|
||||
* @return false|null|string Carrier ID
|
||||
*/
|
||||
public static function getIdCarrierByReference($id_reference)
|
||||
{
|
||||
return DB::getInstance()->getValue('
|
||||
SELECT MAX(`id_carrier`)
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_CARRIER_DB_.'`
|
||||
WHERE `id_reference` = "'.(int)$id_reference.'"
|
||||
');
|
||||
}
|
||||
}
|
||||
459
modules/dpdpoland/classes/Configuration.php
Normal file
459
modules/dpdpoland/classes/Configuration.php
Normal file
@@ -0,0 +1,459 @@
|
||||
<?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 DpdPolandConfiguration Responsible for module settings management
|
||||
*/
|
||||
class DpdPolandConfiguration
|
||||
{
|
||||
const WSDL_URL_LIVE = 'https://dpdservices.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?wsdl';
|
||||
const WSDL_URL_DEMO = 'https://dpdservicesdemo.dpd.com.pl/DPDPackageObjServicesService/DPDPackageObjServices?wsdl';
|
||||
const LOGIN = 'DPDPOLAND_LOGIN';
|
||||
const PASSWORD = 'DPDPOLAND_PASSWORD';
|
||||
const CLIENT_NUMBER = 'DPDPOLAND_CLIENT_NUMBER';
|
||||
const CLIENT_NAME = 'DPDPOLAND_CLIENT_NAME';
|
||||
const NAME_SURNAME = 'DPDPOLAND_NAME_SURNAME';
|
||||
const ADDRESS = 'DPDPOLAND_ADDRESS';
|
||||
const POSTCODE = 'DPDPOLAND_POSTCODE';
|
||||
const CITY = 'DPDPOLAND_CITY';
|
||||
const EMAIL = 'DPDPOLAND_EMAIL';
|
||||
const PHONE = 'DPDPOLAND_PHONE';
|
||||
|
||||
const CARRIER_STANDARD = 'DPDPOLAND_CARRIER_STANDARD';
|
||||
const CARRIER_STANDARD_COD = 'DPDPOLAND_CARRIER_STANDARD_COD';
|
||||
const CARRIER_CLASSIC = 'DPDPOLAND_CARRIER_CLASSIC';
|
||||
const CARRIER_PUDO = 'DPDPOLAND_CARRIER_PUDO';
|
||||
|
||||
const PRICE_CALCULATION_TYPE = 'DPDPOLAND_PRICE_CALCULATION';
|
||||
|
||||
const WEIGHT_CONVERSATION_RATE = 'DPDPOLAND_WEIGHT_RATE';
|
||||
const DIMENSION_CONVERSATION_RATE = 'DPDPOLAND_DIMENSION_RATE';
|
||||
const WS_URL = 'DPDPOLAND_WS_URL';
|
||||
|
||||
const CARRIER_STANDARD_ID = 'DPDPOLAND_STANDARD_ID';
|
||||
const CARRIER_STANDARD_COD_ID = 'DPDPOLAND_STANDARD_COD_ID';
|
||||
const CARRIER_CLASSIC_ID = 'DPDPOLAND_CLASSIC_ID';
|
||||
const CARRIER_PUDO_ID = 'DPDPOLAND_PUDO_ID';
|
||||
|
||||
const CUSTOMER_COMPANY = 'DPDPOLAND_CUSTOMER_COMPANY';
|
||||
const CUSTOMER_NAME = 'DPDPOLAND_CUSTOMER_NAME';
|
||||
const CUSTOMER_PHONE = 'DPDPOLAND_CUSTOMER_PHONE';
|
||||
const CUSTOMER_FID = 'DPDPOLAND_CUSTOMER_FID';
|
||||
|
||||
const FILE_NAME = 'Configuration';
|
||||
const MEASUREMENT_ROUND_VALUE = 6;
|
||||
const COD_MODULE_PREFIX = 'DPDPOLAND_COD_';
|
||||
const PRICE_CALCULATION_CSV = 'csv_calculation';
|
||||
const PRICE_CALCULATION_PRESTASHOP = 'prestashop_calculation';
|
||||
|
||||
const PRINTOUT_FORMAT_A4 = 'A4';
|
||||
const PRINTOUT_FORMAT_LABEL = 'LBL_PRINTER';
|
||||
|
||||
const ADDITIONAL_REF1 = 'DPDPOLAND_ADDITIONAL_REF1';
|
||||
const ADDITIONAL_REF2 = 'DPDPOLAND_ADDITIONAL_REF2';
|
||||
const ADDITIONAL_CUSTOMER_DATA_1 = 'DPDPOLAND_ADDITIONAL_DATA_1';
|
||||
|
||||
const ADDITIONAL_TYPE_NONE = 'DPDPOLAND_NONE';
|
||||
const ADDITIONAL_TYPE_DYNAMIC = 'DPDPOLAND_DYNAMIC';
|
||||
const ADDITIONAL_TYPE_STATIC = 'DPDPOLAND_STATIC';
|
||||
|
||||
const REF1_DYNAMIC = 'DPDPOLAND_REF1_DYNAMIC';
|
||||
const REF1_STATIC = 'DPDPOLAND_REF1_STATIC';
|
||||
const REF2_DYNAMIC = 'DPDPOLAND_REF2_DYNAMIC';
|
||||
const REF2_STATIC = 'DPDPOLAND_REF2_STATIC';
|
||||
const CUSTOMER_DATA_DYNAMIC = 'DPDPOLAND_CUSTOMER_DATA_DYNAMIC';
|
||||
const CUSTOMER_DATA_STATIC = 'DPDPOLAND_CUSTOMER_DATA_STATIC';
|
||||
|
||||
const DYNAMIC_ORDER_ID = 'DPDPOLAND_DYNAMIC_ORDER_ID';
|
||||
const DYNAMIC_ORDER_REFERENCE = 'DPDPOLAND_DYNAMIC_ORDER_REF';
|
||||
const DYNAMIC_INVOICE_ID = 'DPDPOLAND_DYNAMIC_INVOICE_ID';
|
||||
const DYNAMIC_SHIPPING_ADDRESS = 'DPDPOLAND_DYNAMIC_SHIPPING';
|
||||
|
||||
const DECLARED_VALUE = 'DPDPOLAND_DECLARED_VALUE';
|
||||
const CUD = 'DPDPOLAND_CUD';
|
||||
const ROD = 'DPDPOLAND_ROD';
|
||||
const DPDE = 'DPDPOLAND_DPDE';
|
||||
const DPDND = 'DPDPOLAND_DPDND';
|
||||
const DUTY = 'DPDPOLAND_DUTY';
|
||||
const LOG_MODE = 'DPDPOLAND_LOG_MODE';
|
||||
const DISABLE_SEND_SHIPPING_MAIL = 'DPDPOLAND_DISABLE_SEND_SHIPPING_MAIL';
|
||||
|
||||
|
||||
public $login = '';
|
||||
public $password = '';
|
||||
public $client_number = '';
|
||||
public $client_name = '';
|
||||
public $customer_name = '';
|
||||
public $customer_company = '';
|
||||
public $customer_phone = '';
|
||||
public $customer_fid = '';
|
||||
public $price_calculation_type = self::PRICE_CALCULATION_PRESTASHOP;
|
||||
public $carrier_standard = 0;
|
||||
public $carrier_standard_cod = 0;
|
||||
public $carrier_classic = 0;
|
||||
public $carrier_pudo = 0;
|
||||
public $weight_conversation_rate = 1;
|
||||
public $dimension_conversation_rate = 1;
|
||||
public $ws_url = '';
|
||||
|
||||
public $ref1 = self::ADDITIONAL_TYPE_DYNAMIC;
|
||||
public $ref2 = self::ADDITIONAL_TYPE_DYNAMIC;
|
||||
public $customer_data_1 = self::ADDITIONAL_TYPE_NONE;
|
||||
|
||||
public $ref1_dynamic = self::DYNAMIC_ORDER_ID;
|
||||
public $ref2_dynamic = self::DYNAMIC_INVOICE_ID;
|
||||
public $customer_data_dynamic = self::DYNAMIC_SHIPPING_ADDRESS;
|
||||
|
||||
public $ref1_static = '';
|
||||
public $ref2_static = '';
|
||||
public $customer_data_static = '';
|
||||
|
||||
public $declared_value = 0;
|
||||
public $cud = 0;
|
||||
public $rod = 0;
|
||||
public $dpde = 0;
|
||||
public $dpdnd = 0;
|
||||
public $duty = 0;
|
||||
public $log_mode = '';
|
||||
public $disable_send_shipping_mail = '';
|
||||
|
||||
/**
|
||||
* DpdPolandConfiguration class constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves module settings into database
|
||||
*
|
||||
* @return bool Module settings saved successfully
|
||||
*/
|
||||
public static function saveConfiguration()
|
||||
{
|
||||
$success = true;
|
||||
|
||||
$success &= Configuration::updateValue(self::LOGIN, Tools::getValue(self::LOGIN));
|
||||
$success &= Configuration::updateValue(self::PASSWORD, Tools::getValue(self::PASSWORD));
|
||||
$success &= Configuration::updateValue(self::CLIENT_NUMBER, Tools::getValue(self::CLIENT_NUMBER));
|
||||
|
||||
$client_name = DB::getInstance()->getValue('
|
||||
SELECT `name`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PAYER_NUMBERS_DB_ . '`
|
||||
WHERE `payer_number` = "' . pSQL(Configuration::get(self::CLIENT_NUMBER)) . '"
|
||||
AND `id_shop` = "' . (int)Context::getContext()->shop->id . '"
|
||||
');
|
||||
|
||||
$success &= Configuration::updateValue(self::CLIENT_NAME, $client_name);
|
||||
$success &= Configuration::updateValue(self::NAME_SURNAME, Tools::getValue(self::NAME_SURNAME));
|
||||
$success &= Configuration::updateValue(self::ADDRESS, Tools::getValue(self::ADDRESS));
|
||||
$success &= Configuration::updateValue(self::POSTCODE, Tools::getValue(self::POSTCODE));
|
||||
$success &= Configuration::updateValue(self::CITY, Tools::getValue(self::CITY));
|
||||
$success &= Configuration::updateValue(self::EMAIL, Tools::getValue(self::EMAIL));
|
||||
$success &= Configuration::updateValue(self::PHONE, Tools::getValue(self::PHONE));
|
||||
$success &= Configuration::updateValue(self::CUSTOMER_COMPANY, Tools::getValue(self::CUSTOMER_COMPANY));
|
||||
$success &= Configuration::updateValue(self::CUSTOMER_NAME, Tools::getValue(self::CUSTOMER_NAME));
|
||||
$success &= Configuration::updateValue(self::CUSTOMER_PHONE, Tools::getValue(self::CUSTOMER_PHONE));
|
||||
$success &= Configuration::updateValue(self::CUSTOMER_FID, Tools::getValue(self::CUSTOMER_FID));
|
||||
$success &= Configuration::updateValue(self::PRICE_CALCULATION_TYPE, Tools::getValue(self::PRICE_CALCULATION_TYPE));
|
||||
$success &= Configuration::updateValue(self::CARRIER_STANDARD, (int)Tools::isSubmit(self::CARRIER_STANDARD));
|
||||
$success &= Configuration::updateValue(self::CARRIER_STANDARD_COD, (int)Tools::isSubmit(self::CARRIER_STANDARD_COD));
|
||||
$success &= Configuration::updateValue(self::CARRIER_CLASSIC, (int)Tools::isSubmit(self::CARRIER_CLASSIC));
|
||||
$success &= Configuration::updateValue(self::CARRIER_PUDO, (int)Tools::isSubmit(self::CARRIER_PUDO));
|
||||
$success &= Configuration::updateValue(self::WEIGHT_CONVERSATION_RATE, Tools::getValue(self::WEIGHT_CONVERSATION_RATE));
|
||||
$success &= Configuration::updateValue(self::DIMENSION_CONVERSATION_RATE, Tools::getValue(self::DIMENSION_CONVERSATION_RATE));
|
||||
$success &= Configuration::updateValue(self::WS_URL, Tools::getValue(self::WS_URL));
|
||||
|
||||
$success &= Configuration::updateValue(self::ADDITIONAL_REF1, Tools::getValue(self::ADDITIONAL_REF1));
|
||||
$success &= Configuration::updateValue(self::ADDITIONAL_REF2, Tools::getValue(self::ADDITIONAL_REF2));
|
||||
$success &= Configuration::updateValue(self::ADDITIONAL_CUSTOMER_DATA_1, Tools::getValue(self::ADDITIONAL_CUSTOMER_DATA_1));
|
||||
|
||||
$success &= Configuration::updateValue(self::REF1_DYNAMIC, Tools::getValue(self::REF1_DYNAMIC));
|
||||
$success &= Configuration::updateValue(self::REF2_DYNAMIC, Tools::getValue(self::REF2_DYNAMIC));
|
||||
$success &= Configuration::updateValue(self::CUSTOMER_DATA_DYNAMIC, Tools::getValue(self::CUSTOMER_DATA_DYNAMIC));
|
||||
|
||||
$success &= Configuration::updateValue(self::REF1_STATIC, Tools::getValue(self::REF1_STATIC));
|
||||
$success &= Configuration::updateValue(self::REF2_STATIC, Tools::getValue(self::REF2_STATIC));
|
||||
$success &= Configuration::updateValue(self::CUSTOMER_DATA_STATIC, Tools::getValue(self::CUSTOMER_DATA_STATIC));
|
||||
$success &= Configuration::updateValue(self::DECLARED_VALUE, Tools::getValue(self::DECLARED_VALUE));
|
||||
$success &= Configuration::updateValue(self::CUD, Tools::getValue(self::CUD));
|
||||
$success &= Configuration::updateValue(self::ROD, Tools::getValue(self::ROD));
|
||||
$success &= Configuration::updateValue(self::DPDE, Tools::getValue(self::DPDE));
|
||||
$success &= Configuration::updateValue(self::DPDND, Tools::getValue(self::DPDND));
|
||||
$success &= Configuration::updateValue(self::DUTY, Tools::getValue(self::DUTY));
|
||||
$success &= Configuration::updateValue(self::LOG_MODE, Tools::getValue(self::LOG_MODE));
|
||||
$success &= Configuration::updateValue(self::DISABLE_SEND_SHIPPING_MAIL, Tools::getValue(self::DISABLE_SEND_SHIPPING_MAIL));
|
||||
|
||||
foreach (DpdPoland::getPaymentModules() as $payment_module)
|
||||
$success &= Configuration::updateValue(
|
||||
self::COD_MODULE_PREFIX . $payment_module['name'], (int)Tools::isSubmit(self::COD_MODULE_PREFIX . $payment_module['name'])
|
||||
);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects settings from database
|
||||
* Assigns settings values for class variables
|
||||
*/
|
||||
private function getSettings()
|
||||
{
|
||||
$this->login = $this->getSetting(self::LOGIN, $this->login);
|
||||
$this->password = $this->getSetting(self::PASSWORD, $this->password);
|
||||
$this->client_number = $this->getSetting(self::CLIENT_NUMBER, $this->client_number);
|
||||
$this->client_name = $this->getSetting(self::CLIENT_NAME, $this->client_name);
|
||||
$this->customer_company = $this->getSetting(self::CUSTOMER_COMPANY, $this->customer_company);
|
||||
$this->customer_name = $this->getSetting(self::CUSTOMER_NAME, $this->customer_name);
|
||||
$this->customer_phone = $this->getSetting(self::CUSTOMER_PHONE, $this->customer_phone);
|
||||
$this->customer_fid = $this->getSetting(self::CUSTOMER_FID, $this->customer_fid);
|
||||
$this->price_calculation_type = $this->getSetting(self::PRICE_CALCULATION_TYPE, $this->price_calculation_type);
|
||||
$this->carrier_standard = $this->getSetting(self::CARRIER_STANDARD, $this->carrier_standard);
|
||||
$this->carrier_standard_cod = $this->getSetting(self::CARRIER_STANDARD_COD, $this->carrier_standard_cod);
|
||||
$this->carrier_classic = $this->getSetting(self::CARRIER_CLASSIC, $this->carrier_classic);
|
||||
$this->carrier_pudo = $this->getSetting(self::CARRIER_PUDO, $this->carrier_pudo);
|
||||
$this->weight_conversation_rate = $this->getSetting(self::WEIGHT_CONVERSATION_RATE, $this->weight_conversation_rate);
|
||||
$this->dimension_conversation_rate = $this->getSetting(self::DIMENSION_CONVERSATION_RATE, $this->dimension_conversation_rate);
|
||||
$this->ws_url = $this->getSetting(self::WS_URL, $this->ws_url);
|
||||
|
||||
$this->ref1 = $this->getSetting(self::ADDITIONAL_REF1, $this->ref1);
|
||||
$this->ref2 = $this->getSetting(self::ADDITIONAL_REF2, $this->ref2);
|
||||
$this->customer_data_1 = $this->getSetting(self::ADDITIONAL_CUSTOMER_DATA_1, $this->customer_data_1);
|
||||
|
||||
$this->ref1_dynamic = $this->getSetting(self::REF1_DYNAMIC, $this->ref1_dynamic);
|
||||
$this->ref2_dynamic = $this->getSetting(self::REF2_DYNAMIC, $this->ref2_dynamic);
|
||||
$this->customer_data_dynamic = $this->getSetting(self::CUSTOMER_DATA_DYNAMIC, $this->customer_data_dynamic);
|
||||
|
||||
$this->ref1_static = $this->getSetting(self::REF1_STATIC, $this->ref1_static);
|
||||
$this->ref2_static = $this->getSetting(self::REF2_STATIC, $this->ref2_static);
|
||||
$this->customer_data_static = $this->getSetting(self::CUSTOMER_DATA_STATIC, $this->customer_data_static);
|
||||
$this->declared_value = $this->getSetting(self::DECLARED_VALUE, $this->declared_value);
|
||||
$this->cud = $this->getSetting(self::CUD, $this->cud);
|
||||
$this->rod = $this->getSetting(self::ROD, $this->rod);
|
||||
$this->dpde = $this->getSetting(self::DPDE, $this->dpde);
|
||||
$this->dpdnd = $this->getSetting(self::DPDND, $this->dpdnd);
|
||||
$this->duty = $this->getSetting(self::DUTY, $this->duty);
|
||||
$this->log_mode = $this->getSetting(self::LOG_MODE, $this->log_mode);
|
||||
$this->disable_send_shipping_mail = $this->getSetting(self::DISABLE_SEND_SHIPPING_MAIL, $this->disable_send_shipping_mail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a setting from database
|
||||
*
|
||||
* @param string $name Setting name
|
||||
* @param string $default_value Default setting value
|
||||
* @return string Setting value
|
||||
*/
|
||||
private function getSetting($name, $default_value)
|
||||
{
|
||||
return Configuration::get($name) !== false ? Configuration::get($name) : $default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes settings from database
|
||||
*
|
||||
* @return bool Settings deleted successfully
|
||||
*/
|
||||
public static function deleteConfiguration()
|
||||
{
|
||||
$success = true;
|
||||
|
||||
$success &= self::deleteByNames(array(
|
||||
self::LOGIN, self::PASSWORD, self::CLIENT_NUMBER, self::CLIENT_NAME, self::NAME_SURNAME, self::ADDRESS,
|
||||
self::POSTCODE, self::CITY, self::EMAIL, self::PHONE, self::CUSTOMER_COMPANY, self::CUSTOMER_NAME, self::CUSTOMER_PHONE,
|
||||
self::CUSTOMER_FID, self::PRICE_CALCULATION_TYPE, self::CARRIER_STANDARD, self::CARRIER_STANDARD_COD,
|
||||
self::CARRIER_CLASSIC, self::WEIGHT_CONVERSATION_RATE, self::DIMENSION_CONVERSATION_RATE, self::WS_URL, self::CARRIER_STANDARD_ID,
|
||||
self::CARRIER_STANDARD_COD_ID, self::CARRIER_CLASSIC_ID, self::ADDITIONAL_REF1, self::ADDITIONAL_REF2, self::ADDITIONAL_CUSTOMER_DATA_1,
|
||||
self::REF1_DYNAMIC, self::REF2_DYNAMIC, self::CUSTOMER_DATA_DYNAMIC, self::REF1_STATIC, self::REF2_STATIC, self::CUSTOMER_DATA_STATIC,
|
||||
self::CARRIER_PUDO, self::CARRIER_PUDO_ID, self::DECLARED_VALUE, self::CUD, self::ROD, self::DPDE, self::DPDND, self::DUTY, self::LOG_MODE, self::DISABLE_SEND_SHIPPING_MAIL
|
||||
));
|
||||
|
||||
foreach (DpdPoland::getPaymentModules() as $payment_module)
|
||||
$success &= Configuration::deleteByName(self::COD_MODULE_PREFIX . $payment_module['name']);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes settings from database by their names
|
||||
*
|
||||
* @param array $names Settings names list
|
||||
* @return bool Settings deleted successfully
|
||||
*/
|
||||
private static function deleteByNames($names)
|
||||
{
|
||||
$success = true;
|
||||
|
||||
foreach ($names as $name)
|
||||
$success &= Configuration::deleteByName($name);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a single setting from database
|
||||
*
|
||||
* @param string $name Setting name
|
||||
* @return bool Setting deleted successfully
|
||||
*/
|
||||
public static function deleteByName($name)
|
||||
{
|
||||
return Configuration::deleteByName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if required settings are filled
|
||||
*
|
||||
* @return bool Required settings are filled
|
||||
*/
|
||||
public static function checkRequiredConfiguration()
|
||||
{
|
||||
$configuration_obj = new DpdPolandConfiguration();
|
||||
|
||||
if (!$configuration_obj->login ||
|
||||
!$configuration_obj->password ||
|
||||
!$configuration_obj->client_number ||
|
||||
!$configuration_obj->client_name ||
|
||||
!$configuration_obj->weight_conversation_rate ||
|
||||
!$configuration_obj->dimension_conversation_rate ||
|
||||
!$configuration_obj->ws_url ||
|
||||
!$configuration_obj->customer_fid)
|
||||
return false;
|
||||
|
||||
if (DpdPolandSenderAddress::getAddressesCount() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns zones which are assigned to a carrier
|
||||
*
|
||||
* @param int $id_carrier Carrier ID
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Carrier zones
|
||||
*/
|
||||
public static function getCarrierZones($id_carrier)
|
||||
{
|
||||
return DB::getInstance()->executeS('
|
||||
SELECT `id_zone`
|
||||
FROM `' . _DB_PREFIX_ . 'carrier_zone`
|
||||
WHERE `id_carrier` = "' . (int)$id_carrier . '"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns PrestaShop zones for DPD carriers
|
||||
*
|
||||
* @return bool Zones assigned successfully
|
||||
*/
|
||||
public static function saveZonesForCarriers()
|
||||
{
|
||||
$configuration = new DpdPolandConfiguration();
|
||||
|
||||
if ($configuration->carrier_classic) {
|
||||
$id_carrier_classic = (int)Configuration::get(DpdPolandConfiguration::CARRIER_CLASSIC_ID);
|
||||
$classic_carrier_obj = DpdPolandService::getCarrierByReference((int)$id_carrier_classic);
|
||||
|
||||
if (Validate::isLoadedObject($classic_carrier_obj))
|
||||
$id_carrier_classic = $classic_carrier_obj->id;
|
||||
|
||||
if (!self::removeZonesForCarrier($id_carrier_classic) || !self::saveZoneForCarrier('classic', $id_carrier_classic))
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($configuration->carrier_pudo) {
|
||||
$id_carrier_pudo = (int)Configuration::get(DpdPolandConfiguration::CARRIER_PUDO_ID);
|
||||
$pudo_carrier_obj = DpdPolandService::getCarrierByReference((int)$id_carrier_pudo);
|
||||
|
||||
if (Validate::isLoadedObject($pudo_carrier_obj))
|
||||
$id_carrier_pudo = $pudo_carrier_obj->id;
|
||||
|
||||
if (!self::removeZonesForCarrier($id_carrier_pudo) || !self::saveZoneForCarrier('pudo', $id_carrier_pudo))
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($configuration->carrier_standard) {
|
||||
$id_carrier_standard = (int)Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_ID);
|
||||
$carrier_standard_obj = DpdPolandService::getCarrierByReference((int)$id_carrier_standard);
|
||||
|
||||
if (Validate::isLoadedObject($carrier_standard_obj))
|
||||
$id_carrier_standard = $carrier_standard_obj->id;
|
||||
|
||||
if (!self::removeZonesForCarrier($id_carrier_standard) || !self::saveZoneForCarrier('standard', $id_carrier_standard))
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($configuration->carrier_standard_cod) {
|
||||
$id_carrier_standard_cod = (int)Configuration::get(DpdPolandConfiguration::CARRIER_STANDARD_COD_ID);
|
||||
$carrier_standard_cod_obj = DpdPolandService::getCarrierByReference((int)$id_carrier_standard_cod);
|
||||
|
||||
if (Validate::isLoadedObject($carrier_standard_cod_obj))
|
||||
$id_carrier_standard_cod = $carrier_standard_cod_obj->id;
|
||||
|
||||
if (!self::removeZonesForCarrier($id_carrier_standard_cod) || !self::saveZoneForCarrier('standard_cod', $id_carrier_standard_cod))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes zones for carrier
|
||||
*
|
||||
* @param int $id_carrier Carrier ID
|
||||
* @return bool Zones removed from carrier
|
||||
*/
|
||||
private static function removeZonesForCarrier($id_carrier)
|
||||
{
|
||||
return DB::getInstance()->execute('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'carrier_zone`
|
||||
WHERE `id_carrier` = "' . (int)$id_carrier . '"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves zone for carrier into database
|
||||
*
|
||||
* @param string $type Service type
|
||||
* @param int $id_carrier Carrier ID
|
||||
* @return bool Carrier zones saved successfully
|
||||
*/
|
||||
private static function saveZoneForCarrier($type, $id_carrier)
|
||||
{
|
||||
foreach (Zone::getZones() as $zone) {
|
||||
if (Tools::getValue($type . '_' . (int)$zone['id_zone'])) {
|
||||
if (!DB::getInstance()->execute('
|
||||
INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone`
|
||||
(`id_carrier`, `id_zone`)
|
||||
VALUES
|
||||
("' . (int)$id_carrier . '", "' . (int)$zone['id_zone'] . '")
|
||||
')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
192
modules/dpdpoland/classes/Country.php
Normal file
192
modules/dpdpoland/classes/Country.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?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 DpdPolandCountry Responsible for available countries management
|
||||
*/
|
||||
class DpdPolandCountry extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Available country ID
|
||||
*/
|
||||
public $id_dpdpoland_country;
|
||||
|
||||
/**
|
||||
* @var int PrestaShop country ID
|
||||
*/
|
||||
public $id_country;
|
||||
|
||||
/**
|
||||
* @var int Shop ID
|
||||
*/
|
||||
public $id_shop;
|
||||
|
||||
/**
|
||||
* @var datetime Date when available country was added
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Last date when available country was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var Country status
|
||||
*/
|
||||
public $enabled;
|
||||
|
||||
/**
|
||||
* @var array ISO codes list of countries which are enabled by default
|
||||
*/
|
||||
public static $default_enabled_countries = array(
|
||||
'AT', 'BE', 'BA', 'BG', 'HR', 'CZ', 'DK', 'EE', 'FI', 'FR', 'GR', 'ES', 'IE', 'LT', 'LU',
|
||||
'LV', 'DE', 'NO', 'PT', 'RO', 'RS', 'SK', 'SI', 'SZ', 'SE', 'HU', 'GB', 'IT', 'NL'
|
||||
);
|
||||
|
||||
/**
|
||||
* DpdPolandCountry class constructor
|
||||
* @param null|int $id_dpdpoland_country Available country ID
|
||||
*/
|
||||
public function __construct($id_dpdpoland_country = null)
|
||||
{
|
||||
parent::__construct($id_dpdpoland_country);
|
||||
$this->id_shop = (int)Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_COUNTRY_DB_,
|
||||
'primary' => 'id_dpdpoland_country',
|
||||
'multilang_shop' => true,
|
||||
'multishop' => true,
|
||||
'fields' => array(
|
||||
'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'enabled' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects list data and prepares it to be displayed
|
||||
*
|
||||
* @param string $order_by List order by criteria
|
||||
* @param string $order_way List sorting way (ascending, descending)
|
||||
* @param string $filter Criteria by which list is filtered
|
||||
* @param int $start From which element list will be displayed
|
||||
* @param int $pagination How many elements will be displayed in list
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Collected list data
|
||||
*/
|
||||
public function getList($order_by, $order_way, $filter, $start, $pagination)
|
||||
{
|
||||
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
$countries = DB::getInstance()->executeS('
|
||||
SELECT
|
||||
c.`id_country` AS `id_country`,
|
||||
cl.`name` AS `name`,
|
||||
c.`iso_code` AS `iso_code`,
|
||||
IF(dpdc.`enabled` IS NULL, 1, dpdc.`enabled`) AS `enabled`
|
||||
FROM `'._DB_PREFIX_.'country` c
|
||||
LEFT JOIN `'._DB_PREFIX_._DPDPOLAND_COUNTRY_DB_.'` dpdc ON (dpdc.`id_country` = c.`id_country` AND dpdc.`id_shop` = "'.(int)$id_shop.'")
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = c.`id_country` AND cl.`id_lang` = "'.(int)$id_lang.'")'
|
||||
.$filter
|
||||
.($order_by && $order_way ? ' ORDER BY `'.bqSQL($order_by).'` '.pSQL($order_way) : '')
|
||||
.($start !== null && $pagination !== null ? ' LIMIT '.(int)$start.', '.(int)$pagination : '')
|
||||
);
|
||||
else
|
||||
$countries = DB::getInstance()->executeS('
|
||||
SELECT
|
||||
c.`id_country` AS `id_country`,
|
||||
cl.`name` AS `name`,
|
||||
c.`iso_code` AS `iso_code`,
|
||||
IF(dpdc.`enabled` IS NULL, 1, dpdc.`enabled`) AS `enabled`
|
||||
FROM `'._DB_PREFIX_.'country` c
|
||||
LEFT JOIN `'._DB_PREFIX_._DPDPOLAND_COUNTRY_DB_.'` dpdc ON (dpdc.`id_country` = c.`id_country` AND dpdc.`id_shop` = "'.(int)$id_shop.'")
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_shop` cs ON (cs.`id_country` = c.`id_country`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = c.`id_country` AND cl.`id_lang` = "'.(int)$id_lang.'")
|
||||
WHERE cs.`id_shop` = "'.(int)$id_shop.'" '
|
||||
.$filter
|
||||
.($order_by && $order_way ? ' ORDER BY `'.bqSQL($order_by).'` '.pSQL($order_way) : '')
|
||||
.($start !== null && $pagination !== null ? ' LIMIT '.(int)$start.', '.(int)$pagination : '')
|
||||
);
|
||||
|
||||
if (!$countries)
|
||||
$countries = array();
|
||||
|
||||
return $countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns DPD country ID according to PrestaShop country
|
||||
*
|
||||
* @param int $id_country PrestaShop country ID
|
||||
* @return false|null|string DPD country ID
|
||||
*/
|
||||
public static function getIdByCountry($id_country)
|
||||
{
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
|
||||
return DB::getInstance()->getValue('
|
||||
SELECT `id_dpdpoland_country`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_COUNTRY_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)$id_shop.'"
|
||||
AND `id_country` = "'.(int)$id_country.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects data about disabled countries
|
||||
*
|
||||
* @return array Disabled countries IDs
|
||||
*/
|
||||
public static function getDisabledCountriesIDs()
|
||||
{
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
|
||||
$countries = DB::getInstance()->executeS('
|
||||
SELECT `id_country`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_COUNTRY_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)$id_shop.'"
|
||||
AND `enabled` = "0"
|
||||
');
|
||||
|
||||
if (!$countries)
|
||||
$countries = array();
|
||||
|
||||
$countries_array = array();
|
||||
|
||||
foreach ($countries as $country)
|
||||
$countries_array[] = $country['id_country'];
|
||||
|
||||
return $countries_array;
|
||||
}
|
||||
}
|
||||
34
modules/dpdpoland/classes/Log.php
Normal file
34
modules/dpdpoland/classes/Log.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
|
||||
require_once(_DPDPOLAND_CLASSES_DIR_.'Configuration.php');
|
||||
require_once(_DPDPOLAND_MODULE_DIR_.'dpdpoland.php');
|
||||
|
||||
class DpdPolandLog
|
||||
{
|
||||
const LOG_DEBUG = 'LOG_DEBUG';
|
||||
const LOG_ERROR = 'LOG_ERROR';
|
||||
|
||||
public static function addLog($message)
|
||||
{
|
||||
if(!in_array(Configuration::get(DpdPolandConfiguration::LOG_MODE), array(self::LOG_DEBUG)))
|
||||
return;
|
||||
|
||||
$logger = new FileLogger(0);
|
||||
$logger->setFilename(_DPDPOLAND_MODULE_DIR_."/log/logs.log");
|
||||
$logger->logDebug($message);
|
||||
}
|
||||
|
||||
public static function addError($message)
|
||||
{
|
||||
if(!in_array(Configuration::get(DpdPolandConfiguration::LOG_MODE), array(self::LOG_DEBUG, self::LOG_ERROR)))
|
||||
return;
|
||||
|
||||
$logger = new FileLogger(0);
|
||||
$logger->setFilename(_DPDPOLAND_MODULE_DIR_."/log/logs.log");
|
||||
$logger->logError($message);
|
||||
}
|
||||
}
|
||||
244
modules/dpdpoland/classes/Manifest.php
Normal file
244
modules/dpdpoland/classes/Manifest.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?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 DpdPolandManifest Responsible for manifests management
|
||||
*/
|
||||
class DpdPolandManifest extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Manifest ID
|
||||
*/
|
||||
public $id_manifest;
|
||||
|
||||
/**
|
||||
* @var string Manifest ID retrieved via webservices
|
||||
*/
|
||||
public $id_manifest_ws;
|
||||
|
||||
/**
|
||||
* @var string|int Package ID
|
||||
*/
|
||||
public $id_package_ws;
|
||||
|
||||
/**
|
||||
* @var datetime Date when manifest was created
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when record about manifest was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var object Manifest WebServices instance
|
||||
*/
|
||||
private $webservice;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_MANIFEST_DB_,
|
||||
'primary' => 'id_manifest',
|
||||
'multilang' => false,
|
||||
'multishop' => false,
|
||||
'fields' => array(
|
||||
'id_manifest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_manifest_ws' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_package_ws' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects list of packages IDs
|
||||
*
|
||||
* @return array Packages IDs
|
||||
*/
|
||||
public function getPackages()
|
||||
{
|
||||
$packages_ids = array();
|
||||
|
||||
$packages = Db::getInstance()->executeS('
|
||||
SELECT `id_package_ws`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_MANIFEST_DB_.'`
|
||||
WHERE `id_manifest_ws` = "'.(int)$this->id_manifest_ws.'"
|
||||
');
|
||||
|
||||
foreach ($packages as $package)
|
||||
$packages_ids[] = $package['id_package_ws'];
|
||||
|
||||
return $packages_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects list data and prepares it to be displayed
|
||||
*
|
||||
* @param string $order_by List order by criteria
|
||||
* @param string $order_way List sorting way (ascending, descending)
|
||||
* @param string $filter Criteria by which list is filtered
|
||||
* @param int $start From which element list will be displayed
|
||||
* @param int $pagination How many elements will be displayed in list
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Collected list data
|
||||
*/
|
||||
public function getList($order_by, $order_way, $filter, $start, $pagination)
|
||||
{
|
||||
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT m.`id_manifest_ws` AS `id_manifest_ws`,
|
||||
COUNT(p.`id_parcel`) AS `count_parcels`,
|
||||
COUNT(DISTINCT m.`id_package_ws`) AS `count_orders`,
|
||||
m.`date_add` AS `date_add`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_MANIFEST_DB_.'` m
|
||||
LEFT JOIN `'._DB_PREFIX_._DPDPOLAND_PARCEL_DB_.'` p ON (p.`id_package_ws` = m.`id_package_ws`)
|
||||
GROUP BY `id_manifest_ws`
|
||||
'.$filter.'
|
||||
ORDER BY `'.bqSQL($order_by).'` '.pSQL($order_way).
|
||||
($start !== null && $pagination !== null ? ' LIMIT '.(int)$start.', '.(int)$pagination : '')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all fields of sender addresses are valid
|
||||
*
|
||||
* @param array $package_ids Package IDs
|
||||
* @return bool Sender addresses are valid
|
||||
*/
|
||||
public static function validateSenderAddresses($package_ids)
|
||||
{
|
||||
if (!is_array($package_ids))
|
||||
return false;
|
||||
|
||||
$first_package = new DpdPolandPackage((int)$package_ids[0]);
|
||||
$first_package_address = new Address((int)$first_package->id_address_sender);
|
||||
|
||||
$address_keys = array('country', 'company', 'lastname', 'firstname', 'address1', 'address2', 'postcode', 'city', 'phone');
|
||||
$address = array();
|
||||
|
||||
foreach ($address_keys as $key)
|
||||
if (isset($first_package_address->$key))
|
||||
$address[$key] = $first_package_address->$key;
|
||||
else
|
||||
return false;
|
||||
|
||||
foreach ($package_ids as $package_id)
|
||||
{
|
||||
$package = new DpdPolandPackage((int)$package_id);
|
||||
$sender_address = new Address((int)$package->id_address_sender);
|
||||
$current_package_sender_address = array();
|
||||
|
||||
foreach ($address_keys as $key)
|
||||
if (isset($sender_address->$key))
|
||||
$current_package_sender_address[$key] = $sender_address->$key;
|
||||
else
|
||||
return false;
|
||||
|
||||
$differences = array_diff_assoc($address, $current_package_sender_address);
|
||||
|
||||
if (!empty($differences))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns manifest WebService ID according to package ID
|
||||
*
|
||||
* @param int|string $id_package_ws Package ID
|
||||
* @return false|null|string Manifest ID
|
||||
*/
|
||||
public static function getManifestIdWsByPackageIdWs($id_package_ws)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT `id_manifest_ws`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_MANIFEST_DB_.'`
|
||||
WHERE `id_package_ws` = "'.(int)$id_package_ws.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns package ID according to Manifest ID
|
||||
*
|
||||
* @param int|string $id_manifest_ws Manifest ID
|
||||
* @return false|null|string Package ID
|
||||
*/
|
||||
public function getPackageIdWsByManifestIdWs($id_manifest_ws)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT `id_package_ws`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_MANIFEST_DB_.'`
|
||||
WHERE `id_manifest_ws` = "'.(int)$id_manifest_ws.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns package object instance
|
||||
*
|
||||
* @return DpdPolandPackage instance
|
||||
*/
|
||||
public function getPackageInstance()
|
||||
{
|
||||
if (!$this->id_package_ws)
|
||||
$this->id_package_ws = $this->getPackageIdWsByManifestIdWs($this->id_manifest_ws);
|
||||
|
||||
return new DpdPolandPackage($this->id_package_ws);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates manifest
|
||||
*
|
||||
* @param string $output_doc_format Document format
|
||||
* @param string $output_doc_page_format Document page format
|
||||
* @param string $policy Policy type
|
||||
* @return bool Manifest generated successfully
|
||||
*/
|
||||
public function generate($output_doc_format = 'PDF', $output_doc_page_format = 'LBL_PRINTER', $policy = 'STOP_ON_FIRST_ERROR')
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandManifestWS;
|
||||
|
||||
return $this->webservice->generate($this, $output_doc_format, $output_doc_page_format, $policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates multiple manifests
|
||||
*
|
||||
* @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')
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandManifestWS;
|
||||
|
||||
return $this->webservice->generateMultiple($package_ids, $output_doc_format, $output_doc_page_format, $policy);
|
||||
}
|
||||
}
|
||||
148
modules/dpdpoland/classes/ObjectModel.php
Normal file
148
modules/dpdpoland/classes/ObjectModel.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?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 DpdPolandObjectModel Responsible for PrestaShop objects management
|
||||
*/
|
||||
class DpdPolandObjectModel extends ObjectModel
|
||||
{
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array();
|
||||
|
||||
protected $tables = array();
|
||||
protected $table;
|
||||
protected $fieldsValidate = array();
|
||||
|
||||
protected $fieldsRequired = array();
|
||||
protected $fieldsSize = array();
|
||||
|
||||
protected $identifier;
|
||||
|
||||
const TYPE_INT = 1;
|
||||
const TYPE_BOOL = 2;
|
||||
const TYPE_STRING = 3;
|
||||
const TYPE_FLOAT = 4;
|
||||
const TYPE_DATE = 5;
|
||||
const TYPE_HTML = 6;
|
||||
const TYPE_NOTHING = 7;
|
||||
|
||||
/**
|
||||
* DpdPolandObjectModel class constructor
|
||||
* @param null|int $id Object ID
|
||||
*/
|
||||
public function __construct($id = null)
|
||||
{
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
{
|
||||
$caller_class_name = $this->getCallerClassName(); // child class name
|
||||
|
||||
if (isset($caller_class_name::$definition))
|
||||
{
|
||||
$this->tables = array($caller_class_name::$definition['table']);
|
||||
$this->table = $caller_class_name::$definition['table'];
|
||||
$this->identifier = $caller_class_name::$definition['primary'];
|
||||
|
||||
foreach ($caller_class_name::$definition['fields'] as $field_name => $field)
|
||||
{
|
||||
if (!in_array($field_name, array('id_shop', 'date_upd', 'date_add')))
|
||||
{
|
||||
$validate_rule = (isset($field['validate'])) ? $field['validate'] : 'isAnything';
|
||||
$this->fieldsValidate[$field_name] = $validate_rule;
|
||||
|
||||
if (isset($field['required']))
|
||||
array_push($this->fieldsRequired, $field_name);
|
||||
|
||||
if (isset($field['size']))
|
||||
$this->fieldsSize[$field_name] = $field['size'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::__construct($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class name from which functions are called
|
||||
*
|
||||
* @return string Caller class name
|
||||
*/
|
||||
private function getCallerClassName()
|
||||
{
|
||||
return get_class($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects object fields data
|
||||
*
|
||||
* @return array Object fields data
|
||||
*/
|
||||
public function getFields()
|
||||
{
|
||||
if (version_compare(_PS_VERSION_, '1.5', '<'))
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
$caller_class_name = $this->getCallerClassName(); // child class name
|
||||
$fields = array();
|
||||
|
||||
if (isset($caller_class_name::$definition))
|
||||
{
|
||||
foreach ($caller_class_name::$definition['fields'] as $field_name => $field)
|
||||
{
|
||||
if ($field_name == $this->identifier && isset($this->$field_name))
|
||||
$fields[$field_name] = $this->$field_name;
|
||||
else
|
||||
{
|
||||
switch ($field['type'])
|
||||
{
|
||||
case 1:
|
||||
$fields[$field_name] = (int)$this->$field_name;
|
||||
break;
|
||||
case 2:
|
||||
$fields[$field_name] = (bool)$this->$field_name;
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
case 6:
|
||||
$fields[$field_name] = $this->$field_name;
|
||||
break;
|
||||
case 4:
|
||||
$fields[$field_name] = (float)$this->$field_name;
|
||||
break;
|
||||
case 7:
|
||||
$fields[$field_name] = $this->$field_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
else
|
||||
return parent::getFields();
|
||||
}
|
||||
}
|
||||
421
modules/dpdpoland/classes/Package.php
Normal file
421
modules/dpdpoland/classes/Package.php
Normal file
@@ -0,0 +1,421 @@
|
||||
<?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 DpdPolandPackage Responsible for DPD packages management
|
||||
*/
|
||||
class DpdPolandPackage extends DpdPolandObjectModel
|
||||
{
|
||||
public $id_package;
|
||||
|
||||
public $id_package_ws;
|
||||
|
||||
public $id_order;
|
||||
|
||||
public $sessionId;
|
||||
|
||||
public $sessionType;
|
||||
|
||||
public $payerNumber;
|
||||
|
||||
public $id_address_sender;
|
||||
|
||||
public $id_address_delivery;
|
||||
|
||||
public $cod_amount;
|
||||
|
||||
public $declaredValue_amount;
|
||||
|
||||
public $ref1;
|
||||
|
||||
public $ref2;
|
||||
|
||||
public $additional_info;
|
||||
|
||||
public $labels_printed = 0;
|
||||
|
||||
public $id_sender_address;
|
||||
|
||||
public $cud;
|
||||
|
||||
public $rod;
|
||||
|
||||
public $dpde;
|
||||
|
||||
public $dpdnd;
|
||||
|
||||
public $duty;
|
||||
|
||||
public $duty_amount;
|
||||
|
||||
public $duty_currency;
|
||||
|
||||
public $date_add;
|
||||
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var object Package WebServices instance
|
||||
*/
|
||||
private $webservice;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_PACKAGE_DB_,
|
||||
'primary' => 'id_package',
|
||||
'multilang' => false,
|
||||
'multishop' => false,
|
||||
'fields' => array(
|
||||
'id_package' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_package_ws' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'sessionId' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'sessionType' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'payerNumber' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'id_address_sender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_address_delivery' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'cod_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'declaredValue_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'ref1' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'ref2' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'additional_info' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'labels_printed' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'id_sender_address' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'cud' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'rod' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'dpde' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'dpdnd' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'duty' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'duty_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'duty_currency' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* DpdPolandPackage constructor
|
||||
* Object identified by id_package_ws rather than id_package
|
||||
*
|
||||
* @param null|int $id_package_ws Used only as a primary field by ObjectModel
|
||||
*/
|
||||
public function __construct($id_package_ws = null)
|
||||
{
|
||||
$id_package = $this->getPackageIdByPackageIdWs($id_package_ws);
|
||||
|
||||
parent::__construct($id_package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns package ID according to package ID received from WebServices
|
||||
*
|
||||
* @param int|string $id_package_ws Package WebServices ID
|
||||
* @return false|null|string Package ID
|
||||
*/
|
||||
private function getPackageIdByPackageIdWs($id_package_ws)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT `id_package`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '`
|
||||
WHERE `id_package_ws` = "' . (int)$id_package_ws . '"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes packages duplicates for order to have only one package
|
||||
*
|
||||
* @return bool Packages duplicates removed successfully
|
||||
*/
|
||||
public function removeOrderDuplicates()
|
||||
{
|
||||
$id_last_package_by_order = Db::getInstance()->getValue('
|
||||
SELECT `id_package`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '`
|
||||
WHERE `id_order` = "' . (int)$this->id_order . '"
|
||||
ORDER BY `id_package` DESC
|
||||
');
|
||||
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '`
|
||||
WHERE `id_order` = "' . (int)$this->id_order . '"
|
||||
AND `id_package` != "' . (int)$id_last_package_by_order . '"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates package instance according to order ID
|
||||
*
|
||||
* @param int $id_order Order ID
|
||||
* @return DpdPolandPackage object instance
|
||||
*/
|
||||
public static function getInstanceByIdOrder($id_order)
|
||||
{
|
||||
$id_package_ws = Db::getInstance()->getValue('
|
||||
SELECT `id_package_ws`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '`
|
||||
WHERE `id_order` = "' . (int)$id_order . '"
|
||||
ORDER BY `id_package` DESC
|
||||
');
|
||||
|
||||
return new DpdPolandPackage($id_package_ws);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current package has printed labels
|
||||
*
|
||||
* @return int Printed labels count
|
||||
*/
|
||||
public function isManifestPrinted()
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(`id_manifest_ws`)
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_MANIFEST_DB_ . '`
|
||||
WHERE `id_package_ws`=' . (int)$this->id_package_ws
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted session type
|
||||
*
|
||||
* @return string Formatted session type
|
||||
*/
|
||||
public function getSessionType()
|
||||
{
|
||||
return $this->sessionType == 'international' ? 'INTERNATIONAL' : 'DOMESTIC';
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects list data and prepares it to be displayed
|
||||
*
|
||||
* @param string $order_by List order by criteria
|
||||
* @param string $order_way List sorting way (ascending, descending)
|
||||
* @param string $filter Criteria by which list is filtered
|
||||
* @param int $start From which element list will be displayed
|
||||
* @param int $pagination How many elements will be displayed in list
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Collected list data
|
||||
*/
|
||||
public function getList($order_by, $order_way, $filter, $start, $pagination)
|
||||
{
|
||||
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
|
||||
$list = DB::getInstance()->executeS('
|
||||
SELECT
|
||||
p.`id_package_ws` AS `id_package_ws`,
|
||||
p.`date_add` AS `date_add`,
|
||||
p.`id_order` AS `id_order`,
|
||||
(SELECT COUNT(par.`id_parcel`)
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PARCEL_DB_ . '` par
|
||||
WHERE par.`id_package_ws` = p.`id_package_ws`) AS `count_parcel`,
|
||||
(SELECT parc.`waybill`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PARCEL_DB_ . '` parc
|
||||
WHERE parc.`id_package_ws` = p.`id_package_ws`
|
||||
ORDER BY parc.`id_parcel`
|
||||
LIMIT 1) AS `package_number`,
|
||||
CONCAT(a.`firstname`, " ", a.`lastname`) AS `receiver`,
|
||||
cl.`name` AS `country`,
|
||||
a.`postcode` AS `postcode`,
|
||||
a.`city` AS `city`,
|
||||
CONCAT(a.`address1`, " ", a.`address2`) AS `address`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '` p
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = p.`id_order`)
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON (a.`id_address` = p.`id_address_delivery`)
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = "' . (int)$id_lang . '")
|
||||
WHERE ' . (version_compare(_PS_VERSION_, '1.5', '<') ? '' : 'o.`id_shop` = "' . (int)$id_shop . '" AND ') . '
|
||||
NOT EXISTS(
|
||||
SELECT m.`id_manifest_ws`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_MANIFEST_DB_ . '` m
|
||||
WHERE m.`id_package_ws` = p.`id_package_ws`
|
||||
) ' .
|
||||
$filter .
|
||||
($order_by && $order_way ? ' ORDER BY `' . bqSQL($order_by) . '` ' . pSQL($order_way) : '') .
|
||||
($start !== null && $pagination !== null ? ' LIMIT ' . (int)$start . ', ' . (int)$pagination : '')
|
||||
);
|
||||
|
||||
if (!$list)
|
||||
$list = array();
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits packages into groups
|
||||
* according to session type
|
||||
*
|
||||
* @param array $ids Packages WebServices IDs
|
||||
* @return array Formatted packages groups
|
||||
*/
|
||||
public static function separatePackagesBySession($ids)
|
||||
{
|
||||
$international_packages = array();
|
||||
$domestic_packages = array();
|
||||
|
||||
foreach ($ids as $id_package_ws) {
|
||||
$package = new DpdPolandPackage((int)$id_package_ws);
|
||||
$session_type = $package->getSessionType();
|
||||
if ($session_type == 'INTERNATIONAL')
|
||||
$international_packages[] = (int)$id_package_ws;
|
||||
elseif ($session_type == 'DOMESTIC')
|
||||
$domestic_packages[] = (int)$id_package_ws;
|
||||
}
|
||||
|
||||
return array('INTERNATIONAL' => $international_packages, 'DOMESTIC' => $domestic_packages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns parcel for package
|
||||
*
|
||||
* @param array $parcel Parcel data
|
||||
* @param string $additional_info Order additional info
|
||||
*/
|
||||
public function addParcel($parcel, $additional_info)
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandPackageWS;
|
||||
|
||||
$this->webservice->addParcel($parcel, $additional_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates package
|
||||
*
|
||||
* @return bool Package created successfully
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandPackageWS;
|
||||
|
||||
return $this->webservice->create($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates multiple labels for selected packages
|
||||
*
|
||||
* @param array $waybills Packages waybills
|
||||
* @param string $outputDocPageFormat Document page format
|
||||
* @param string $session_type Session type (DOMESTIC, INTERNATIONAL)
|
||||
* @param string $outputLabelType
|
||||
* @return bool Multiple labels generated successfully
|
||||
*/
|
||||
public function generateMultipleLabels($waybills, $outputDocPageFormat = 'A4', $session_type = 'INTERNATIONAL', $outputLabelType = 'BIC3')
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandPackageWS;
|
||||
|
||||
return $this->webservice->generateMultipleLabels($waybills, $outputDocPageFormat, $session_type, $outputLabelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates package labels
|
||||
*
|
||||
* @param string $outputDocFormat Document format
|
||||
* @param string $outputDocPageFormat Document page format
|
||||
* @param string $policy Policy type
|
||||
* @param string $outputLabelType
|
||||
* @return bool Labels generated successfully
|
||||
*/
|
||||
public function generateLabels($outputDocFormat = 'PDF', $outputDocPageFormat = 'A4', $policy = 'STOP_ON_FIRST_ERROR', $outputLabelType = 'BIC3')
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandPackageWS;
|
||||
|
||||
return $this->webservice->generateLabels($this, $outputDocFormat, $outputDocPageFormat, $policy, $outputLabelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates labels for selected packages
|
||||
*
|
||||
* @param array $package_ids Packages IDs
|
||||
* @param string $outputDocFormat Document format
|
||||
* @param string $outputDocPageFormat Document page format
|
||||
* @param string $policy Policy type
|
||||
* @param string $outputLabelType
|
||||
* @return bool Labels generated successfully
|
||||
*/
|
||||
public function generateLabelsForMultiplePackages($package_ids, $outputDocFormat = 'PDF', $outputDocPageFormat = 'LBL_PRINTER', $policy = 'STOP_ON_FIRST_ERROR', $outputLabelType = 'BIC3')
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandPackageWS;
|
||||
|
||||
return $this->webservice->generateLabelsForMultiplePackages($package_ids, $outputDocFormat, $outputDocPageFormat, $policy, $outputLabelType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects sender address according to package
|
||||
*
|
||||
* @param int|string $package_number Package number
|
||||
* @return array Sender address data
|
||||
*/
|
||||
public function getSenderAddress()
|
||||
{
|
||||
if (!$this->webservice)
|
||||
$this->webservice = new DpdPolandPackageWS;
|
||||
|
||||
return $this->webservice->getSenderAddress($this->id_sender_address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects data about order which has no saved shipments
|
||||
*
|
||||
* @return array Orders which has no saved shipments
|
||||
*/
|
||||
public static function getLabelExceptions()
|
||||
{
|
||||
$orders = Db::getInstance()->executeS('
|
||||
SELECT `id_order`
|
||||
FROM `' . _DB_PREFIX_ . 'orders`
|
||||
');
|
||||
|
||||
if (empty($orders)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$orders_ids = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$orders_ids[] = (int)$order['id_order'];
|
||||
}
|
||||
|
||||
$packages = Db::getInstance()->executeS('
|
||||
SELECT `id_order`
|
||||
FROM `' . _DB_PREFIX_ . _DPDPOLAND_PACKAGE_DB_ . '`
|
||||
');
|
||||
|
||||
if (empty($packages)) {
|
||||
return $orders_ids;
|
||||
}
|
||||
|
||||
$package_orders_ids = array();
|
||||
|
||||
foreach ($packages as $package) {
|
||||
$package_orders_ids[] = $package['id_order'];
|
||||
}
|
||||
|
||||
return array_diff($orders_ids, $package_orders_ids);
|
||||
}
|
||||
}
|
||||
230
modules/dpdpoland/classes/Parcel.php
Normal file
230
modules/dpdpoland/classes/Parcel.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?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 DpdPolandParcel Responsible for DPD parcels management
|
||||
*/
|
||||
class DpdPolandParcel extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Parcel ID
|
||||
*/
|
||||
public $id_parcel;
|
||||
|
||||
/**
|
||||
* @var int|string Parcel WebService ID
|
||||
*/
|
||||
public $id_package_ws;
|
||||
|
||||
/**
|
||||
* @var string Parcel waybill
|
||||
*/
|
||||
public $waybill;
|
||||
|
||||
/**
|
||||
* @var string Parcel content
|
||||
*/
|
||||
public $content;
|
||||
|
||||
/**
|
||||
* @var float Parcel weight
|
||||
*/
|
||||
public $weight;
|
||||
|
||||
/**
|
||||
* @var float Parcel height
|
||||
*/
|
||||
public $height;
|
||||
|
||||
/**
|
||||
* @var float Parcel length
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* @var float Parcel width
|
||||
*/
|
||||
public $width;
|
||||
|
||||
/**
|
||||
* @var int|string Parcel number
|
||||
*/
|
||||
public $number;
|
||||
|
||||
/**
|
||||
* @var datetime Date when parcel was created
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when parcel data was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_PARCEL_DB_,
|
||||
'primary' => 'id_parcel',
|
||||
'multilang' => false,
|
||||
'multishop' => false,
|
||||
'fields' => array(
|
||||
'id_parcel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_package_ws' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'waybill' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'content' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
|
||||
'height' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
|
||||
'length' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
|
||||
'width' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
|
||||
'number' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects orders waybills data
|
||||
*
|
||||
* @param array $orders_ids Orders IDs
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Orders Waybills
|
||||
*/
|
||||
public static function getOrdersWaybills(array $orders_ids)
|
||||
{
|
||||
if (empty($orders_ids)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$waybills = Db::getInstance()->executeS('
|
||||
SELECT parc.`waybill`, pack.`sessionType`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PACKAGE_DB_.'` pack
|
||||
LEFT JOIN `'._DB_PREFIX_._DPDPOLAND_PARCEL_DB_.'` parc
|
||||
ON (parc.`id_package_ws` = pack.`id_package_ws`)
|
||||
WHERE pack.`id_order` IN ('.implode(',', $orders_ids).')
|
||||
');
|
||||
|
||||
return $waybills;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects parcels data for order
|
||||
*
|
||||
* @param int $id_order Order ID
|
||||
* @param null|int|string $id_package_ws Package WebServices ID
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Order parcels
|
||||
*/
|
||||
public static function getParcels($id_order, $id_package_ws = null)
|
||||
{
|
||||
if ($id_package_ws)
|
||||
{
|
||||
$parcels = Db::getInstance()->executeS('
|
||||
SELECT `id_parcel`, `content`, `weight`, `height`, `length`, `width`, `number`
|
||||
FROM `'.bqSQL(_DB_PREFIX_.self::$definition['table']).'`
|
||||
WHERE `id_package_ws`='.(int)$id_package_ws
|
||||
);
|
||||
return $parcels;
|
||||
}
|
||||
|
||||
$products = DpdPolandParcelProduct::getShippedProducts($id_order);
|
||||
|
||||
$parcels = array();
|
||||
$content = '';
|
||||
$weight = $height = $length = $width = 0;
|
||||
|
||||
$products_count = count($products);
|
||||
|
||||
if ($products_count == 1)
|
||||
{
|
||||
$product = reset($products);
|
||||
$height = DpdPoland::convertDimension($product['height']);
|
||||
$length = DpdPoland::convertDimension($product['length']);
|
||||
$width = DpdPoland::convertDimension($product['width']);
|
||||
}
|
||||
|
||||
foreach ($products as $product)
|
||||
{
|
||||
$content .= $product['id_product'].'_'.$product['id_product_attribute'];
|
||||
|
||||
if (--$products_count)
|
||||
$content .= ', ';
|
||||
|
||||
$weight += DpdPoland::convertWeight($product['weight']);
|
||||
}
|
||||
|
||||
$parcels[] = array(
|
||||
'number' => 1,
|
||||
'content' => $content,
|
||||
'weight' => $weight,
|
||||
'height' => sprintf('%.6f', $height),
|
||||
'length' => sprintf('%.6f', $length),
|
||||
'width' => sprintf('%.6f', $width)
|
||||
);
|
||||
|
||||
return $parcels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects list data and prepares it to be displayed
|
||||
*
|
||||
* @param string $order_by List order by criteria
|
||||
* @param string $order_way List sorting way (ascending, descending)
|
||||
* @param string $filter Criteria by which list is filtered
|
||||
* @param int $start From which element list will be displayed
|
||||
* @param int $pagination How many elements will be displayed in list
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Collected list data
|
||||
*/
|
||||
public function getList($order_by, $order_way, $filter, $start, $pagination)
|
||||
{
|
||||
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
|
||||
$list = DB::getInstance()->executeS('
|
||||
SELECT
|
||||
p.`id_order` AS `id_order`,
|
||||
par.`waybill` AS `id_parcel`,
|
||||
CONCAT(a.`firstname`, " ", a.`lastname`) AS `receiver`,
|
||||
cl.`name` AS `country`,
|
||||
a.`postcode` AS `postcode`,
|
||||
a.`city` AS `city`,
|
||||
CONCAT(a.`address1`, " ", a.`address2`) AS `address`,
|
||||
p.`date_add` AS `date_add`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PARCEL_DB_.'` par
|
||||
LEFT JOIN `'._DB_PREFIX_._DPDPOLAND_PACKAGE_DB_.'` p ON (p.`id_package_ws` = par.`id_package_ws`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = p.`id_order`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_address` = p.`id_address_delivery`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = "'.(int)$id_lang.'")'.
|
||||
(version_compare(_PS_VERSION_, '1.5', '<') ? ' ' : 'WHERE o.`id_shop` = "'.(int)$id_shop.'" ').
|
||||
$filter.
|
||||
($order_by && $order_way ? ' ORDER BY `'.bqSQL($order_by).'` '.pSQL($order_way) : '').
|
||||
($start !== null && $pagination !== null ? ' LIMIT '.(int)$start.', '.(int)$pagination : '')
|
||||
);
|
||||
|
||||
if (!$list)
|
||||
$list = array();
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
250
modules/dpdpoland/classes/ParcelProduct.php
Normal file
250
modules/dpdpoland/classes/ParcelProduct.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?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 DpdPolandParcelProduct Responsible for parcel products management
|
||||
*/
|
||||
class DpdPolandParcelProduct extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Parcel product ID
|
||||
*/
|
||||
public $id_parcel_product;
|
||||
|
||||
/**
|
||||
* @var int Parcel ID
|
||||
*/
|
||||
public $id_parcel;
|
||||
|
||||
/**
|
||||
* @var int Product ID
|
||||
*/
|
||||
public $id_product;
|
||||
|
||||
/**
|
||||
* @var int Product attribute ID
|
||||
*/
|
||||
public $id_product_attribute;
|
||||
|
||||
/**
|
||||
* @var string Product name
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var Product weight
|
||||
*/
|
||||
public $weight;
|
||||
|
||||
/**
|
||||
* @var datetime Date when product was assigned for order
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when product data of assignation for order was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_PARCEL_PRODUCT_DB_,
|
||||
'primary' => 'id_parcel_product',
|
||||
'multilang' => false,
|
||||
'multishop' => false,
|
||||
'fields' => array(
|
||||
'id_parcel' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects data about parcels products details
|
||||
*
|
||||
* @param array $parcels Parcels
|
||||
* @return array Parcels products data
|
||||
*/
|
||||
public static function getProductDetailsByParcels($parcels)
|
||||
{
|
||||
$products = array();
|
||||
|
||||
foreach ($parcels as $parcel)
|
||||
{
|
||||
if (isset($parcel['id_parcel']))
|
||||
{
|
||||
if ($products_array = self::getProductByIdParcel($parcel['id_parcel']))
|
||||
{
|
||||
foreach ($products_array as $product)
|
||||
{
|
||||
if (self::isLabelPrinted($parcel['id_parcel']))
|
||||
{
|
||||
$product_data = self::getProductNameAndWeight($parcel['id_parcel'], $product['id_product'],
|
||||
$product['id_product_attribute']);
|
||||
$products[] = array_merge($product, array(
|
||||
'name' => $product_data['name'],
|
||||
'weight' => (float)$product_data['weight'],
|
||||
'id_parcel' => (int)$parcel['id_parcel']
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
$product_obj = new Product($product['id_product']);
|
||||
$combination = new Combination($product['id_product_attribute']);
|
||||
|
||||
$products[] = array_merge($product, array(
|
||||
'name' => (version_compare(_PS_VERSION_, '1.5', '<') ?
|
||||
$product_obj->name[(int)Context::getContext()->language->id] :
|
||||
Product::getProductName($product['id_product'], $product['id_product_attribute'])),
|
||||
'weight' => (float)$combination->weight + (float)$product_obj->weight,
|
||||
'id_parcel' => (int)$parcel['id_parcel']
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects products IDs according to parcel
|
||||
*
|
||||
* @param int $id_parcel Parcel ID
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Parcel products IDs
|
||||
*/
|
||||
private static function getProductByIdParcel($id_parcel)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `id_product`, `id_product_attribute`
|
||||
FROM `'._DB_PREFIX_.bqSQL(self::$definition['table']).'`
|
||||
WHERE `id_parcel`='.(int)$id_parcel
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and formats data about order shipped products
|
||||
*
|
||||
* @param int $id_order Order ID
|
||||
* @param array $products Products information
|
||||
* @return array Shipped products data
|
||||
*/
|
||||
public static function getShippedProducts($id_order, $products = array())
|
||||
{
|
||||
$order = is_object($id_order) ? $id_order : new Order((int)$id_order);
|
||||
|
||||
if (!$products)
|
||||
$products = $order->getProductsDetail();
|
||||
|
||||
$shipped_products = array();
|
||||
|
||||
foreach ($products as $product)
|
||||
{
|
||||
if (isset($product['product_quantity']))
|
||||
$quantity = (int)$product['product_quantity'];
|
||||
elseif (isset($product['quantity']))
|
||||
$quantity = (int)$product['quantity'];
|
||||
else
|
||||
$quantity = 1;
|
||||
|
||||
self::extractAndFormatProductData($product);
|
||||
|
||||
for ($i = 0; $i < $quantity; $i++)
|
||||
$shipped_products[] = $product;
|
||||
}
|
||||
|
||||
return $shipped_products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and formats needed products data
|
||||
*
|
||||
* @param array $product Product properties
|
||||
*/
|
||||
private static function extractAndFormatProductData(&$product)
|
||||
{
|
||||
$id_product = isset($product['product_id']) ? (int)$product['product_id'] : (int)$product['id_product'];
|
||||
$id_product_attribute = isset($product['product_attribute_id']) ? (int)$product['product_attribute_id'] :
|
||||
(int)$product['id_product_attribute'];
|
||||
$product_name = isset($product['product_name']) ? $product['product_name'] : $product['name'];
|
||||
$product_weight = isset($product['product_weight']) ? $product['product_weight'] : $product['weight'];
|
||||
|
||||
if (isset($product['id_parcel']))
|
||||
$id_parcel = (int)$product['id_parcel'];
|
||||
|
||||
$product = array(
|
||||
'id_product' => $id_product,
|
||||
'id_product_attribute' => $id_product_attribute,
|
||||
'name' => $product_name,
|
||||
'weight' => DpdPoland::convertWeight($product_weight),
|
||||
'width' => isset($product['width']) ? DpdPoland::convertDimension($product['width']) : null,
|
||||
'height' => isset($product['height']) ? DpdPoland::convertDimension($product['height']) : null,
|
||||
'length' => isset($product['height']) ? DpdPoland::convertDimension($product['depth']) : null
|
||||
);
|
||||
|
||||
if (isset($id_parcel))
|
||||
$product['id_parcel'] = $id_parcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if label is printed and record about it was saved in database
|
||||
*
|
||||
* @param int $id_parcel Parcel ID
|
||||
* @return bool Label was printed
|
||||
*/
|
||||
private static function isLabelPrinted($id_parcel)
|
||||
{
|
||||
return (bool)DB::getInstance()->getValue('
|
||||
SELECT pac.`labels_printed`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PARCEL_DB_.'` par
|
||||
LEFT JOIN `'._DB_PREFIX_._DPDPOLAND_PACKAGE_DB_.'` pac ON (pac.`id_package_ws` = par.`id_package_ws`)
|
||||
WHERE par.`id_parcel` = "'.(int)$id_parcel.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects product name and weight
|
||||
*
|
||||
* @param int $id_parcel Parcel ID
|
||||
* @param int $id_product Product ID
|
||||
* @param int $id_product_attribute Product combination ID
|
||||
* @return array|bool|null|object Product name and weight
|
||||
*/
|
||||
private static function getProductNameAndWeight($id_parcel, $id_product, $id_product_attribute)
|
||||
{
|
||||
return DB::getInstance()->getRow('
|
||||
SELECT `name`, `weight`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PARCEL_PRODUCT_DB_.'`
|
||||
WHERE `id_parcel` = "'.(int)$id_parcel.'"
|
||||
AND `id_product` = "'.(int)$id_product.'"
|
||||
AND `id_product_attribute` = "'.(int)$id_product_attribute.'"
|
||||
');
|
||||
}
|
||||
}
|
||||
123
modules/dpdpoland/classes/PayerNumber.php
Normal file
123
modules/dpdpoland/classes/PayerNumber.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?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 DpdPolandPayerNumber Responsible for payer number management
|
||||
*/
|
||||
class DpdPolandPayerNumber extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Payer number ID
|
||||
*/
|
||||
public $id_dpdpoland_payer_number;
|
||||
|
||||
/**
|
||||
* @var string|int Payer number
|
||||
*/
|
||||
public $payer_number;
|
||||
|
||||
/**
|
||||
* @var string Payer number name
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int Shop ID
|
||||
*/
|
||||
public $id_shop;
|
||||
|
||||
/**
|
||||
* @var datetime Date when payer number was added
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when payer number was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* DpdPolandPayerNumber class constructor
|
||||
* @param null|int $id_dpdpoland_payer_number DPD payer number ID
|
||||
*/
|
||||
public function __construct($id_dpdpoland_payer_number = null)
|
||||
{
|
||||
parent::__construct($id_dpdpoland_payer_number);
|
||||
$this->id_shop = (int)Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_PAYER_NUMBERS_DB_,
|
||||
'primary' => 'id_dpdpoland_payer_number',
|
||||
'multilang_shop' => true,
|
||||
'multishop' => true,
|
||||
'fields' => array(
|
||||
'payer_number' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Checks if payer number exists in database
|
||||
*
|
||||
* @param string $number Payer number
|
||||
* @param null|int $id_shop Shop ID
|
||||
* @return bool Payer number exists in database
|
||||
*/
|
||||
public static function payerNumberExists($number, $id_shop = null)
|
||||
{
|
||||
if ($id_shop === null)
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
|
||||
return (bool)DB::getInstance()->getValue('
|
||||
SELECT `id_dpdpoland_payer_number`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PAYER_NUMBERS_DB_.'`
|
||||
WHERE `payer_number` = "'.pSQL($number).'"
|
||||
AND `id_shop` = "'.(int)$id_shop.'"
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects data of merchant payer numbers saved in database
|
||||
*
|
||||
* @param null|int $id_shop Shop ID
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Payer numbers
|
||||
*/
|
||||
public static function getPayerNumbers($id_shop = null)
|
||||
{
|
||||
if ($id_shop === null)
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
|
||||
return DB::getInstance()->executeS('
|
||||
SELECT `id_dpdpoland_payer_number`, `payer_number`, `name`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PAYER_NUMBERS_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)$id_shop.'"
|
||||
');
|
||||
}
|
||||
}
|
||||
188
modules/dpdpoland/classes/PickupHistory.php
Normal file
188
modules/dpdpoland/classes/PickupHistory.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Class DpdPolandPickupHistory
|
||||
*/
|
||||
class DpdPolandPickupHistory extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Courier order ID, incremental
|
||||
*/
|
||||
public $id_pickup_history;
|
||||
|
||||
/**
|
||||
* @var string Order number
|
||||
*/
|
||||
public $order_number;
|
||||
|
||||
/**
|
||||
* @var string Sender address
|
||||
*/
|
||||
public $sender_address;
|
||||
|
||||
/**
|
||||
* @var string Sender company
|
||||
*/
|
||||
public $sender_company;
|
||||
|
||||
/**
|
||||
* @var string Sender name
|
||||
*/
|
||||
public $sender_name;
|
||||
|
||||
/**
|
||||
* @var string Sender phone
|
||||
*/
|
||||
public $sender_phone;
|
||||
|
||||
/**
|
||||
* @var datetime Pickup date
|
||||
*/
|
||||
public $pickup_date;
|
||||
|
||||
/**
|
||||
* @var string Pickup time range
|
||||
*/
|
||||
public $pickup_time;
|
||||
|
||||
/**
|
||||
* @var string Type
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @var int envelope
|
||||
*/
|
||||
public $envelope;
|
||||
|
||||
/**
|
||||
* @var int package
|
||||
*/
|
||||
public $package;
|
||||
|
||||
/**
|
||||
* @var decimal Package weight all
|
||||
*/
|
||||
public $package_weight_all;
|
||||
|
||||
/**
|
||||
* @var decimal Package heaviest weight
|
||||
*/
|
||||
public $package_heaviest_weight;
|
||||
|
||||
/**
|
||||
* @var decimal Package heaviest width
|
||||
*/
|
||||
public $package_heaviest_width;
|
||||
|
||||
/**
|
||||
* @var decimal Package heaviest length
|
||||
*/
|
||||
public $package_heaviest_length;
|
||||
|
||||
/**
|
||||
* @var decimal Package heaviest height
|
||||
*/
|
||||
public $package_heaviest_height;
|
||||
|
||||
/**
|
||||
* @var int Pallet
|
||||
*/
|
||||
public $pallet;
|
||||
|
||||
/**
|
||||
* @var decimal Pallet weight
|
||||
*/
|
||||
public $pallet_weight;
|
||||
|
||||
/**
|
||||
* @var decimal Pallet heaviest weight
|
||||
*/
|
||||
public $pallet_heaviest_weight;
|
||||
|
||||
/**
|
||||
* @var decimal Pallet heaviest height
|
||||
*/
|
||||
public $pallet_heaviest_height;
|
||||
|
||||
/**
|
||||
* @var datetime Date when sender address was saved
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when sender address was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var int Shop ID
|
||||
*/
|
||||
public $id_shop;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_PICKUP_HISTORY_DB_,
|
||||
'primary' => 'id_pickup_history',
|
||||
'multilang' => false,
|
||||
'multishop' => true,
|
||||
'fields' => array(
|
||||
'order_number' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'sender_address' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'sender_company' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'sender_name' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'sender_phone' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'pickup_date' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'pickup_time' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'type' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
||||
'envelope' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'package' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'pallet' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects list data and prepares it to be displayed
|
||||
*
|
||||
* @param string $order_by List order by criteria
|
||||
* @param string $order_way List sorting way (ascending, descending)
|
||||
* @param string $filter Criteria by which list is filtered
|
||||
* @param int $start From which element list will be displayed
|
||||
* @param int $pagination How many elements will be displayed in list
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Collected list data
|
||||
*/
|
||||
public static function getList($order_by, $order_way, $filter, $start, $pagination)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PICKUP_HISTORY_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
'.$filter.'
|
||||
ORDER BY `'.bqSQL($order_by).'` '.pSQL(Validate::isOrderWay($order_way) ? $order_way : 'ASC').
|
||||
($start !== null && $pagination !== null ? ' LIMIT '.(int)$start.', '.(int)$pagination : '')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates how many addresses are saved in current shop
|
||||
*
|
||||
* @return int count
|
||||
*/
|
||||
public static function getCourierOrderCount()
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(`id_pickup_history`)
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_PICKUP_HISTORY_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
');
|
||||
}
|
||||
}
|
||||
175
modules/dpdpoland/classes/SenderAddress.php
Normal file
175
modules/dpdpoland/classes/SenderAddress.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?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 DpdPolandSenderAddress Responsible for sender addresses management
|
||||
*/
|
||||
class DpdPolandSenderAddress extends DpdPolandObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int Sender address ID, incremental
|
||||
*/
|
||||
public $id_sender_address;
|
||||
|
||||
/**
|
||||
* @var string Sender address alias
|
||||
*/
|
||||
public $alias;
|
||||
|
||||
/**
|
||||
* @var string Sender name
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string Sender phone number
|
||||
*/
|
||||
public $phone;
|
||||
|
||||
/**
|
||||
* @var string Sender address
|
||||
*/
|
||||
public $address;
|
||||
|
||||
/**
|
||||
* @var string Sender city name
|
||||
*/
|
||||
public $city;
|
||||
|
||||
/**
|
||||
* @var string Sender company name
|
||||
*/
|
||||
public $company;
|
||||
|
||||
/**
|
||||
* @var string Sender email address
|
||||
*/
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* @var string Sender postcode
|
||||
*/
|
||||
public $postcode;
|
||||
|
||||
/**
|
||||
* @var datetime Date when sender address was saved
|
||||
*/
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @var datetime Date when sender address was updated
|
||||
*/
|
||||
public $date_upd;
|
||||
|
||||
/**
|
||||
* @var int Shop ID
|
||||
*/
|
||||
public $id_shop;
|
||||
|
||||
/**
|
||||
* @var array Class variables and their validation types
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => _DPDPOLAND_SENDER_ADDRESS_DB_,
|
||||
'primary' => 'id_sender_address',
|
||||
'multilang' => false,
|
||||
'multishop' => false,
|
||||
'fields' => array(
|
||||
'alias' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
|
||||
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isName'),
|
||||
'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber'),
|
||||
'address' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress'),
|
||||
'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName'),
|
||||
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail'),
|
||||
'postcode' => array('type' => self::TYPE_STRING, 'validate' => 'isPostCode'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Collects list data and prepares it to be displayed
|
||||
*
|
||||
* @param string $order_by List order by criteria
|
||||
* @param string $order_way List sorting way (ascending, descending)
|
||||
* @param string $filter Criteria by which list is filtered
|
||||
* @param int $start From which element list will be displayed
|
||||
* @param int $pagination How many elements will be displayed in list
|
||||
* @return array|false|mysqli_result|null|PDOStatement|resource Collected list data
|
||||
*/
|
||||
public function getList($order_by, $order_way, $filter, $start, $pagination)
|
||||
{
|
||||
$order_way = Validate::isOrderWay($order_way) ? $order_way : 'ASC';
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_SENDER_ADDRESS_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
'.$filter.'
|
||||
ORDER BY `'.bqSQL($order_by).'` '.pSQL($order_way).
|
||||
($start !== null && $pagination !== null ? ' LIMIT '.(int)$start.', '.(int)$pagination : '')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and returns data about sender addresses saved in current shop
|
||||
*
|
||||
* @return array Sender addresses
|
||||
*/
|
||||
public static function getAddresses()
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$addresses = Db::getInstance()->executeS('
|
||||
SELECT `id_sender_address`, `alias`
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_SENDER_ADDRESS_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
');
|
||||
|
||||
if (!$addresses) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
foreach ($addresses as $address) {
|
||||
$result[$address['id_sender_address']] = $address['alias'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates how many addresses are saved in current shop
|
||||
*
|
||||
* @return int Sender addresses count
|
||||
*/
|
||||
public static function getAddressesCount()
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(`id_sender_address`)
|
||||
FROM `'._DB_PREFIX_._DPDPOLAND_SENDER_ADDRESS_DB_.'`
|
||||
WHERE `id_shop` = "'.(int)Context::getContext()->shop->id.'"
|
||||
');
|
||||
}
|
||||
}
|
||||
29
modules/dpdpoland/classes/index.php
Normal file
29
modules/dpdpoland/classes/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;
|
||||
Reference in New Issue
Block a user