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 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)); } }
protected function buildForm() { $this->formBuilder->add("enabled", "checkbox", array("label" => "Enabled", "label_attr" => ["for" => "enabled", "help" => Translator::getInstance()->trans('Check if you want to activate Colissimo', [], Colissimo::DOMAIN_NAME)], "required" => false, "constraints" => array(), "value" => Colissimo::getConfigValue(ColissimoConfigValue::ENABLED, 1))); }
/** * * in this function you add all the fields you need for your Form. * Form this you have to call add method on $this->formBuilder attribute : * * $this->formBuilder->add("name", "text") * ->add("email", "email", array( * "attr" => array( * "class" => "field" * ), * "label" => "email", * "constraints" => array( * new \Symfony\Component\Validator\Constraints\NotBlank() * ) * ) * ) * ->add('age', 'integer'); * * @return null */ protected function buildForm() { $this->formBuilder->add("freeshipping", "checkbox", array("label" => Translator::getInstance()->trans("Activate free shipping: ", [], Colissimo::DOMAIN_NAME), "value" => Colissimo::getConfigValue(ColissimoConfigValue::FREE_SHIPPING, false))); }
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)); } }