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]);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user