SELECT p.product_id,p.quantity_sklad,p.viewed ,p.is_price AS isr_available,p.quantity AS quantity
           
        
         FROM oc_category_path cp LEFT JOIN oc_product_to_category p2c ON (cp.category_id = p2c.category_id) LEFT JOIN oc_product p ON (p2c.product_id = p.product_id) LEFT JOIN (
                        SELECT ps.product_id, MIN(ps.price) AS special_price
                        FROM oc_product_special ps
                        WHERE ps.customer_group_id = '1'
                        AND (ps.date_start = '0000-00-00' OR ps.date_start < NOW())
                        AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())
                        GROUP BY ps.product_id
                 ) AS pspec ON p.product_id = pspec.product_id
               LEFT JOIN (
                                SELECT r1.product_id, AVG(r1.rating) AS avg_rating
                                FROM oc_review r1
                                WHERE r1.status = '1'
                                GROUP BY r1.product_id
                            ) AS r ON p.product_id = r.product_id     LEFT JOIN (
                                SELECT pd2.product_id, MIN(pd2.price) AS discount_price
                                FROM oc_product_discount pd2
                                WHERE pd2.customer_group_id = '1' AND pd2.quantity = '1' 
                                AND (pd2.date_start = '0000-00-00' OR pd2.date_start < NOW())
                                AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())
                                GROUP BY pd2.product_id
                            ) AS pdisc ON p.product_id = pdisc.product_id  LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) LEFT JOIN oc_product_to_store p2s ON (p.product_id = p2s.product_id)  WHERE pd.language_id = '2' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '0'AND (  
         
           -- ( SELECT COALESCE(SUM(`quantity`), 0)  FROM `isr_store_stock` issWHERE iss.`code` = p.`ean` AND iss.isradon_store_id > 0)   > 0 OR 
           -- (SELECT COALESCE(SUM(`quantity`), 0) FROM `isr_store_stock` iss	WHERE iss.`code` = p.`ean` AND iss.isradon_store_id = 0)  > 0 
            p.quantity_sklad >0   
            OR  p.quantity > 0  
            OR  p.is_price = 1
			 -- OR  p.ean IN (SELECT code FROM view_product_availability)  
			)  AND cp.path_id = '497' GROUP BY p.product_id ORDER BY p.rating DESC, p.quantity_sklad DESC LIMIT 0,100