[eluser]shobekhan[/eluser]
<?php
class Shopmodel extends Model {
function Shopmodel()
{
// Call the Model constructor
parent::Model();
}
function getProducts($productid = 0, $folderid = 0)
{
$sql = "SELECT products.id as productid, folders.id as folderid, folders.name as foldername,
manufacturer.id as manufacturerid, manufacturer.name as manufacturername,
fk_modelid as modelid, model.name as modelname, product_number, imageurl,
price, company_price, products.name, products.short_description, products.description, suggested_retail,
compatibility, substitute1, substitute2,
CONCAT( created.firstname, ' ', created.lastname ) createdby, UNIX_TIMESTAMP( products.createdon ) createdon, CONCAT( modified.firstname, ' ', modified.lastname ) modifiedby, UNIX_TIMESTAMP( products.modifiedon ) modifiedon,
products.isactive, products.isdeleted, products.orderid, products.stock
FROM t_products as products
INNER JOIN t_folders folders ON products.fk_folderid = folders.id
LEFT JOIN t_manufacturer manufacturer ON products.fk_manufacturerid = manufacturer.id
LEFT JOIN t_model model ON products.fk_modelid = model.id
LEFT JOIN t_users created ON created.id = products.createdby
LEFT JOIN t_users modified ON modified.id = products.modifiedby
WHERE products.isdeleted =0
";
if($productid!=0)
$sql .= " AND products.id = " . $productid;
if($folderid!=0)
$sql .= " AND folders.id = " . $folderid;
$sql .= " ORDER BY products.orderid, products.name";
$query = $this->db->query($sql);
$data = array();
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$data[$row['productid']]['productid'] = $row['productid'];
$data[$row['productid']]['folderid'] = $row['folderid'];
$data[$row['productid']]['foldername'] = $row['foldername'];
$data[$row['productid']]['manufacturerid'] = $row['manufacturerid'];
$data[$row['productid']]['manufacturername'] = $row['manufacturername'];
$data[$row['productid']]['modelid'] = $row['modelid'];
$data[$row['productid']]['modelname'] = $row['modelname'];
$data[$row['productid']]['product_number'] = $row['product_number'];
$data[$row['productid']]['imageurl'] = $row['imageurl'];
$data[$row['productid']]['price'] = $row['price'];
$data[$row['productid']]['company_price'] = $row['company_price'];
$data[$row['productid']]['product_name'] = $row['name'];
$data[$row['productid']]['short_description'] = $row['short_description'];
$data[$row['productid']]['description'] = $row['description'];
$data[$row['productid']]['suggested_retail'] = $row['suggested_retail'];
$data[$row['productid']]['compatibility'] = $row['compatibility'];
$data[$row['productid']]['substitute1'] = $row['substitute1'];
$data[$row['productid']]['substitute2'] = $row['substitute2'];
$data[$row['productid']]['createdon'] = $row['createdon'];
$data[$row['productid']]['modifiedon'] = $row['modifiedon'];
$data[$row['productid']]['modifiedby'] = $row['modifiedby'];
$data[$row['productid']]['createdon'] = $row['createdon'];
$data[$row['productid']]['createdby'] = $row['createdby'];
$data[$row['productid']]['isactive'] = $row['isactive'];
$data[$row['productid']]['orderid'] = $row['orderid'];
$data[$row['productid']]['stock'] = $row['stock'];
}
}
return $data;
}
}
?>