Skip to content

Instantly share code, notes, and snippets.

@heathdutton
Created November 26, 2012 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heathdutton/4149003 to your computer and use it in GitHub Desktop.
Save heathdutton/4149003 to your computer and use it in GitHub Desktop.
Magento Custom - Get a list of customers/contracts that are affected by forceful product deletion
SELECT DISTINCT
customer_entity.email as Email,
enterprise_giftregistry_entity.tui_holiday_contract_id as Contract,
enterprise_giftregistry_entity.tui_holiday_departure_date as Departure
FROM
enterprise_giftregistry_item,
enterprise_giftregistry_entity,
customer_entity
WHERE
# Only do this for holidays that have not yet departed
enterprise_giftregistry_entity.tui_holiday_departure_date > NOW() AND
# Product no longer exists because it was forcibly deleted
enterprise_giftregistry_item.product_id NOT IN
(SELECT entity_id FROM catalog_product_entity) AND
# Product has not yet been purchased (If the item is already paid for we are not removing it)
(enterprise_giftregistry_item.qty_fulfilled IS NULL OR
enterprise_giftregistry_item.qty_fulfilled < enterprise_giftregistry_item.qty) AND
# Get the associated giftregistry entity
enterprise_giftregistry_entity.entity_id = enterprise_giftregistry_item.entity_id AND
# Get the associated user entity
enterprise_giftregistry_entity.customer_id = customer_entity.entity_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment