public function setGlobalConfig() { if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('DeliveryDelay'), AccessManager::UPDATE))) { return $response; } $form = $this->createForm("deliverydelay.form"); try { $data = $this->validateForm($form)->getData(); // Configs DeliveryDelay::setConfigValue("delivery_min", $data["delivery_min"]); DeliveryDelay::setConfigValue("delivery_max", $data["delivery_max"]); DeliveryDelay::setConfigValue("restock_min", $data["restock_min"]); DeliveryDelay::setConfigValue("restock_max", $data["restock_max"]); // Exclude weekend ? $excludeWeekend = $data["exclude_weekend"] === "on" ? 1 : 0; DeliveryDelay::setConfigValue("exclude_weekend", $excludeWeekend); // Exclude easter day ? $excludeEasterDay = $data["exclude_easter_day"] === "on" ? 1 : 0; DeliveryDelay::setConfigValue("exclude_easter_day", $excludeEasterDay); // Exclude easter day based holidays ? $excludeEasterHolidays = $data["exclude_easter_day_based_holidays"] === "on" ? 1 : 0; DeliveryDelay::setConfigValue("exclude_easter_day_based_holidays", $excludeEasterHolidays); return $this->generateSuccessRedirect($form); } catch (\Exception $e) { $this->setupFormErrorContext($this->getTranslator()->trans("Error on delivery delay configuration : %message", ["message" => $e->getMessage()], DeliveryDelay::DOMAIN_NAME), $e->getMessage(), $form); return self::viewAction(); } }
public function checkIsDeliverableDate($date) { //If config say exclude weekend and the date is on weekend return false if (DeliveryDelay::getConfigValue("exclude_weekend") && date("N", strtotime($date)) > 5) { return false; } $undeliverableDates = UndeliverableDateQuery::create()->filterByActive(true)->select("date")->find()->toArray(); if (in_array(date("m-d", strtotime($date)), $undeliverableDates)) { return false; } if (DeliveryDelay::getConfigValue("exclude_easter_day") && true === $this->isEasterDay($date)) { return false; } return true; }
protected function buildForm() { $request = $this->getRequest(); $productId = $request->get("product_id"); $productData = ProductDelayQuery::create()->filterByProductId($productId)->findOneOrCreate(); if (null !== $productId) { $data["delivery_min"] = $productData->getDeliveryDelayMin(); $data["delivery_max"] = $productData->getDeliveryDelayMax(); $data["restock_min"] = $productData->getRestockDelayMin(); $data["restock_max"] = $productData->getRestockDelayMax(); $data["delivery_date_start"] = $productData->getDeliveryDateStart(); $data["delivery_type"] = $productData->getDeliveryType(); } else { $data["delivery_min"] = DeliveryDelay::getConfigValue("delivery_min"); $data["delivery_max"] = DeliveryDelay::getConfigValue("delivery_max"); $data["restock_min"] = DeliveryDelay::getConfigValue("restock_min"); $data["restock_max"] = DeliveryDelay::getConfigValue("restock_max"); $data["delivery_date_start"] = null; $data["delivery_type"] = null; } $this->formBuilder->add("delivery_min", "text", array('data' => $data["delivery_min"], 'label' => Translator::getInstance()->trans("Minimum delivery delay (days)", array(), DeliveryDelay::DOMAIN_NAME), 'label_attr' => array("for" => "delivery_min")))->add("delivery_max", "text", array('data' => $data["delivery_max"], 'label' => Translator::getInstance()->trans("Maximum delivery delay (days)", array(), DeliveryDelay::DOMAIN_NAME), 'label_attr' => array("for" => "delivery_max")))->add("restock_min", "text", array('data' => $data["restock_min"], 'label' => Translator::getInstance()->trans("Minimum restock delay (days)", array(), DeliveryDelay::DOMAIN_NAME), 'label_attr' => array("for" => "restock_min")))->add("restock_max", "text", array('data' => $data["restock_max"], 'label' => Translator::getInstance()->trans("Maximum restock delay (days)", array(), DeliveryDelay::DOMAIN_NAME), 'label_attr' => array("for" => "restock_max")))->add("exclude_weekend", "text", array('label' => Translator::getInstance()->trans("Exclude weekend from delay count", array(), DeliveryDelay::DOMAIN_NAME), 'data' => DeliveryDelay::getConfigValue("exclude_weekend"), 'label_attr' => array("for" => "exclude_weekend")))->add("exclude_easter_day", "text", array('label' => Translator::getInstance()->trans("Exclude easter day from delay count", array(), DeliveryDelay::DOMAIN_NAME), 'data' => DeliveryDelay::getConfigValue("exclude_easter_day"), 'label_attr' => array("for" => "exclude_easter_day")))->add("exclude_easter_day_based_holidays", "text", array('label' => Translator::getInstance()->trans("Exclude holidays based on easter day date", array(), DeliveryDelay::DOMAIN_NAME), 'data' => DeliveryDelay::getConfigValue("exclude_easter_day_based_holidays"), 'label_attr' => array("for" => "exclude_easter_day_based_holidays")))->add("delivery_date_start", "text", array('label' => Translator::getInstance()->trans("This product is only available from", array(), DeliveryDelay::DOMAIN_NAME), 'data' => $data['delivery_date_start'], 'label_attr' => array("for" => "delivery_date_start")))->add("delivery_type", "text", array('label' => Translator::getInstance()->trans("Type of delivery", array(), DeliveryDelay::DOMAIN_NAME), 'data' => $data["delivery_type"], 'label_attr' => array("for" => "delivery_type"))); }
public function getDefaultValue() { $this->setDeliveryDelayMin(DeliveryDelay::getConfigValue("delivery_min", 1))->setDeliveryDelayMax(DeliveryDelay::getConfigValue("delivery_min", 1))->setRestockDelayMin(DeliveryDelay::getConfigValue("restock_min", 1))->setRestockDelayMax(DeliveryDelay::getConfigValue("restock_max", 1))->setDeliveryDateStart(null)->setDeliveryType(null); return $this; }