|
@@ -14,27 +14,70 @@ class DB_Assets_Manager {
|
|
|
global $wpdb;
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$sql = "CREATE OR REPLACE VIEW vsu_orders_car_prod_qty_img AS
|
|
$sql = "CREATE OR REPLACE VIEW vsu_orders_car_prod_qty_img AS
|
|
|
- SELECT
|
|
|
|
|
|
|
+ SELECT
|
|
|
`orders`.`id` AS `order_no`,
|
|
`orders`.`id` AS `order_no`,
|
|
|
`t`.`name` AS `prod_cat`,
|
|
`t`.`name` AS `prod_cat`,
|
|
|
`products`.`post_title` AS `prod_name`,
|
|
`products`.`post_title` AS `prod_name`,
|
|
|
`product_variations`.`post_title` AS `prod_var`,
|
|
`product_variations`.`post_title` AS `prod_var`,
|
|
|
`images`.`guid` AS `prod_img_url`,
|
|
`images`.`guid` AS `prod_img_url`,
|
|
|
`order_products`.`product_qty` AS `qty`
|
|
`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
|
|
WHERE
|
|
|
- `orders`.`status` = 'wc-processing'
|
|
|
|
|
- AND `tt`.`taxonomy` = 'product_cat'
|
|
|
|
|
|
|
+ `orders`.`status` = 'wc-processing' AND `tt`.`taxonomy` = 'product_cat'
|
|
|
ORDER BY
|
|
ORDER BY
|
|
|
- `orders`.`id`";
|
|
|
|
|
|
|
+ `orders`.`id`;";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
$wpdb->query($sql);
|
|
$wpdb->query($sql);
|
|
|
UtilsLog::log('View created');
|
|
UtilsLog::log('View created');
|