first commit
This commit is contained in:
96
admin/suppliers.php
Normal file
96
admin/suppliers.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Admin;
|
||||
|
||||
use KupShop\BalikonosBundle\Balikobot;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Suppliers\SuppliersUtil;
|
||||
|
||||
class Suppliers extends \Window
|
||||
{
|
||||
public function get_vars()
|
||||
{
|
||||
$vars = parent::get_vars();
|
||||
|
||||
$this->unserializeCustomData($vars['body']['data']);
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
$data = parent::getData();
|
||||
|
||||
if (getVal('Submit')) {
|
||||
$this->serializeCustomData($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function handlePrintLabel(): void
|
||||
{
|
||||
$this->handleUpdate();
|
||||
$this->setID($this->getID());
|
||||
$this->action = 'edit';
|
||||
|
||||
$balikobot = ServiceContainer::getService(Balikobot::class);
|
||||
|
||||
try {
|
||||
$ids = $this->sendToBalikobot();
|
||||
$balikobot->printTickets($ids, null);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->addHTMLError('<p><strong>'.translate('incompleteAddress', 'suppliers').'</strong>:</p>
|
||||
<p>'.nl2br(translate('addressPlaceholder', 'suppliers')).'</p>
|
||||
');
|
||||
} catch (\KupShop\BalikonosBundle\Exception\BalikonosException $e) {
|
||||
$this->returnError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function sendToBalikobot(): ?array
|
||||
{
|
||||
$balikobot = ServiceContainer::getService(Balikobot::class);
|
||||
$suppliersUtil = ServiceContainer::getService(SuppliersUtil::class);
|
||||
$data = $this->getData();
|
||||
|
||||
$address = $suppliersUtil->parseAddress($data);
|
||||
if (!$suppliersUtil->validateAddress($address)) {
|
||||
throw new \InvalidArgumentException('Incomplete address');
|
||||
}
|
||||
|
||||
$balikobot->setIDs([
|
||||
0 => [
|
||||
'type' => Balikobot::TYPE_CUSTOM,
|
||||
'invoice_email' => $data['email'],
|
||||
'invoice_name' => $address['name'],
|
||||
'invoice_surname' => $address['surname'],
|
||||
'invoice_street' => $address['street'],
|
||||
'invoice_city' => $address['city'],
|
||||
'invoice_zip' => $address['zip'],
|
||||
'invoice_country' => $address['country'] ? $address['country'] : 'CZ',
|
||||
'invoice_phone' => $data['phone'],
|
||||
'total_price' => 0,
|
||||
'id_delivery' => $data['delivery'],
|
||||
'cod_price' => 0,
|
||||
'order_id' => '9999'.$this->getID(),
|
||||
'id_supplier' => $this->getID(),
|
||||
'weight' => $data['weight'],
|
||||
'packages' => $data['packages'] ?? 1,
|
||||
],
|
||||
]);
|
||||
|
||||
$balikobot->sendDeliveries();
|
||||
|
||||
$result = $balikobot->getResult();
|
||||
$result = reset($result);
|
||||
|
||||
if (!empty($result['error_message']) && $result['error_message'] != 'OK') {
|
||||
$this->returnError('Chyba při odesílání do balíkobotu: '.$result['error_message']);
|
||||
}
|
||||
|
||||
return $result['balikonos_ids'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return Suppliers::class;
|
||||
Reference in New Issue
Block a user