33namespace GoogleShoppingXml \Service \Provider ;
44
55use Propel \Runtime \Propel ;
6+ use Thelia \Model \Map \ProductSaleElementsTableMap ;
7+ use Thelia \Model \ProductSaleElementsQuery ;
68use Thelia \Tools \URL ;
79
810class SQLQueryService
911{
1012 /**
1113 * @param string $locale
1214 */
13- public function getPses (string $ locale )
15+ public function getPsesWithSqlOptimisation (string $ locale )
1416 {
1517 $ baseUrl = URL ::getInstance ()->absoluteUrl ('/ ' );
1618
@@ -30,9 +32,9 @@ public function getPses(string $locale)
3032 ), attribute_title AS (
3133 SELECT ac.product_sale_elements_id AS id, GROUP_CONCAT(DISTINCT avi.title ORDER BY a.id SEPARATOR " - ") AS title
3234 from attribute_combination AS ac
33- JOIN attribute a ON a.id = ac.attribute_id
34- JOIN attribute_av av ON ac.attribute_av_id = av.id
35- JOIN attribute_av_i18n avi ON av.id = avi.id
35+ LEFT JOIN attribute a ON a.id = ac.attribute_id
36+ LEFT JOIN attribute_av av ON ac.attribute_av_id = av.id
37+ LEFT JOIN attribute_av_i18n avi ON av.id = avi.id
3638 WHERE avi.locale=:p1
3739 GROUP BY ac.product_sale_elements_id
3840
@@ -52,7 +54,8 @@ public function getPses(string $locale)
5254
5355 SELECT
5456 pse.id AS "id",
55- CONCAT(pi.title," - ", attrib.title) AS "title",
57+ pi.title AS "product_title",
58+ attrib.title AS "attrib_title",
5659 pi.description AS "description",
5760 IF(pse.quantity>0, "in stock", "out of stock") AS "availability",
5861 CONCAT(@BASEURL := " ' . $ baseUrl . '",rurl.url) AS "link",
@@ -69,19 +72,19 @@ public function getPses(string $locale)
6972
7073 FROM `product_sale_elements`AS pse
7174
72- JOIN product AS p ON pse.product_id = p.id
73- JOIN product_i18n AS pi ON p.id = pi.id
74- JOIN attribute_title AS attrib ON attrib.id = pse.id
75- JOIN rewriting_url AS rurl ON rurl.view = "product" AND rurl.view_id = p.id
76- JOIN product_price AS pp ON pp.product_sale_elements_id = pse.id
77- JOIN brand AS b ON b.id = p.brand_id
78- JOIN brand_i18n AS bi ON b.id = bi.id
79- JOIN product_category AS pc ON pc.product_id=p.id AND pc.default_category=1
80- JOIN product_images_query AS pimgs ON pimgs.pid=p.id
75+ LEFT JOIN product AS p ON pse.product_id = p.id
76+ LEFT JOIN product_i18n AS pi ON p.id = pi.id
77+ LEFT JOIN attribute_title AS attrib ON attrib.id = pse.id
78+ LEFT JOIN rewriting_url AS rurl ON rurl.view = "product" AND rurl.view_id = p.id
79+ LEFT JOIN product_price AS pp ON pp.product_sale_elements_id = pse.id
80+ LEFT JOIN brand AS b ON b.id = p.brand_id
81+ LEFT JOIN brand_i18n AS bi ON b.id = bi.id
82+ LEFT JOIN product_category AS pc ON pc.product_id=p.id AND pc.default_category=1
83+ LEFT JOIN product_images_query AS pimgs ON pimgs.pid=p.id
8184 LEFT JOIN pse_images_query AS pseimgs ON pseimgs.pseid=pse.id
82- JOIN category AS c ON c.id=pc.category_id
83- JOIN googleshoppingxml_taxonomy AS gt ON gt.thelia_category_id = c.id
84- JOIN category_path cp ON cp.id = pc.category_id
85+ LEFT JOIN category AS c ON c.id=pc.category_id
86+ LEFT JOIN googleshoppingxml_taxonomy AS gt ON gt.thelia_category_id = c.id
87+ LEFT JOIN category_path cp ON cp.id = pc.category_id
8588
8689 WHERE
8790
@@ -110,4 +113,69 @@ public function getPses(string $locale)
110113
111114 return $ stmt ;
112115 }
116+
117+ public function getPses (string $ locale )
118+ {
119+ $ baseUrl = URL ::getInstance ()->absoluteUrl ('/ ' );
120+
121+ $ sql = '
122+ SELECT
123+ pse.id AS "id",
124+ pi.title AS "product_title",
125+ GROUP_CONCAT(DISTINCT avi.title ORDER BY a.id SEPARATOR " - ") AS "attrib_title",
126+ pi.description AS "description",
127+ IF(pse.quantity>0, "in stock", "out of stock") AS "availability",
128+ CONCAT(@BASEURL := " ' . $ baseUrl . '",rurl.url) AS "link",
129+ IF(pse.promo=1, pp.promo_price, pp.price) AS "price",
130+ bi.title AS "brand",
131+ IF(pse.ean_code!="", "yes", "no") AS "identifier_exists",
132+ pse.ean_code AS "gtin",
133+ p.ref AS "item_group_id",
134+ gt.google_category AS "google_product_category",
135+ "new" AS "condition",
136+ p.tax_rule_id AS "TAX_RULE_ID",
137+ c.id AS "default_category_id"
138+
139+ FROM `product_sale_elements`AS pse
140+
141+ LEFT JOIN product AS p ON pse.product_id = p.id
142+ LEFT JOIN product_i18n AS pi ON p.id = pi.id
143+ LEFT JOIN attribute_combination AS ac ON ac.product_sale_elements_id = pse.id
144+ LEFT JOIN attribute AS a ON a.id = ac.attribute_id
145+ LEFT JOIN attribute_av AS av ON ac.attribute_av_id = av.id
146+ LEFT JOIN attribute_av_i18n AS avi ON av.id = avi.id
147+ LEFT JOIN rewriting_url AS rurl ON rurl.view = "product" AND rurl.view_id = p.id
148+ LEFT JOIN product_price AS pp ON pp.product_sale_elements_id = pse.id
149+ LEFT JOIN brand AS b ON b.id = p.brand_id
150+ LEFT JOIN brand_i18n AS bi ON b.id = bi.id
151+ LEFT JOIN product_category AS pc ON pc.product_id=p.id AND pc.default_category=1
152+ LEFT JOIN category AS c ON c.id=pc.category_id
153+ LEFT JOIN googleshoppingxml_taxonomy AS gt ON gt.thelia_category_id = c.id
154+
155+ WHERE
156+
157+ pi.locale=:p2
158+ AND rurl.view_locale=:p3
159+ AND bi.locale=:p4
160+ AND p.visible=1
161+ AND pi.title!=""
162+ AND pi.description!=""
163+
164+ GROUP BY pse.id ' ;
165+
166+ $ con = Propel::getConnection ();
167+
168+ /** @var PDOStatement $stmt */
169+ $ stmt = $ con ->prepare ($ sql );
170+
171+ //$stmt->bindValue(':p1', $locale);
172+ $ stmt ->bindValue (':p2 ' , $ locale );
173+ $ stmt ->bindValue (':p3 ' , $ locale );
174+ $ stmt ->bindValue (':p4 ' , $ locale );
175+
176+ $ stmt ->execute ();
177+
178+ return $ stmt ;
179+
180+ }
113181}
0 commit comments