コード例 #1
0
ファイル: EditPresenter.php プロジェクト: shophp/shophp
 private function updateShipment(ShipmentForm $form)
 {
     $values = $form->getValues();
     if ($this->shipment instanceof ShipmentPersonalPoint || $this->shipment instanceof ShipmentCollectionPoint) {
         $this->shipment->setAddress($values->address->name !== '' ? $values->address->name : null, $values->address->street, $values->address->city, $values->address->zip);
         if ($values->address->longitude !== '') {
             $this->shipment->setGps($values->address->longitude, $values->address->latitude);
         } else {
             $this->shipment->removeGps();
         }
     }
     if ($this->shipment instanceof ShipmentTransportCompany || $this->shipment instanceof ShipmentCollectionPoint) {
         $this->shipment->setPrice($values->price);
         if ($values->enableFreeFromCertainOrderPrice) {
             $this->shipment->setMinimumOrderPriceToBeFree($values->minimumOrderPriceToBeFree);
         } else {
             $this->shipment->eraseToBeFreeFromCertainOrderPrice();
         }
     }
     if ($this->shipment instanceof ShipmentTransportCompany) {
         $this->shipment->setName($values->companyName);
     }
     try {
         if (!$form->hasErrors()) {
             $this->shipmentService->update($this->shipment);
             $this->flashMessage('Shipment has been updated.');
             $this->redirect(':Admin:Shipment:List:');
         }
     } catch (EntityDuplicateException $e) {
         $form->addError(sprintf('Shipment company with name %s already exists.', $this->shipment->getName()));
     }
 }
コード例 #2
0
ファイル: ShipmentForm.php プロジェクト: shophp/shophp
 private function createFields()
 {
     $shipmentOptions = [];
     $personalPoints = $this->shipmentService->getPersonalPoints();
     foreach ($personalPoints as $personalPoint) {
         $key = sprintf('%d-%d', ShipmentType::PERSONAL, $personalPoint->getId());
         $shipmentOptions[$key] = sprintf('Personally at: %s', $this->shipmentHelper->formatShipmentOption($personalPoint));
     }
     $collectionPoints = $this->shipmentService->getCollectionPoints();
     foreach ($collectionPoints as $collectionPoint) {
         $key = sprintf('%d-%d', ShipmentType::TO_COLLECTION_POINT, $collectionPoint->getId());
         $shipmentOptions[$key] = sprintf('At collection point: %s', $this->shipmentHelper->formatShipmentOption($collectionPoint));
     }
     $transportCompanies = $this->shipmentService->getTransportCompanies();
     $transportCompanyKeys = [];
     $hasTransportCompany = false;
     foreach ($transportCompanies as $transportCompany) {
         $key = sprintf('%d-%d', ShipmentType::BY_TRANSPORT_COMPANY, $transportCompany->getId());
         $shipmentOptions[$key] = $this->shipmentHelper->formatShipmentOption($transportCompany);
         $transportCompanyKeys[] = $key;
         $hasTransportCompany = true;
     }
     $shipmentControl = $this->addRadioList('shipment', 'Shipment', $shipmentOptions)->setDefaultValue(key($shipmentOptions))->setRequired();
     if ($this->shipment !== null) {
         $shipmentControl->setDefaultValue(sprintf('%d-%d', $this->shipment->getShipmentOption()->getType()->getValue(), $this->shipment->getShipmentOption()->getId()));
     }
     $defaultName = null;
     $defaultStreet = null;
     $defaultCity = null;
     $defaultZip = null;
     if ($this->shipment instanceof ShipmentByTransportCompany) {
         $defaultName = $this->shipment->getName();
         $defaultStreet = $this->shipment->getStreet();
         $defaultCity = $this->shipment->getCity();
         $defaultZip = $this->shipment->getZip();
     } elseif ($this->user !== null) {
         $defaultName = $this->user->getName();
         $defaultStreet = $this->user->getStreet();
         $defaultCity = $this->user->getCity();
         $defaultZip = $this->user->getZip();
     }
     if ($hasTransportCompany) {
         $requiring = function (TextInput $control) use($shipmentControl, $transportCompanyKeys) {
             return $control->addConditionOn($shipmentControl, self::IS_IN, $transportCompanyKeys);
         };
         $addressContainer = new AddressFormContainer();
         $this->addComponent($addressContainer, 'address');
         $addressContainer->addNameControl('name', $defaultName, $requiring);
         $addressContainer->addStreetControl('street', $defaultStreet, $requiring);
         $addressContainer->addCityControl('city', $defaultCity, $requiring);
         $addressContainer->addZipControl('zip', $defaultZip, $requiring);
         $shipmentControl->addCondition(self::IS_IN, $transportCompanyKeys)->toggle('order-shipment-address');
     }
     $this->addSubmit('next', 'Next');
 }
コード例 #3
0
ファイル: CreatePresenter.php プロジェクト: shophp/shophp
 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()));
     }
 }
コード例 #4
0
ファイル: CartPresenter.php プロジェクト: shophp/shophp
 public function renderDefault()
 {
     $this->template->offersShipment = $this->shipmentService->existsAnyShipmentOption();
 }
コード例 #5
0
ファイル: ListPresenter.php プロジェクト: shophp/shophp
 public function renderDefault()
 {
     $this->template->personalPoints = $this->shipmentService->getPersonalPoints();
     $this->template->transportCompanies = $this->shipmentService->getTransportCompanies();
     $this->template->collectionPoints = $this->shipmentService->getCollectionPoints();
 }
コード例 #6
0
ファイル: ShipmentPresenter.php プロジェクト: shophp/shophp
 public function actionDefault()
 {
     if (!$this->shipmentService->existsAnyShipmentOption()) {
         $this->redirect(':Front:Order:Payment:');
     }
 }