first commit
This commit is contained in:
@@ -0,0 +1,966 @@
|
||||
<?php
|
||||
|
||||
class stPaczkomatyBackendActions extends autostPaczkomatyBackendActions
|
||||
{
|
||||
public function preExecute()
|
||||
{
|
||||
parent::preExecute();
|
||||
|
||||
if (!in_array($this->getActionName(), ['config', 'easypackWidget']) && !stConfig::getInstance('stPaczkomatyBackend')->get('enabled'))
|
||||
{
|
||||
$this->setFlash('error', $this->getContext()->getI18N()->__('app.requires.configuration'), false);
|
||||
return $this->forward('stPaczkomatyBackend', 'config');
|
||||
}
|
||||
}
|
||||
|
||||
public function executeDispatchOrderPrintOut()
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
$id = $this->getRequestParameter('id');
|
||||
$dispatchOrder = PaczkomatyDispatchOrderPeer::retrieveByPK($id);
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
if (null === $dispatchOrder)
|
||||
{
|
||||
$this->setFlash('error', $i18n->__('Wybrane zlecenie odbioru nie istnieje.'));
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$response = $api->getDispatchOrderPrintOut($dispatchOrder->getDispatchOrderId());
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$message = [$i18n->__('Wystąpił błąd podczas drukowania zlecenia odbioru') . ':'];
|
||||
|
||||
if (!empty($api->getLastError()->details))
|
||||
{
|
||||
$error = $api->getLastError()->details;
|
||||
}
|
||||
elseif (!empty($api->getLastError()->message))
|
||||
{
|
||||
$error = $api->getLastError()->message;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
$message[] = $error;
|
||||
$this->setFlash('error', implode('<br>', $message));
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
return $this->downloadDocument($response, stPropelSeoUrlBehavior::makeSeoFriendly($i18n->__('Zlecenie odbioru')).'-'.$dispatchOrder->getDispatchOrderExternalId());
|
||||
}
|
||||
|
||||
public function executeDispatchOrder()
|
||||
{
|
||||
if (!stDeliveryTypeConfiguration::has('inpostk'))
|
||||
{
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
if ($this->getRequest()->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$ids = $this->getRequestParameter('paczkomaty_pack[selected]');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ids = [$this->getRequestParameter('id')];
|
||||
}
|
||||
|
||||
$shipmentIds = [];
|
||||
|
||||
$packs = PaczkomatyPackPeer::retrieveByPKsOrder(array_values($ids));
|
||||
|
||||
if (empty($packs))
|
||||
{
|
||||
$this->setFlash('error', $i18n->__('Przesyłki o id %%id%% nie istnieją.', [
|
||||
'%%id%%' => implode(', ', $ids),
|
||||
]));
|
||||
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
$api = stInPostApi::getInstance();
|
||||
$errors = [];
|
||||
|
||||
foreach ($packs as $pack)
|
||||
{
|
||||
if (null !== $pack->getDispatchOrderId())
|
||||
{
|
||||
$errors[] = $i18n->__('Dla przesyłki <b>%%shipment%%</b> zostało już utworzone zlecenie odbioru.', [
|
||||
'%%shipment%%' => $pack->getTrackingNumber(),
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($pack->getSendingMethod() != 'dispatch_order')
|
||||
{
|
||||
$errors[] = $i18n->__('Przesyłka <b>%%shipment%%</b> ma nieprawidłową metodę wysyłki', [
|
||||
'%%shipment%%' => $pack->getTrackingNumber(),
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$shipmentIds[] = $pack->getInpostShipmentId();
|
||||
}
|
||||
|
||||
if (!empty($errors))
|
||||
{
|
||||
$errors = array_merge([$i18n->__('Wystąpił błąd podczas tworzenia zlecenia odbioru') . ':'], $errors);
|
||||
$this->setFlash('error', implode('<br>', $errors));
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$response = $api->createDispatchOrders($shipmentIds);
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$error = $api->getLastError();
|
||||
|
||||
$message = [$i18n->__('Wystąpił błąd podczas tworzenia zlecenia odbioru') . ':'];
|
||||
|
||||
if (isset($error->details->shipments))
|
||||
{
|
||||
foreach ($error->details->shipments as $index => $shipmentError)
|
||||
{
|
||||
$message[] = stInPostApi::translateErrorMessage($shipmentError, [
|
||||
'%%subject%%' => $i18n->__('Przesyłka'),
|
||||
'%%subject_id%%' => $packs[$index]->getTrackingNumber(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->setFlash('error', implode('<br>', $message));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setFlash('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
while (!isset($response->external_id))
|
||||
{
|
||||
sleep(5);
|
||||
|
||||
$response = stInPostApi::getInstance()->getDispatchOrder($response->id);
|
||||
}
|
||||
|
||||
|
||||
$dispatchOrder = new PaczkomatyDispatchOrder();
|
||||
$dispatchOrder->setDispatchOrderId($response->id);
|
||||
$dispatchOrder->setDispatchOrderExternalId($response->external_id);
|
||||
$dispatchOrder->setStatus($response->status);
|
||||
$dispatchOrder->save();
|
||||
|
||||
foreach ($packs as $pack)
|
||||
{
|
||||
$pack->setPaczkomatyDispatchOrder($dispatchOrder);
|
||||
$pack->save();
|
||||
}
|
||||
|
||||
return $this->redirect($this->getRequest()->getReferer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param PaczkomatyPack $paczkomaty_pack
|
||||
* @return void
|
||||
*/
|
||||
protected function deletePaczkomatyPack($paczkomaty_pack)
|
||||
{
|
||||
$api = stInPostApi::getInstance();
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
try
|
||||
{
|
||||
$api->deleteShipment($paczkomaty_pack->getInpostShipmentId());
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
throw new Exception($i18n->__('Przesyłka dla zamówienia "%%order%%": %%message%%', [
|
||||
'%%order%%' => $paczkomaty_pack->getOrder()->getNumber(),
|
||||
'%%message%%' => $e->getMessage(),
|
||||
]));
|
||||
}
|
||||
|
||||
parent::deletePaczkomatyPack($paczkomaty_pack);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return PaczkomatyPack
|
||||
*/
|
||||
protected function getPaczkomatyPackOrCreate($id = 'id')
|
||||
{
|
||||
if (!isset($this->paczkomaty_pack))
|
||||
{
|
||||
$pack = parent::getPaczkomatyPackOrCreate($id);
|
||||
$order = $pack->getOrder();
|
||||
|
||||
if ($pack->hasCourierService() && !stDeliveryTypeConfiguration::has('inpostk'))
|
||||
{
|
||||
return $this->redirect('@stOrder?action=edit&id=' . $order->getId());
|
||||
}
|
||||
|
||||
if ($pack->isNew())
|
||||
{
|
||||
$packs = $order->getPaczkomatyPacks();
|
||||
|
||||
if ($packs)
|
||||
{
|
||||
return $this->redirect('@stPaczkomatyPlugin?action=edit&id=' . $packs[0]->getId() . '&order_id=' . $order->getId());
|
||||
}
|
||||
}
|
||||
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
if ($pack->isNew())
|
||||
{
|
||||
$config = stConfig::getInstance('stPaczkomatyBackend');
|
||||
$pack->setSendingMethod($config->get('sending_method'));
|
||||
$pack->setDropOffPoint($config->get('dropoff_point'));
|
||||
$pack->setDescription($i18n->__('Zamówienie ' . $pack->getOrder()->getNumber()));
|
||||
|
||||
if ($pack->hasCourierService() && $pack->hasCashOnDelivery())
|
||||
{
|
||||
$pack->setInsurance($pack->getCashOnDelivery(true));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
try
|
||||
{
|
||||
$response = $api->getShipment($pack->getInpostShipmentId());
|
||||
|
||||
$pack->setSendingMethod($response->custom_attributes->sending_method);
|
||||
|
||||
if (isset($response->custom_attributes->target_point))
|
||||
{
|
||||
$pack->setCustomerPickupPoint($response->custom_attributes->target_point);
|
||||
}
|
||||
|
||||
if (isset($response->custom_attributes->dropoff_point))
|
||||
{
|
||||
$pack->setDropOffPoint($response->custom_attributes->dropoff_point);
|
||||
}
|
||||
|
||||
if (!$pack->getTrackingNumber())
|
||||
{
|
||||
$pack->setTrackingNumber($response->tracking_number);
|
||||
}
|
||||
|
||||
if (isset($response->parcels[0]->template))
|
||||
{
|
||||
$pack->setParcelTemplate($response->parcels[0]->template);
|
||||
}
|
||||
|
||||
$pack->setStatus($response->status);
|
||||
$pack->setEndOfWeekCollection($response->end_of_week_collection);
|
||||
|
||||
$pack->setCashOnDelivery(isset($response->cod) && $response->cod && $response->cod->amount ? $response->cod->amount : 0);
|
||||
$pack->setInsurance(isset($response->insurance) && $response->insurance && $response->insurance->amount ? $response->insurance->amount : 0);
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$this->getRequest()->setError('api', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if ($pack->hasCourierService())
|
||||
{
|
||||
$this->removeField('customer_pickup_point');
|
||||
$this->removeField('pack_type');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->removeField('parcels');
|
||||
$this->removeField('customer_country_code');
|
||||
$this->removeField('customer_name');
|
||||
$this->removeField('customer_company_name');
|
||||
$this->removeField('customer_post_code');
|
||||
$this->removeField('customer_city');
|
||||
$this->removeField('customer_street');
|
||||
$this->removeField('customer_building_number');
|
||||
}
|
||||
|
||||
if (!$pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
$this->hideAction('download_sticker');
|
||||
$this->removeField('status_label');
|
||||
$this->removeField('tracking_number');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->hideAction('_save');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->paczkomaty_pack;
|
||||
}
|
||||
|
||||
public function executeList()
|
||||
{
|
||||
if (!stDeliveryTypeConfiguration::has('inpostk'))
|
||||
{
|
||||
$this->hideField('dispatch_order_id');
|
||||
}
|
||||
|
||||
if ($this->getRequestParameter('order_id'))
|
||||
{
|
||||
return $this->redirect('@stOrder?action=edit&id=' . $this->getRequestParameter('order_id'));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$result = parent::executeList();
|
||||
$this->pager->getResults();
|
||||
|
||||
return $result;
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
$this->setFlash('error', $i18n->__('Wystąpił podczas próby nawiązania połączenia z API (błąd: %%error%%)', [
|
||||
'%%error%%' =>$e->getMessage()
|
||||
]));
|
||||
|
||||
return $this->redirect('@stPaczkomatyPlugin?action=config');
|
||||
}
|
||||
}
|
||||
|
||||
public function executeDownloadLabel()
|
||||
{
|
||||
$pack = PaczkomatyPackPeer::retrieveByPK($this->getRequestParameter('id'));
|
||||
$api = stInPostApi::getInstance();
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
try
|
||||
{
|
||||
if ($pack->getInpostShipmentId())
|
||||
{
|
||||
$id = $pack->getInpostShipmentId();
|
||||
}
|
||||
else
|
||||
{
|
||||
$shipment = $api->getShipmentByTrackingNumber($pack->getTrackingNumber());
|
||||
|
||||
$id = $shipment->id;
|
||||
}
|
||||
|
||||
$response = $api->downloadLabel($id);
|
||||
|
||||
return $this->downloadDocument($response, $i18n->__('etykieta').'-'.$pack->getTrackingNumber(), stConfig::getInstance('stPaczkomatyBackend')->get('label_format'));
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
if (!empty($api->getLastError()->details))
|
||||
{
|
||||
$error = $api->getLastError()->details;
|
||||
}
|
||||
elseif (!empty($api->getLastError()->message))
|
||||
{
|
||||
$error = $api->getLastError()->message;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->getRequest()->setError('api', $i18n->__('Wystąpił bład podczas pobierania etykiety (Błąd: "%error%")', array('%error%' => $error)));
|
||||
|
||||
return $this->forward('stPaczkomatyBackend', 'edit');
|
||||
}
|
||||
}
|
||||
|
||||
public function validateEdit()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$this->related_object = OrderPeer::retrieveByPK($this->getRequestParameter('order_id'));
|
||||
$pack = $this->getPaczkomatyPackOrCreate();
|
||||
|
||||
$this->updatePaczkomatyPackFromRequest();
|
||||
|
||||
$api = stInPostApi::getInstance();
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
$config = stConfig::getInstance('stPaczkomatyBackend');
|
||||
$required = ['customer_email', 'customer_phone', 'customer_pickup_point'];
|
||||
$data = $this->getRequestParameter('paczkomaty_pack');
|
||||
|
||||
if ($pack->hasCourierService())
|
||||
{
|
||||
$required = ['customer_street', 'customer_building_number', 'customer_post_code', 'customer_city', 'customer_country_code', 'customer_email', 'customer_phone', 'parcels'];
|
||||
}
|
||||
|
||||
if (in_array($pack->getSendingMethod(), array('parcel_locker')))
|
||||
{
|
||||
$required[] = 'dropoff_point';
|
||||
}
|
||||
|
||||
foreach ($required as $fieldName)
|
||||
{
|
||||
if (!isset($data[$fieldName]) || empty($data[$fieldName]))
|
||||
{
|
||||
$request->setError('paczkomaty_pack{' . $fieldName . '}', $i18n->__('Proszę uzupełnić pole.'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($pack->hasCourierService() && empty($data['customer_name']) && empty($data['customer_company_name']))
|
||||
{
|
||||
$request->setError('paczkomaty_pack{customer_name}', $i18n->__('Musisz podać nazwę firmy lub imię i nazwisko odbiorcy'));
|
||||
$request->setError('paczkomaty_pack{customer_company_name}', $i18n->__('Musisz podać nazwę firmy lub imię i nazwisko odbiorcy'));
|
||||
}
|
||||
|
||||
if ($pack->hasCourierService() && isset($data['parcels']))
|
||||
{
|
||||
$this->validateParcelSize($pack, $data['parcels']);
|
||||
}
|
||||
|
||||
if ($request->hasErrors())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$shipmentRequest = array(
|
||||
'receiver' => array(
|
||||
'email' => $pack->getCustomerEmail(),
|
||||
'phone' => $pack->getCustomerPhone(),
|
||||
),
|
||||
'sender' => array(
|
||||
"company_name" => !empty($config->get('sender_company')) ? $config->get('sender_company') : null,
|
||||
"first_name" => !empty($config->get('sender_name')) ? $config->get('sender_name') : null,
|
||||
"last_name" => !empty($config->get('sender_surname')) ? $config->get('sender_surname') : null,
|
||||
"email" => trim($config->get('sender_email')),
|
||||
"phone" => str_replace(array('+48', ' ', '-'), '', $config->get('sender_phone')),
|
||||
"address" => array(
|
||||
"street" => $config->get('sender_street'),
|
||||
"building_number" => $config->get('sender_building'),
|
||||
"city" => $config->get('sender_city'),
|
||||
"post_code" => $config->get('sender_post_code'),
|
||||
"country_code" => $config->get('sender_country_code'),
|
||||
),
|
||||
),
|
||||
'custom_attributes' => array(
|
||||
'target_point' => $pack->getCustomerPickupPoint(),
|
||||
'sending_method' => $pack->getSendingMethod(),
|
||||
),
|
||||
'service' => $pack->getService(),
|
||||
'reference' => $pack->getDescription(),
|
||||
'only_choice_of_offer' => false,
|
||||
);
|
||||
|
||||
if (!$pack->hasCourierService())
|
||||
{
|
||||
$shipmentRequest['parcels'] = [
|
||||
['template' => $pack->getParcelTemplate()],
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$parcels = [];
|
||||
|
||||
list($firstName, $lastName) = explode(' ', $pack->getCustomerName(), 2);
|
||||
|
||||
foreach (array_values($pack->getParcels()) as $index => $parcel)
|
||||
{
|
||||
$parcels[] = [
|
||||
'id' => $index + 1,
|
||||
'dimensions' => [
|
||||
'width' => $parcel['width'] * 10,
|
||||
'height' => $parcel['height'] * 10,
|
||||
'length' => $parcel['length'] * 10,
|
||||
'unit' => 'mm',
|
||||
],
|
||||
'weight' => [
|
||||
'amount' => $parcel['weight'],
|
||||
'unit' => 'kg',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$shipmentRequest['parcels'] = $parcels;
|
||||
$shipmentRequest['receiver'] = array_merge($shipmentRequest['receiver'], [
|
||||
'company_name' => !empty($pack->getCustomerCompanyName()) ? $pack->getCustomerCompanyName() : null,
|
||||
'first_name' => !empty($firstName) ? $firstName : null,
|
||||
'last_name' => !empty($lastName) ? $lastName : null,
|
||||
'address' => [
|
||||
'street' => $pack->getCustomerStreet(),
|
||||
'building_number' => $pack->getCustomerBuildingNumber(),
|
||||
'post_code' => $pack->getCustomerPostCode(),
|
||||
'city' => $pack->getCustomerCity(),
|
||||
'country_code' => $pack->getCustomerCountryCode(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($pack->getInsurance() > 0)
|
||||
{
|
||||
$shipmentRequest['insurance'] = array(
|
||||
'amount' => $pack->getInsurance(),
|
||||
'currency' => 'PLN',
|
||||
);
|
||||
}
|
||||
|
||||
if ($pack->getEndOfWeekCollection())
|
||||
{
|
||||
$shipmentRequest['end_of_week_collection'] = true;
|
||||
}
|
||||
|
||||
if ($pack->getCashOnDelivery() > 0)
|
||||
{
|
||||
$shipmentRequest['cod'] = array(
|
||||
'amount' => $pack->getCashOnDelivery(),
|
||||
'currency' => 'PLN',
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array($pack->getSendingMethod(), array('parcel_locker')))
|
||||
{
|
||||
$shipmentRequest['custom_attributes']['dropoff_point'] = $pack->getDropOffPoint();
|
||||
}
|
||||
|
||||
if (!$request->hasErrors())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
$response = $api->createShipment($shipmentRequest);
|
||||
|
||||
$count = 0;
|
||||
|
||||
while ((null === $response->tracking_number || $response->status != 'confirmed') && $count <= 5)
|
||||
{
|
||||
sleep(5);
|
||||
|
||||
$result = $api->getShipment($response->id);
|
||||
|
||||
if ($result && is_object($result))
|
||||
{
|
||||
$response = $result;
|
||||
}
|
||||
|
||||
if (!empty($response->offers) && $response->offers[0]->status == 'unavailable')
|
||||
{
|
||||
$request->setError('api', stInPostApi::formatUnavailableError($response->offers[0]->unavailability_reasons));
|
||||
break;
|
||||
}
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$request->setParameter('create_shipment', $response, 'soteshop/stInPostApi');
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$error = $api->getLastError();
|
||||
|
||||
if ($error && $error->error == stInPostApi::VALIDATION_FAILED)
|
||||
{
|
||||
if (isset($error->details->cod))
|
||||
{
|
||||
$request->setError('paczkomaty_pack{cash_on_delivery}', stInPostApi::formatDetailError($error->details->cod));
|
||||
}
|
||||
|
||||
if (isset($error->details->insurance))
|
||||
{
|
||||
$request->setError('paczkomaty_pack{insurance}', stInPostApi::formatDetailError($error->details->insurance));
|
||||
}
|
||||
|
||||
if (isset($error->details->custom_attributes))
|
||||
{
|
||||
foreach ($error->details->custom_attributes as $item)
|
||||
{
|
||||
if (isset($item->dropoff_point) && $item->dropoff_point[0] == "dropoff_and_target_points_must_be_different")
|
||||
{
|
||||
$request->setError('paczkomaty_pack{dropoff_point}', $i18n->__('Paczkomat nadawcy nie może być taki sam jak paczkomat odbiorcy'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($error->details->receiver[0]->email))
|
||||
{
|
||||
$request->setError('paczkomaty_pack{customer_email}', stInPostApi::formatDetailError($error->details->receiver[0]->email));
|
||||
}
|
||||
|
||||
if (isset($error->details->receiver[0]->address[0]->post_code))
|
||||
{
|
||||
$request->setError('paczkomaty_pack{customer_post_code}', stInPostApi::formatDetailError($error->details->receiver[0]->address[0]->post_code));
|
||||
}
|
||||
|
||||
if (isset($error->details->sender[0]->phone))
|
||||
{
|
||||
sfLoader::loadHelpers(array('Helper', 'stUrl'));
|
||||
$request->setError('api', $i18n->__('Numer nadawcy jest nieprawidłowy. Numer musi być podany w formacie 9 cyfrowym bez spacji oraz myślników. Przejdź do %link%, aby skorygować problem.', array(
|
||||
'%link%' => st_link_to($i18n->__('konfiguracji'), '@stPaczkomatyPlugin?action=config', array('target' => '_blank')),
|
||||
)));
|
||||
}
|
||||
|
||||
if (isset($error->details->sender[0]->address[0]->post_code))
|
||||
{
|
||||
sfLoader::loadHelpers(array('Helper', 'stUrl'));
|
||||
$request->setError('api', $i18n->__('Nieprawidłowy kod pocztowy nadawcy. Przejdź do %link%, aby skorygować problem.', array(
|
||||
'%link%' => st_link_to($i18n->__('konfiguracji'), '@stPaczkomatyPlugin?action=config', array('target' => '_blank')),
|
||||
)));
|
||||
}
|
||||
|
||||
if (isset($error->details->service))
|
||||
{
|
||||
$request->setError('api', stInPostApi::formatDetailError($error->details->service));
|
||||
}
|
||||
|
||||
if (!$request->hasErrors())
|
||||
{
|
||||
$request->setError('api', $i18n->__("Wystąpił nieobsługiwany wyjątek (błąd: %error%)", array('%error%' => json_encode($error->details))));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$request->setError('api', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !$request->hasErrors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje model PaczkomatyPack
|
||||
*
|
||||
* @param PaczkomatyPack $pack
|
||||
* @return void
|
||||
*/
|
||||
protected function savePaczkomatyPack($pack)
|
||||
{
|
||||
$response = $this->getRequest()->getParameter('create_shipment', null, 'soteshop/stInPostApi');
|
||||
|
||||
if (!$pack->isNew() && $pack->getInpostShipmentId())
|
||||
{
|
||||
$api = stInPostApi::getInstance();
|
||||
$api->deleteShipment($pack->getInpostShipmentId());
|
||||
}
|
||||
|
||||
$pack->setInpostShipmentId($response->id);
|
||||
$pack->setStatus($response->status);
|
||||
$pack->setTrackingNumber($response->tracking_number);
|
||||
|
||||
$parcels = $pack->getParcels();
|
||||
|
||||
foreach ($response->parcels as $index => $parcel)
|
||||
{
|
||||
$parcels[$index]['number'] = $parcel->tracking_number;
|
||||
}
|
||||
|
||||
$pack->setParcels($parcels);
|
||||
|
||||
$isNew = $pack->isNew();
|
||||
|
||||
$result = parent::savePaczkomatyPack($pack);
|
||||
|
||||
if ($isNew)
|
||||
{
|
||||
$this->updateOrderStatus($pack->getOrder());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function executeEasypackWidget()
|
||||
{
|
||||
$this->setLayout(false);
|
||||
|
||||
if (!$this->getRequestParameter('sandbox'))
|
||||
{
|
||||
$this->endpoint = 'https://api-pl-points.easypack24.net/v1';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->endpoint = 'https://stage-api-pl-points.easypack24.net/v1';
|
||||
}
|
||||
|
||||
$this->scope = $this->getRequestParameter('scope');
|
||||
}
|
||||
|
||||
public function validateConfig()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$this->config = stConfig::getInstance('stPaczkomatyBackend');
|
||||
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
if ($request->getMethod() == sfRequest::POST)
|
||||
{
|
||||
$this->updateConfigFromRequest();
|
||||
|
||||
if ($this->config->get('enabled'))
|
||||
{
|
||||
if (!$this->config->get('token'))
|
||||
{
|
||||
$request->setError('config{token}', $i18n->__('Proszę uzupełnić pole.'));
|
||||
}
|
||||
|
||||
if (!$request->hasErrors())
|
||||
{
|
||||
if ($api->isValid())
|
||||
{
|
||||
if (!$this->config->get('sending_method'))
|
||||
{
|
||||
$request->setError('config{sending_method}', $i18n->__('Proszę uzupełnić pole.'));
|
||||
}
|
||||
elseif ($this->config->get('sending_method') == 'parcel_locker' && !$this->config->get('dropoff_point'))
|
||||
{
|
||||
$request->setError('config{dropoff_point}', $i18n->__('Proszę uzupełnić pole.'));
|
||||
}
|
||||
|
||||
$required = array('sender_email', 'sender_country_code', 'sender_street', 'sender_building', 'sender_city', 'sender_post_code');
|
||||
|
||||
if (!$this->config->get('sender_company') && (!$this->config->get('sender_company') || !$this->config->get('sender_company')))
|
||||
{
|
||||
$required = array_merge(array('sender_name', 'sender_surname'), $required);
|
||||
}
|
||||
|
||||
foreach ($required as $field)
|
||||
{
|
||||
if (!$this->config->get($field))
|
||||
{
|
||||
$request->setError('config{' . $field . '}', $i18n->__('Proszę uzupełnić pole.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$organizations = $api->getOrganizations();
|
||||
|
||||
$request->setParameter('organizations', $organizations, 'soteshop/stInPostApi');
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
$request->setError('api', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($this->config->get('enabled') && $this->config->get('token') && !$request->hasErrors() && !$api->isValid())
|
||||
{
|
||||
$request->setError('api', $api->getLastErrorMessage());
|
||||
}
|
||||
|
||||
return !$request->hasErrors();
|
||||
}
|
||||
|
||||
protected function updateConfigFromRequest()
|
||||
{
|
||||
parent::updateConfigFromRequest();
|
||||
|
||||
$this->updateSenderFromOrganization();
|
||||
}
|
||||
|
||||
protected function updateOrderStatus(Order $order)
|
||||
{
|
||||
$config = stConfig::getInstance('stPaczkomatyBackend');
|
||||
|
||||
if ($config->get('order_status') && $order->getOrderStatusId() != $config->get('order_status'))
|
||||
{
|
||||
$order->setOrderStatusId($config->get('order_status'));
|
||||
$order->save();
|
||||
|
||||
if ($order->getOrderStatus()->getHasMailNotification())
|
||||
{
|
||||
$orderNotification = new stOrderMailNotification($this->getContext());
|
||||
$orderNotification->sendStatusChangeNotification($order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveConfig()
|
||||
{
|
||||
$ret = parent::saveConfig();
|
||||
stTheme::clearSmartyCache(true);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
protected function updateSenderFromOrganization()
|
||||
{
|
||||
$organizations = $this->getRequest()->getParameter('organizations', null, 'soteshop/stInPostApi');
|
||||
|
||||
if ($organizations && !$this->config->get('organization'))
|
||||
{
|
||||
$organization = $organizations->items[0];
|
||||
|
||||
$this->config->set('organization', $organization->id);
|
||||
$this->config->set('sender_company', $organization->name);
|
||||
$this->config->set('sender_street', $organization->address->street);
|
||||
$this->config->set('sender_building', $organization->address->building_number);
|
||||
$this->config->set('sender_post_code', $organization->address->post_code);
|
||||
$this->config->set('sender_country_code', $organization->address->country_code);
|
||||
$this->config->set('sender_city', $organization->address->city);
|
||||
$this->config->set('sender_email', $organization->contact_person->email);
|
||||
$this->config->set('sender_phone', $organization->contact_person->phone);
|
||||
$this->config->set('sender_name', $organization->contact_person->first_name);
|
||||
$this->config->set('sender_surname', $organization->contact_person->last_name);
|
||||
$this->config->set('services', $organization->services);
|
||||
}
|
||||
}
|
||||
|
||||
protected function updatePaczkomatyPackFromRequest()
|
||||
{
|
||||
parent::updatePaczkomatyPackFromRequest();
|
||||
|
||||
$data = $this->getRequestParameter('paczkomaty_pack');
|
||||
|
||||
foreach (array('customer_email', 'customer_phone', 'customer_paczkomat', 'use_sender_paczkomat', 'sender_paczkomat', 'pack_type', 'insurance', 'cash_on_delivery', 'description') as $v)
|
||||
{
|
||||
if (isset($data[$v]))
|
||||
{
|
||||
call_user_func(array($this->paczkomaty_pack, sfInflector::camelize('set_' . $v)), $data[$v]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data['insurance']))
|
||||
{
|
||||
$this->paczkomaty_pack->setInsurance(null);
|
||||
}
|
||||
|
||||
if (!isset($data['cash_on_delivery']))
|
||||
{
|
||||
$this->paczkomaty_pack->setCashOnDelivery(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getLabels()
|
||||
{
|
||||
$labels = parent::getLabels();
|
||||
|
||||
$labels['api'] = 'InPost';
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
protected function getConfigLabels()
|
||||
{
|
||||
$labels = parent::getConfigLabels();
|
||||
|
||||
$labels['api'] = 'InPost';
|
||||
|
||||
return $labels;
|
||||
}
|
||||
|
||||
protected function addFiltersCriteria($c)
|
||||
{
|
||||
parent::addFiltersCriteria($c);
|
||||
|
||||
if (isset($this->filters['dispatch_order']) && !empty($this->filters['dispatch_order']))
|
||||
{
|
||||
$c->add(PaczkomatyDispatchOrderPeer::DISPATCH_ORDER_EXTERNAL_ID, $this->filters['dispatch_order']);
|
||||
}
|
||||
|
||||
if (isset($this->filters['service_type']) && !empty($this->filters['service_type']))
|
||||
{
|
||||
$c->addJoin(OrderPeer::ORDER_DELIVERY_ID, OrderDeliveryPeer::ID);
|
||||
$c->addJoin(OrderDeliveryPeer::DELIVERY_ID, DeliveryPeer::ID);
|
||||
$c->addJoin(DeliveryPeer::TYPE_ID, DeliveryTypePeer::ID);
|
||||
$c->add(DeliveryTypePeer::TYPE, $this->filters['service_type']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function deleteDispatchOrderPaczkomatyDispatchOrder($dispatchOrder)
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
if (!in_array($dispatchOrder->getStatus(), ['sent', 'new']))
|
||||
{
|
||||
throw new Exception($i18n->__('Zlecenie odbioru %%dispatch_order%% posiada nieprawidłowy status.', ['%%dispatch_order%%' => $dispatchOrder->getDispatchOrderExternalId()]));
|
||||
}
|
||||
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
try
|
||||
{
|
||||
$api->deleteDispatchOrder($dispatchOrder->getDispatchOrderId());
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
throw new Exception($i18n->__('Zlecenie odbioru "%%dispatch_order%%": %%message%%', [
|
||||
'%%dispatch_order%%' => $dispatchOrder->getDispatchOrderExternalId(),
|
||||
'%%message%%' => $e->getMessage(),
|
||||
]));
|
||||
}
|
||||
|
||||
return parent::deleteDispatchOrderPaczkomatyDispatchOrder($dispatchOrder);
|
||||
}
|
||||
|
||||
protected function downloadDocument(string $content, string $filename, string $type = 'Pdf')
|
||||
{
|
||||
$types = [
|
||||
'Pdf' => 'application/pdf',
|
||||
'Zpl' => 'application/octet-stream',
|
||||
'Epl' => 'application/octet-stream',
|
||||
];
|
||||
|
||||
if (!isset($types[$type]))
|
||||
{
|
||||
throw new Exception(sprintf('Przekazany typ plik nie jest obsługiwany (dostępne: %s)', implode(', ', array_keys($types))));
|
||||
}
|
||||
|
||||
$this->getResponse()->clearHttpHeaders();
|
||||
$this->getResponse()->setHttpHeader('Content-Type', $types[$type]);
|
||||
$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment;filename=' . $filename . '.' . lcfirst($type));
|
||||
|
||||
return $this->renderText($content);
|
||||
}
|
||||
|
||||
protected function validateParcelSize(PaczkomatyPack $pack, array $parcels)
|
||||
{
|
||||
$errors = [];
|
||||
$validator = new stInPostParcelSizeValidator();
|
||||
$validator->initialize($this->getContext(), [
|
||||
'service' => $pack->getService(),
|
||||
]);
|
||||
|
||||
if (!$validator->execute($parcels, $errors))
|
||||
{
|
||||
$this->getRequest()->setError('paczkomaty_pack{parcels}', implode('<br>', $errors));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getActionSelectControlOptions()
|
||||
{
|
||||
$options = parent::getActionSelectControlOptions();
|
||||
|
||||
if (!stDeliveryTypeConfiguration::has('inpostk'))
|
||||
{
|
||||
array_pop($options['NONE']);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class stPaczkomatyBackendComponents extends autostPaczkomatyBackendComponents
|
||||
{
|
||||
public function addListMenuItems(array $items)
|
||||
{
|
||||
if (!stDeliveryTypeConfiguration::has('inpostk'))
|
||||
{
|
||||
unset($items['@stPaczkomatyPlugin?action=dispatchOrderList']);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
generator:
|
||||
class: stAdminGenerator
|
||||
param:
|
||||
model_class: PaczkomatyPack
|
||||
dispatch_order_model_class: PaczkomatyDispatchOrder
|
||||
theme: simple
|
||||
head:
|
||||
package: stPaczkomatyPlugin
|
||||
documentation:
|
||||
pl: "https://www.sote.pl/docs/paczkomaty"
|
||||
en: "https://www.soteshop.com/docs/paczkomaty"
|
||||
|
||||
custom_actions:
|
||||
list: [dispatch_order]
|
||||
|
||||
fields:
|
||||
created_at: {name: Data utworzenia}
|
||||
sender_paczkomat: {name: Paczkomat nadawcy}
|
||||
use_sender_paczkomat: {name: Użyj Paczkomaty}
|
||||
pack_type: {name: Rozmiar, type: plain}
|
||||
insurance: {name: Kwota ubezpieczenia, type: plain}
|
||||
cash_on_delivery: {name: Kwota pobrania, type: plain}
|
||||
description: {name: Kod referencyjny, type: plain}
|
||||
code: {name: Numer trackingowy przesyłki}
|
||||
status_label: {name: Status, type: plain}
|
||||
status_changed_at: {name: Aktualizacja statusu w systemie Paczkomaty.pl}
|
||||
order_number: {name: Numer zamówienia}
|
||||
tracking_number: {name: Numer trackingowy przesyłki, type: plain}
|
||||
|
||||
list:
|
||||
use_helper: [stPaczkomatyBackend]
|
||||
forward_parameters: [order_id]
|
||||
menu:
|
||||
display: [list, dispatch_order_list, config]
|
||||
fields:
|
||||
list: {name: Przesyłki, action: "@stPaczkomatyPlugin"}
|
||||
dispatch_order_list: {name: Zlecenia odbioru, action: "@stPaczkomatyPlugin?action=dispatchOrderList"}
|
||||
config: {name: Konfiguracja, action: "@stPaczkomatyPlugin?action=config"}
|
||||
title: Przesyłki
|
||||
description: Zarządzanie paczkami
|
||||
display: [created_at, order_number, code, service_type, _sending_method, status_label, _dispatch_order_id]
|
||||
sort: [created_at, desc]
|
||||
fields:
|
||||
order_number: {sort_field: order.number}
|
||||
dispatch_order_id: {name: Zlecenie odbioru}
|
||||
sending_method: {name: Metoda wysyłki, params: truncate_text=true}
|
||||
status_label: {params: truncate_text=true}
|
||||
service_type: {name: Rodzaj, params: truncate_text=true}
|
||||
filters:
|
||||
sending_method: {partial: sending_method_filter}
|
||||
dispatch_order_id: {partial: dispatch_order_filter}
|
||||
service_type: {partial: service_type_filter}
|
||||
peer_method: doSelectWithShipX
|
||||
actions: []
|
||||
object_actions:
|
||||
dispatch_order: {name: Zlecenie odbioru, action: dispatchOrder, icon: courier, params: show_preloader=true}
|
||||
download_label: {name: Pobierz etykietę, action: downloadLabel, i18n: stPaczkomatyBackend, icon: download}
|
||||
_edit: {name: "Edycja"}
|
||||
_delete: -
|
||||
select_actions:
|
||||
display:
|
||||
"NONE": [dispatch_order]
|
||||
actions:
|
||||
_delete: -
|
||||
dispatch_order: {name: "Zleć odbiór", action: dispatchOrder}
|
||||
|
||||
|
||||
create:
|
||||
title: Dodaj nową paczkę
|
||||
|
||||
edit:
|
||||
use_helper: [stPaczkomatyBackend, stPrice, stDelivery, Countries]
|
||||
title: Przesyłka
|
||||
display:
|
||||
"NONE": [service_type, status_label, tracking_number]
|
||||
"Dane odbiorcy": [customer_company_name, customer_name, customer_street, customer_building_number, customer_post_code, customer_city, _customer_country_code, customer_email, customer_phone, _customer_pickup_point]
|
||||
"Dane nadawcy": [_sending_method, _dropoff_point]
|
||||
"Zawartość": [_parcels]
|
||||
"Dodatkowe informacje": [_pack_type, _insurance, _cash_on_delivery, _end_of_week_collection, _description]
|
||||
fields:
|
||||
service_type: {name: Rodzaj, type: plain}
|
||||
customer_street: {name: Ulica, plain_on_edit: true, required: true}
|
||||
customer_building_number: {name: Numer budynku/lokalu, plain_on_edit: true, required: true}
|
||||
customer_country_code: {name: Kraj, required: true, params: iso=true, plain_on_edit: true}
|
||||
customer_post_code: {name: Kod pocztowy, required: true, plain_on_edit: true}
|
||||
customer_city: {name: Miasto, required: true, plain_on_edit: true}
|
||||
customer_name: {name: Imię i nazwisko, plain_on_edit: true}
|
||||
customer_company_name: {name: Nazwa firmy, plain_on_edit: true}
|
||||
customer_email: {name: Adres e-mail, plain_on_edit: true, required: true}
|
||||
customer_phone: {name: Numer telefonu, plain_on_edit: true, required: true}
|
||||
sending_method: {name: Metoda wysyłki, type: plain}
|
||||
dropoff_point: {name: Paczkomat nadawcy, required: true, type: custom}
|
||||
customer_pickup_point: {name: Paczkomat odbiorcy, required: true, type: custom}
|
||||
end_of_week_collection: {name: Paczka w weekend, type: checkbox_tag, plain_on_edit: true}
|
||||
parcels: {name: Paczki}
|
||||
actions:
|
||||
download_sticker: {name: Pobierz etykietę, action: downloadLabel, i18n: stPaczkomatyBackend, icon: download}
|
||||
_save: {name: Utwórz i opłać paczkę, i18n: stPaczkomatyBackend}
|
||||
|
||||
dispatch_order_list:
|
||||
title: Zlecenia odbioru
|
||||
display: [created_at, dispatch_order_external_id, parcels, status_label]
|
||||
fields:
|
||||
created_at: {name: Utworzone}
|
||||
dispatch_order_external_id: {name: Numer}
|
||||
status: {name: Status, sort_field: status}
|
||||
parcels: {name: Przesyłki, params: truncate_text=true truncate_text_lines=2}
|
||||
peer_method: doSelectWithShipX
|
||||
actions: []
|
||||
object_actions:
|
||||
dispatch_order_printout: {name: "Pobierz wydruk", action: dispatchOrderPrintOut, icon: download}
|
||||
_delete: -
|
||||
|
||||
config:
|
||||
use_helper: [stPaczkomatyBackend, Countries]
|
||||
use_javascript: [/plugins/stPaczkomatyPlugin/js/backend.js]
|
||||
menu: {use: list.menu}
|
||||
title: Konfiguracja
|
||||
display:
|
||||
"NONE": [enabled, sandbox, token, _organization, _order_status]
|
||||
"Domyślne ustawienia": [label_type, label_format, sending_method, dropoff_point]
|
||||
"Informacje o nadawcy na paczce": [sender_company, sender_name, sender_surname, sender_email, sender_phone, sender_country_code, sender_street, sender_building, sender_city, sender_post_code]
|
||||
fields:
|
||||
sandbox: {name: Tryb testowy, type: checkbox}
|
||||
enabled: {name: Włącz, type: checkbox}
|
||||
organization: {name: Organizacja, required: true}
|
||||
token: {name: Token, type: password, params: size=80 autocomplete=off, required: true}
|
||||
order_status: {name: Zmień status zamówienia na, help: "Zmienia status zamówienia po utworzeniu paczki"}
|
||||
sending_method: {name: Metoda wysyłki, callback: st_inpost_sending_method_select_tag, params: service=inpost_locker_standard target=".row_dropoff_point", required: true}
|
||||
dropoff_point: {name: Paczkomat nadawcy, callback: st_inpost_point_select_tag, required: true, type: plain}
|
||||
label_type:
|
||||
name: Typ etykiety
|
||||
type: select
|
||||
display: [a4, a6]
|
||||
options:
|
||||
a4: {name: A4, value: normal}
|
||||
a6: {name: A6, value: A6}
|
||||
label_format:
|
||||
name: Format etykiety
|
||||
type: select
|
||||
options:
|
||||
Epl: {name: EPL}
|
||||
Pdf: {name: PDF}
|
||||
Zpl: {name: ZPL}
|
||||
sender_name: {name: Imię}
|
||||
sender_company: {name: Nazwa firmy}
|
||||
sender_surname: {name: Nazwisko}
|
||||
sender_email: {name: E-mail, required: true}
|
||||
sender_phone: {name: Numer telefonu, required: true}
|
||||
sender_street: {name: Ulica, required: true}
|
||||
sender_building: {name: Numer budynku / lokalu, params: size=7, required: true}
|
||||
sender_city: {name: Miasto, required: true}
|
||||
sender_post_code: {name: Kod pocztowy, params: size=7, required: true}
|
||||
sender_country_code: {name: Kraj, callback: st_countries_select_tag, params: iso=true, required: true}
|
||||
actions:
|
||||
_save: {name: Zapisz}
|
||||
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
function st_inpost_organization_select_tag($name, $value, array $params = array())
|
||||
{
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
$organizations = sfContext::getInstance()->getRequest()->getParameter('organizations', null, 'soteshop/stInPostApi');
|
||||
|
||||
if (null === $organizations)
|
||||
{
|
||||
try
|
||||
{
|
||||
$organizations = $api->getOrganizations();
|
||||
}
|
||||
catch(stInPostApiException $e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if ($organizations)
|
||||
{
|
||||
foreach ($organizations->items as $organization)
|
||||
{
|
||||
$options[$organization->id] = $organization->name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = array();
|
||||
}
|
||||
|
||||
return select_tag($name, options_for_select($options, $value), $params);
|
||||
}
|
||||
|
||||
function st_inpost_sending_method_select_tag($name, $value, array $params = array())
|
||||
{
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
$service = null;
|
||||
|
||||
if (isset($params['service']))
|
||||
{
|
||||
$service = $params['service'];
|
||||
unset($params['service']);
|
||||
}
|
||||
|
||||
$target = null;
|
||||
|
||||
if (isset($params['target']))
|
||||
{
|
||||
$target = $params['target'];
|
||||
}
|
||||
|
||||
$includeCustom = __('Wybierz');
|
||||
|
||||
if (isset($params['include_custom']))
|
||||
{
|
||||
$includeCustom = $params['include_custom'];
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
try
|
||||
{
|
||||
$options = $api->getSendingMethods($service);
|
||||
}
|
||||
catch (stInPostApiException $e)
|
||||
{
|
||||
}
|
||||
|
||||
$content = select_tag($name, options_for_select($options, $value, array('include_custom' => $includeCustom)), $params);
|
||||
|
||||
if ($target)
|
||||
{
|
||||
$id = get_id_from_name($name);
|
||||
$content .=<<<HTML
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
\$('#$id').change(function() {
|
||||
var select = \$(this);
|
||||
|
||||
if (select.val() == 'parcel_locker') {
|
||||
$('$target').show();
|
||||
} else {
|
||||
$('$target').hide();
|
||||
}
|
||||
}).change();
|
||||
});
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
function st_inpost_point_select_tag($name, $value, array $params = array())
|
||||
{
|
||||
static $init = false;
|
||||
|
||||
$config = stConfig::getInstance('stPaczkomatyBackend');
|
||||
|
||||
$api = stInPostApi::getInstance();
|
||||
|
||||
$i18n = sfContext::getInstance()->getI18N();
|
||||
|
||||
$label = $i18n->__('Wybierz punkt');
|
||||
|
||||
$id = get_id_from_name($name);
|
||||
|
||||
$title = isset($params['title']) ? __($params['title']) : __('Wybierz punkt');
|
||||
|
||||
$disabled = isset($params['disabled']) && $params['disabled'];
|
||||
|
||||
$js = '';
|
||||
$trigger = '';
|
||||
|
||||
if (!$disabled)
|
||||
{
|
||||
if (!$init)
|
||||
{
|
||||
$easypackWidgetUrl = st_url_for('@stPaczkomatyPlugin?action=easypackWidget&sandbox=' . $api->isSandbox());
|
||||
$js =<<<HTML
|
||||
<div id="inpost-easypack-modal" class="popup_window" style="width: 800px">
|
||||
<div class="close"><img src="/images/backend/beta/gadgets/close.png" alt="" /></div>
|
||||
<h2></h2>
|
||||
<div class="content"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
$('body').append($('#inpost-easypack-modal'));
|
||||
$('.inpost-easypack-widget').overlay({
|
||||
closeOnClick: false,
|
||||
closeOnEsc: false,
|
||||
top: "5%",
|
||||
speed: 'fast',
|
||||
oneInstance: true,
|
||||
fixed: false,
|
||||
|
||||
mask: {
|
||||
color: '#444',
|
||||
loadSpeed: 'fast',
|
||||
opacity: 0.5,
|
||||
zIndex: 30000
|
||||
},
|
||||
|
||||
target: '#inpost-easypack-modal',
|
||||
onClose: function() {
|
||||
|
||||
},
|
||||
onBeforeLoad: function() {
|
||||
var api = this;
|
||||
var content = this.getOverlay().children('.content');
|
||||
var title = this.getOverlay().children('h2');
|
||||
var overlay = this.getOverlay();
|
||||
|
||||
var scope = this.getTrigger().data('related')
|
||||
|
||||
|
||||
title.html(this.getTrigger().data('title'));
|
||||
content.html('<iframe src="$easypackWidgetUrl?scope='+scope+'" style="width: 100%; height: 536px; border: none;"></iframe>');
|
||||
|
||||
|
||||
overlay.css("top", Math.max(28, $(window).scrollTop() + 60) + "px");
|
||||
overlay.css("left", Math.max(0, (($(window).width() - overlay.outerWidth()) / 2) +
|
||||
$(window).scrollLeft()) + "px");
|
||||
},
|
||||
onLoad: function() {
|
||||
var overlay = this.getOverlay();
|
||||
|
||||
overlay.css("top", Math.max(28, $(window).scrollTop() + 60) + "px");
|
||||
overlay.css("left", Math.max(0, (($(window).width() - overlay.outerWidth()) / 2) +
|
||||
$(window).scrollLeft()) + "px");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
window.easyPackAsyncInit = function () {
|
||||
var defaults = {
|
||||
defaultLocale: 'pl',
|
||||
apiEndpoint: '',
|
||||
mapType: 'osm',
|
||||
searchType: 'osm',
|
||||
display: {
|
||||
showTypesFilters: false
|
||||
},
|
||||
points: {
|
||||
types: ['parcel_locker', 'pop']
|
||||
},
|
||||
map: {
|
||||
initialTypes: ['parcel_locker', 'pop']
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(function($) {
|
||||
easyPack.init(defaults);
|
||||
var link = null;
|
||||
var map = null;
|
||||
$('.inpost-easypack-widget').click(function() {
|
||||
link = $(this);
|
||||
|
||||
if (link.data('selected')) {
|
||||
map.searchLockerPoint(link.data('selected'));
|
||||
}
|
||||
|
||||
map = easyPack.modalMap(function(point, modal) {
|
||||
var scope = '#' + link.data('related');
|
||||
$(scope + '_label').html(point.name + '<p>' + point.address.line1 + ', ' + point.address.line2 + '</p>');
|
||||
link.data('selected', point.name);
|
||||
$(scope).val(point.name);
|
||||
modal.closeModal();
|
||||
}, { width: 500, height: 600 });
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
*/
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
$trigger = st_get_admin_button('default', $label, '#', array(
|
||||
'id' => $id.'_trigger',
|
||||
'class' => 'inpost-easypack-widget bs-mt-1',
|
||||
'data-title' => $title,
|
||||
'data-related' => $id,
|
||||
'size' => 'small',
|
||||
));
|
||||
// $trigger = '<a href="#" id="'.$id.'_trigger" class="inpost-easypack-widget" data-title="'. $title .'" data-related="' . $id . '">' . $label . '</a>';
|
||||
$init = true;
|
||||
}
|
||||
|
||||
$selected = __('Brak wybranego punktu');
|
||||
|
||||
if ($value)
|
||||
{
|
||||
try
|
||||
{
|
||||
$point = $api->getPoint($value);
|
||||
|
||||
$selected = $point->name . '<p>' . $point->address->line1 . ', ' . $point->address->line2 . '</p>';
|
||||
}
|
||||
catch(stInPostApiException $e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return input_hidden_tag($name, $value) . '<div id="' . $id . '_label">' . $selected . '</div>' . $trigger . $js;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class stPaczkomatyBackendBreadcrumbsBuilder extends autoStPaczkomatyBackendBreadcrumbsBuilder
|
||||
{
|
||||
public function getDefaultBreadcrumbs()
|
||||
{
|
||||
if ($this->relatedObject instanceof Order)
|
||||
{
|
||||
if (null === $this->defaultBreadcrumbs)
|
||||
{
|
||||
stAdminGeneratorHelper::generate('stOrder');
|
||||
|
||||
if (isset($this->forwardParameters['order_id']))
|
||||
{
|
||||
unset($this->forwardParameters['order_id']);
|
||||
}
|
||||
|
||||
$orderBreadcrumbsBuilder = new stOrderBreadcrumbsBuilder($this->context, $this->breadcrumbs, null, $this->forwardParameters);
|
||||
$this->defaultBreadcrumbs = $orderBreadcrumbsBuilder->getEditBreadcrumbs($this->relatedObject);
|
||||
$this->defaultBreadcrumbs->add($this->appTitle, $this->appRoute);
|
||||
}
|
||||
|
||||
return $this->defaultBreadcrumbs;
|
||||
}
|
||||
|
||||
return parent::getDefaultBreadcrumbs();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php use_javascript('stPrice.js') ?>
|
||||
<?php if($paczkomaty_pack->isNew()):?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_pack_type">
|
||||
<?php echo __('Rozmiar', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo select_tag('paczkomaty_pack[pack_type]', options_for_select(array('A' => 'A (8 x 38 x 64 cm)', 'B' => 'B (19 x 38 x 64 cm)', 'C' => 'C (41 x 38 x 64 cm)'), !$sf_request->hasParameter('paczkomaty_pack[pack_type]') ? $paczkomaty_pack->getPackType() : $sf_request->getParameter('paczkomaty_pack[pack_type]')));?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_insurance">
|
||||
<?php echo __('Kwota ubezpieczenia', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo st_admin_optional_input('paczkomaty_pack[insurance]', $paczkomaty_pack->getInsurance() ? $paczkomaty_pack->getInsurance() : $paczkomaty_pack->getInsurance(true), array('size' => 7, 'disabled' => !$paczkomaty_pack->getInsurance() && !$paczkomaty_pack->hasAllegroInsurance())); ?> PLN
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_cash_on_delivery">
|
||||
<?php echo __('Kwota pobrania', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo st_admin_optional_input('paczkomaty_pack[cash_on_delivery]', $paczkomaty_pack->getCashOnDelivery() ? $paczkomaty_pack->getCashOnDelivery() : $paczkomaty_pack->getCashOnDelivery(true), array('size' => 7, 'disabled' => !$paczkomaty_pack->getCashOnDelivery() && ($sf_request->getMethod() == sfRequest::POST || !$paczkomaty_pack->hasCashOnDelivery()))); ?> PLN
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_description">
|
||||
<?php echo __('Numer referencyjny', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo input_tag('paczkomaty_pack[description]', !$sf_request->hasParameter('paczkomaty_pack[description]') ? $paczkomaty_pack->getDescription() : $sf_request->getParameter('paczkomaty_pack[description]'), array('size' => 80));?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
jQuery(function($) {
|
||||
$(document).ready(function() {
|
||||
$('#paczkomaty_pack_insurance').change(function() {
|
||||
$(this).val(stPrice.fixNumberFormat($(this).val()));
|
||||
});
|
||||
$('#paczkomaty_pack_cash_on_delivery').change(function() {
|
||||
$(this).val(stPrice.fixNumberFormat($(this).val()));
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php else:?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_pack_type">
|
||||
<?php echo __('Rozmiar', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo $paczkomaty_pack->getPackType();?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_insurance">
|
||||
<?php echo __('Kwota ubezpieczenia', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo stPrice::round($paczkomaty_pack->getInsurance()); ?> PLN
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_cash_on_delivery">
|
||||
<?php echo __('Kwota pobrania', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo stPrice::round($paczkomaty_pack->getCashOnDelivery()); ?> PLN
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_description">
|
||||
<?php echo __('Numer referencyjny', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo $paczkomaty_pack->getDescription();?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @var PaczkomatyPack $paczkomaty_pack
|
||||
*/
|
||||
$currency = 'PLN';
|
||||
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
$cashOnDelivery = $paczkomaty_pack->getCashOnDelivery() ? $paczkomaty_pack->getCashOnDelivery() : $paczkomaty_pack->getCashOnDelivery(true);
|
||||
|
||||
echo st_admin_optional_input('paczkomaty_pack[cash_on_delivery]', st_price_format($cashOnDelivery), array(
|
||||
'size' => 7,
|
||||
'disabled' => !$paczkomaty_pack->getCashOnDelivery() && ($sf_request->getMethod() == sfRequest::POST || !$paczkomaty_pack->hasCashOnDelivery())
|
||||
)) . ' ' . $currency;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo stPrice::round($paczkomaty_pack->getCashOnDelivery()) . ' ' . $currency;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript" language="javascript">
|
||||
jQuery(function($) {
|
||||
$('#paczkomaty_pack_cash_on_delivery').change(function() {
|
||||
$(this).val(stPrice.fixNumberFormat($(this).val()));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use_helper('stPaczkomaty');
|
||||
$paczkomaty_params = array();
|
||||
|
||||
if ($paczkomaty_pack->hasAllegroTransactionId())
|
||||
{
|
||||
$paczkomaty_params['function'] = 'AllegroParcelCollect';
|
||||
}
|
||||
else
|
||||
{
|
||||
$paczkomaty_params['function'] = 'ParcelCollect';
|
||||
}
|
||||
|
||||
if ($paczkomaty_pack->hasCashOnDelivery())
|
||||
{
|
||||
$paczkomaty_params['paymentavailable'] = 't';
|
||||
}
|
||||
|
||||
?>
|
||||
<?php if($paczkomaty_pack->isNew()):?>
|
||||
<?php echo input_hidden_tag('order', $sf_request->getParameter('order'));?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_email">
|
||||
<?php echo __('Adres e-mail odbiorcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<div class="field<?php if ($sf_request->hasError('paczkomaty_pack{customer_email}')):?> form-error<?php endif; ?>">
|
||||
<?php if ($sf_request->hasError('paczkomaty_pack{customer_email}')):?>
|
||||
<?php echo form_error('paczkomaty_pack{customer_email}', array('class' => 'form-error-msg'));?>
|
||||
<?php endif;?>
|
||||
<?php echo input_tag('paczkomaty_pack[customer_email]', !$sf_request->hasParameter('paczkomaty_pack[customer_email]') ? $paczkomaty_pack->getCustomerEmail() : $sf_request->getParameter('paczkomaty_pack[customer_email]'), array('size' => 30));?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_phone">
|
||||
<?php echo __('Numer komórkowy odbiorcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<div class="field<?php if ($sf_request->hasError('paczkomaty_pack{customer_phone}')): ?> form-error<?php endif;?>">
|
||||
<?php if ($sf_request->hasError('paczkomaty_pack{customer_phone}')):?>
|
||||
<?php echo form_error('paczkomaty_pack{customer_phone}', array('class' => 'form-error-msg'));?>
|
||||
<?php endif;?>
|
||||
<?php echo input_tag('paczkomaty_pack[customer_phone]', !$sf_request->hasParameter('paczkomaty_pack[customer_phone]') ? $paczkomaty_pack->getCustomerPhone() : $sf_request->getParameter('paczkomaty_pack[customer_phone]'), array('size' => 15));?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_paczkomat">
|
||||
<?php echo __('Paczkomat odbiorcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php show_paczkomaty_dropdown_list('paczkomaty_pack[customer_paczkomat]', $paczkomaty_pack->getCustomerPaczkomat(), array('paczkomaty' => $paczkomaty_params));?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<?php else:?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_email">
|
||||
<?php echo __('Adres e-mail odbiorcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo $paczkomaty_pack->getCustomerEmail();?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_phone">
|
||||
<?php echo __('Numer komórkowy odbiorcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo $paczkomaty_pack->getCustomerPhone();?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_paczkomat">
|
||||
<?php echo __('Paczkomat odbiorcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<div id="st-paczkomaty-customer-machine">
|
||||
<img src="/images/backend/icons/indicator.gif" alt="loading..." />
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
if (!$value->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo st_countries_select_tag($name, $value->$method(), $options);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $value->$method() ? CountriesPeer::retrieveByIsoA2($value->$method()) : '-';
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo input_tag('paczkomaty_pack[customer_email]', $paczkomaty_pack->getCustomerEmail(), array('size' => 80));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $paczkomaty_pack->getCustomerEmail();
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo input_tag('paczkomaty_pack[customer_phone]', $paczkomaty_pack->getCustomerPhone(), array('size' => 80));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $paczkomaty_pack->getCustomerPhone();
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php echo st_inpost_point_select_tag('paczkomaty_pack[customer_pickup_point]', $paczkomaty_pack->getCustomerPickupPoint(), array (
|
||||
'title' => 'Paczkomat odbiorcy',
|
||||
'disabled' => $paczkomaty_pack->isAdminGeneratorPlainField()
|
||||
)); ?>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php use_helper('stPaczkomaty');
|
||||
echo show_paczkomaty_dropdown_list('config[default_sender_paczkomat]', !$sf_request->hasParameter('config[default_sender_paczkomat]') ? $config->get('default_sender_paczkomat') : $sf_request->getParameter('config[default_sender_paczkomat]'), array('paczkomaty' => array('function' => 'ParcelSend')));
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo input_tag('paczkomaty_pack[description]', !$sf_request->hasParameter('paczkomaty_pack[description]') ? $paczkomaty_pack->getDescription() : $sf_request->getParameter('paczkomaty_pack[description]'), array('size' => 80));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $paczkomaty_pack->getDescription();
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo input_tag('filters[dispatch_order]', isset($filters['dispatch_order']) ? $filters['dispatch_order'] : null, ['id' => 'filters_dispatch_order_id', 'size' => 14]);
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @var PaczkomatyPack $paczkomaty_pack
|
||||
*/
|
||||
|
||||
echo $paczkomaty_pack->getPaczkomatyDispatchOrder();
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php echo st_inpost_point_select_tag('paczkomaty_pack[dropoff_point]', $paczkomaty_pack->getDropoffPoint(), array (
|
||||
'title' => 'Paczkomat nadawcy',
|
||||
'disabled' => $paczkomaty_pack->isAdminGeneratorPlainField()
|
||||
)); ?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo st_admin_checkbox_tag('paczkomaty_pack[end_of_week_collection]', true, $paczkomaty_pack->getEndOfWeekCollection());
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $paczkomaty_pack->getEndOfWeekCollection() ? __("Tak", null, "stAdminGeneratorPlugin") : __("Nie", null, "stAdminGeneratorPlugin");
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @var PaczkomatyPack $paczkomaty_pack
|
||||
*/
|
||||
$currency = 'PLN';
|
||||
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
$insuranceAmount = $paczkomaty_pack->getInsurance() ? $paczkomaty_pack->getInsurance() : $paczkomaty_pack->getInsurance(true);
|
||||
echo st_admin_optional_input('paczkomaty_pack[insurance]', st_price_format($insuranceAmount), array(
|
||||
'size' => 7,
|
||||
'disabled' => !$paczkomaty_pack->getInsurance() && !$paczkomaty_pack->hasAllegroInsurance()
|
||||
)) . ' ' . $currency;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo stPrice::round($paczkomaty_pack->getInsurance()) . ' ' . $currency;
|
||||
}
|
||||
?>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
jQuery(function($) {
|
||||
$('#paczkomaty_pack_insurance').change(function() {
|
||||
$(this).val(stPrice.fixNumberFormat($(this).val()));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,7 @@
|
||||
<div>
|
||||
<?php if ($pp): ?>
|
||||
<a href="<?php echo $pp->getTrackingUrl() ?>" target="_blank" style="display: inline-block; padding-right: 15px; background: #444; color: #fafafa; text-decoration: none"><img src="/images/backend/icons/inpost-zolte-tlo.png" style="line-height: 0; vertical-align: middle; padding-right: 15px"; /><span style="vertical-align: middle;"><?php echo __('Śledź przesyłkę') ?></span></a>
|
||||
<?php else: ?>
|
||||
<a href="<?php echo url_for('@stPaczkomatyCreatePack?order='.$order->getId());?>" style="display: inline-block; padding-right: 15px; background: #444; color: #fafafa; text-decoration: none"><img src="/images/backend/icons/inpost-zolte-tlo.png" style="line-height: 0; vertical-align: middle; padding-right: 15px"; /><span style="vertical-align: middle;"><?php echo __('Wyślij paczkę') ?></span></a>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php use_helper('stOrder') ?>
|
||||
|
||||
<?php echo st_order_status_select_tag('config[order_status]', $config->get('order_status'), array('include_custom' => true)) ?>
|
||||
@@ -0,0 +1 @@
|
||||
<?php echo st_inpost_organization_select_tag('config[organization]', $config->get('organization')); ?>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php if(!$paczkomaty_pack->isNew()):?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_code">
|
||||
<?php echo __('Numer paczki', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php echo $paczkomaty_pack->getCode();?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_status">
|
||||
<?php echo __('Status paczki', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<div id="st-paczkomaty-status">
|
||||
<img src="/images/backend/icons/indicator.gif" alt="loading..." />
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_status_changed_at">
|
||||
<?php echo __('Aktualizacja statusu w systemie Paczkomaty.pl', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<div id="st-paczkomaty-status-date">
|
||||
<img src="/images/backend/icons/indicator.gif" alt="loading..." />
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
jQuery(function ($) {
|
||||
$(document).ready(function() {
|
||||
$.getJSON('/backend.php/paczkomaty/getPackStatus?code=<?php echo $paczkomaty_pack->getCode();?>', function(data) {
|
||||
$('#st-paczkomaty-status').html(data.clientStatus);
|
||||
$('#st-paczkomaty-status-date').html(data.date);
|
||||
<?php if($paczkomaty_pack->getStatus() == 'Created'):?>
|
||||
if (data.status != 'Created') {
|
||||
$('.action-pay_for_pack').hide();
|
||||
$('.action-download_sticker input').attr('value', 'Pobierz etykiete');
|
||||
$('.action-download_sticker input').css('background-image', 'url(/images/backend/icons/download_sticker.png)');
|
||||
}
|
||||
<?php endif;?>
|
||||
});
|
||||
$.getJSON('/paczkomaty/getMachine?number=<?php echo $paczkomaty_pack->getCustomerPaczkomat();?>', function(data) {
|
||||
$('#st-paczkomaty-customer-machine').html(data.number + ', ' + data.street + ' ' + data.house + ', ' + data.postCode + ' ' + data.city);
|
||||
});
|
||||
<?php if($paczkomaty_pack->getUseSenderPaczkomat()):?>
|
||||
$.getJSON('/paczkomaty/getMachine?number=<?php echo $paczkomaty_pack->getSenderPaczkomat();?>', function(data) {
|
||||
$('#st-paczkomaty-sender-machine').html(data.number + ', ' + data.street + ' ' + data.house + ', ' + data.postCode + ' ' + data.city);
|
||||
});
|
||||
<?php endif;?>
|
||||
$('.action-save').hide();
|
||||
<?php if(!is_null($paczkomaty_pack->getStatus()) && $paczkomaty_pack->getStatus() != 'Created'):?>
|
||||
$('.action-pay_for_pack').hide();
|
||||
$('.action-download_sticker input').attr('value', 'Pobierz etykiete');
|
||||
<?php else:?>
|
||||
$('.action-download_sticker input').css('background-image', 'url(/images/backend/icons/pay_and_download.png)');
|
||||
<?php endif;?>
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php else:?>
|
||||
<script type="text/javascript" language="javascript">
|
||||
jQuery(function($) {
|
||||
$(document).ready(function() {
|
||||
$('#sf_fieldset_informacje_o_paczce').hide();
|
||||
$('.action-pay_for_pack').hide();
|
||||
$('.action-download_sticker').hide();
|
||||
$('.action-list').hide();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php endif;?>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$options = array('A' => 'A (8 x 38 x 64 cm)', 'B' => 'B (19 x 38 x 64 cm)', 'C' => 'C (41 x 38 x 64 cm)');
|
||||
|
||||
if (!$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo select_tag('paczkomaty_pack[pack_type]', options_for_select($options, !$sf_request->hasParameter('paczkomaty_pack[pack_type]') ? $paczkomaty_pack->getPackType() : $sf_request->getParameter('paczkomaty_pack[pack_type]')));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $options[$paczkomaty_pack->getPackType()];
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
<?php echo select_tag('delivery_dimension[paczkomaty_size]', options_for_select(array('NONE' => '-', 'A' => 'A (8 x 38 x 64 cm)', 'B' => 'B (19 x 38 x 64 cm)', 'C' => 'C (41 x 38 x 64 cm)'), !$sf_request->hasParameter('delivery_dimension[paczkomaty_size]') ? $delivery_dimension->getPaczkomatySize() : $sf_request->getParameter('delivery_dimension[paczkomaty_size]')));
|
||||
@@ -0,0 +1 @@
|
||||
<?php echo select_tag('delivery[paczkomaty_type]', options_for_select(array('NONE' => __('Wyłączone'), 'ALL' => __('Wszystkie'), 'COD' => __('Z płatnością przy odbiorze')), $delivery->getPaczkomatyType()));
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @var PaczkomatyPack $paczkomaty_pack
|
||||
*/
|
||||
if ($type == 'list')
|
||||
{
|
||||
$trackingNumbers = [];
|
||||
|
||||
foreach ($paczkomaty_pack->getParcels() as $parcel)
|
||||
{
|
||||
$trackingNumbers[] = $parcel['number'];
|
||||
}
|
||||
|
||||
echo implode(', ', $trackingNumbers);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo delivery_parcels_manager_tag('paczkomaty_pack[parcels]', $paczkomaty_pack->getParcels(), [
|
||||
'fields' => [
|
||||
'weight' => [
|
||||
'label' => __('Waga [kg]'),
|
||||
'type' => !$paczkomaty_pack->isAdminGeneratorPlainField() ? 'input_tag' : 'plain',
|
||||
'options' => [
|
||||
'data-format' => 'decimal',
|
||||
'data-format-min-value' => 0.1,
|
||||
'size' => 8
|
||||
],
|
||||
],
|
||||
'width' => [
|
||||
'label' => __('Szerokość [cm]'),
|
||||
'type' => !$paczkomaty_pack->isAdminGeneratorPlainField() ? 'input_tag' : 'plain',
|
||||
'options' => [
|
||||
'data-format' => 'integer',
|
||||
'data-format-min-value' => 1,
|
||||
'size' => 8,
|
||||
'class' => 'app-dpd-size'
|
||||
],
|
||||
],
|
||||
'height' => [
|
||||
'label' => __('Wysokość [cm]'),
|
||||
'type' => !$paczkomaty_pack->isAdminGeneratorPlainField() ? 'input_tag' : 'plain',
|
||||
'options' => [
|
||||
'data-format' => 'integer',
|
||||
'data-format-min-value' => 1,
|
||||
'size' => 8,
|
||||
'class' => 'app-dpd-size'
|
||||
],
|
||||
],
|
||||
'length' => [
|
||||
'label' => __('Długość [cm]'),
|
||||
'type' => !$paczkomaty_pack->isAdminGeneratorPlainField() ? 'input_tag' : 'plain',
|
||||
'options' => [
|
||||
'data-format' => 'integer',
|
||||
'data-format-min-value' => 1,
|
||||
'size' => 8,
|
||||
'class' => 'app-dpd-size'
|
||||
],
|
||||
],
|
||||
],
|
||||
'disabled' => $paczkomaty_pack->isAdminGeneratorPlainField(),
|
||||
]);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php use_helper('stPaczkomaty');?>
|
||||
<?php if($paczkomaty_pack->isNew()):
|
||||
$paczkomaty_params = array();
|
||||
|
||||
if ($paczkomaty_pack->hasAllegroTransactionId())
|
||||
{
|
||||
$paczkomaty_params['function'] = 'ParcelSend,AllegroParcelSend';
|
||||
}
|
||||
else
|
||||
{
|
||||
$paczkomaty_params['function'] = 'ParcelSend';
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_use_sender_paczkomat">
|
||||
<?php echo __('Użyj Paczkomatu', array(), 'stPaczkomatyBackend');?>
|
||||
</label>
|
||||
<?php $useSenderPaczkomat = !$sf_request->hasParameter('paczkomaty_pack[use_sender_paczkomat]') ? $paczkomaty_pack->getUseSenderPaczkomat() : $sf_request->getParameter('paczkomaty_pack[use_sender_paczkomat]');?>
|
||||
<?php echo checkbox_tag('paczkomaty_pack[use_sender_paczkomat]', 1, $useSenderPaczkomat);?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_sender_paczkomat">
|
||||
<?php echo __('Paczkomat nadawcy', array(), 'stPaczkomatyBackend');?>
|
||||
</label>
|
||||
<?php show_paczkomaty_dropdown_list('paczkomaty_pack[sender_paczkomat]', $paczkomaty_pack->getSenderPaczkomat(), array('disabled' => !$useSenderPaczkomat, 'paczkomaty' => array('function' => 'ParcelSend')));?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<script type="text/javascript" language="javascript">
|
||||
jQuery(function($) {
|
||||
$(document).ready(function() {
|
||||
$('#paczkomaty_pack_use_sender_paczkomat').change(function() {
|
||||
$('#paczkomaty_pack_sender_paczkomat').prop('disabled', !$(this).prop('checked'));
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php else:?>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_customer_email">
|
||||
<?php echo __('Użyj Paczkomatu', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php if ($paczkomaty_pack->getUseSenderPaczkomat()):?>
|
||||
<img src="/images/backend/beta/icons/16x16/tick.png" alt="loading..." />
|
||||
<?php else:?>
|
||||
<img src="/images/backend/beta/icons/16x16/cancel.png" alt="loading..." />
|
||||
<?php endif;?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="paczkomaty_pack_sender_paczkomat">
|
||||
<?php echo __('Paczkomat nadawcy', array(), 'stPaczkomatyBackend');?>:
|
||||
</label>
|
||||
<?php if ($paczkomaty_pack->getUseSenderPaczkomat()):?>
|
||||
<div id="st-paczkomaty-sender-machine">
|
||||
<img src="/images/backend/icons/indicator.gif" alt="loading..." />
|
||||
</div>
|
||||
<?php else:?>
|
||||
-
|
||||
<?php endif;?>
|
||||
<div class="clr"></div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
<?php
|
||||
/**
|
||||
* @var PaczkomatyPack $paczkomaty_pack
|
||||
*/
|
||||
if ($type == 'edit' && !$paczkomaty_pack->isAdminGeneratorPlainField())
|
||||
{
|
||||
echo st_inpost_sending_method_select_tag('paczkomaty_pack[sending_method]', $paczkomaty_pack->getSendingMethod(), array (
|
||||
'service' => $paczkomaty_pack->getService(),
|
||||
'target' => '.row_dropoff_point',
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
$api = stInPostApi::getInstance();
|
||||
$methods = $api->getSendingMethods();
|
||||
echo $methods[$paczkomaty_pack->getSendingMethod()];
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ($type == 'edit' && $paczkomaty_pack->isAdminGeneratorPlainField() && $paczkomaty_pack->getSendingMethod() != 'parcel_locker'): ?>
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
$('.row_dropoff_point').hide();
|
||||
});
|
||||
</script>
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
echo st_inpost_sending_method_select_tag($name, $value, ['include_custom' => '---']);
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$selectOptions = [];
|
||||
|
||||
foreach (['inpostp', 'inpostk'] as $type)
|
||||
{
|
||||
if (stDeliveryTypeConfiguration::has($type))
|
||||
{
|
||||
$service = stDeliveryTypeService::get($type);
|
||||
$selectOptions[$service->getType()] = $service->getLabel();
|
||||
}
|
||||
}
|
||||
|
||||
echo select_tag($name, $selectOptions, [
|
||||
'include_custom' => '---',
|
||||
'selected' => isset($filters['service_type']) ? $filters['service_type'] : null
|
||||
]);
|
||||
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl" style="height: 100%;">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||
<meta http-equiv="x-ua-compatible" content="IE=11"/>
|
||||
<title>Geowidget v4 - Example - Search Locker Point</title>
|
||||
<script src="https://geowidget.easypack24.net/js/sdk-for-javascript.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.easyPackAsyncInit = function () {
|
||||
easyPack.init({
|
||||
instance: 'pl',
|
||||
mapType: 'osm',
|
||||
apiEndpoint: '<?php echo $endpoint ?>',
|
||||
searchType: 'osm',
|
||||
points: {
|
||||
types: ['pop', 'parcel_locker'],
|
||||
},
|
||||
display: {
|
||||
showTypesFilters: false
|
||||
},
|
||||
map: {
|
||||
useGeolocation: true,
|
||||
initialTypes: ['parcel_locker']
|
||||
}
|
||||
});
|
||||
|
||||
var scope = '#<?php echo $scope ?>';
|
||||
|
||||
$ = window.parent.jQuery;
|
||||
|
||||
var selected = $(scope);
|
||||
|
||||
var map = easyPack.mapWidget('easypack-map', function(point) {
|
||||
$(scope + '_label').html(point.name + '<p>' + point.address.line1 + ', ' + point.address.line2 + '</p>');
|
||||
selected.val(point.name);
|
||||
$(scope + '_trigger').data('overlay').close();
|
||||
});
|
||||
|
||||
|
||||
if (selected.val()) {
|
||||
map.searchLockerPoint(selected.val());
|
||||
}
|
||||
|
||||
// setTimeout(function() {
|
||||
// var modal = window.parent.jQuery('#inpost-easypack-modal');
|
||||
|
||||
// modal.find('iframe').height(window.document.body.scrollHeight);
|
||||
|
||||
// console.log('test');
|
||||
// }, 2000);
|
||||
}
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://geowidget.easypack24.net/css/easypack.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="easypack-map"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php use_helper('I18N', 'stAdminGenerator', 'Validation');?>
|
||||
<?php echo st_get_admin_head('stPaczkomatyPlugin', __('Konfiguracja', array()), __('',array()),array('stPayment', 'stProduct','stDeliveryPlugin'));?>
|
||||
<div id="sf_admin_content">
|
||||
<div id="sf_admin_content_config">
|
||||
<form>
|
||||
<fieldset>
|
||||
<div class="st_fieldset-content">
|
||||
<div class="form-row">
|
||||
<a href="<?php echo get_7_link();?>" target="_blank">Zamów aktualizację do wersji 7</a>
|
||||
<br class="st_clear_all" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<br class="st_clear_all" />
|
||||
<?php echo st_get_admin_foot();?>
|
||||
@@ -0,0 +1,8 @@
|
||||
fields:
|
||||
config{sender_phone}:
|
||||
required:
|
||||
msg: Proszę uzupełnić pole.
|
||||
sfRegexValidator:
|
||||
match: Yes
|
||||
match_error: Podany numer jest nieprawidłowy. Numer musi być podany w formacie 9 cyfrowym bez spacji oraz myślników.
|
||||
pattern: /^\d{9}$/
|
||||
@@ -0,0 +1,11 @@
|
||||
fields:
|
||||
paczkomaty_pack{customer_email}:
|
||||
required:
|
||||
msg: Proszę uzupełnić pole.
|
||||
paczkomaty_pack{customer_phone}:
|
||||
required:
|
||||
msg: Proszę uzupełnić pole.
|
||||
sfRegexValidator:
|
||||
match: Yes
|
||||
match_error: Podany numer jest nieprawidłowy. Numer musi być podany w formacie 9 cyfrowym bez spacji oraz myślników.
|
||||
pattern: /^\d{9}$/
|
||||
Reference in New Issue
Block a user