Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- sptp.id AS timeline_id, sptp.product_id AS product_id,
- sptp.time_begin AS time_begin, sptp.time_expire AS time_expire,
- cpev.value AS product_name, cpe.type_id AS product_type,
- COUNT(sfoi.item_id) AS order_count, SUM(sfoi.price) AS price_pretax,
- -- SUM(sfoi.price) + SUM(sfoi.tax_invoiced) AS price_tax,
- -- SUM(sfoi.price) + SUM(sfoi.tax_invoiced) - SUM(sfoi.discount_invoiced) AS price_discount
- SUM(sfoi.price) + SUM(sfoi.tax_amount) AS price_tax,
- SUM(sfoi.price) + SUM(sfoi.tax_amount) - SUM(sfoi.discount_amount) AS price_discount
- FROM sptimelineproduct AS sptp
- INNER JOIN catalog_product_entity AS cpe
- ON cpe.entity_id = sptp.product_id
- INNER JOIN catalog_product_entity_varchar AS cpev
- ON cpev.entity_id = sptp.product_id
- INNER JOIN eav_attribute AS ea1
- ON ea1.attribute_id = cpev.attribute_id
- AND ea1.attribute_code = 'name'
- INNER JOIN eav_entity_type AS eet1
- ON eet1.entity_type_id = ea1.entity_type_id
- AND eet1.entity_type_code = 'catalog_product'
- LEFT JOIN catalog_product_link AS cpl
- ON cpl.product_id = sptp.product_id
- LEFT JOIN sales_flat_order_item AS sfoi
- ON sfoi.product_id = IF(cpe.type_id = 'grouped', cpl.linked_product_id, sptp.product_id)
- AND sfoi.created_at >= sptp.time_begin - INTERVAL 1 HOUR
- AND sfoi.created_at <= sptp.time_expire + INTERVAL 1 HOUR
- WHERE (
- SELECT soi1.value
- FROM sales_order_int AS soi1
- INNER JOIN eav_attribute AS ea2
- ON ea2.attribute_id = soi1.attribute_id
- AND ea2.attribute_code = 'cancel_flag'
- INNER JOIN eav_entity_type AS eet2
- ON eet2.entity_type_id = ea2.entity_type_id
- AND eet2.entity_type_code = 'order'
- WHERE soi1.entity_id = sfoi.order_id
- AND soi1.value = 1
- ) IS NULL
- AND (
- (SELECT soev.value
- FROM sales_order_entity_varchar AS soev
- INNER JOIN eav_attribute AS ea3
- ON ea3.attribute_id = soev.attribute_id
- AND ea3.attribute_code = 'method'
- INNER JOIN eav_entity_type AS eet3
- ON eet3.entity_type_id = ea3.entity_type_id
- AND eet3.entity_type_code = 'order_payment'
- INNER JOIN sales_order_entity AS soe
- ON soe.entity_id = soev.entity_id
- WHERE soe.parent_id = sfoi.order_id
- LIMIT 1
- ) = 'checkmo'
- AND (
- SELECT soi2.value
- FROM sales_order_int AS soi2
- INNER JOIN eav_attribute AS ea4
- ON ea4.attribute_id = soi2.attribute_id
- AND ea4.attribute_code = 'invoice_flag'
- INNER JOIN eav_entity_type AS eet4
- ON eet4.entity_type_id = ea4.entity_type_id
- AND eet4.entity_type_code = 'order'
- WHERE soi2.entity_id = sfoi.order_id
- LIMIT 1
- ) = 0
- ) IS FALSE
- GROUP BY sptp.id
Add Comment
Please, Sign In to add comment