first commit
This commit is contained in:
144
class/deliveries/class.OdberNaProdejne.php
Normal file
144
class/deliveries/class.OdberNaProdejne.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\OrderingBundle\Exception\DeliveryException;
|
||||
use KupShop\SellerBundle\Utils\SellerUtil;
|
||||
|
||||
class OdberNaProdejne extends Delivery
|
||||
{
|
||||
public static $type = Delivery::TYPE_IN_PERSON;
|
||||
public static $className = 'Odběr na prodejně';
|
||||
|
||||
public $defaultIcon = '../../common/static/deliveries/osobni-odber.svg';
|
||||
|
||||
protected $zbozi_delivery_id = 'VLASTNI_VYDEJNI_MISTA';
|
||||
|
||||
protected $templateDescription = 'deliveries/delivery.OdberNaProdejne.description.tpl';
|
||||
protected $AdminTemplateSettings = 'deliveries/block.delivery.OdberNaProdejne.tpl';
|
||||
|
||||
public static function isEnabled()
|
||||
{
|
||||
return findModule(Modules::SELLERS);
|
||||
}
|
||||
|
||||
public function getInfo($id = null): array
|
||||
{
|
||||
if ($id === null) {
|
||||
$id = getVal('seller_id', $this->data);
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sellerUtil = ServiceContainer::getService(SellerUtil::class);
|
||||
$seller = $sellerUtil->getSeller((int) $id);
|
||||
|
||||
return [
|
||||
'id' => $seller['id'] ?? '',
|
||||
'name' => $seller['title'] ?? '',
|
||||
'address' => ($seller['psc'] ?? '').', '.($seller['title'] ?? ''),
|
||||
'street' => implode(' ', array_filter([$seller['street'] ?? '', $seller['number'] ?? ''])),
|
||||
'zip' => $seller['psc'] ?? '',
|
||||
'city' => $seller['city'] ?? '',
|
||||
'country' => $seller['country'] ?? 'CZ',
|
||||
];
|
||||
}
|
||||
|
||||
public function storeDeliveryInfo($data)
|
||||
{
|
||||
$id = trim($data['seller_id'] ?? '');
|
||||
|
||||
// Potrebuju to tady invalidovat kvuli napr. manipulacnim poplatkum, ktere jsou udelane pres slevy
|
||||
ServiceContainer::getService(\KupShop\OrderingBundle\Cart::class)->invalidatePurchaseState();
|
||||
|
||||
return empty($id) ? [] : ($this->data = array_merge($data, ['seller_id' => $id]));
|
||||
}
|
||||
|
||||
public function setPointId($id): self
|
||||
{
|
||||
$this->data['seller_id'] = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPointId()
|
||||
{
|
||||
return $this->data['seller_id'] ?? null;
|
||||
}
|
||||
|
||||
public function applyToOrder(&$data, $order)
|
||||
{
|
||||
parent::applyToOrder($data, $order);
|
||||
|
||||
$info = $this->getInfo();
|
||||
if (empty($info['id'])) {
|
||||
return 'Není zvolena pobočka pro vyzvednutí!';
|
||||
}
|
||||
|
||||
$data['delivery_firm'] = $info['name'];
|
||||
$data['delivery_zip'] = $info['zip'];
|
||||
$data['delivery_street'] = $info['street'];
|
||||
$data['delivery_city'] = $info['city'];
|
||||
$data['delivery_country'] = $info['country'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
public function checkSelected(Cart $cart, ?Payment $payment = null)
|
||||
{
|
||||
if (empty($this->data['seller_id']) && $cart->hasData('delivery')) {
|
||||
throw new DeliveryException('Nevybrali jste pobočku pro vyzvednutí!');
|
||||
}
|
||||
|
||||
return parent::checkSelected($cart, $payment);
|
||||
}
|
||||
|
||||
public function requiresDeliveryAddress()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function printDeliveryInfo()
|
||||
{
|
||||
$info = $this->getInfo();
|
||||
|
||||
return "<strong>{$info['city']}</strong>, {$info['street']}, {$info['name']}, <strong>{$info['zip']}</strong>";
|
||||
}
|
||||
|
||||
public function getDeliveryDate()
|
||||
{
|
||||
$purchaseState = ServiceContainer::getService(\KupShop\OrderingBundle\Cart::class)->getPurchaseState();
|
||||
$sellerUtil = ServiceContainer::getService(SellerUtil::class);
|
||||
|
||||
$sellers = $sellerUtil->getSellers();
|
||||
|
||||
$sellerUtil->loadSellersDeliveryInfoByPurchaseState($purchaseState, $sellers);
|
||||
|
||||
if ($sellers[$this->getPointId()]['deliveryDate'] ?? false) {
|
||||
return $sellers[$this->getPointId()]['deliveryDate'];
|
||||
}
|
||||
|
||||
return parent::getDeliveryDate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user