199 lines
6.8 KiB
PHP
199 lines
6.8 KiB
PHP
<?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;
|
|
}
|
|
}
|