/** * @param ShipmentCollectionPoint|ShipmentTransportCompany $shipment */ private function addPriceDescription(ShipmentOption $shipment, $description) { if ($shipment->getPrice() > 0) { $description = sprintf('%s (%s)', $description, $this->moneyHelper->formatPrice($shipment->getPrice())); } return $description; }
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())); } }
private function checkDuplicity(ShipmentOption $shipment) { if ($shipment instanceof ShipmentTransportCompany) { $duplicate = $this->transportCompanyRepository->findOneBy(['name' => $shipment->getName()]); if ($duplicate !== null) { throw new EntityDuplicateException(sprintf('Shipment company with name %s already exists.', $shipment->getName())); } } }
/** * @param ShipmentTransportCompany|ShipmentCollectionPoint|null $shipment */ private function addMinimumOrderPriceToBeFreeControl(ShipmentOption $shipment = null, ChoiceControl $typeControl = null) { $enableControl = $this->addCheckbox('enableFreeFromCertainOrderPrice', 'Free from certain order price'); $enableControl->addCondition(self::EQUAL, true)->toggle('shipment-free-price-input'); $errorMessage = 'Minimum order price must be positive number.'; $priceControl = $this->addText('minimumOrderPriceToBeFree', 'Minimum order price to be free'); $priceControl->setType('number')->setAttribute('step', 'any')->setDefaultValue(0); if ($typeControl === null) { $requiredCondition = $priceControl; $enableControl->setDefaultValue($shipment->isFreeFromCertainOrderPrice()); if ($shipment->isFreeFromCertainOrderPrice()) { $priceControl->setDefaultValue($shipment->getMinimumOrderPriceToBeFree()); } } else { $requiredCondition = $priceControl->addConditionOn($typeControl, self::NOT_EQUAL, ShipmentType::PERSONAL); $typeControl->addCondition(self::NOT_EQUAL, ShipmentType::PERSONAL)->toggle('shipment-free-price'); } $requiredCondition->addConditionOn($enableControl, self::EQUAL, true)->setRequired()->addRule(self::FLOAT, $errorMessage)->addRule(function (TextInput $input) { return $input->getValue() > 0; }, $errorMessage); }