public function weightExists($value, ExecutionContextInterface $context) { $translator = Translator::getInstance(); $weight_check = @(bool) $this->getWeightCheck(); $msg = "The weight \"%weight\" " . ($weight_check ? "doens't" : "already") . " exist in the area: %area"; if (PricesQuery::sliceExists($this->getForm()->getData()['area'], $value) !== $weight_check) { $context->addViolation($translator->trans($msg, ["%weight" => $value, "%area" => $this->getForm()->getData()['area']], Predict::MESSAGE_DOMAIN)); } }
public function buildArray() { $area = $this->getArea(); $prices = PricesQuery::getPrices(); if (!isset($prices[$area]) || !isset($prices[$area]["slices"])) { return array(); } $areaPrices = $prices[$area]["slices"]; ksort($areaPrices); return $areaPrices; }
/** * * calculate and return delivery price * * @param Country $country * @return mixed * @throws DeliveryException */ public function getPostage(Country $country) { $cartWeight = $this->getRequest()->getSession()->getCart()->getWeight(); $postage = PricesQuery::getPostageAmount($country->getAreaId(), $cartWeight); return $postage; }
public function deletePrice() { if (null !== ($response = $this->checkAuth([AdminResources::MODULE], ['Predict'], AccessManager::DELETE))) { return $response; } $error_msg = false; $form = new DeletePriceForm($this->getRequest()); try { $vform = $this->validateForm($form, "post"); PricesQuery::setPostageAmount(false, $vform->get("area")->getData(), $vform->get("weight")->getData()); } catch (FormValidationException $e) { $error_msg = $this->createStandardFormValidationErrorMessage($e); } catch (\Exception $e) { $error_msg = $e->getMessage(); } if (false !== $error_msg) { $form->setErrorMessage($error_msg); $this->getParserContext()->addForm($form)->setGeneralError($error_msg); } return $this->render("module-configure", ["module_code" => "Predict", "tab" => "prices"]); }