 SELECT p.id ,  trim( LEFT(p.fname,500))  as 'title' ,   trim(IFNULL( LEFT(p.flatiName,500)     , ''))    as 'subtitle',
    p.id as 'page_unique', v.fgarantidesc   as  guarantee ,
        RETURN_PRODUCT_PRICEUNIT(v.id, v.fis_amazing) AS current_price,
     v.fprice as 'old_price' ,  (CASE IFNULL(v.fManage_stock_quantity, 0)
               WHEN 0 THEN "instock"
               ELSE (    CASE (SELECT RETURNSTOCK_QUANTITY(p.id, v.fstock_quantity)  )
               WHEN 0 THEN "outofstock"
               ELSE "instock"
           END)
           END) AS availability ,  (CASE IFNULL(p.fidCateg, 0)
               WHEN 0 THEN 'بدون دسته بندی'
               ELSE (SELECT
                       IFNULL(postscatag.fname, '') AS b
                   FROM
                       postscatag
                   WHERE
                       ((postscatag.id = p.fidCateg)
                           AND (postscatag.factive = 1)))
           END)  as 'category_name' ,  fimages    as "image_link" ,   ""    as "image_links" ,
           furl as  'page_url' ,    LEFT(p.fdesc,1000)   as  'short_desc'  ,  "" as  'spec'
     FROM  products as p inner join products_varients as v on p.id = v.fidproduct
      where  v.fprice> 0  and  IFNULL(p.fhidden, 0) = 0   and  p.fdefult_variabels = v.id  and p.fdeleted= 0 and v.fdeleted = 0
      and p.factive = 1 and v.factive = 1