Exemple #1
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()));
     }
 }
Exemple #2
0
 private function addCompanyNameControl(ShipmentTransportCompany $shipment = null, ChoiceControl $typeControl = null)
 {
     $control = $this->addText('companyName', 'Company name');
     if ($typeControl === null) {
         $requiredCondition = $control;
         $control->setDefaultValue($shipment->getName());
     } else {
         $requiredCondition = $control->addConditionOn($typeControl, self::EQUAL, ShipmentType::BY_TRANSPORT_COMPANY);
         $typeControl->addCondition(self::EQUAL, ShipmentType::BY_TRANSPORT_COMPANY)->toggle('shipment-company-name');
     }
     $requiredCondition->setRequired('Please fill company name.');
     return $control;
 }