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('

'.translate('incompleteAddress', 'suppliers').':

'.nl2br(translate('addressPlaceholder', 'suppliers')).'

'); } 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;