Example #1
0
 public function getChosenShipment()
 {
     /** @var RadioList $control */
     $control = $this->getComponent('shipment');
     list($shipmentType, $shipmentId) = explode('-', $control->getValue());
     $shipmentType = ShipmentType::createFromValue((int) $shipmentType);
     return $this->shipmentService->getById($shipmentType, (int) $shipmentId);
 }
Example #2
0
 public function actionDefault($id, $type)
 {
     if ($id !== null) {
         $type = (int) $type;
         if (!ShipmentType::isValidValue($type)) {
             throw new BadRequestException(sprintf('Unknown shipment type %d.', $type));
         }
         $this->shipment = $this->shipmentService->getById(ShipmentType::createFromValue($type), $id);
     }
     if ($this->shipment === null) {
         throw new BadRequestException(sprintf('Shipment with ID %d not found.', $id));
     }
 }
Example #3
0
 private function createShipment(ShipmentForm $form)
 {
     $values = $form->getValues();
     $type = ShipmentType::createFromValue($values->type);
     switch ($type->getValue()) {
         case ShipmentType::PERSONAL:
             $shipmentOption = new ShipmentPersonalPoint($values->address->name !== '' ? $values->address->name : null, $values->address->street, $values->address->city, $values->address->zip);
             if ($values->address->longitude !== '') {
                 $shipmentOption->setGps($values->address->longitude, $values->address->latitude);
             }
             break;
         case ShipmentType::BY_TRANSPORT_COMPANY:
             $shipmentOption = new ShipmentTransportCompany($values->companyName, $values->price);
             if ($values->enableFreeFromCertainOrderPrice) {
                 $shipmentOption->setMinimumOrderPriceToBeFree($values->minimumOrderPriceToBeFree);
             }
             break;
         case ShipmentType::TO_COLLECTION_POINT:
             $shipmentOption = new ShipmentCollectionPoint($values->address->name !== '' ? $values->address->name : null, $values->address->street, $values->address->city, $values->address->zip, $values->price);
             if ($values->address->longitude !== '') {
                 $shipmentOption->setGps($values->address->longitude, $values->address->latitude);
             }
             if ($values->enableFreeFromCertainOrderPrice) {
                 $shipmentOption->setMinimumOrderPriceToBeFree($values->minimumOrderPriceToBeFree);
             }
             break;
         default:
             throw new \LogicException();
     }
     try {
         if (!$form->hasErrors()) {
             $this->shipmentService->create($shipmentOption);
             $this->flashMessage('Shipment has been created.');
             $this->redirect(':Admin:Shipment:List:');
         }
     } catch (EntityDuplicateException $e) {
         $form->addError(sprintf('Shipment company with name %s already exists.', $shipmentOption->getName()));
     }
 }
Example #4
0
 /**
  * @return ShipmentType|null
  */
 public function getShipmentType()
 {
     if ($this->shipmentType !== null) {
         return ShipmentType::createFromValue($this->shipmentType);
     }
     return null;
 }