Guest User

Untitled

a guest
Jun 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. SELECT
  2. sptp.id AS timeline_id, sptp.product_id AS product_id,
  3. sptp.time_begin AS time_begin, sptp.time_expire AS time_expire,
  4. cpev.value AS product_name, cpe.type_id AS product_type,
  5. COUNT(sfoi.item_id) AS order_count, SUM(sfoi.price) AS price_pretax,
  6. -- SUM(sfoi.price) + SUM(sfoi.tax_invoiced) AS price_tax,
  7. -- SUM(sfoi.price) + SUM(sfoi.tax_invoiced) - SUM(sfoi.discount_invoiced) AS price_discount
  8. SUM(sfoi.price) + SUM(sfoi.tax_amount) AS price_tax,
  9. SUM(sfoi.price) + SUM(sfoi.tax_amount) - SUM(sfoi.discount_amount) AS price_discount
  10. FROM sptimelineproduct AS sptp
  11. INNER JOIN catalog_product_entity AS cpe
  12. ON cpe.entity_id = sptp.product_id
  13. INNER JOIN catalog_product_entity_varchar AS cpev
  14. ON cpev.entity_id = sptp.product_id
  15. INNER JOIN eav_attribute AS ea1
  16. ON ea1.attribute_id = cpev.attribute_id
  17. AND ea1.attribute_code = 'name'
  18. INNER JOIN eav_entity_type AS eet1
  19. ON eet1.entity_type_id = ea1.entity_type_id
  20. AND eet1.entity_type_code = 'catalog_product'
  21. LEFT JOIN catalog_product_link AS cpl
  22. ON cpl.product_id = sptp.product_id
  23. LEFT JOIN sales_flat_order_item AS sfoi
  24. ON sfoi.product_id = IF(cpe.type_id = 'grouped', cpl.linked_product_id, sptp.product_id)
  25. AND sfoi.created_at >= sptp.time_begin - INTERVAL 1 HOUR
  26. AND sfoi.created_at <= sptp.time_expire + INTERVAL 1 HOUR
  27. WHERE (
  28. SELECT soi1.value
  29. FROM sales_order_int AS soi1
  30. INNER JOIN eav_attribute AS ea2
  31. ON ea2.attribute_id = soi1.attribute_id
  32. AND ea2.attribute_code = 'cancel_flag'
  33. INNER JOIN eav_entity_type AS eet2
  34. ON eet2.entity_type_id = ea2.entity_type_id
  35. AND eet2.entity_type_code = 'order'
  36. WHERE soi1.entity_id = sfoi.order_id
  37. AND soi1.value = 1
  38. ) IS NULL
  39. AND (
  40. (SELECT soev.value
  41. FROM sales_order_entity_varchar AS soev
  42. INNER JOIN eav_attribute AS ea3
  43. ON ea3.attribute_id = soev.attribute_id
  44. AND ea3.attribute_code = 'method'
  45. INNER JOIN eav_entity_type AS eet3
  46. ON eet3.entity_type_id = ea3.entity_type_id
  47. AND eet3.entity_type_code = 'order_payment'
  48. INNER JOIN sales_order_entity AS soe
  49. ON soe.entity_id = soev.entity_id
  50. WHERE soe.parent_id = sfoi.order_id
  51. LIMIT 1
  52. ) = 'checkmo'
  53. AND (
  54. SELECT soi2.value
  55. FROM sales_order_int AS soi2
  56. INNER JOIN eav_attribute AS ea4
  57. ON ea4.attribute_id = soi2.attribute_id
  58. AND ea4.attribute_code = 'invoice_flag'
  59. INNER JOIN eav_entity_type AS eet4
  60. ON eet4.entity_type_id = ea4.entity_type_id
  61. AND eet4.entity_type_code = 'order'
  62. WHERE soi2.entity_id = sfoi.order_id
  63. LIMIT 1
  64. ) = 0
  65. ) IS FALSE
  66. GROUP BY sptp.id
Add Comment
Please, Sign In to add comment