Kaynağa Gözat

fix view vsu_orders_car_prod_qty_img in class-db-assets-manager

Dalibor Votruba 1 yıl önce
ebeveyn
işleme
5b4d872643

+ 56 - 13
studiou-wc-ord-print-statuses/includes/class-db-assets-manager.php

@@ -14,27 +14,70 @@ class DB_Assets_Manager {
         global $wpdb;
 
         $sql = "CREATE OR REPLACE VIEW vsu_orders_car_prod_qty_img AS
-                SELECT 
+                SELECT
                     `orders`.`id` AS `order_no`,
                     `t`.`name` AS `prod_cat`,
                     `products`.`post_title` AS `prod_name`,
                     `product_variations`.`post_title` AS `prod_var`,
                     `images`.`guid` AS `prod_img_url`,
                     `order_products`.`product_qty` AS `qty`
-                FROM
-                    `{$wpdb->prefix}wc_orders` `orders`
-                    JOIN `{$wpdb->prefix}wc_order_product_lookup` `order_products` ON `orders`.`id` = `order_products`.`order_id`
-                    JOIN `{$wpdb->posts}` `products` ON `products`.`ID` = `order_products`.`product_id`
-                    JOIN `{$wpdb->posts}` `images` ON `images`.`post_parent` = `products`.`ID` AND `images`.`post_type` = 'attachment'
-                    JOIN `{$wpdb->posts}` `product_variations` ON `product_variations`.`ID` = `order_products`.`variation_id`
-                    JOIN `{$wpdb->term_relationships}` `tr` ON `products`.`ID` = `tr`.`object_id`
-                    JOIN `{$wpdb->term_taxonomy}` `tt` ON `tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`
-                    JOIN `{$wpdb->terms}` `t` ON `tt`.`term_id` = `t`.`term_id`
+                FROM (
+                        (
+                            (
+                                (
+                                    (
+                                        (
+                                            (
+                                                `{$wpdb->prefix}wc_orders` `orders`
+                                            JOIN `{$wpdb->prefix}wc_order_product_lookup` `order_products`
+                                            ON
+                                                (
+                                                    `orders`.`id` = `order_products`.`order_id`
+                                                )
+                                            )
+                                        JOIN `{$wpdb->posts}` `products`
+                                        ON
+                                            (
+                                                `products`.`ID` = `order_products`.`product_id`
+                                            )
+                                        )
+                                    JOIN `{$wpdb->posts}` `product_variations`
+                                    ON
+                                        (
+                                            `product_variations`.`ID` = `order_products`.`variation_id`
+                                        )
+                                    )
+                                LEFT JOIN `{$wpdb->postmeta}` `product_meta`
+                                ON
+                                    (
+                                        `product_meta`.`post_id` = `products`.`ID` AND `product_meta`.`meta_key` = '_thumbnail_id'
+                                    )
+                                )
+                            LEFT JOIN `{$wpdb->posts}` `images`
+                            ON
+                                (
+                                    `images`.`ID` = `product_meta`.`meta_value` AND `images`.`post_type` = 'attachment'
+                                )
+                            JOIN `{$wpdb->term_relationships}` `tr`
+                            ON
+                                (`products`.`ID` = `tr`.`object_id`)
+                            )
+                        JOIN `{$wpdb->term_taxonomy}` `tt`
+                        ON
+                            (
+                                `tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`
+                            )
+                        )
+                    JOIN `{$wpdb->terms}` `t`
+                    ON
+                        (`tt`.`term_id` = `t`.`term_id`)
+                    )
                 WHERE
-                    `orders`.`status` = 'wc-processing'
-                    AND `tt`.`taxonomy` = 'product_cat'
+                    `orders`.`status` = 'wc-processing' AND `tt`.`taxonomy` = 'product_cat'
                 ORDER BY
-                    `orders`.`id`";
+                    `orders`.`id`;";
+
+
 
         $wpdb->query($sql);
         UtilsLog::log('View created');