*/ class EditPrices extends BaseAdminController { /** * Redirect to the configuration page */ protected function redirectToConfigurationPage() { return RedirectResponse::create(URL::getInstance()->absoluteUrl('/admin/module/DHL')); } public function editprices() { // Get data & treat $post = $this->getRequest(); $operation = $post->get('operation'); $area = $post->get('area'); $module_id = $post->get('module_id'); $weight = $post->get('weight'); $price = $post->get('price'); $price_id = $post->get('price_id'); $con = Propel::getServiceContainer()->getReadConnection(DHLDeliveryPriceTableMap::DATABASE_NAME); switch ($operation) { case "add" : $this->createAction($con, $module_id, $area, $weight, $price); break; case "update" : $this->updateAction($con, $module_id, $price_id, $price); break; case "delete" : $this->deleteAction($con, $module_id, $price_id); break; } return $this->redirectToConfigurationPage(); } public function updateAction(ConnectionInterface $con, $moduleId, $priceId, $price) { if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'DHL', AccessManager::UPDATE)) { return $response; } $errorMessage = false; try { DHLDeliveryPriceQuery::create()->filterById($priceId) ->update(['PriceWithTax' => $price], $con); } catch (\Exception $ex) { $errorMessage = $ex->getMessage(); Tlog::getInstance()->error("Failed to update price : $errorMessage"); } return $this->render('module_configuration', [ 'module_id' => $moduleId, 'error_message' => $errorMessage ]); } public function createAction(ConnectionInterface $con, $moduleId, $areaId, $weight, $price) { if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'DHL', AccessManager::UPDATE)) { return $response; } $errorMessage = false; try { (new DHLDeliveryPrice()) ->setAreaId($areaId) ->setPriceWithTax($price) ->setMaxWeight($weight) ->save(); } catch (\Exception $ex) { $errorMessage = $ex->getMessage(); Tlog::getInstance()->error("Failed to add price : $errorMessage"); } return $this->render('module_configuration', [ 'module_id' => $moduleId, 'error_message' => $errorMessage ]); } public function deleteAction(ConnectionInterface $con, $moduleId, $priceId) { if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'DHL', AccessManager::DELETE)) { return $response; } DHLDeliveryPriceQuery::create()->filterById($priceId)->delete(); return $this->render('module_configuration', [ 'module_id' => $moduleId ]); } }