public function editprices() { // Get data & treat $post = $this->getRequest(); $operation = $post->get('operation'); $area = $post->get('area'); $weight = $post->get('weight'); $price = $post->get('price'); if (preg_match("#^add|delete\$#", $operation) && preg_match("#^\\d+\$#", $area) && preg_match("#^\\d+\\.?\\d*\$#", $weight)) { // check if area exists in db $exists = AreaQuery::create()->findPK($area); if ($exists !== null) { if (null !== ($data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null))) { $json_data = json_decode($data, true); } if ((double) $weight > 0 && $operation == "add" && preg_match("#\\d+\\.?\\d*#", $price)) { $json_data[$area]['slices'][$weight] = $price; } elseif ($operation == "delete") { if (isset($json_data[$area]['slices'][$weight])) { unset($json_data[$area]['slices'][$weight]); } } else { throw new \Exception("Weight must be superior to 0"); } ksort($json_data[$area]['slices']); Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data)); } else { throw new \Exception("Area not found"); } } else { throw new \ErrorException("Arguments are missing or invalid"); } return $this->redirectToConfigurationPage(); }
/** * @param AreaDeleteEvent $event */ public function updateConfig(AreaDeleteEvent $event) { if (null !== ($data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null))) { $areaId = $event->getAreaId(); $json_data = json_decode($data, true); unset($json_data[$areaId]); Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data, true)); } }
public function set() { $response = $this->checkAuth(AdminResources::MODULE, [Colissimo::DOMAIN_NAME], AccessManager::UPDATE); if (null !== $response) { return $response; } $form = $this->createForm('colissimo.freeshipping.form'); try { $validateForm = $this->validateForm($form); $data = $validateForm->getData(); Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, (int) $data["freeshipping"]); return $this->redirectToConfigurationPage(); } catch (\Exception $e) { $response = JsonResponse::create(array("error" => $e->getMessage()), 500); } return $response; }
public function editConfiguration() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, [Colissimo::DOMAIN_NAME], AccessManager::UPDATE))) { return $response; } $form = $this->createForm('colissimo.configuration'); $error_message = null; try { $validateForm = $this->validateForm($form); $data = $validateForm->getData(); Colissimo::setConfigValue(ColissimoConfigValue::ENABLED, is_bool($data["enabled"]) ? (int) $data["enabled"] : $data["enabled"]); return $this->redirectToConfigurationPage(); } catch (FormValidationException $e) { $error_message = $this->createStandardFormValidationErrorMessage($e); } if (null !== $error_message) { $this->setupFormErrorContext('configuration', $error_message, $form); $response = $this->render("module-configure", ['module_code' => 'Colissimo']); } return $response; }
public function update($currentVersion, $newVersion, ConnectionInterface $con = null) { $uploadDir = __DIR__ . '/Config/prices.json'; $database = new Database($con); $table_exists = $database->execute("SELECT COUNT(*)\n FROM information_schema.tables\n WHERE table_schema = 'thelia'\n AND table_name = 'colissimo_freeshipping'")->fetch()["COUNT(*)"] ? true : false; if (Colissimo::getConfigValue(ColissimoConfigValue::FREE_SHIPPING, null) == null && $table_exists) { $result = $database->execute('SELECT active FROM colissimo_freeshipping WHERE id=1')->fetch()["active"]; Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, $result); } if (is_readable($uploadDir) && Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null) == null) { Colissimo::setConfigValue(ColissimoConfigValue::PRICES, file_get_contents($uploadDir)); } }
public function update($currentVersion, $newVersion, ConnectionInterface $con = null) { $uploadDir = __DIR__ . '/Config/prices.json'; $database = new Database($con); $tableExists = $database->execute("SHOW TABLES LIKE 'colissimo_freeshipping'")->rowCount(); if (Colissimo::getConfigValue(ColissimoConfigValue::FREE_SHIPPING, null) == null && $tableExists) { $result = $database->execute('SELECT active FROM colissimo_freeshipping WHERE id=1')->fetch()["active"]; Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, $result); $database->execute("DROP TABLE `colissimo_freeshipping`"); } if (is_readable($uploadDir) && Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null) == null) { Colissimo::setConfigValue(ColissimoConfigValue::PRICES, file_get_contents($uploadDir)); } }