'', 'category_ids' => '', 'product_ids' => '', 'discount_code' => '', 'discount_type' => 1, 'discount_value' => 0, 'start_date' => date('Y-m-d\TH:i'), 'end_date' => date('Y-m-d\TH:i', strtotime('+1 month', strtotime(date('Y-m-d\TH:i')))), 'categories' => [], 'products' => [] ]; //GET ALL CATEGORIES $api_url = '/v2/categories/'; $categories = ioServer($api_url,''); //Decode Payload if (!empty($categories)){$categories = json_decode($categories,true);}else{$categories = null;} //GET PRODUCTS $api_url = '/v2/products/list='; $products = ioServer($api_url,''); //Decode Payload if (!empty($products)){$products = json_decode($products,true);}else{$products = null;} if (isset($_GET['id'])) { //CALL TO API FOR DISCOUNT $api_url = '/v2/discounts/id='.$_GET['id']; $discount = ioServer($api_url,''); //Decode Payload if (!empty($discount)){$discount = json_decode($discount,true);}else{$discount = null;} $discount = $discount[0]; //GET CATEGORY NAMES RELATED TO DISCOUNT discount_category_id $api_url = '/v2/discounts/discount_category_id='.$_GET['id']; $discount_cat = ioServer($api_url,''); //Decode Payload if (!empty($discount_cat)){$discount['categories'] = json_decode($discount_cat,true);}else{$discount['categories']= null;} //GET CATEGORY NAMES RELATED TO DISCOUNT discount_products_id $api_url = '/v2/discounts/discount_products_id='.$_GET['id']; $discount_prod = ioServer($api_url,''); //Decode Payload if (!empty($discount_prod)){$discount['products'] = json_decode($discount_prod,true);}else{$discount['products']= null;} if (isset($_POST['submit'])) { //Update the discount //GET ALL POST DATA $payload = json_encode($_POST, JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/discounts', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=discounts&success_msg=2'); exit; } } if (isset($_POST['delete'])) { //GET ALL POST DATA $payload = json_encode($_POST, JSON_UNESCAPED_UNICODE); var_dump($payload); //API call $responses = ioServer('/v2/discounts', $payload); if ($responses === 'NOK'){ } else { //Redirect and delete product header('Location: index.php?page=discounts&success_msg=3'); exit; } } } else { // Create a new discount $page = 'Create'; if (isset($_POST['submit'])) { //GET ALL POST DATA $payload = json_encode($_POST , JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/discounts', $payload); if ($responses === 'NOK'){ // DO nothing } else { header('Location: index.php?page=discounts&success_msg=1'); exit; } } } template_header('discount', 'discounts', 'manage'); $view ='
'; //Output echo $view; template_footer(); ?>