I have a Kickstart installation and. I defined a coupon for free shipping and I encountered problems with it, I tried to change the order of checkout so that shipping details were asked for before the coupon, didn't work well, and I went back to my previous solution without free shipping.

After that, I'm now receiving the error message "EntityMetadataWrapperException: Unable to get the data property coupon_id as the parent data structure is not set" when I try to access the Orders view that is predefined by Kickstart. How could I track what could be causing the problem? My first guess is that some db entry is corrupted, but it could be something else. I don't know how to fix it either. I've tried to delete the orders that contain some coupon but it doesn't seem to work. Maybe I haven't been exhaustive.

I'm using version 2.0-rc2 of Commerce Coupon.

Comments

dpico created an issue. See original summary.

dpico’s picture

I've found that only some orders fail (orders that maybe were using coupons, though there is not coupon configured in the order page, apparently). Viewing them through the Orders view or trying to change their state to completed produces the "EntityMetadataWrapperException: Unable to get the data property coupon_id as the parent data structure is not set" error.

dpico’s picture

Ok, I got it. Some coupon definitions had been removed from table commerce_coupon but they were still being refenced elsewhere. I've done some surgery to the database and added fake entries with the coupon_id's that were missing and the error has disappeared.

mglaman’s picture

So on coupon delete we need to remove references. Or coupons should not be able to be deleted if referenced, only disabled.

dpico’s picture

Yes, that's right. The table that contains the coupons had many references to coupons that didn't exist any more (missing coupon_id in table commerce_coupon) and that seems to be causing the errors I described.

johnmcc’s picture

I suffered the same issue, and the information that @dpico offered helped. Here are the exact steps I took to fix the problem, in case anyone else is in the same boat:

  • Backed up my database
  • Looked at the commerce_coupon table, and checked the coupon_id field for a list of IDs
  • Checked the commerce_coupon_usage_transaction table and took a note of any coupon_id that was not present in the commerce_coupon table. (In my case, only one coupon_id was missing)
  • Created a new row in the commerce_coupon table, and made sure that the new coupon_id matched the missing one from the step above. (I copied an existing row and changed the coupon_id field.)

In my case, the problem appeared when I was trying to edit the order status in the admin area. Hope this helps someone!

vasike’s picture

Version: 7.x-2.0-rc2 » 7.x-2.x-dev
Status: Active » Closed (duplicate)
Related issues: +#2818607: EntityMetadataWrapperException for orders with deleted coupons
sudoman0’s picture

Based on Johnmcc's advice, these were my SQL commands:

select * from shop_commerce_coupon_usage_transaction where coupon_id not in (select coupon_id from shop_commerce_coupon);

things to change when running the following query: the updated coupon_id and its code name.

CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM shop_commerce_coupon WHERE coupon_id = 14;
UPDATE tmptable_1 SET coupon_id = 17;
UPDATE tmptable_1 SET code = 'RESURRECTED0';
INSERT INTO shop_commerce_coupon SELECT * FROM tmptable_1;
DROP TEMPORARY TABLE IF EXISTS tmptable_1;