Skip to content

Instantly share code, notes, and snippets.

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 tegansnyder/5331988 to your computer and use it in GitHub Desktop.
Save tegansnyder/5331988 to your computer and use it in GitHub Desktop.
Yes for some reason Magento serialized a bunch of arrays into the sales_recurring_profile tables. Using substring hacks we can get at some fields without having to use PHP to unserialize them.
SELECT
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(order_info,';',74),':',-1), '"', '') as coupon_code,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(order_info,';',6),':"',-1), '"', '') as order_created_at,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',22),':',-1), '"', '') as shipping_firstname,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',26),':',-1), '"', '') as shipping_lastname,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',32),':',-1), '"', '') as shipping_street,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',34),':',-1), '"', '') as shipping_city,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',36),':',-1), '"', '') as shipping_region,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',195),':',-1), '"', '') as shipping_state,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(shipping_address_info,';',40),':',-1), '"', '') as shipping_postcode,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(order_info,';',66),':',-1), '"', '') as remote_ip,
DATE_FORMAT(FROM_UNIXTIME(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(additional_info,';',2),':',-1), '"', '')), '%d-%m-%Y') as last_bill,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(additional_info,';',6),':',-1), '"', '') as billed_count,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(additional_info,';',8),':',-1), '"', '') as failure_count,
REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(additional_info,';',12),':',-1), '"', '') as outstanding,
sales_recurring_profile.* FROM sales_recurring_profile
HAVING coupon_code <> 'coupon_code;N'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment