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