first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View 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;
}
}