-- get order with saved cc data SELECT so.increment_id FROM sales_order_entity_varchar soev INNER JOIN sales_order_entity soe ON soev.entity_id = soe.entity_id INNER JOIN sales_order so ON soe.parent_id = so.entity_id WHERE soev.attribute_id = 280 AND soev.VALUE != "" -- get saved credit card owner select value from sales_order_entity_varchar where attribute_id = 282 and entity_id in ( select entity_id from sales_order_entity_varchar where attribute_id = 280 and value != "" ); -- erase credit card data by order id SET @orderId = '100000013'; UPDATE sales_order_entity_varchar SET VALUE = NULL WHERE entity_id = ( SELECT entity_id FROM sales_order_entity WHERE entity_type_id =14 AND parent_id = ( SELECT entity_id FROM sales_order WHERE increment_id = @orderId ) ) AND attribute_id IN ( SELECT attribute_id FROM eav_attribute WHERE attribute_code LIKE 'cc_%' ); -- erase credit card data by cc owner SET @ccOwner = 'Mr. Smith'; SET @entityId = (select entity_id from sales_order_entity_varchar where value = @ccOwner); update sales_order_entity_varchar set value = null where entity_id = @entityId and attribute_id in ( SELECT attribute_id FROM eav_attribute WHERE attribute_code LIKE 'cc_%' ); -- get attribute ids SELECT attribute_id FROM eav_attribute where attribute_code in ('cc_number_enc', 'cc_last4', 'cc_owner', 'cc_exp_month', 'cc_exp_year', 'cc_type'); -- script to autocheck saved cc data http://www.panticz.de/sites/default/files/magento/creditcard/checkSavedCcData.sh #!/bin/bash DB_USER=YOUR_USER DB_PASS=YOUR_PASS DB_NAME=YOUR_DB MAIL_TO=YOUR_EMAIL # search for saved cc customer echo 'SELECT VALUE FROM sales_order_entity_varchar WHERE attribute_id = 282 AND entity_id IN (SELECT entity_id FROM sales_order_entity_varchar WHERE attribute_id = 280 AND VALUE != "")' | mysql -u ${DB_USER} -p${DB_PASS} ${DB_NAME} > /tmp/cc.log # notify if [ $(cat /tmp/cc.log | wc -l) -gt 1 ]; then echo 'Subject: Please delete CC data' | cat - /tmp/cc.log | sendmail ${MAIL_TO} fi # clean up rm /tmp/cc.log