274 lines
8.8 KiB
PHP
274 lines
8.8 KiB
PHP
<?php
|
|
|
|
class stPocztaPolskaPackage
|
|
{
|
|
/**
|
|
* Model zamówienia
|
|
*
|
|
* @var Order
|
|
*/
|
|
protected $order = null;
|
|
|
|
protected $service = null;
|
|
|
|
protected $amount = null;
|
|
|
|
protected $bufor = null;
|
|
|
|
protected $serviceName = null;
|
|
|
|
protected static $instance = array();
|
|
|
|
public static function getInstance(Order $order, $serviceName = null)
|
|
{
|
|
if (!isset(self::$instance[$order->getId()]))
|
|
{
|
|
$instance = new static($order, $serviceName);
|
|
$instance->initialize();
|
|
self::$instance[$order->getId()] = $instance;
|
|
}
|
|
|
|
return self::$instance[$order->getId()];
|
|
}
|
|
|
|
public function __construct(Order $order, $serviceName)
|
|
{
|
|
$this->order = $order;
|
|
$this->serviceName = $serviceName;
|
|
}
|
|
|
|
public function initialize()
|
|
{
|
|
$pobranie = $this->order->getOrderPayment()->getPaymentType()->getIsCod();
|
|
|
|
$delivery = $this->order->getOrderDelivery();
|
|
|
|
if (null === $this->serviceName)
|
|
{
|
|
$this->serviceName = $delivery->getDeliveryParam('usluga');
|
|
}
|
|
|
|
$service = stPocztaPolskaClient::createService($this->serviceName);
|
|
|
|
$i18n = sfContext::getInstance()->getI18N();
|
|
|
|
$config = stConfig::getInstance('stPocztaPolskaBackend');
|
|
|
|
$service->masa = $this->order->getTotalWeight() * 1000;
|
|
|
|
if (property_exists($service, 'opis'))
|
|
{
|
|
$service->opis = $i18n->__("Zamówienie numer %number%", array('%number%' => $this->order->getNumber()));
|
|
}
|
|
|
|
if (property_exists($service, 'pobranie'))
|
|
{
|
|
$service->pobranie = new pobranieType();
|
|
|
|
if ($pobranie)
|
|
{
|
|
$service->pobranie->sposobPobrania = "RACHUNEK_BANKOWY";
|
|
$service->pobranie->kwotaPobrania = $this->order->getUnpaidAmount() * 100;
|
|
$service->pobranie->tytulem = $i18n->__("Zamówienie numer %number%", array('%number%' => $this->order->getNumber()));
|
|
}
|
|
}
|
|
|
|
if ($this->serviceName == 'przesylka_biznesowa')
|
|
{
|
|
$service->gabaryt = $config->get('przesylka_biznesowa_gabaryt', 'M');
|
|
}
|
|
|
|
$orderUserDataDelivery = $this->order->getOrderUserDataDelivery();
|
|
|
|
if ($delivery->isType('ppo'))
|
|
{
|
|
$user = $this->order->getOrderUserDataBilling();
|
|
$placowkaPocztowa = stPocztaPolskaClient::getInstance()->getPlacowkaPocztowa($delivery->getPickupPoint());
|
|
|
|
if (property_exists($service, 'urzadWydaniaEPrzesylki'))
|
|
{
|
|
$urzadWydaniaEPrzesylkiType = new urzadWydaniaEPrzesylkiType();
|
|
$urzadWydaniaEPrzesylkiType->id = $placowkaPocztowa->id;
|
|
$urzadWydaniaEPrzesylkiType->wojewodztwo = $placowkaPocztowa->wojewodztwo;
|
|
$service->urzadWydaniaEPrzesylki = $urzadWydaniaEPrzesylkiType;
|
|
}
|
|
else
|
|
{
|
|
$urzadWydaniaEPrzesylkiType = new punktOdbioruType();
|
|
$urzadWydaniaEPrzesylkiType->id = $placowkaPocztowa->id;
|
|
$urzadWydaniaEPrzesylkiType->wojewodztwo = $placowkaPocztowa->wojewodztwo;
|
|
$service->punktOdbioru = $urzadWydaniaEPrzesylkiType;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$user = $this->order->getOrderUserDataDelivery();
|
|
}
|
|
|
|
if (property_exists($service, 'punktNadania'))
|
|
{
|
|
$service->punktNadania = new placowkaPocztowaType();
|
|
$service->punktNadania->id = $config->get('urzad_nadania');
|
|
}
|
|
|
|
if ($this->serviceName == 'paczka_zagraniczna' || $this->serviceName == 'paczka_zagraniczna_ue')
|
|
{
|
|
$service->zwrot = new zwrotType();
|
|
$service->zwrot->zwrotPoLiczbieDni = 15;
|
|
$service->zwrot->sposobZwrotu = 'LADOWO_MORSKA';
|
|
}
|
|
|
|
$service->adres = new adresType();
|
|
|
|
$service->ponadgabaryt = false;
|
|
|
|
if ($delivery->isType('ppo'))
|
|
{
|
|
$service->adres->nazwa = $orderUserDataDelivery->getFullName();
|
|
$service->adres->telefon = $orderUserDataDelivery->getPhone();
|
|
$service->adres->mobile = '';
|
|
$service->adres->email = $this->order->getOptClientEmail();
|
|
}
|
|
else
|
|
{
|
|
if ($user->getCompany())
|
|
{
|
|
$service->adres->nazwa = $user->getCompany();
|
|
$service->adres->nazwa2 = $user->getFullname();
|
|
}
|
|
else
|
|
{
|
|
$service->adres->nazwa = $user->getFullname();
|
|
}
|
|
|
|
$service->adres->ulica = $user->getAddress();
|
|
|
|
if ($user->getAddressMore())
|
|
{
|
|
$service->adres->ulica .= ' '.$user->getAddressMore();
|
|
}
|
|
$service->adres->numerDomu = null;
|
|
$service->adres->numerLokalu = null;
|
|
$service->adres->miejscowosc = $user->getTown();
|
|
$service->adres->kodPocztowy = $user->getCode();
|
|
$service->adres->telefon = $user->getPhone();
|
|
$service->adres->mobile = '';
|
|
$service->adres->email = $this->order->getOptClientEmail();
|
|
$service->adres->kraj = $user->getCountry()->getOptName();
|
|
}
|
|
|
|
$service->nadawca = new adresType();
|
|
|
|
if ($config->get('is_company'))
|
|
{
|
|
$service->nadawca->nazwa = $config->get('company');
|
|
|
|
if ($config->get('name'))
|
|
{
|
|
$name = $config->get('name').' '.$config->get('surname');
|
|
$service->nadawca->nazwa2 = trim($name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$service->nadawca->nazwa = $config->get('name').' '.$config->get('surname');
|
|
}
|
|
|
|
$address = $config->get('address');
|
|
|
|
if (!$address)
|
|
{
|
|
$address = $config->get('street') . ' ' . $config->get('house');
|
|
|
|
if ($config->get('flat'))
|
|
{
|
|
$address .= '/' . $config->get('flat');
|
|
}
|
|
}
|
|
|
|
if ($config->get('return_address_enabled'))
|
|
{
|
|
$adresDlaZwrotu = new adresType();
|
|
$adresDlaZwrotu->nazwa = $config->get('return_address_name');
|
|
$adresDlaZwrotu->ulica = $config->get('return_address_address');
|
|
$adresDlaZwrotu->kodPocztowy = $config->get('return_address_zip_code');
|
|
$adresDlaZwrotu->miejscowosc = $config->get('return_address_town');
|
|
|
|
$service->adresDlaZwrotu = $adresDlaZwrotu;
|
|
}
|
|
|
|
$service->nadawca->ulica = trim($address);
|
|
$service->nadawca->numerDomu = null;
|
|
$service->nadawca->numerLokalu = null;
|
|
$service->nadawca->miejscowosc = $config->get('town');
|
|
$service->nadawca->kodPocztowy = $config->get('zip_code');
|
|
$service->nadawca->telefon = $config->get('phone');
|
|
$service->nadawca->mobile = '';
|
|
$service->nadawca->email = $config->get('email');
|
|
$service->nadawca->kraj = $config->get('country', 'Polska');
|
|
|
|
if (property_exists($service, 'zawartosc') && in_array($this->serviceName, ['pocztex_2021_kurier', 'pocztex_2021_na_dzis']))
|
|
{
|
|
$zawartosc = new zawartoscPocztex2021Type();
|
|
$service->zawartosc = $zawartosc;
|
|
}
|
|
|
|
stEventDispatcher::getInstance()->notify(new sfEvent($this, 'stPocztaPolskaPackage.initialize', ['service' => $service, 'order' => $this->order]));
|
|
|
|
$this->service = $service;
|
|
|
|
$this->setCountry($service->adres->kraj);
|
|
|
|
$bufor = new buforType();
|
|
$bufor->dataNadania = date("Y-m-d");
|
|
$bufor->urzadNadania = $config->get('urzad_nadania');
|
|
|
|
$this->bufor = $bufor;
|
|
}
|
|
|
|
public function setCountry($name)
|
|
{
|
|
$this->service->adres->kraj = $name;
|
|
|
|
if (property_exists($this->service, 'deklaracjaCelna2'))
|
|
{
|
|
$this->service->deklaracjaCelna2 = new deklaracjaCelna2Type();
|
|
$this->service->deklaracjaCelna2->zawartoscPrzesylki = 'SPRZEDAZ_TOWARU';
|
|
$this->service->deklaracjaCelna2->dokumentyTowarzyszace = array();
|
|
$this->service->deklaracjaCelna2->szczegolyZawartosciPrzesylki = array();
|
|
$this->service->deklaracjaCelna2->walutaKodISO = $this->order->getOrderCurrency()->getShortcut();
|
|
}
|
|
}
|
|
|
|
public function getServiceName()
|
|
{
|
|
return $this->serviceName;
|
|
}
|
|
|
|
public function getService()
|
|
{
|
|
return $this->service;
|
|
}
|
|
|
|
public function getOrder()
|
|
{
|
|
return $this->order;
|
|
}
|
|
|
|
public function getBufor()
|
|
{
|
|
return $this->bufor;
|
|
}
|
|
|
|
public function getOrderAmount()
|
|
{
|
|
$amount = $this->order->getUnpaidAmount() * 100;
|
|
|
|
if ($this->order->getOrderCurrency()->getShortcut() != 'PLN')
|
|
{
|
|
$amount = $this->order->getOrderCurrency()->exchange($amount, true);
|
|
}
|
|
|
|
return $amount;
|
|
}
|
|
} |