Skip to content

Instantly share code, notes, and snippets.

@wikimo
Created December 15, 2016 17:26
Show Gist options
  • Save wikimo/f110f6ad29a7f7bf3c7d2d7e82901f44 to your computer and use it in GitHub Desktop.
Save wikimo/f110f6ad29a7f7bf3c7d2d7e82901f44 to your computer and use it in GitHub Desktop.
# find promotion's products with promotion_id = 2
# if product ids result is 2,7
select product_id from spree_product_promotion_rules
where promotion_rule_id=(select id from spree_promotion_rules where type='Spree::Promotion::Rules::Product' and promotion_id=2)
# find the promotion product's quantity if order_id = 3
select distinct(spree_line_items.variant_id), spree_line_items.quantity from spree_product_promotion_rules
left join spree_line_items on spree_product_promotion_rules.product_id = spree_line_items.variant_id
where spree_product_promotion_rules.product_id in (2,7) and spree_line_items.order_id=3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment