first commit
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user