$productData = findAllProducts($query, '');
        }
        $supplierData = array();
        $query2 = $db->suppliers();
        foreach ($query2 as $p) {
            $supplierData[] = findSupplierDetails($query2);
        }
        $data = array_merge($supplierData, $productData);
        $app->response()->header('content-type', 'application/json');
        echo json_encode(array('supplier_details' => $supplierData, 'supplier_products' => $productData));
    }
});
// For finding usages of given type say tiles or marbles
$app->get('/shiningfloor/products(/:type)/usages', function ($type) use($app, $db) {
    $usages_area;
    $type_id = $db->types()->where('type_name', $type)->select('id')->fetch();
    // $query = $db->products->where('type_id',$type_id);
    $query = $db->products_usages()->where('type_id', $type_id);
    foreach ($query as $p) {
        $usages_area[] = $p->usages['usage_name'];
    }
    $app->response()->header('content-type', 'application/json');
    echo json_encode(array('products_name' => $type, 'locations' => $usages_area));
    // echo json_encode($_GET['sortkey']);
});
// --------------------------------------
$app->get('/shiningfloor/chooseproducts(/:id)', function ($id = null) use($app, $db) {
    $data = array();
    //$query = $db->products();
    global $colorFilters, $priceFilters, $brandFilters;
    global $resultPerPage, $pageNo;
Exemple #2
0
    if ($id != null) {
        $query = $db->products()->where('id', $id);
        $data = findAllProducts($query, '');
        $app->response()->header('content-type', 'application/json');
        echo json_encode(array('product_data' => $data));
    }
});
// Search product results
$app->get('/shiningfloor/products/search(/:type)/(:input)', function ($type = null, $input = null) use($app, $db) {
    global $resultPerPage, $pageNo;
    if (isset($_GET['pageNo'])) {
        $pageNo = $_GET['pageNo'];
    }
    findAllFilters();
    $data = array();
    $type_id = $db->types()->where('type_name', $type)->select('id');
    $query = '';
    if ($type == null or $type == 'all') {
        $query = $db->products();
    } else {
        $query = $db->products->where('type_id', $type_id);
    }
    if ($input != null) {
        $query = $query->where('product_name LIKE ?', "%" . $input . "%");
    }
    $query = setFinalFilterQuery($query);
    $totalResults = count($query);
    $start = ($pageNo - 1) * (int) $resultPerPage;
    $last = $start + $resultPerPage;
    if ($last > $totalResults) {
        $last = $totalResults;