first commit
This commit is contained in:
89
class/deliveries/class.BalikDoRuky.php
Normal file
89
class/deliveries/class.BalikDoRuky.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
class BalikDoRuky extends Delivery
|
||||
{
|
||||
public static $className = 'Česká pošta - Balík do ruky';
|
||||
|
||||
protected $heureka_delivery_id = 'CESKA_POSTA';
|
||||
protected $zbozi_delivery_id = 'CESKA_POSTA';
|
||||
|
||||
protected $track_and_trace = 'https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=[PACKAGE_ID]';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_zip_codes`';
|
||||
public static $jsonFile = 'https://test20cztest:QKCufcWs@api.balikobot.cz/cp/zipcodes/DR';
|
||||
public static $jsonFileSk = 'https://test20cztest:QKCufcWs@api.balikobot.cz/dpd/zipcodes/1/SK';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/cp-do-ruky.svg';
|
||||
|
||||
public $config = [
|
||||
// L (nejdelší strana do 100 cm)
|
||||
'maxLength' => 100.0, // Maximální rozměr strany položky
|
||||
'maxSumOfDimensions' => 300.0, // Maximální součet rozměrů všech tří stran položky
|
||||
// legacy config:
|
||||
'max_length' => 98, // Maximální rozměr jedné strany zásilky
|
||||
'max_dimensions' => 300, // Maximální součet rozměrů všech tří stran zásilky
|
||||
];
|
||||
|
||||
public function getInfo($PSC = null)
|
||||
{
|
||||
if (is_null($PSC)) {
|
||||
$PSC = getVal('dDR-time-zone-psc');
|
||||
}
|
||||
|
||||
if (strlen($PSC) != 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.'
|
||||
WHERE zip=:psc', ['psc' => $PSC]));
|
||||
|
||||
if (!$data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = [];
|
||||
|
||||
return join('<br>',
|
||||
array_map(
|
||||
function ($name, $value) {
|
||||
return "<strong>{$value}</strong>";
|
||||
},
|
||||
array_keys($info),
|
||||
$info
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('delivery') && $cart->hasData('user')) {
|
||||
$this->zipExists($cart->invoice);
|
||||
$this->zipExists($cart->delivery);
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$json = file_get_contents(static::$jsonFile);
|
||||
$data = json_decode_strict($json);
|
||||
if (!$data || empty($data->zip_codes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sqlGetConnection()->transactional(
|
||||
function () use ($data) {
|
||||
sqlQueryBuilder()->delete(self::$tableName)->where(\Query\Operator::equals(['country' => 'CZ']))->execute();
|
||||
foreach ($data->zip_codes as $post) {
|
||||
sqlQuery('INSERT INTO '.self::$tableName.' SET zip = :psc,time_zone = :time_zone, country = :country', ['psc' => $post->zip, 'time_zone' => $post->{'1B'}, 'country' => $post->country]);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
8
class/deliveries/class.BalikDoRukyGarantovane.php
Normal file
8
class/deliveries/class.BalikDoRukyGarantovane.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__.'/class.BalikDoRuky.php';
|
||||
|
||||
class BalikDoRukyGarantovane extends BalikDoRuky
|
||||
{
|
||||
public static $className = 'Česká pošta - Balík do ruky - Garantovaný čas doručení';
|
||||
}
|
||||
25
class/deliveries/class.BalikDoRukySobotni.php
Normal file
25
class/deliveries/class.BalikDoRukySobotni.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__.'/class.BalikDoRuky.php';
|
||||
|
||||
class BalikDoRukySobotni extends BalikDoRuky
|
||||
{
|
||||
public static $className = 'Česká pošta - Balík do ruky (sobotní doručení)';
|
||||
|
||||
protected $heureka_delivery_id;
|
||||
protected $zbozi_delivery_id;
|
||||
|
||||
public function isWorkday($date, ?array $countries = null)
|
||||
{
|
||||
$result = parent::isWorkday($date, $countries);
|
||||
|
||||
if (!$result) {
|
||||
// pokud je sobota
|
||||
if ($date->format('N') == 6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
236
class/deliveries/class.BalikNaPostu.php
Normal file
236
class/deliveries/class.BalikNaPostu.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
class BalikNaPostu extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Česká pošta - Balík na poštu';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.BalikNaPostu.description.tpl';
|
||||
protected $templateInit = 'deliveries/delivery.BalikNaPostu.init.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.BalikNaPostu.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_balik_na_postu`';
|
||||
|
||||
protected $heureka_delivery_id = 'CESKA_POSTA_NAPOSTU';
|
||||
protected $zbozi_delivery_id = 'CESKA_POSTA_NA_POSTU';
|
||||
|
||||
protected $track_and_trace = 'https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=[PACKAGE_ID]';
|
||||
|
||||
public static $xmlFile = 'http://napostu.cpost.cz/vystupy/napostu.xml';
|
||||
public static $xlsDelivery = 'https://www.ceskaposta.cz/documents/10180/483935/zv_doruc_pasmo-sluzby.xls';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/cp-na-postu.svg';
|
||||
|
||||
public $psc;
|
||||
|
||||
public $config = [
|
||||
// L (nejdelší strana do 100 cm)
|
||||
'maxLength' => 100.0, // Maximální rozměr strany položky
|
||||
'maxSumOfDimensions' => 300.0, // Maximální součet rozměrů všech tří stran položky
|
||||
// legacy config:
|
||||
'max_length' => 98, // Maximální rozměr jedné strany zásilky
|
||||
'max_dimensions' => 300, // Maximální součet rozměrů všech tří stran zásilky
|
||||
];
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->psc);
|
||||
|
||||
return parent::getName().' - '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$psc = trim($data['balik_na_postu_zip'] ?? '');
|
||||
if (!empty($psc)) {
|
||||
if (strlen($psc) != 5) {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
return $this->data += [
|
||||
'psc' => $psc,
|
||||
];
|
||||
}
|
||||
|
||||
$point = $data['balik_na_postu_point'] ?? '';
|
||||
$point = json_decode($point, true);
|
||||
|
||||
if (empty($point)) {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
return $this->data += [
|
||||
'psc' => getVal('zip', $point) ?? getVal('psc', $point),
|
||||
'point_name' => getVal('name', $point),
|
||||
'address' => getVal('address', $point),
|
||||
];
|
||||
}
|
||||
|
||||
public function getInfo($PSC = null)
|
||||
{
|
||||
if (is_null($PSC) && getVal('point_name', $this->data)) {
|
||||
$data = [];
|
||||
$data['psc'] = getVal('psc', $this->data);
|
||||
$data['name'] = getVal('point_name', $this->data);
|
||||
$data['address'] = getVal('address', $this->data);
|
||||
} else {
|
||||
if (is_null($PSC)) {
|
||||
$PSC = getVal('psc', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlQueryBuilder()->select('*')->from(self::$tableName)
|
||||
->andWhere(\Query\Operator::equals(['psc' => $PSC]))
|
||||
->execute()->fetch();
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pošta'];
|
||||
}
|
||||
|
||||
$data['hours'] = unserialize($data['hours']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['psc'])) {
|
||||
return 'Není zvolena žádná pošta!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['psc'];
|
||||
$address = explode(', ', $info['address']);
|
||||
$data['delivery_street'] = reset($address);
|
||||
$data['delivery_city'] = $info['name'];
|
||||
$data['delivery_country'] = 'CZ';
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['psc'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['psc'];
|
||||
$address = explode(', ', $info['address']);
|
||||
$cart->delivery['street'] = reset($address);
|
||||
$cart->delivery['city'] = end($address);
|
||||
$cart->delivery['country'] = 'CZ';
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['name']}</strong> PSČ: <strong>{$info['psc']}</strong>";
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['psc'] ?? null;
|
||||
}
|
||||
|
||||
public static function generateOpeningHours($days)
|
||||
{
|
||||
$hours = [];
|
||||
foreach ($days->den as $day) {
|
||||
$fromTo = [];
|
||||
foreach ($day->od_do as $od_do) {
|
||||
$fromTo[] = [strval($od_do->od), strval($od_do->do)];
|
||||
}
|
||||
$hours[strval($day['name'])] = $fromTo;
|
||||
}
|
||||
|
||||
return $hours;
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['psc']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate_shop('no_zipcode', 'delivery'));
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$xml = simplexml_load_file(self::$xmlFile);
|
||||
|
||||
if (count($xml->row) > 1000) {
|
||||
sqlGetConnection()->transactional(function () use ($xml) {
|
||||
global $cfg;
|
||||
sqlQuery('DELETE FROM '.self::$tableName.' WHERE 1');
|
||||
|
||||
foreach ($xml->row as $post) {
|
||||
if (strval($post->V_PROVOZU) == 'A') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'psc' => strval($post->PSC),
|
||||
'name' => strval($post->NAZ_PROV),
|
||||
'address' => strval($post->ADRESA),
|
||||
'hours' => serialize(self::generateOpeningHours($post->OTV_DOBA)),
|
||||
'region' => strval($post->OKRES),
|
||||
];
|
||||
|
||||
sqlQuery(
|
||||
'INSERT INTO '.self::$tableName.'
|
||||
SET name=:name, psc=:psc, address=:address, hours=:hours, region=:region',
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
file_put_contents($cfg['Path']['data'].'tmp/CPpasmo.xls', fopen(self::$xlsDelivery, 'r'));
|
||||
|
||||
$import = new AutomaticImportTransform($cfg['Path']['data'].'tmp/CPpasmo.xls');
|
||||
$users_array = $import->LoadBinfileAsArray();
|
||||
|
||||
foreach ($users_array['Doruč_pásmo'] as $post) {
|
||||
$psc = substr($post['B'], 0, 5);
|
||||
sqlQuery('UPDATE '.self::$tableName.' SET time_zone = 1 WHERE psc = :psc', ['psc' => $psc]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$sentry = getRaven();
|
||||
$sentry->captureMessage(
|
||||
'CeskaPosta odpoledni doruceni: file not found',
|
||||
[],
|
||||
[
|
||||
'extra' => [
|
||||
'err_msg' => $e->getMessage(),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
11
class/deliveries/class.Balikobot.php
Normal file
11
class/deliveries/class.Balikobot.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class Balikobot extends Delivery
|
||||
{
|
||||
public static $className = 'Ostatní Balíkobot dopravci';
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return findModule(\Modules::BALIKONOS);
|
||||
}
|
||||
}
|
||||
262
class/deliveries/class.Balikovna.php
Normal file
262
class/deliveries/class.Balikovna.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
use KupShop\OrderingBundle\Exception\PaymentException;
|
||||
|
||||
class Balikovna extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Česká pošta - Balíkovna';
|
||||
|
||||
protected $heureka_delivery_id = 'BALIKOVNA_DEPOTAPI';
|
||||
protected $zbozi_delivery_id = 'CESKA_POSTA_BALIKOVNA';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.Balikovna.description.tpl';
|
||||
protected $templateInit = 'deliveries/delivery.Balikovna.init.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.Balikovna.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_balikovna`';
|
||||
|
||||
protected $track_and_trace = 'https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=[PACKAGE_ID]';
|
||||
|
||||
public static $xmlFile = 'http://napostu.ceskaposta.cz/vystupy/balikovny.xml';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/balikovna.svg';
|
||||
|
||||
public $zip;
|
||||
|
||||
public $config = [
|
||||
'weight_limit' => 20,
|
||||
'price_limit' => 30000,
|
||||
'maxWeight' => 20.0,
|
||||
'maxLength' => 70.0, // Maximální rozměr strany položky
|
||||
'maxDimensions' => [70.0, 50.0, 50.0],
|
||||
// legacy config:
|
||||
'max_length' => 70, // Maximální rozměr jedné strany zásilky
|
||||
'max_dimensions' => 50, // Maximální rozměry 70 cm x 50cm x 50 cm
|
||||
];
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo();
|
||||
|
||||
return parent::getName().' - '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$zip = trim($data['zip'] ?? '');
|
||||
|
||||
if (!empty($zip)) {
|
||||
return $this->data += [
|
||||
'zip' => $zip,
|
||||
];
|
||||
}
|
||||
|
||||
$point = $data['balikovna_point'] ?? '';
|
||||
$point = json_decode($point, true);
|
||||
|
||||
if (empty($point)) {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
return $this->data += [
|
||||
'zip' => getVal('zip', $point),
|
||||
'point_name' => getVal('name', $point),
|
||||
'address' => getVal('address', $point),
|
||||
'subtype' => getVal('subtype', $point),
|
||||
];
|
||||
}
|
||||
|
||||
public function getInfo($zip = null)
|
||||
{
|
||||
if (is_null($zip) && getVal('point_name', $this->data)) {
|
||||
$data = [];
|
||||
$data['zip'] = getVal('zip', $this->data);
|
||||
$data['name'] = getVal('point_name', $this->data);
|
||||
$data['address'] = getVal('address', $this->data);
|
||||
$data['subtype'] = getVal('subtype', $this->data);
|
||||
} else {
|
||||
if (is_null($zip)) {
|
||||
$zip = getVal('zip', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.'
|
||||
WHERE zip=:zip',
|
||||
['zip' => $zip]));
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
$data['hours'] = unserialize($data['hours']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['zip'])) {
|
||||
return 'Není zvolena Balíkovna!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = 'BALÍKOVNA';
|
||||
$data['delivery_city'] = $info['name'];
|
||||
$data['delivery_country'] = 'CZ';
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['zip'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = 'BALÍKOVNA';
|
||||
$cart->delivery['city'] = $info['name'];
|
||||
$cart->delivery['country'] = 'CZ';
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['name']}</strong> PSČ: <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($price_limit = ($this->config['price_limit'] ?? 0)) {
|
||||
$price_limit = toDecimal($price_limit);
|
||||
if (!$cart->totalPricePay->lowerThan($price_limit)) {
|
||||
// Cenovy limit pro tento typ dopravy byl prekrocen
|
||||
throw new DeliveryException(sprintf(translate_shop('balikovna_price_limit', 'delivery'), $price_limit->printValue().' Kč.'),
|
||||
translate_shop('price_limit_short', 'delivery'),
|
||||
DeliveryException::ERROR_DELIVERY_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['zip']) && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
if (($payment instanceof Dobirka) && (Settings::getDefault()['deliveries']['Balikovna']['dobirkaBOX'] ?? null)) {
|
||||
$subtype = $this->data['subtype'] ?? null;
|
||||
if ($subtype == 'BOX') {
|
||||
throw new PaymentException('Platba dobírkou není dostupná v případě doručení do Balíkovna-BOXu.
|
||||
Zvolte prosím pobočku jiného typu nebo platbu předem.', 'Nedostupná pro Balíkovna-BOX');
|
||||
}
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
protected static function generateOpeningHours($days)
|
||||
{
|
||||
$hours = [];
|
||||
foreach ($days->den as $day) {
|
||||
$fromTo = [];
|
||||
foreach ($day->od_do as $od_do) {
|
||||
$fromTo[] = [strval($od_do->od), strval($od_do->do)];
|
||||
}
|
||||
$hours[strval($day['name'])] = $fromTo;
|
||||
}
|
||||
|
||||
return $hours;
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$xml = simplexml_load_file(self::$xmlFile);
|
||||
if ($xml->count() > 0) {
|
||||
sqlGetConnection()->transactional(function () use ($xml) {
|
||||
sqlQuery('DELETE FROM '.self::$tableName.' WHERE 1');
|
||||
|
||||
foreach ($xml->row as $post) {
|
||||
$data = [
|
||||
'zip' => strval($post->PSC),
|
||||
'name' => strval($post->NAZEV),
|
||||
'city' => strval($post->OBEC),
|
||||
'city_part' => strval($post->C_OBCE),
|
||||
'address' => strval($post->ADRESA),
|
||||
'hours' => serialize(self::generateOpeningHours($post->OTEV_DOBY)),
|
||||
];
|
||||
sqlQueryBuilder()->insert(self::$tableName)->directValues($data)->execute();
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDimensionsSum(array $dimensions)
|
||||
{
|
||||
// Maximální rozměry 70 cm x 50cm x 50 cm
|
||||
|
||||
if ($dimensions[0] > 70) {
|
||||
return $dimensions[0];
|
||||
}
|
||||
|
||||
if ($dimensions[1] > 50) {
|
||||
return $dimensions[1];
|
||||
}
|
||||
|
||||
return $dimensions[2];
|
||||
}
|
||||
|
||||
public static function getSettingsConfiguration(): array
|
||||
{
|
||||
return [
|
||||
'fields' => [
|
||||
'dobirkaBOX' => [
|
||||
'title' => 'Zakázat dobírku pro Balíkovna-BOX',
|
||||
'type' => 'toggle',
|
||||
'tooltip' => 'Nepovolit platbu dobírkou při vybrání doručení do Balíkovna-BOXu',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['zip'] ?? '';
|
||||
}
|
||||
}
|
||||
22
class/deliveries/class.BalikovnaNaAdresu.php
Normal file
22
class/deliveries/class.BalikovnaNaAdresu.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class BalikovnaNaAdresu extends Delivery
|
||||
{
|
||||
public static $className = 'Česká pošta - Balíkovna na adresu';
|
||||
|
||||
protected $heureka_delivery_id = ''; // wait for heureka to implement new code
|
||||
protected $zbozi_delivery_id = 'BALIKOVNA_NA_ADRESU';
|
||||
|
||||
protected $track_and_trace = 'https://www.balikovna.cz/cs/sledovat-balik/-/balik/[PACKAGE_ID]';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/balikovna-na-adresu.svg';
|
||||
|
||||
public $config = [
|
||||
// L (nejdelší strana do 100 cm)
|
||||
'maxLength' => 100.0, // Maximální rozměr strany položky
|
||||
'maxSumOfDimensions' => 300.0, // Maximální součet rozměrů všech tří stran položky
|
||||
// legacy config:
|
||||
'max_length' => 98, // Maximální rozměr jedné strany zásilky
|
||||
'max_dimensions' => 300, // Maximální součet rozměrů všech tří stran zásilky
|
||||
];
|
||||
}
|
||||
22
class/deliveries/class.DHL.php
Normal file
22
class/deliveries/class.DHL.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class DHL extends Delivery
|
||||
{
|
||||
public static $className = 'DHL';
|
||||
|
||||
protected $heureka_delivery_id = 'DHL';
|
||||
|
||||
protected $zbozi_delivery_id = 'DHL';
|
||||
|
||||
protected $track_and_trace = [
|
||||
// fallback na nejaky default (prvni v poradi)
|
||||
'EN' => 'https://www.logistics.dhl/gb-en/home/tracking.html?tracking-id=[PACKAGE_ID]&submit=1',
|
||||
// podle zeme
|
||||
'CZ' => 'https://www.logistics.dhl/cz-cs/home/tracking.html?tracking-id=[PACKAGE_ID]&submit=1',
|
||||
'SK' => 'https://www.logistics.dhl/sk-sk/home/tracking.html?tracking-id=[PACKAGE_ID]&submit=1',
|
||||
'DE' => 'https://www.dhl.de/de/privatkunden/dhl-sendungsverfolgung.html?piececode=[PACKAGE_ID]',
|
||||
'NL' => 'https://my.dhlparcel.nl/home/tracktrace/[PACKAGE_ID]',
|
||||
];
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/dhl.svg';
|
||||
}
|
||||
144
class/deliveries/class.DHLServicePoint.php
Normal file
144
class/deliveries/class.DHLServicePoint.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
|
||||
class DHLServicePoint extends Delivery
|
||||
{
|
||||
public static $className = 'DHL ServicePoint';
|
||||
public static $type = self::TYPE_POINT;
|
||||
|
||||
protected $track_and_trace = 'https://www.logistics.dhl/de-de/home/tracking.html?tracking-id=[PACKAGE_ID]&submit=1';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.DHLServicePoint.description.tpl';
|
||||
protected $templateInit = 'deliveries/delivery.DHLServicePoint.init.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.DHLServicePoint.tpl';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/dhl.svg';
|
||||
|
||||
public array $pointData = [];
|
||||
|
||||
public function storeDeliveryInfo($data): array
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$this->pointData = [];
|
||||
$pointData = $data['DHLServicePoint_point'] ?? [];
|
||||
|
||||
if (empty($pointData)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$pointData = json_decode($pointData, true);
|
||||
$pointIds = $this->storeIds($pointData);
|
||||
$this->pointData = array_merge($pointData, $pointIds);
|
||||
|
||||
return $this->pointData;
|
||||
}
|
||||
|
||||
public function loadDeliveryInfo($data)
|
||||
{
|
||||
$this->pointData = $data;
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
return $this->pointData;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->pointData['id'] ?? null;
|
||||
}
|
||||
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
if (empty($this->pointData['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['firm'] = $this->pointData['name'];
|
||||
$cart->delivery['zip'] = $this->pointData['address']['zipCode'];
|
||||
$cart->delivery['street'] = $this->pointData['address']['street'].' '.$this->pointData['address']['number'];
|
||||
$cart->delivery['city'] = $this->pointData['address']['city'];
|
||||
$cart->delivery['country'] = $this->pointData['address']['countryCode'];
|
||||
|
||||
// Je-li zvolena doprava do do vydejniho boxu (Packstation), zapisuju jeji nazev do pole 'street'
|
||||
if (str_contains($this->pointData['name'], 'Packstation')) {
|
||||
$cart->delivery['street'] = $this->pointData['name'];
|
||||
$cart->delivery['custom_address'] = $this->pointData['rec_id'] ?? '';
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
if (empty($this->pointData['id'])) {
|
||||
return 'Není zvolen ServicePoint!';
|
||||
}
|
||||
$data['delivery_firm'] = $this->pointData['name'];
|
||||
$data['delivery_zip'] = $this->pointData['address']['zipCode'];
|
||||
$data['delivery_street'] = $this->pointData['address']['street'].' '.$this->pointData['address']['number'];
|
||||
$data['delivery_city'] = $this->pointData['address']['city'];
|
||||
$data['delivery_country'] = $this->pointData['address']['countryCode'];
|
||||
|
||||
// Je-li zvolena doprava do vydejniho boxu (Packstation), zapisuju jeji nazev do pole 'delivery_street'
|
||||
if (str_contains($this->pointData['name'], 'Packstation')) {
|
||||
$data['delivery_street'] = $this->pointData['name'];
|
||||
$data['delivery_custom_address'] = $this->pointData['rec_id'] ?? '';
|
||||
$data['delivery_firm'] = '';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('delivery', false) && $this->pointData) {
|
||||
// parcel-first-mile - svozove misto odkud se baliky odesilaji
|
||||
// parcel-last-mile - misto pro vyzvednuti baliku
|
||||
// pokud tedy objednavam zbozi, tak pobocka musi podporovat "parcel-last-mile", aby tam balik bylo mozne vyzvednout
|
||||
// bohuzel to nyni nejde odfiltrovat ve widgetu, tak treba az to jednou pujde, tak bude moct jit tenhle if pryc
|
||||
if (!in_array('parcel-last-mile', $this->pointData['serviceTypes'] ?? [])) {
|
||||
throw new DeliveryException(
|
||||
translate_shop('point_pickup_not_supported', 'delivery'),
|
||||
translate_shop('point_pickup_not_supported', 'delivery'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
public function requiresDeliveryAddress(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function storeIds(array $pointData): array
|
||||
{
|
||||
if (!isset($pointData)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// ulozim si Ids do pole a vyparsuju rec_id (Postnummer), pokud je predany v 'id'
|
||||
$pointIds['id'] = $pointData['id'] ?? '';
|
||||
$pointIds['harmonisedId'] = $pointData['harmonisedId'] ?? '';
|
||||
|
||||
if (str_contains($pointIds['id'], '|')) {
|
||||
$pointIds['rec_id'] = substr(strchr($pointIds['id'], '|'), 1);
|
||||
$pointIds['id'] = strchr($pointIds['id'], '|', true);
|
||||
}
|
||||
|
||||
return $pointIds;
|
||||
}
|
||||
}
|
||||
117
class/deliveries/class.DPD.php
Normal file
117
class/deliveries/class.DPD.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Delivery\RestrictionParams;
|
||||
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
|
||||
class DPD extends Delivery
|
||||
{
|
||||
public static $className = 'DPD';
|
||||
|
||||
protected $heureka_delivery_id = 'DPD';
|
||||
protected $zbozi_delivery_id = 'DPD';
|
||||
|
||||
protected $track_and_trace = [
|
||||
'CZ' => 'https://www.dpdgroup.com/cz/mydpd/my-parcels/track?parcelNumber=[PACKAGE_ID]',
|
||||
'FR' => 'https://www.chronopost.fr/tracking-no-cms/suivi-page?listeNumerosLT=[PACKAGE_ID]',
|
||||
];
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_dpd_zip`';
|
||||
|
||||
public static $jsonZipCodesURLs = [
|
||||
'CZ' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/dpd/zipcodes/1/CZ',
|
||||
'SK' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/dpd/zipcodes/1/SK',
|
||||
];
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/dpd.svg';
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('user') && $cart->addressesSet && !empty($cart->invoice['zip'])) {
|
||||
// Check ZIP exists
|
||||
$country = $cart->invoice['country'];
|
||||
if ($country == 'CZ' || $country == 'SK') {
|
||||
$zip = $cart->invoice['zip'];
|
||||
$zipRow = sqlQueryBuilder()->select('id')->from('kupshop_shared.delivery_dpd_zip')
|
||||
->where('country=:country AND zip=:zip')->setParameters(['country' => $country, 'zip' => $zip])
|
||||
->setMaxResults(1)->execute()->fetch();
|
||||
if (!$zipRow && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException(translate('unsupported_zip', 'order_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
$dataToImport = [];
|
||||
foreach (self::$jsonZipCodesURLs as $country => $url) {
|
||||
$json = file_get_contents($url);
|
||||
$data = json_decode_strict($json, true);
|
||||
if (($data['status'] ?? 0 === 200) && (count($data['zip_codes'] ?? []) > 0)) {
|
||||
$dataToImport[$country] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($dataToImport) !== count(self::$jsonZipCodesURLs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlGetConnection()->transactional(function () use ($dataToImport) {
|
||||
sqlQuery('DELETE FROM '.self::$tableName.' WHERE 1');
|
||||
$index = 1;
|
||||
foreach ($dataToImport as $data) {
|
||||
foreach ($data['zip_codes'] as $id => $zipData) {
|
||||
if (!empty($zipData['country']) && !empty($zipData['zip_start'])) {
|
||||
foreach (range($zipData['zip_start'], $zipData['zip_end']) as $zip) {
|
||||
sqlQueryBuilder()->insert(self::$tableName)
|
||||
->directValues(
|
||||
[
|
||||
'id' => $index++,
|
||||
'country' => $zipData['country'],
|
||||
'zip' => $this->prepareZip($zip, $zipData['country']),
|
||||
]
|
||||
)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareZip($zip, $country)
|
||||
{
|
||||
switch ($country) {
|
||||
case 'SK':
|
||||
case 'DE':
|
||||
return str_pad($zip, 5, '0', STR_PAD_LEFT);
|
||||
case 'AT':
|
||||
return str_pad($zip, 4, '0', STR_PAD_LEFT);
|
||||
default:
|
||||
return $zip;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getRestrictionParams(PurchaseState $purchaseState): RestrictionParams
|
||||
{
|
||||
$rParams = clone parent::getRestrictionParams($purchaseState);
|
||||
|
||||
// DPD ma vypocet obvodu stejnej jako PPL
|
||||
Delivery::includeClass('PPL');
|
||||
$rParams->setMaxSumOfDimensions(
|
||||
PPL::calculateMaxSumOfDimensions($rParams)
|
||||
);
|
||||
|
||||
return $rParams;
|
||||
}
|
||||
}
|
||||
198
class/deliveries/class.DPDPickup.php
Normal file
198
class/deliveries/class.DPDPickup.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Delivery\RestrictionParams;
|
||||
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
use Query\Operator;
|
||||
|
||||
class DPDPickup extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'DPD Pickup';
|
||||
|
||||
protected $heureka_delivery_id = 'DPD_PICKUP';
|
||||
protected $zbozi_delivery_id = 'DPD_PICKUP';
|
||||
|
||||
protected $track_and_trace = 'https://tracking.dpd.de/parcelstatus?query=[PACKAGE_ID]&locale=cs_CZ';
|
||||
|
||||
protected $templateInit = 'deliveries/delivery.DPDPickup.init.tpl';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.DPDPickup.description.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.DPDPickup.tpl';
|
||||
protected $adminWindowTemplate = 'delivery/delivery.DPDPickup.customData.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_dpdpickup`';
|
||||
public static $jsonDeliveryBalikobot = ['CZ' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/dpd/fullbranches/3/CZ',
|
||||
'SK' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/dpd/fullbranches/3/SK',
|
||||
'PL' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/dpd/fullbranches/3/PL',
|
||||
];
|
||||
public static $tableColumns = ['id' => 'id', 'country' => 'country', 'name' => 'place',
|
||||
'zip' => 'zip', 'city' => 'city', 'street' => 'street', ];
|
||||
|
||||
public $zip;
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/dpd.svg';
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
if (($this->data['DPDPickup_data']['deliveryId'] ?? false) == $this->id) {
|
||||
$data = $this->data['DPDPickup_data'];
|
||||
} else {
|
||||
if (is_null($id)) {
|
||||
$id = getVal('dpdpickup_id', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlQueryBuilder()
|
||||
->select('*')
|
||||
->from(self::$tableName)
|
||||
->where(Operator::equals(['id' => $id]))
|
||||
->execute()->fetchAssociative();
|
||||
|
||||
if ($data) {
|
||||
$data['code'] = $id ?? '';
|
||||
$data['hours'] = unserialize($data['hours'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['dpdpickup_id'] ?? $this->data['DPDPickup_data']['id'] ?? null;
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$deliveryData = json_decode($data['DPDPickup_data'] ?? '', true);
|
||||
$deliveryData['deliveryId'] = $this->id;
|
||||
|
||||
if (empty($deliveryData)) {
|
||||
$deliveryData = $data['DPDPickup_data'] ?? '';
|
||||
if (empty($deliveryData)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data += ['DPDPickup_data' => $deliveryData];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka DPD Pickup!';
|
||||
}
|
||||
|
||||
$data['delivery_zip'] = $info['address']['zip'] ?? '';
|
||||
$data['delivery_street'] = $info['address']['street'] ?? '';
|
||||
$data['delivery_city'] = $info['address']['city'] ?? '';
|
||||
$data['delivery_country'] = $info['address']['country'] ?? '';
|
||||
$data['delivery_firm'] = $info['firm'] ?? '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['address']['zip'] ?? '';
|
||||
$cart->delivery['street'] = $info['address']['street'] ?? '';
|
||||
$cart->delivery['city'] = $info['address']['city'] ?? '';
|
||||
$cart->delivery['country'] = $info['address']['country'] ?? '';
|
||||
$cart->delivery['firm'] = $info['firm'] ?? '';
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if ($cart->hasData('delivery')) {
|
||||
if (empty($this->data['DPDPickup_data']['id'])) {
|
||||
throw new DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function importFromBalikobot($url = null, $where = null)
|
||||
{
|
||||
foreach (static::$jsonDeliveryBalikobot as $country => $url) {
|
||||
parent::importFromBalikobot($url, Operator::equals(['country' => $country]));
|
||||
}
|
||||
}
|
||||
|
||||
// FULLBRANCHES method used - additional info (opening hours etc.)
|
||||
public function importCustomData($custom_data, $insert)
|
||||
{
|
||||
if ($custom_data) {
|
||||
$days = ['monday' => ['day' => 1, 'dayName' => 'Pondělí'], 'tuesday' => ['day' => 2, 'dayName' => 'Úterý'],
|
||||
'wednesday' => ['day' => 3, 'dayName' => 'Středa'], 'thursday' => ['day' => 4, 'dayName' => 'Čtvrtek'],
|
||||
'friday' => ['day' => 5, 'dayName' => 'Pátek'], 'saturday' => ['day' => 6, 'dayName' => 'Sobota'],
|
||||
'sunday' => ['day' => 7, 'dayName' => 'Neděle'], ];
|
||||
$hours = false;
|
||||
foreach ($custom_data as $key => $item) {
|
||||
$keys = explode('_', $key);
|
||||
if ($keys[0] == 'opening') {
|
||||
$day = $keys[1] ?? '';
|
||||
if (array_key_exists($day, $days)) {
|
||||
$times = explode(',', $item);
|
||||
$morning = explode('-', $times[0]);
|
||||
$days[$day]['openMorning'] = trim($morning[0]);
|
||||
$days[$day]['closeMorning'] = trim($morning[1] ?? '');
|
||||
$afternoon = explode('-', $times[1] ?? '');
|
||||
$days[$day]['openAfternoon'] = trim($afternoon[0]);
|
||||
$days[$day]['closeAfternoon'] = trim($afternoon[1] ?? '');
|
||||
$hours = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($hours) {
|
||||
$insert['hours'] = serialize($days);
|
||||
}
|
||||
$insert['data'] = serialize($custom_data);
|
||||
}
|
||||
|
||||
return $insert;
|
||||
}
|
||||
|
||||
protected function getRestrictionParams(PurchaseState $purchaseState): RestrictionParams
|
||||
{
|
||||
$rParams = clone parent::getRestrictionParams($purchaseState);
|
||||
|
||||
// DPD ma vypocet obvodu stejnej jako PPL
|
||||
Delivery::includeClass('PPL');
|
||||
$rParams->setMaxSumOfDimensions(
|
||||
PPL::calculateMaxSumOfDimensions($rParams)
|
||||
);
|
||||
|
||||
return $rParams;
|
||||
}
|
||||
}
|
||||
15
class/deliveries/class.DiePost.php
Normal file
15
class/deliveries/class.DiePost.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
class DiePost extends Delivery
|
||||
{
|
||||
public static $className = 'DiePost';
|
||||
|
||||
protected $heureka_delivery_id = 'DiePost';
|
||||
|
||||
protected $track_and_trace = 'https://service.post.ch/EasyTrack/submitParcelData.do?formattedParcelCodes=[PACKAGE_ID]';
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return findModule('abra', 'web') == 'parfimo.ch';
|
||||
}
|
||||
}
|
||||
14
class/deliveries/class.DoporucenaZasilka.php
Normal file
14
class/deliveries/class.DoporucenaZasilka.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class DoporucenaZasilka extends Delivery
|
||||
{
|
||||
public static $className = 'Česká pošta - Doporučená zásilka';
|
||||
|
||||
protected $heureka_delivery_id = 'CESKA_POSTA_DOPORUCENA_ZASILKA';
|
||||
|
||||
protected $track_and_trace = 'https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=[PACKAGE_ID]';
|
||||
|
||||
public $config = [
|
||||
'maxDimensions' => [50.0, 35.0, 5.0],
|
||||
];
|
||||
}
|
||||
11
class/deliveries/class.EMS.php
Normal file
11
class/deliveries/class.EMS.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
include_once __DIR__.'/class.BalikDoRuky.php';
|
||||
|
||||
class EMS extends BalikDoRuky
|
||||
{
|
||||
public static $className = 'EMS - EXPRESS MAIL SERVICE';
|
||||
|
||||
protected $heureka_delivery_id;
|
||||
protected $zbozi_delivery_id;
|
||||
}
|
||||
47
class/deliveries/class.FANCourier.php
Normal file
47
class/deliveries/class.FANCourier.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Functional\Mapping;
|
||||
|
||||
class FANCourier extends Delivery
|
||||
{
|
||||
public static $className = 'FAN Courier';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_ro_regions`';
|
||||
|
||||
private $county;
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return findModule('deliveries', 'ro_deliveries');
|
||||
}
|
||||
|
||||
public function getCounty()
|
||||
{
|
||||
if ($this->county) {
|
||||
return $this->county;
|
||||
}
|
||||
|
||||
$county = sqlQueryBuilder()->select('county')
|
||||
->from(self::$tableName)
|
||||
->groupBy('county')
|
||||
->orderBy('county', 'ASC')
|
||||
->execute()->fetchAll();
|
||||
|
||||
return $this->county = Mapping::mapKeys($county, function ($k, $v) {
|
||||
return [$k, $v['county']];
|
||||
});
|
||||
}
|
||||
|
||||
public function getCities($county)
|
||||
{
|
||||
$cities = sqlQueryBuilder()->select('city')
|
||||
->from(self::$tableName)
|
||||
->where(\Query\Operator::equals(['county' => $county]))
|
||||
->orderBy('city', 'ASC')
|
||||
->execute()->fetchAll();
|
||||
|
||||
return Mapping::mapKeys($cities, function ($k, $v) {
|
||||
return [$k, $v['city']];
|
||||
});
|
||||
}
|
||||
}
|
||||
11
class/deliveries/class.Fedex.php
Normal file
11
class/deliveries/class.Fedex.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class Fedex extends Delivery
|
||||
{
|
||||
public static $className = 'Fedex';
|
||||
|
||||
protected $heureka_delivery_id = 'FEDEX';
|
||||
protected $zbozi_delivery_id = 'FEDEX';
|
||||
|
||||
protected $track_and_trace = 'https://www.fedex.com/apps/fedextrack/?action=track&trackingnumber=[PACKAGE_ID]';
|
||||
}
|
||||
75
class/deliveries/class.GLS.php
Normal file
75
class/deliveries/class.GLS.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Delivery\RestrictionParams;
|
||||
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
||||
|
||||
class GLS extends Delivery
|
||||
{
|
||||
public static $className = 'GLS';
|
||||
|
||||
protected $heureka_delivery_id = 'GLS';
|
||||
protected $zbozi_delivery_id = 'GLS';
|
||||
|
||||
protected $track_and_trace = [
|
||||
'CZ' => 'https://gls-group.eu/CZ/cs/sledovani-zasilek?match=[PACKAGE_ID]',
|
||||
'DE' => 'https://www.gls-pakete.de/sendungsverfolgung?match=[PACKAGE_ID]',
|
||||
'HR' => 'https://gls-group.eu/HR/hr/pracenje-paketa/?match=[PACKAGE_ID]',
|
||||
'SI' => 'https://gls-group.eu/SI/sl/sledenje-posiljki?match=[PACKAGE_ID]',
|
||||
'RO' => 'https://gls-group.eu/RO/ro/urmarire-colet.html?match=[PACKAGE_ID]',
|
||||
'SK' => 'https://gls-group.eu/SK/sk/sledovanie-zasielok.html?match=[PACKAGE_ID]',
|
||||
'PL' => 'https://gls-group.com/PL/pl/sledzenie-paczek.html?match=[PACKAGE_ID]',
|
||||
'ES' => 'https://www.gls-spain.es/es/recibir-paquetes/seguimiento-envio/?match=[PACKAGE_ID]&international=1',
|
||||
'DK' => 'https://gls-group.eu/DK/da/find-pakke.html?match=[PACKAGE_ID]',
|
||||
'FI' => 'https://gls-group.eu/FI/fi/laehetysseuranta.html?match=[PACKAGE_ID]',
|
||||
'FR' => 'https://gls-group.eu/FR/fr/suivi-colis.html?match=[PACKAGE_ID]',
|
||||
'IE' => 'https://gls-group.eu/IE/en/parcel-tracking.html?match=[PACKAGE_ID]',
|
||||
'IT' => 'https://gls-group.eu/IT/it/servizi-online/ricerca-spedizioni.html?match=[PACKAGE_ID]&type=INT',
|
||||
'HU' => 'https://gls-group.eu/HU/hu/csomagkovetes.html?match=[PACKAGE_ID]',
|
||||
];
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/gls.svg';
|
||||
|
||||
public $config = [
|
||||
'price_limit' => 60000,
|
||||
'maxLength' => 200.0, // Maximální rozměr strany položky
|
||||
// kombinace délky + obvodu je max 300cm.
|
||||
// Vypočte se jako 2x výška plus 2x šířka plus 1x nejdelší strana.
|
||||
// Např. balík 25x25x200cm => součet rozměrů tří stran 250cm
|
||||
'maxSumOfDimensions' => 250.0, // Maximální součet rozměrů všech tří stran položky
|
||||
'maxDimensions' => [80.0, 60.0, 200.0],
|
||||
// legacy config:
|
||||
'max_length' => 230, // Maximální rozměr jedné strany zásilky
|
||||
'max_dimensions' => 300, // Maximální součet délky a obvodu
|
||||
];
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('delivery') && $cart->hasData('user')) {
|
||||
$this->zipExists($cart->invoice);
|
||||
$this->zipExists($cart->delivery);
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
protected function getRestrictionParams(PurchaseState $purchaseState): RestrictionParams
|
||||
{
|
||||
$rParams = clone parent::getRestrictionParams($purchaseState);
|
||||
|
||||
// GLS ma vypocet obvodu stejnej jako PPL
|
||||
Delivery::includeClass('PPL');
|
||||
$rParams->setMaxSumOfDimensions(
|
||||
PPL::calculateMaxSumOfDimensions($rParams)
|
||||
);
|
||||
|
||||
return $rParams;
|
||||
}
|
||||
|
||||
public function getDimensionsSum(array $dimensions)
|
||||
{
|
||||
// Součet délky a obvodu = Obvod obchodního balíku plus nejdelší strana
|
||||
// x+2*y+2*z= max 300
|
||||
|
||||
return $dimensions[0] + 2 * ($dimensions[1] + $dimensions[2]);
|
||||
}
|
||||
}
|
||||
222
class/deliveries/class.GLSParcelShop.php
Normal file
222
class/deliveries/class.GLSParcelShop.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
use KupShop\OrderingBundle\Exception\PaymentException;
|
||||
|
||||
class GLSParcelShop extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'GLS ParcelShop';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.GLSParcelShop.description.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.GLSParcelShop.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_glsparcelshop`';
|
||||
|
||||
public static $jsonDeliveryBalikobot = 'https://test20cztest:QKCufcWs@api.balikobot.cz/gls/branches/2';
|
||||
|
||||
public $zip;
|
||||
|
||||
public $delivery_glsparcelshop_id;
|
||||
|
||||
protected $heureka_delivery_id = 'GLS_PARCELSHOP';
|
||||
|
||||
protected $zbozi_delivery_id = 'GLS_PARCELSHOP';
|
||||
|
||||
protected $track_and_trace = 'https://gls-group.eu/CZ/cs/sledovani-zasilek?match=[PACKAGE_ID]';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/gls.svg';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->delivery_glsparcelshop_id);
|
||||
|
||||
return parent::getName().' - '.$info['city'].', '.($info['address'] ?? $info['street']).', '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$pointData = $data['widget'] ?? '';
|
||||
$pointData = json_decode($pointData, true);
|
||||
|
||||
if (empty($pointData)) {
|
||||
$id = trim($data['glsparcelshop_id'] ?? '');
|
||||
|
||||
$info = $this->getInfo($id);
|
||||
|
||||
return empty($id) ? [] : ($this->data = [
|
||||
'zip' => $info['zip'],
|
||||
'glsparcelshop_id' => $info['id'],
|
||||
'subtype' => $info['type'],
|
||||
]);
|
||||
}
|
||||
$pointData['deliveryId'] = $this->id;
|
||||
$this->data += ['widget' => $pointData];
|
||||
|
||||
return $this->data += [
|
||||
'glsparcelshop_id' => $this->getPointId(), // BC
|
||||
];
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
// Není to úplně pěkný, ale jestli chceme do budoucna řešit extra instanci widgetu pro boxy/pobočky tak to je potřeba
|
||||
if (!empty($this->data['widget'])) {
|
||||
$data = $this->data['widget'];
|
||||
} else {
|
||||
if (is_null($id)) {
|
||||
if (!($id = getVal('glsparcelshop_id', $this->data))) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
}
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.' WHERE id=:id', ['id' => $id]));
|
||||
// Make old data compatible with new data
|
||||
$data['code'] = $id;
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['pclshopid'] ?? $this->data['widget']['pclshopid'] ?? $this->data['glsparcelshop_id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id']) && empty($info['pclshopid'])) {
|
||||
return 'Není zvolena pobočka GLS ParcelShop!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'] ?? $info['zipcode'] ?? null;
|
||||
$data['delivery_street'] = $info['street'] ?? $info['address'] ?? null;
|
||||
$data['delivery_city'] = $info['city'] ?? null;
|
||||
$data['delivery_country'] = $info['country'] ?? $info['ctrcode'] ?? null;
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['pclshopid'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zipcode'] ?? null;
|
||||
$cart->delivery['street'] = $info['address'] ?? null;
|
||||
$cart->delivery['city'] = $info['city'] ?? null;
|
||||
$cart->delivery['country'] = $info['ctrcode'] ?? null;
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
$street = $info['street'] ?? $info['address'] ?? '';
|
||||
$zip = $info['zip'] ?? $info['zipcode'] ?? '';
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$street}, {$info['name']}, <strong>{$zip}</strong>";
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['glsparcelshop_id']) && empty($this->data['widget']) && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
if (($payment instanceof Dobirka) && (Settings::getDefault()['deliveries']['GLSParcelShop']['dobirkaGLSBOX'] ?? null)) {
|
||||
$subtype = $this->data['subtype'] ?? $this->data['widget']['parcelBox'] ?? null;
|
||||
if ($subtype == 'box' || $subtype == 1) {
|
||||
throw new PaymentException('Platba dobírkou není dostupná v případě doručení do GLS ParcelBoxu.
|
||||
Zvolte prosím pobočku jiného typu nebo platbu předem.', 'Nedostupná pro GLS ParcelBox');
|
||||
}
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
if (!empty($this->data['widget'])) {
|
||||
if (($info['ctrcode'] ?? null) && $info['ctrcode'] != $this->getCountryByCurrency($currencyContext->getActiveId())) {
|
||||
throw new DeliveryException('Vybraná pobočka GLS ParcelShop nepodporuje vaši měnu.');
|
||||
}
|
||||
} else {
|
||||
if (!empty($this->data['glsparcelshop_id']) && ($info['country'] ?? false) && $info['country'] != $this->getCountryByCurrency($currencyContext->getActiveId())) {
|
||||
throw new DeliveryException('Vybraná pobočka GLS ParcelShop nepodporuje vaši měnu.');
|
||||
}
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currency string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCountryByCurrency($currency)
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return 'CZ';
|
||||
break;
|
||||
case 'EUR':
|
||||
return 'SK';
|
||||
break;
|
||||
case 'HUF':
|
||||
return 'HU';
|
||||
break;
|
||||
case 'RON':
|
||||
return 'RO';
|
||||
break;
|
||||
case 'PLN':
|
||||
return 'PL';
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSettingsConfiguration(): array
|
||||
{
|
||||
return [
|
||||
'fields' => [
|
||||
'dobirkaGLSBOX' => [
|
||||
'title' => 'Zakázat dobírku pro GLS ParcelBox',
|
||||
'type' => 'toggle',
|
||||
'tooltip' => 'Nepovolit platbu dobírkou při vybrání doručení do GLS ParcelBox',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
13
class/deliveries/class.Geis.php
Normal file
13
class/deliveries/class.Geis.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class Geis extends Delivery
|
||||
{
|
||||
public static $className = 'Geis';
|
||||
|
||||
protected $heureka_delivery_id = 'GEIS';
|
||||
protected $zbozi_delivery_id = 'GEIS';
|
||||
|
||||
protected $track_and_trace = 'https://www.geis-group.cz/cs/sledovani-zasilky?p=[PACKAGE_ID]';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/geis.svg';
|
||||
}
|
||||
177
class/deliveries/class.GeisPoint.php
Normal file
177
class/deliveries/class.GeisPoint.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
class GeisPoint extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $className = 'Geis Point';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.GeisPoint.description.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.GeisPoint.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_geispoint`';
|
||||
|
||||
public static $jsonDeliveryBalikobot = 'https://test20cztest:QKCufcWs@api.balikobot.cz/geis/branches/6';
|
||||
|
||||
public $zip;
|
||||
|
||||
public $delivery_geispoint_id;
|
||||
|
||||
// protected $heureka_delivery_id = 'GEIS'; // ?? Geis (nejedná se o Geis Point)
|
||||
protected $zbozi_delivery_id = 'GEIS_POINT';
|
||||
|
||||
protected $track_and_trace = 'https://www.geis-group.cz/cs/sledovani-zasilky?p=[PACKAGE_ID]';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/geis.svg';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->delivery_geispoint_id);
|
||||
|
||||
return parent::getName().' - '.$info['city'].', '.$info['street'].', '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$id = trim($data['geispoint_id'] ?? '');
|
||||
|
||||
$info = $this->getInfo($id);
|
||||
|
||||
return empty($id) ? [] : ($this->data = [
|
||||
'zip' => $info['zip'],
|
||||
'geispoint_id' => $info['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = getVal('geispoint_id', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.'
|
||||
WHERE id=:id',
|
||||
['id' => $id]));
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
$data['address'] = $data['street'].', '.$data['zip'].', '.$data['city'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka Geis Point!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['name']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function requiresDeliveryAddress()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \KupShop\OrderingBundle\Exception\DeliveryException
|
||||
*/
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if (empty($this->data['geispoint_id']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
if (!empty($this->data['geispoint_id']) && $info['country'] != $this->getCountryByCurrency($currencyContext->getActiveId())) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException('Vybraná pobočka Geis Point nepodporuje vaši měnu.');
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currency string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCountryByCurrency($currency)
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return 'CZ';
|
||||
break;
|
||||
case 'EUR':
|
||||
return 'SK';
|
||||
break;
|
||||
case 'HUF':
|
||||
return 'HU';
|
||||
break;
|
||||
case 'RON':
|
||||
return 'RO';
|
||||
break;
|
||||
case 'PLN':
|
||||
return 'PL';
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
11
class/deliveries/class.InTime.php
Normal file
11
class/deliveries/class.InTime.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class InTime extends Delivery
|
||||
{
|
||||
public static $className = 'InTime';
|
||||
|
||||
protected $heureka_delivery_id = 'INTIME';
|
||||
protected $zbozi_delivery_id = 'INTIME';
|
||||
|
||||
protected $track_and_trace = 'http://trace.intime.cz/index.php?action=vSearch';
|
||||
}
|
||||
157
class/deliveries/class.InTimePoint.php
Normal file
157
class/deliveries/class.InTimePoint.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
class InTimePoint extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'InTime - Výdejní místa';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_intime`';
|
||||
public static $jsonDeliveryBalikobot = 'https://test20cztest:QKCufcWs@api.balikobot.cz/intime/branches/4';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.InTimePoint.description.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.InTimePoint.tpl';
|
||||
|
||||
public $zip;
|
||||
|
||||
public $intime_id;
|
||||
|
||||
protected $track_and_trace = 'https://trace.intime.cz/index.php?action=vSearch';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->intime_id);
|
||||
|
||||
return parent::getName().' - '.$info['city'].', '.$info['street'].', '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$id = trim($data['intime_id'] ?? '');
|
||||
|
||||
$info = $this->getInfo($id);
|
||||
|
||||
return empty($id) ? [] : ($this->data = [
|
||||
'zip' => $info['zip'],
|
||||
'intime_id' => $info['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = getVal('intime_id', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.'
|
||||
WHERE id=:id', ['id' => $id]));
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
$data['address'] = $data['street'].', '.$data['zip'].', '.$data['city'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka InTime!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['name']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['intime_id']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
if (!empty($this->data['intime_id']) && $info['country'] != $this->getCountryByCurrency($currencyContext->getActiveId())) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException('Vybraná pobočka InTime nepodporuje vaši měnu.');
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currency string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCountryByCurrency($currency)
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return 'CZ';
|
||||
break;
|
||||
case 'EUR':
|
||||
return 'SK';
|
||||
break;
|
||||
case 'HUF':
|
||||
return 'HU';
|
||||
break;
|
||||
case 'RON':
|
||||
return 'RO';
|
||||
break;
|
||||
case 'PLN':
|
||||
return 'PL';
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
115
class/deliveries/class.Lockers.php
Normal file
115
class/deliveries/class.Lockers.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
class Lockers extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Lockers';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.Lockers.widget.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.Lockers.tpl';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo();
|
||||
|
||||
return parent::getName().' - '.$info['box_name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$data = array_filter($data['lockers'] ?? []);
|
||||
|
||||
$data += $this->getInfo($data['lockers_id'], $data['lockers_carrier']);
|
||||
|
||||
return empty($data) ? [] : ($this->data = $data);
|
||||
}
|
||||
|
||||
public function getInfo($id = null, $carrier = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = getVal('lockers_id', $this->data);
|
||||
}
|
||||
if (is_null($carrier)) {
|
||||
$carrier = getVal('lockers_carrier', $this->data);
|
||||
}
|
||||
|
||||
if (!$id || !$carrier) {
|
||||
return ['box_name' => translate_shop('branch_unknown', 'delivery')];
|
||||
}
|
||||
|
||||
$data = $this->data;
|
||||
$data['lockers_id'] = $id;
|
||||
$data['carrier'] = $carrier;
|
||||
$box_name = $data['lockers_box_name'] ?? null;
|
||||
if (!$box_name) {
|
||||
$data['box_name'] = translate_shop('branch_unknown', 'delivery');
|
||||
$data['address'] = '';
|
||||
} else {
|
||||
$box_name = explode(',', $box_name);
|
||||
$data['box_name'] = array_shift($box_name);
|
||||
$data['address'] = trim(implode(',', $box_name));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['lockers_id'])) {
|
||||
return translate_shop('branch_not_selected', 'delivery');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['lockers_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
$cart->delivery['firm'] = $info['box_name'];
|
||||
$cart->delivery['custom_address'] = $info['address'];
|
||||
}
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['lockers_id'])) {
|
||||
return $info['box_name'];
|
||||
}
|
||||
|
||||
return "<strong>{$info['box_name']}</strong>, {$info['address']}";
|
||||
}
|
||||
|
||||
public function isInPerson()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['lockers_id']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate_shop('branch_not_selected', 'delivery'));
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
}
|
||||
144
class/deliveries/class.OdberNaProdejne.php
Normal file
144
class/deliveries/class.OdberNaProdejne.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
use KupShop\SellerBundle\Utils\SellerUtil;
|
||||
|
||||
class OdberNaProdejne extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_IN_PERSON;
|
||||
public static $className = 'Odběr na prodejně';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/osobni-odber.svg';
|
||||
|
||||
protected $zbozi_delivery_id = 'VLASTNI_VYDEJNI_MISTA';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.OdberNaProdejne.description.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.OdberNaProdejne.tpl';
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return findModule(Modules::SELLERS);
|
||||
}
|
||||
|
||||
public function getInfo($id = null): array
|
||||
{
|
||||
if ($id === null) {
|
||||
$id = getVal('seller_id', $this->data);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sellerUtil = ServiceContainer::getService(SellerUtil::class);
|
||||
$seller = $sellerUtil->getSeller((int) $id);
|
||||
|
||||
return [
|
||||
'id' => $seller['id'] ?? '',
|
||||
'name' => $seller['title'] ?? '',
|
||||
'address' => ($seller['psc'] ?? '').', '.($seller['title'] ?? ''),
|
||||
'street' => implode(' ', array_filter([$seller['street'] ?? '', $seller['number'] ?? ''])),
|
||||
'zip' => $seller['psc'] ?? '',
|
||||
'city' => $seller['city'] ?? '',
|
||||
'country' => $seller['country'] ?? 'CZ',
|
||||
];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$id = trim($data['seller_id'] ?? '');
|
||||
|
||||
// Potrebuju to tady invalidovat kvuli napr. manipulacnim poplatkum, ktere jsou udelane pres slevy
|
||||
ServiceContainer::getService(\KupShop\OrderingBundle\Cart::class)->invalidatePurchaseState();
|
||||
|
||||
return empty($id) ? [] : ($this->data = array_merge($data, ['seller_id' => $id]));
|
||||
}
|
||||
|
||||
public function setPointId($id): self
|
||||
{
|
||||
$this->data['seller_id'] = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['seller_id'] ?? null;
|
||||
}
|
||||
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka pro vyzvednutí!';
|
||||
}
|
||||
|
||||
$data['delivery_firm'] = $info['name'];
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['seller_id']) && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException('Nevybrali jste pobočku pro vyzvednutí!');
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function requiresDeliveryAddress()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['name']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function getDeliveryDate()
|
||||
{
|
||||
$purchaseState = ServiceContainer::getService(\KupShop\OrderingBundle\Cart::class)->getPurchaseState();
|
||||
$sellerUtil = ServiceContainer::getService(SellerUtil::class);
|
||||
|
||||
$sellers = $sellerUtil->getSellers();
|
||||
|
||||
$sellerUtil->loadSellersDeliveryInfoByPurchaseState($purchaseState, $sellers);
|
||||
|
||||
if ($sellers[$this->getPointId()]['deliveryDate'] ?? false) {
|
||||
return $sellers[$this->getPointId()]['deliveryDate'];
|
||||
}
|
||||
|
||||
return parent::getDeliveryDate();
|
||||
}
|
||||
}
|
||||
87
class/deliveries/class.OsobniOdber.php
Normal file
87
class/deliveries/class.OsobniOdber.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\DateUtil;
|
||||
|
||||
class OsobniOdber extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_IN_PERSON;
|
||||
public static $className = 'Osobní odběr';
|
||||
protected $adminWindowTemplate = 'delivery/deliveryOpeningHours.tpl';
|
||||
protected $zbozi_delivery_id = 'VLASTNI_VYDEJNI_MISTA';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/osobni-odber.svg';
|
||||
|
||||
public function processAdminWindowData($data)
|
||||
{
|
||||
if (!empty($data['opening_hours'])) {
|
||||
$dataPresent = false;
|
||||
foreach ($data['opening_hours'] as &$time) {
|
||||
if (!empty($time[0]) && !empty($time[1])) {
|
||||
$time0 = DateTime::createFromFormat('H:i', $time[0]);
|
||||
$time1 = DateTime::createFromFormat('H:i', $time[1]);
|
||||
if (!$time0 || !$time1 || $time0 >= $time1) {
|
||||
$time[0] = null;
|
||||
$time[1] = null;
|
||||
} else {
|
||||
$dataPresent = true;
|
||||
}
|
||||
} else {
|
||||
$time[0] = null;
|
||||
$time[1] = null;
|
||||
}
|
||||
}
|
||||
if (!$dataPresent) {
|
||||
unset($data['opening_hours']);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function isWorkday($date, ?array $countries = null)
|
||||
{
|
||||
if (empty($this->custom_data['opening_hours'])) {
|
||||
return parent::isWorkday($date);
|
||||
}
|
||||
|
||||
static $holidays = null;
|
||||
|
||||
if (is_null($holidays)) {
|
||||
$holidays = Yasumi\Yasumi::create('CzechRepublic', $date->format('Y'));
|
||||
}
|
||||
|
||||
if ($holidays->isHoliday($date)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($this->custom_data['opening_hours'][$date->format('N')][1])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isOpen(): bool
|
||||
{
|
||||
$is_open = false;
|
||||
if (!empty($this->custom_data['opening_hours'])) {
|
||||
$result = DateUtil::isOpen($this->custom_data['opening_hours']);
|
||||
$this->is_open = $result['is_open_today'];
|
||||
$is_open = $result['is_open'];
|
||||
}
|
||||
|
||||
return $is_open;
|
||||
}
|
||||
|
||||
public function createFromArray($row)
|
||||
{
|
||||
parent::createFromArray($row);
|
||||
|
||||
if (!$this->time_hours && !empty($this->custom_data)) {
|
||||
$dayofweek = (new DateTime())->format('N');
|
||||
if (isset($this->custom_data['opening_hours'][$dayofweek][1])) {
|
||||
$this->time_hours = $this->custom_data['opening_hours'][$dayofweek][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
118
class/deliveries/class.PPL.php
Normal file
118
class/deliveries/class.PPL.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Delivery\RestrictionParams;
|
||||
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
|
||||
class PPL extends Delivery
|
||||
{
|
||||
public static $className = 'PPL';
|
||||
|
||||
protected $heureka_delivery_id = 'PPL';
|
||||
protected $zbozi_delivery_id = 'PPL';
|
||||
|
||||
protected $track_and_trace = [
|
||||
'EN' => 'https://www.ppl.cz/en/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'CZ' => 'https://www.ppl.cz/cs/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'SK' => 'https://www.ppl.cz/cs/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'DE' => 'https://www.ppl.cz/en/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
];
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_ppl_zip`';
|
||||
|
||||
public static $jsonZipCodesURLs = [
|
||||
'CZ' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/ppl/zipcodes/4',
|
||||
'SK' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/ppl/zipcodes/2/SK',
|
||||
];
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/ppl.svg';
|
||||
|
||||
/**
|
||||
* @param $cart \Cart
|
||||
*/
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('user') && $cart->addressesSet && !empty($cart->invoice['zip'])) {
|
||||
// Check ZIP exists
|
||||
$country = $cart->invoice['country'];
|
||||
if ($country == 'CZ' || $country == 'SK') {
|
||||
$zip = $cart->invoice['zip'];
|
||||
$zipRow = sqlQueryBuilder()->select('id')->from('kupshop_shared.delivery_ppl_zip')
|
||||
->where('country=:country AND zip=:zip')->setParameters(['country' => $country, 'zip' => $zip])
|
||||
->setMaxResults(1)->execute()->fetch();
|
||||
if (!$zipRow && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException(translate('false_zip', 'order_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
protected function getRestrictionParams(PurchaseState $purchaseState): RestrictionParams
|
||||
{
|
||||
$rParams = clone parent::getRestrictionParams($purchaseState);
|
||||
|
||||
$rParams->setMaxSumOfDimensions(
|
||||
static::calculateMaxSumOfDimensions($rParams)
|
||||
);
|
||||
|
||||
return $rParams;
|
||||
}
|
||||
|
||||
public static function calculateMaxSumOfDimensions(RestrictionParams $rParams): float
|
||||
{
|
||||
$dimensions = $rParams->getMaxDimensions();
|
||||
|
||||
if (is_array($dimensions)) {
|
||||
sort($dimensions);
|
||||
}
|
||||
|
||||
// A + 2B + 2C, kde A je nejdelsi strana
|
||||
return (float) ($rParams->getMaxLength() + (2 * ($dimensions[0] ?? 0.0)) + (2 * ($dimensions[1] ?? 0.0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
$dataToImport = [];
|
||||
foreach (self::$jsonZipCodesURLs as $country => $url) {
|
||||
$json = file_get_contents($url);
|
||||
$data = json_decode_strict($json, true);
|
||||
if ($data['status'] ?? 0 === 200 && count($data['zip_codes'] ?? []) > 0) {
|
||||
$dataToImport[$country] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($dataToImport) !== count(self::$jsonZipCodesURLs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlGetConnection()->transactional(function () use ($dataToImport) {
|
||||
sqlQuery('DELETE FROM '.self::$tableName.' WHERE 1');
|
||||
$index = 1;
|
||||
foreach ($dataToImport as $data) {
|
||||
foreach ($data['zip_codes'] as $id => $zipData) {
|
||||
if (!empty($zipData['country']) && !empty($zipData['zip'])) {
|
||||
sqlQueryBuilder()->insert(self::$tableName)
|
||||
->directValues(
|
||||
[
|
||||
'id' => $index++,
|
||||
'country' => $zipData['country'],
|
||||
'zip' => $zipData['zip'],
|
||||
'evening_delivery' => $zipData['del_eveninig'] ?? $zipData['del_evening'] ?? false,
|
||||
]
|
||||
)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
228
class/deliveries/class.PPLParcelShop.php
Normal file
228
class/deliveries/class.PPLParcelShop.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Delivery\RestrictionParams;
|
||||
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
||||
|
||||
class PPLParcelShop extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'PPL ParcelShop';
|
||||
|
||||
protected $track_and_trace = [
|
||||
'EN' => 'https://www.ppl.cz/en/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'CZ' => 'https://www.ppl.cz/cs/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'SK' => 'https://www.ppl.cz/cs/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'PL' => 'https://www.ppl.cz/en/track-a-shipment?shipmentId=[PACKAGE_ID]',
|
||||
'DE' => 'https://www.logistics.dhl/de-de/home/tracking.html?tracking-id=[PACKAGE_ID]&submit=1',
|
||||
];
|
||||
|
||||
protected $templateInit = 'deliveries/delivery.PPLParcelShop.init.tpl';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.PPLParcelShop.description.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.PPLParcelShop.tpl';
|
||||
protected $adminWindowTemplate = 'delivery/delivery.PPLParcelShop.customData.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_pplparcelshop`';
|
||||
|
||||
public static $jsonDeliveryBalikobot = [
|
||||
'CZ' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/ppl/branches/4',
|
||||
'SK' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/ppl/branches/2/SK',
|
||||
'DE' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/ppl/branches/2/DE',
|
||||
'PL' => 'https://test20cztest:QKCufcWs@api.balikobot.cz/ppl/branches/2/PL',
|
||||
];
|
||||
|
||||
public $zip;
|
||||
|
||||
public $delivery_pplparcelshop_id;
|
||||
|
||||
protected $heureka_delivery_id = 'PPL_PARCELSHOP';
|
||||
protected $zbozi_delivery_id = 'PPL_PARCELSHOP';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/ppl.svg';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->delivery_pplparcelshop_id);
|
||||
|
||||
return parent::getName().' - '.$info['city'].', '.$info['street'].', '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$pointData = $data['PPLParcelShop_data'] ?? '';
|
||||
$pointData = json_decode($pointData, true);
|
||||
$pointData['deliveryId'] = $this->id;
|
||||
|
||||
if (empty($pointData)) {
|
||||
$pointData = $data['pplparcelshop_id'] ?? '';
|
||||
if (empty($pointData)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data += ['PPLParcelShop_data' => $pointData];
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
// Není to úplně pěkný, ale jestli chceme do budoucna řešit extra instanci widgetu pro boxy/pobočky tak to je potřeba
|
||||
if (($this->data['PPLParcelShop_data']['deliveryId'] ?? false) == $this->id) {
|
||||
$data = $this->data['PPLParcelShop_data'];
|
||||
} else {
|
||||
if (is_null($id)) {
|
||||
$id = getVal('pplparcelshop_id', $this->data);
|
||||
}
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.' WHERE id=:id', ['id' => $id]));
|
||||
// Make old data compatible with new data
|
||||
$data['code'] = $id;
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka PPL ParcelShop!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'] ?? $info['zipCode'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'] ?? $info['zipCode'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
$zip = $info['zip'] ?? $info['zipCode'];
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['name']}, <strong>{$zip}</strong>";
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['PPLParcelShop_data']['code'] ?? $this->data['pplparcelshop_id'] ?? null;
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['pplparcelshop_id']) && empty($this->data['PPLParcelShop_data']['code']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
if (!empty($this->data['pplparcelshop_id']) && !in_array($info['country'],
|
||||
$this->getCountryByCurrency($currencyContext->getActiveId()))) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate('branch_currency_not_supported', 'delivery'));
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function importFromBalikobot($url = null, $where = null)
|
||||
{
|
||||
foreach (static::$jsonDeliveryBalikobot as $country => $url) {
|
||||
parent::importFromBalikobot($url, \Query\Operator::equals(['country' => $country]));
|
||||
}
|
||||
}
|
||||
|
||||
protected function getRestrictionParams(PurchaseState $purchaseState): RestrictionParams
|
||||
{
|
||||
$rParams = clone parent::getRestrictionParams($purchaseState);
|
||||
|
||||
$rParams->setMaxSumOfDimensions(
|
||||
PPL::calculateMaxSumOfDimensions($rParams)
|
||||
);
|
||||
|
||||
return $rParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currency string
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function getCountryByCurrency($currency)
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return ['CZ'];
|
||||
break;
|
||||
case 'EUR':
|
||||
return ['SK', 'DE'];
|
||||
break;
|
||||
case 'HUF':
|
||||
return ['HU'];
|
||||
break;
|
||||
case 'RON':
|
||||
return ['RO'];
|
||||
break;
|
||||
case 'PLN':
|
||||
return ['PL'];
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function BOXOnly(): bool
|
||||
{
|
||||
$hidden_points = $this->getCustomData()['widget_options']['hidden_points'] ?? [];
|
||||
|
||||
if (in_array('ParcelShop', $hidden_points)) {
|
||||
// hidden ParcelShop - show only boxes
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
142
class/deliveries/class.Paczkomaty.php
Normal file
142
class/deliveries/class.Paczkomaty.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
class Paczkomaty extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Paczkomaty';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.Paczkomaty.description.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.Paczkomaty.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_paczkomaty`';
|
||||
|
||||
public static $jsonDeliveryBalikobot = 'https://test20cztest:QKCufcWs@api.balikobot.cz/pbh/branches/14';
|
||||
public static $tableColumns = ['id' => 'id', 'country' => 'country', 'name' => 'name',
|
||||
'zip' => 'zip', 'city' => 'city', 'address' => 'street', 'district' => 'district', 'type' => 'type', 'street' => 'street', ];
|
||||
public static $excludeColumns = ['latitude', 'longitude'];
|
||||
|
||||
public $delivery_paczkomaty_id;
|
||||
|
||||
protected $track_and_trace = 'https://inpost.pl/sledzenie-przesylek?number=[PACKAGE_ID]';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->delivery_paczkomaty_id);
|
||||
|
||||
return parent::getName().' - '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$id = trim($data['paczkomaty_id'] ?? '');
|
||||
|
||||
$info = $this->getInfo($id);
|
||||
|
||||
return empty($id) ? [] : ($this->data = [
|
||||
'zip' => $info['zip'],
|
||||
'paczkomaty_id' => $info['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = getVal('paczkomaty_id', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlFetchAssoc(sqlQueryBuilder()->select('*')
|
||||
->from(self::$tableName)->where(\Query\Operator::equals(['id' => $id]))->execute());
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => translate_shop('branch_unknown', 'delivery')];
|
||||
}
|
||||
|
||||
$data['address'] = $data['street'].', '.$data['zip'].', '.$data['city'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return translate_shop('branch_not_selected', 'delivery');
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return $info['name'];
|
||||
}
|
||||
|
||||
return "{$info['name']}, {$info['street']}, <strong>{$info['zip']} {$info['city']}</strong>";
|
||||
}
|
||||
|
||||
public function requiresDeliveryAddress()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['paczkomaty_id']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate_shop('branch_not_selected', 'delivery'));
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function setPointId($id): self
|
||||
{
|
||||
$this->data['paczkomaty_id'] = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['paczkomaty_id'];
|
||||
}
|
||||
}
|
||||
8
class/deliveries/class.Raben.php
Normal file
8
class/deliveries/class.Raben.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Raben extends Delivery
|
||||
{
|
||||
public static $className = 'Raben';
|
||||
|
||||
protected $track_and_trace = 'https://myraben.com/link/ShipmentInformation?shipmentNumber=[PACKAGE_ID]';
|
||||
}
|
||||
129
class/deliveries/class.SPBalikoBOX.php
Normal file
129
class/deliveries/class.SPBalikoBOX.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
|
||||
class SPBalikoBOX extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Slovenská pošta - BalíkoBOX';
|
||||
|
||||
protected $heureka_delivery_id = 'BALIKOBOX';
|
||||
|
||||
protected $track_and_trace = 'https://tandt.posta.sk/zasielky/[PACKAGE_ID]';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_sp_balikobox`';
|
||||
public static $jsonDeliveryBalikobot = 'https://test20cztest:QKCufcWs@api.balikobot.cz/sp/branches/BNB';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.SPBalikoBOX.description.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.SPBalikoBOX.tpl';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo();
|
||||
|
||||
return parent::getName().' - '.$info['name'];
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = getVal('spbalikobox_id', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlQueryBuilder()->select('*')
|
||||
->from(static::$tableName)
|
||||
->where(\Query\Operator::equals(['id' => $id]))
|
||||
->execute()->fetch();
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$id = trim($data['spbalikobox_id'] ?? '');
|
||||
|
||||
$info = $this->getInfo($id);
|
||||
|
||||
return empty($info['id']) ? [] : ($this->data = [
|
||||
'zip' => $info['zip'],
|
||||
'spbalikobox_id' => $info['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return translate_shop('branch_not_selected', 'delivery');
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['name']}</strong>, {$info['zip']} {$info['city']}, {$info['street']}";
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['spbalikobox_id']) && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException(translate_shop('branch_not_selected', 'delivery'));
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function importCustomData($custom_data, $insert)
|
||||
{
|
||||
return $insert;
|
||||
}
|
||||
}
|
||||
11
class/deliveries/class.SPS.php
Normal file
11
class/deliveries/class.SPS.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class SPS extends Delivery
|
||||
{
|
||||
public static $className = 'SPS';
|
||||
|
||||
protected $heureka_delivery_id = 'SPS';
|
||||
protected $zbozi_delivery_id = 'SPS';
|
||||
|
||||
protected $track_and_trace = 'https://www.sps-sro.sk/sledovanie-zasielky/';
|
||||
}
|
||||
159
class/deliveries/class.SPSParcelShop.php
Normal file
159
class/deliveries/class.SPSParcelShop.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
class SPSParcelShop extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'SPS Parcel Shop';
|
||||
|
||||
protected $heureka_delivery_id = 'SPS';
|
||||
protected $zbozi_delivery_id = 'SPS';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.SPSParcelShop.description.tpl';
|
||||
protected $templateInit = 'deliveries/delivery.SPSParcelShop.init.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.SPSParcelShop.tpl';
|
||||
|
||||
protected $track_and_trace = 'https://www.sps-sro.sk/sledovanie-zasielky/';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return parent::getName().' - '.$info['city'].', '.$info['street'].', '.$info['description'];
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['id_point'] ?? null;
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
if (isset($data['sps_parcel_shop_point'])) {
|
||||
$point = $data['sps_parcel_shop_point'];
|
||||
$point = json_decode($point, true);
|
||||
|
||||
if (isset($point['id'])) {
|
||||
$this->data += [
|
||||
'id_point' => $point['id'],
|
||||
'zip' => $point['zip'],
|
||||
'street' => $point['address'],
|
||||
'city' => $point['city'],
|
||||
'country' => $point['countryISO'],
|
||||
'description' => $point['description'],
|
||||
];
|
||||
} else {
|
||||
$this->data += $point;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
if (!empty($this->data)) {
|
||||
return $this->data;
|
||||
} else {
|
||||
return ['description' => 'Neznámá pobočka'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id_point'])) {
|
||||
return 'Není zvolena pobočka SPS ParcelShop!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id_point'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['description']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['id_point']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
if (!empty($this->data['id_point']) && !in_array($info['country'], $this->getCountryByCurrency($currencyContext->getActiveId()))) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException('Vybraná pobočka SPS ParcelShop nepodporuje vaši měnu.');
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
private function getCountryByCurrency($currency)
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return ['CZ'];
|
||||
break;
|
||||
case 'EUR':
|
||||
return ['SK', 'DE'];
|
||||
break;
|
||||
case 'HUF':
|
||||
return ['HU'];
|
||||
break;
|
||||
case 'RON':
|
||||
return ['RO'];
|
||||
break;
|
||||
case 'PLN':
|
||||
return ['PL'];
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
44
class/deliveries/class.SlovenskaPosta.php
Normal file
44
class/deliveries/class.SlovenskaPosta.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class SlovenskaPosta extends Delivery
|
||||
{
|
||||
public static $className = 'Slovenská pošta - Balík na adresu';
|
||||
|
||||
protected $heureka_delivery_id = 'SLOVENSKA_POSTA';
|
||||
|
||||
protected $track_and_trace = 'https://tandt.posta.sk/zasielky/[PACKAGE_ID]';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_zip_codes`';
|
||||
public static $jsonFile = 'https://test20cztest:QKCufcWs@api.balikobot.cz/sp/zipcodes/BNA';
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('delivery') && $cart->hasData('user')) {
|
||||
$this->zipExists($cart->invoice);
|
||||
$this->zipExists($cart->delivery);
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$json = file_get_contents(static::$jsonFile);
|
||||
$data = json_decode_strict($json);
|
||||
if (!$data || empty($data->zip_codes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sqlGetConnection()->transactional(
|
||||
function () use ($data) {
|
||||
sqlQueryBuilder()->delete(self::$tableName)->where(\Query\Operator::equals(['country' => 'SK']))->execute();
|
||||
foreach ($data->zip_codes as $post) {
|
||||
sqlQuery(
|
||||
'INSERT IGNORE INTO '.self::$tableName.' SET zip = :psc, time_zone = :time_zone, country = :country',
|
||||
['psc' => $post->zip, 'time_zone' => 0, 'country' => $post->country]
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
13
class/deliveries/class.Toptrans.php
Normal file
13
class/deliveries/class.Toptrans.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class Toptrans extends Delivery
|
||||
{
|
||||
public static $className = 'Toptrans';
|
||||
|
||||
protected $heureka_delivery_id = 'TOPTRANS';
|
||||
protected $zbozi_delivery_id = 'TOPTRANS';
|
||||
|
||||
protected $track_and_trace = 'https://apis.toptrans.cz/search?order_id=[PACKAGE_ID]';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/toptrans.svg';
|
||||
}
|
||||
29
class/deliveries/class.UPS.php
Normal file
29
class/deliveries/class.UPS.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Delivery\RestrictionParams;
|
||||
use KupShop\OrderingBundle\Entity\Purchase\PurchaseState;
|
||||
|
||||
class UPS extends Delivery
|
||||
{
|
||||
public static $className = 'UPS';
|
||||
|
||||
protected $heureka_delivery_id = 'UPS';
|
||||
protected $zbozi_delivery_id = 'UPS';
|
||||
|
||||
protected $track_and_trace = 'https://wwwapps.ups.com/tracking/tracking.cgi?loc=cs_CZ&tracknum=[PACKAGE_ID]';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/ups.svg';
|
||||
|
||||
protected function getRestrictionParams(PurchaseState $purchaseState): RestrictionParams
|
||||
{
|
||||
$rParams = clone parent::getRestrictionParams($purchaseState);
|
||||
|
||||
// UPS ma vypocet obvodu stejnej jako PPL nebo GLS
|
||||
Delivery::includeClass('PPL');
|
||||
$rParams->setMaxSumOfDimensions(
|
||||
PPL::calculateMaxSumOfDimensions($rParams)
|
||||
);
|
||||
|
||||
return $rParams;
|
||||
}
|
||||
}
|
||||
153
class/deliveries/class.Ulozenka.php
Normal file
153
class/deliveries/class.Ulozenka.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
class Ulozenka extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Uloženka';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_ulozenka`';
|
||||
public static $jsonDeliveryBalikobot = 'https://test20cztest:QKCufcWs@api.balikobot.cz/ulozenka/branches/1';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.Ulozenka.description.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.Ulozenka.tpl';
|
||||
|
||||
public $ulozenka_id;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo($this->ulozenka_id);
|
||||
|
||||
return parent::getName().' - '.$info['city'].', '.$info['street'].', '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$id = trim($data['ulozenka_id'] ?? '');
|
||||
|
||||
$info = $this->getInfo($id);
|
||||
|
||||
return empty($id) ? [] : ($this->data = [
|
||||
'zip' => $info['zip'],
|
||||
'ulozenka_id' => $info['id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInfo($id = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
$id = getVal('ulozenka_id', $this->data);
|
||||
}
|
||||
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.'
|
||||
WHERE id=:id', ['id' => $id]));
|
||||
|
||||
if (!$data) {
|
||||
return ['name' => 'Neznámá pobočka'];
|
||||
}
|
||||
|
||||
$data['address'] = $data['street'].', '.$data['zip'].', '.$data['city'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka Uloženky!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = '';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = '';
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['name']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['ulozenka_id']) && $cart->hasData('delivery')) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
if (!empty($this->data['ulozenka_id']) && $info['country'] != $this->getCountryByCurrency($currencyContext->getActiveId())) {
|
||||
throw new \KupShop\OrderingBundle\Exception\DeliveryException('Vybraná pobočka Uloženky nepodporuje vaši měnu.');
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currency string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCountryByCurrency($currency)
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return 'CZ';
|
||||
break;
|
||||
case 'EUR':
|
||||
return 'SK';
|
||||
break;
|
||||
case 'HUF':
|
||||
return 'HU';
|
||||
break;
|
||||
case 'RON':
|
||||
return 'RO';
|
||||
break;
|
||||
case 'PLN':
|
||||
return 'PL';
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
65
class/deliveries/class.UrgentCargus.php
Normal file
65
class/deliveries/class.UrgentCargus.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Functional\Mapping;
|
||||
|
||||
class UrgentCargus extends Delivery
|
||||
{
|
||||
public static $className = 'Urgent Cargus';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_ro_regions`';
|
||||
|
||||
public static $xmlRegions = 'https://export.balikobot.cz/pbh_ro_cargus.xml';
|
||||
|
||||
private $county;
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return findModule('deliveries', 'ro_deliveries');
|
||||
}
|
||||
|
||||
public function getCounty()
|
||||
{
|
||||
if ($this->county) {
|
||||
return $this->county;
|
||||
}
|
||||
|
||||
$county = sqlQueryBuilder()->select('county')
|
||||
->from(self::$tableName)
|
||||
->groupBy('county')
|
||||
->orderBy('county', 'ASC')
|
||||
->execute()->fetchAll();
|
||||
|
||||
return $this->county = Mapping::mapKeys($county, function ($k, $v) {
|
||||
return [$k, $v['county']];
|
||||
});
|
||||
}
|
||||
|
||||
public function getCities($county)
|
||||
{
|
||||
$cities = sqlQueryBuilder()->select('city')
|
||||
->from(self::$tableName)
|
||||
->where(\Query\Operator::equals(['county' => $county]))
|
||||
->orderBy('city', 'ASC')
|
||||
->execute()->fetchAll();
|
||||
|
||||
return Mapping::mapKeys($cities, function ($k, $v) {
|
||||
return [$k, $v['city']];
|
||||
});
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$xml = simplexml_load_file(static::$xmlRegions);
|
||||
if (!$xml) {
|
||||
return;
|
||||
}
|
||||
|
||||
sqlQuery('TRUNCATE TABLE '.self::$tableName);
|
||||
foreach ($xml->lokalita as $location) {
|
||||
sqlQueryBuilder()->insert(self::$tableName)->directValues([
|
||||
'county' => $location->county->__toString(),
|
||||
'city' => $location->mesto->__toString(),
|
||||
])->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
class/deliveries/class.VirtualDelivery.php
Normal file
7
class/deliveries/class.VirtualDelivery.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
class VirtualDelivery extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_VIRTUAL;
|
||||
public static $className = 'V elektronické podobě';
|
||||
}
|
||||
9
class/deliveries/class.VlastniPreprava.php
Normal file
9
class/deliveries/class.VlastniPreprava.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class VlastniPreprava extends Delivery
|
||||
{
|
||||
public static $className = 'Vlastní přeprava';
|
||||
|
||||
protected $heureka_delivery_id = 'VLASTNI_PREPRAVA';
|
||||
protected $zbozi_delivery_id = 'VLASTNI_PREPRAVA';
|
||||
}
|
||||
385
class/deliveries/class.Zasilkovna.php
Normal file
385
class/deliveries/class.Zasilkovna.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
|
||||
class Zasilkovna extends Delivery
|
||||
{
|
||||
use DatabaseCommunication;
|
||||
|
||||
public static $type = Delivery::TYPE_POINT;
|
||||
public static $className = 'Zásilkovna';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.Zasilkovna.widget.tpl';
|
||||
protected $templateInit = 'deliveries/delivery.Zasilkovna.init.tpl';
|
||||
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.Zasilkovna.tpl';
|
||||
protected $adminWindowTemplate = 'delivery/settings.Zasilkovna.tpl';
|
||||
|
||||
public static $tableName = '`kupshop_shared`.`delivery_zasilkovna`';
|
||||
|
||||
protected $track_and_trace = [
|
||||
'CZ' => 'https://tracking.packeta.com/cs/?id=[PACKAGE_ID]',
|
||||
'DE' => 'https://tracking.packeta.com/de/?id=[PACKAGE_ID]',
|
||||
'HR' => 'https://tracking.packeta.com/hr/?id=[PACKAGE_ID]',
|
||||
'SI' => 'https://tracking.packeta.com/sl/?id=[PACKAGE_ID]',
|
||||
'RO' => 'https://tracking.packeta.com/ro/?id=[PACKAGE_ID]',
|
||||
'SK' => 'https://tracking.packeta.com/sk/?id=[PACKAGE_ID]',
|
||||
'HU' => 'https://tracking.packeta.com/hu/?id=[PACKAGE_ID]',
|
||||
'DK' => 'https://tracking.packeta.com/dk/?id=[PACKAGE_ID]',
|
||||
'ES' => 'https://tracking.packeta.com/es/?id=[PACKAGE_ID]',
|
||||
'FI' => 'https://tracking.packeta.com/fi/?id=[PACKAGE_ID]',
|
||||
'FR' => 'https://tracking.packeta.com/fr/?id=[PACKAGE_ID]',
|
||||
'BE' => 'https://tracking.packeta.com/fr/?id=[PACKAGE_ID]',
|
||||
'IE' => 'https://tracking.packeta.com/en/?id=[PACKAGE_ID]',
|
||||
'IT' => 'https://tracking.packeta.com/it/?id=[PACKAGE_ID]',
|
||||
'PL' => 'https://tracking.packeta.com/pl/?id=[PACKAGE_ID]',
|
||||
'SV' => 'https://tracking.packeta.com/sv/?id=[PACKAGE_ID]',
|
||||
'LV' => 'https://tracking.packeta.com/lv/?id=[PACKAGE_ID]',
|
||||
'LT' => 'https://tracking.packeta.com/lt/?id=[PACKAGE_ID]',
|
||||
'EE' => 'https://tracking.packeta.com/et/?id=[PACKAGE_ID]',
|
||||
'UA' => 'https://tracking.packeta.com/uk/?id=[PACKAGE_ID]',
|
||||
'GR' => 'https://tracking.packeta.com/el/?id=[PACKAGE_ID]',
|
||||
];
|
||||
|
||||
public static $jsonDelivery = 'http://www.zasilkovna.cz/api/v4/80aa13c913f62111/branch.json';
|
||||
|
||||
protected $heureka_delivery_id = 'ZASILKOVNA';
|
||||
protected $zbozi_delivery_id = 'ZASILKOVNA';
|
||||
|
||||
public $zip;
|
||||
|
||||
public $config = [
|
||||
'maxCOD' => 20000,
|
||||
'maxWeight' => 10.0,
|
||||
'maxLength' => 120.0, // Maximální rozměr strany položky
|
||||
'maxSumOfDimensions' => 150.0, // Maximální součet rozměrů všech tří stran položky
|
||||
// legacy config:
|
||||
'limit' => [
|
||||
'CZK' => 20000,
|
||||
'EUR' => 700,
|
||||
],
|
||||
'weight_limit' => 15,
|
||||
'max_length' => 70, // Maximální rozměr jedné strany zásilky: 70 cm
|
||||
'max_dimensions' => 150, // Maximální součet rozměrů všech tří stran zásilky
|
||||
];
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/zasilkovna.svg';
|
||||
|
||||
public static function getSettingsConfiguration(): array
|
||||
{
|
||||
return [
|
||||
'fields' => [
|
||||
'apiKey' => [
|
||||
'title' => 'API klíč',
|
||||
'type' => 'text',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$info = self::getInfo();
|
||||
|
||||
return parent::getName().' - '.$info['name'];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data): array
|
||||
{
|
||||
parent::storeDeliveryInfo($data);
|
||||
|
||||
$pointData = $data['zasilkovna_point_data'] ?? '';
|
||||
$pointData = json_decode($pointData, true);
|
||||
|
||||
if (empty($pointData)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$label = getVal('routingCode', $pointData) ?? getVal('labelRouting', $pointData);
|
||||
|
||||
return $this->data += [
|
||||
'fromWidget' => true,
|
||||
'idZ' => $pointData['id'] ?? $pointData['idZ'] ?? '',
|
||||
'carrierId' => $pointData['carrierId'] ?? null,
|
||||
'zip' => getVal('zip', $pointData),
|
||||
'hours' => getVal('openingHours', $pointData) ?? getVal('hours', $pointData),
|
||||
'street' => getVal('street', $pointData),
|
||||
'country' => strtoupper(getVal('country', $pointData)),
|
||||
'city' => getVal('city', $pointData),
|
||||
'place_name' => getVal('name', $pointData),
|
||||
'place' => getVal('place', $pointData),
|
||||
'labelRouting' => $label,
|
||||
'directions' => getVal('directions', $pointData),
|
||||
];
|
||||
}
|
||||
|
||||
public function setPointId($id): self
|
||||
{
|
||||
$this->data['idZ'] = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['idZ'] ?? null;
|
||||
}
|
||||
|
||||
public function getInfo($idZ = null)
|
||||
{
|
||||
$data = null;
|
||||
|
||||
if (is_null($idZ)) {
|
||||
$idZ = $this->data['idZ'] ?? null;
|
||||
}
|
||||
|
||||
if (getVal('fromWidget', $this->data)) {
|
||||
$data = $this->data;
|
||||
$data['name'] = getVal('name', $this->data) ?? getVal('place_name', $this->data);
|
||||
unset($data['place_name']);
|
||||
} elseif ($idZ) {
|
||||
$data = sqlFetchAssoc(sqlQuery('SELECT * FROM '.self::$tableName.'
|
||||
WHERE id=:id',
|
||||
['id' => $idZ]));
|
||||
|
||||
if ($data) {
|
||||
$data['idZ'] = $data['id'];
|
||||
$data['hours'] = unserialize($data['hours']);
|
||||
$data['address'] = $data['street'].', '.$data['zip'].', '.$data['city'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
return [
|
||||
'name' => 'Neznámá pobočka',
|
||||
'city' => 'Neznámé',
|
||||
'place' => 'Neznámé',
|
||||
'street' => 'Neznámé',
|
||||
'zip' => 'Neznámé',
|
||||
'country' => 'Neznámé',
|
||||
'idZ' => $idZ,
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data admin order data
|
||||
* @param Order $order
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['labelRouting'])) {
|
||||
$this->data['labelRouting'] = null;
|
||||
|
||||
return 'Není zvolena zásilkovna!';
|
||||
}
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
$data['delivery_firm'] = $info['place'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cart CartBase
|
||||
*/
|
||||
public function applyToCart(CartBase $cart)
|
||||
{
|
||||
parent::applyToCart($cart);
|
||||
|
||||
$info = $this->getInfo();
|
||||
|
||||
if (empty($info['labelRouting'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($cart->invoice['name'])) {
|
||||
$cart->delivery['name'] = $cart->invoice['name'];
|
||||
$cart->delivery['surname'] = $cart->invoice['surname'];
|
||||
}
|
||||
|
||||
$cart->delivery['zip'] = $info['zip'];
|
||||
$cart->delivery['street'] = $info['street'];
|
||||
$cart->delivery['city'] = $info['city'];
|
||||
$cart->delivery['country'] = $info['country'];
|
||||
$cart->delivery['firm'] = $info['place'];
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['place']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($weight_limit = ($this->config['weight_limit'] ?? 0)) {
|
||||
if ($cart->getTotalWeight() > $weight_limit) {
|
||||
// Vahovy limit pro tento typ dopravy byl prekrocen
|
||||
throw new DeliveryException(translate_shop('weight_limit', 'delivery'),
|
||||
translate_shop('weight_limit_short', 'delivery'),
|
||||
DeliveryException::ERROR_DELIVERY_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
// check selected combination of delivery and payment
|
||||
|
||||
if (($cart->max_step != 0) && ($payment instanceof Dobirka)) {
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
$currency = $currencyContext->getActive();
|
||||
if (!empty($this->config['limit'][$currency->getId()])) {
|
||||
$limit = toDecimal($this->config['limit'][$currency->getId()]);
|
||||
if (!$cart->totalPricePay->lowerThan($limit)) {
|
||||
throw new DeliveryException(sprintf(translate_shop('zasilkovna_dobirka_limit', 'delivery'),
|
||||
$limit->printValue().' '.$currency->getSymbol()), '', DeliveryException::ERROR_DELIVERY_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($cart->hasData('delivery')) {
|
||||
if (empty($this->data['labelRouting'])) {
|
||||
throw new DeliveryException(translate('branch_missing_zip', 'delivery'));
|
||||
}
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['labelRouting'])) {
|
||||
throw new DeliveryException('Neznámá pobočka.');
|
||||
}
|
||||
$currencyContext = ServiceContainer::getService(CurrencyContext::class);
|
||||
$currency = $this->custom_data['balikobot']['currency'] ?? $currencyContext->getActiveId();
|
||||
|
||||
if (
|
||||
!empty($this->data['labelRouting'])
|
||||
&& !in_array($info['country'], $this->getCountryByCurrency($currency))
|
||||
) {
|
||||
throw new DeliveryException(translate('branch_currency_not_supported', 'delivery'));
|
||||
}
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$json = file_get_contents(self::$jsonDelivery);
|
||||
$data = json_decode_strict($json, true);
|
||||
|
||||
if (count($data) > 0) {
|
||||
sqlGetConnection()->transactional(function () use ($data) {
|
||||
sqlQuery('UPDATE '.self::$tableName.' SET visible = "N" ');
|
||||
$separatedCol = [
|
||||
'id',
|
||||
'zip',
|
||||
'street',
|
||||
'country',
|
||||
'city',
|
||||
'name',
|
||||
'place',
|
||||
'labelRouting',
|
||||
'directions',
|
||||
'url',
|
||||
];
|
||||
|
||||
$excludeColumns = [
|
||||
'photos',
|
||||
];
|
||||
|
||||
foreach ($data['data'] as $id => $branch) {
|
||||
$data = [];
|
||||
foreach ($branch as $title => $value) {
|
||||
if (in_array($title, $separatedCol)) {
|
||||
if ($title == 'zip') {
|
||||
$data[$title] = str_replace(' ', '', $value);
|
||||
} elseif ($title == 'url') {
|
||||
if (is_array($value)) {
|
||||
$data[$title] = serialize($value);
|
||||
} else {
|
||||
$data[$title] = $value;
|
||||
}
|
||||
} elseif ($title == 'country') {
|
||||
$data[$title] = strtoupper($value);
|
||||
} else {
|
||||
if ($value === []) { // Sulini tam obcas misto prazdnyho stringu maji prazdny objekt
|
||||
$value = '';
|
||||
}
|
||||
$data[$title] = $value;
|
||||
}
|
||||
} elseif ($title == 'openingHours') {
|
||||
// foreach ($value['regular'] as $day => $hours) {
|
||||
// $formatter = new IntlDateFormatter('cs_CZ', IntlDateFormatter::FULL, IntlDateFormatter::FULL);
|
||||
// $formatter->setPattern('EEEE');
|
||||
// $p = $formatter->format(new DateTime($day));
|
||||
//
|
||||
// $openingHours[mb_convert_case($p, MB_CASE_TITLE, 'UTF-8')] = $hours;
|
||||
// }
|
||||
$data['hours'] = serialize($value['compactShort']);
|
||||
} elseif (!in_array($title, $excludeColumns)) {
|
||||
$data['data'][$title] = $value;
|
||||
}
|
||||
}
|
||||
$data['data'] = serialize($data['data']);
|
||||
$data['visible'] = 'Y';
|
||||
|
||||
$this->replaceSQL(self::$tableName, $data);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getCountryByCurrency($currency): array
|
||||
{
|
||||
switch ($currency) {
|
||||
case 'CZK':
|
||||
return ['CZ'];
|
||||
break;
|
||||
case 'EUR':
|
||||
return ['SK', 'DE', 'AT', 'FR', 'ES', 'HR', 'IT'];
|
||||
break;
|
||||
case 'HUF':
|
||||
return ['HU'];
|
||||
break;
|
||||
case 'RON':
|
||||
return ['RO'];
|
||||
break;
|
||||
case 'PLN':
|
||||
return ['PL'];
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function ZBOXOnly(): bool
|
||||
{
|
||||
$vendors = $this->getCustomData()['widget_options']['vendors'] ?? [];
|
||||
|
||||
foreach ($vendors as $vendor) {
|
||||
if (($vendor['group'] ?? '') != 'zbox') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
39
class/deliveries/class.ZasilkovnaDodaniNaAdresu.php
Normal file
39
class/deliveries/class.ZasilkovnaDodaniNaAdresu.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
|
||||
class ZasilkovnaDodaniNaAdresu extends Delivery
|
||||
{
|
||||
public static $className = 'Zásilkovna - Dodání na adresu';
|
||||
protected $track_and_trace = 'https://www.zasilkovna.cz/vyhledavani/[PACKAGE_ID]';
|
||||
|
||||
protected $heureka_delivery_id = 'ZASILKOVNA_NA_ADRESU';
|
||||
protected $zbozi_delivery_id = 'ZASILKOVNA_NA_ADRESU';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/zasilkovna.svg';
|
||||
|
||||
public function check(Cart $cart)
|
||||
{
|
||||
if ($cart->hasData('user') && $cart->addressesSet && !empty($cart->invoice['zip'])) {
|
||||
// Check ZIP exists
|
||||
$country = $cart->invoice['country'];
|
||||
if ($country == 'CZ' || $country == 'SK') {
|
||||
$zip = $cart->invoice['zip'];
|
||||
$zipRow = sqlQueryBuilder()
|
||||
->select('*')
|
||||
->from('kupshop_shared.delivery_zip_codes')
|
||||
->where('country=:country AND zip=:zip')
|
||||
->setParameters(['country' => $country, 'zip' => $zip])
|
||||
->setMaxResults(1)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
if (!$zipRow && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException(translate('false_zip', 'order_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::check($cart);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user