/** * @return ShipmentOption */ public function getById(ShipmentType $type, $id) { if ($type->isPersonal()) { return $this->personalPointRepository->find($id); } elseif ($type->isByTransportCompany()) { return $this->transportCompanyRepository->find($id); } elseif ($type->isToCollectionPoint()) { return $this->collectionPointRepository->find($id); } else { throw new \LogicException(); } }
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); }
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)); } }
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())); } }
public function getType() { return ShipmentType::TO_COLLECTION_POINT(); }
public function getType() { return ShipmentType::BY_TRANSPORT_COMPANY(); }
/** * @return ShipmentType|null */ public function getShipmentType() { if ($this->shipmentType !== null) { return ShipmentType::createFromValue($this->shipmentType); } return null; }
private function addTypeControl() { $control = $this->addRadioList('type', 'Type', ShipmentType::getLabels()); $control->setDefaultValue(ShipmentType::PERSONAL); return $control; }