Esempio n. 1
0
 public function products()
 {
     $product_id = null;
     $fourth = null;
     $variant_id = null;
     if ($this->uri->segment(3) !== false) {
         $product_id = $this->uri->segment(3);
     }
     if ($this->uri->segment(4) !== false) {
         $fourth = $this->uri->segment(4);
     }
     if ($this->uri->segment(5) !== false) {
         $variant_id = $this->uri->segment(5);
     }
     //request/products
     if (is_null($product_id)) {
         $response = Thing::getProducts();
     } else {
         if (!is_null($product_id) && is_null($fourth)) {
             $response = Thing::getProducts($product_id);
         } else {
             if (!is_null($fourth) && is_null($variant_id)) {
                 $response = Thing::getVariants($product_id);
             } else {
                 if (!is_null($fourth) && !is_null($variant_id)) {
                     $response = Thing::getVariants($product_id, $variant_id);
                 }
             }
         }
     }
     //encode json
     $responseProd = array();
     foreach ($response as $rsp) {
         $responseProd[] = $rsp->toJson();
     }
     echo json_encode($responseProd, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT);
 }