If I apply a coupon during checkout, then go back and remove all items from the cart, kaboom!

Fatal error: Exception thrown without a stack frame in Unknown on line 0

The logs say:

error type: commerce_line_item
DatabaseTransactionOutOfOrderException: in DatabaseConnection->rollback() (line 1039 of /.../database.inc).

Also (quite possibly related), if I go back and add items and then checkout, sometimes the calculated coupon amount doesn't update at the top of the checkout page (shopping cart contents) while it does update the amount correctly at the bottom where the "coupon code" and "coupon granted amount" are.

Comments

hibersh’s picture

Priority: Major » Critical

When I apply a coupon during checkout

Error DatabaseTransactionOutOfOrderException: in DatabaseConnection->rollback()

frixos12’s picture

+1

frixos12’s picture

Do we have any information about this exception???

adamgerthel’s picture

Having the same issue on an order with only the discount coupon applied on the order (a product was removed) that I tried to change order status on.

hibersh’s picture

function commerce_coupon_basic_apply_percentage_amounts()

hibersh’s picture

StatusFileSize
new864 bytes
--- a/sites/all/modules/commerce_coupon/modules/basic/commerce_coupon_basic.modu
+++ b/sites/all/modules/commerce_coupon/modules/basic/commerce_coupon_basic.modu
@@ -238,7 +238,7 @@ function commerce_coupon_basic_apply_percentage_amounts($com
 
     $fields = $coupon->getPropertyInfo();
 
-    $component_name = 'commerce_coupon_apply_' . $coupon->type->type->value() .
+    $component_name = 'commerce_coupon_apply_' . $coupon->value()->type . '_to_
     if (isset($fields['commerce_coupon_percent_amount'])
       && $coupon->commerce_coupon_percent_amount->value() > 0
       && isset($components[$component_name])
frixos12’s picture

does this patch solves both fixed and percentage coupons?

balintd’s picture

+1 Same error during checkout if coupon applied.

schultetwin’s picture

geek-merlin’s picture

Status: Active » Needs review
StatusFileSize
new2.24 KB

patch in #6 removes this nasty bug here too.

attached patch
* is rerolled to module dir and
* changes some more instances of "$coupon->type->type->value()" to "$coupon->value()->type"
which should provide a fix-for-now

but: looks to me like "$coupon->type->type->value()" should work and this is in fact a problem of #1314364: provide entity references as properties
where the offending line comes from:
drupalcode.org Git - project/commerce_coupon.git/blame - modules/basic/commerce_coupon_basic.module
3ea336c6

so i think a proper fix should of that might make this patch obsolete.

fago’s picture

That's probably caused by the application of a not more existing coupon type.

geek-merlin’s picture

@fago: seems not to be - to not clutter this issue up moved this to #1370046: EntityMetadataWrapperException: Unknown data property type.

geek-merlin’s picture

Status: Needs review » Reviewed & tested by the community

i think #12 is merely an academic thing so i would appreciate a review or commit (think i thoroughly tested and now it's in production here)

schultetwin’s picture

I have used this patch and have found no issues with it.

schultetwin’s picture

Or wait, I'm not sure how you want this, in a new issue or in this one, but I think there is one more instance where $coupon->type->value() needs to be switched to $coupon->value()->type.

geek-merlin’s picture

@schultetwin: you are completely right.
attached is a patch from #10 extended by #15

geek-merlin’s picture

here it comes.

schultetwin’s picture

To fast for me, sorry.

geek-merlin’s picture

no problems, reviewing and rerolling is just one go.

lukus’s picture

I experienced the same error.

Using Drupal 7.10 - the patch in #17 works for me.

Could this be committed?

geek-merlin’s picture

Status: Reviewed & tested by the community » Fixed

and committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jonathan_hunt’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta4
Status: Closed (fixed) » Needs work

This still occurs for me on 7.x-1.0-beta4. Add product to cart, apply % coupon, go back to cart, remove product from cart, crash.

Watchdog shows:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'commerce_unit_price_amount' cannot be null: INSERT INTO {field_data_commerce_unit_price} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_unit_price_amount, commerce_unit_price_currency_code, commerce_unit_price_data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => commerce_line_item [:db_insert_placeholder_1] => 12 [:db_insert_placeholder_2] => 12 [:db_insert_placeholder_3] => coupon [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => USD [:db_insert_placeholder_8] => a:1:{s:10:"components";a:1:{i:0;a:3:{s:4:"name";s:28:"commerce_coupon_basic_coupon";s:5:"price";a:3:{s:6:"amount";N;s:13:"currency_code";s:3:"USD";s:4:"data";a:1:{s:10:"components";a:0:{}}}s:8:"included";b:1;}}} ) in field_sql_storage_field_storage_write() (line 448 of /Users/jonathan/Sites/drupal-7.12/modules/field/modules/field_sql_storage/field_sql_storage.module).

and

DatabaseTransactionOutOfOrderException: in DatabaseConnection->rollback() (line 1039 of /Users/jonathan/Sites/drupal-7.12/includes/database/database.inc).
adamgerthel’s picture

I just upgraded to latest dev (the beta 4 is full of errors, due to patch from issue #1408800: Abstract and standardize commerce coupon to fix general coupon problems not being applied yet) and I have the same problem, with the following errors when emptying cart with coupons applied:

Warning: array_sum() expects parameter 1 to be array, null given i commerce_coupon_basic_apply_percentage_amounts() (rad 263 av /path-to-site/sites/all/modules/contrib/commerce_coupon/modules/basic/commerce_coupon_basic.module).

and:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'commerce_unit_price_amount' cannot be null: INSERT INTO {field_data_commerce_unit_price} (entity_type, entity_id, revision_id, bundle, delta, language, commerce_unit_price_amount, commerce_unit_price_currency_code, commerce_unit_price_data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => commerce_line_item [:db_insert_placeholder_1] => 9054 [:db_insert_placeholder_2] => 9054 [:db_insert_placeholder_3] => coupon [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => SEK [:db_insert_placeholder_8] => a:1:{s:10:"components";a:1:{i:0;a:3:{s:4:"name";s:28:"commerce_coupon_basic_coupon";s:5:"price";a:3:{s:6:"amount";N;s:13:"currency_code";s:3:"SEK";s:4:"data";a:1:{s:10:"components";a:0:{}}}s:8:"included";b:1;}}} ) i field_sql_storage_field_storage_write() (rad 448 av /path-to-site/modules/field/modules/field_sql_storage/field_sql_storage.module).

as well as:

DatabaseTransactionOutOfOrderException: i DatabaseConnection->rollback() (rad 1039 av /path-to-site/includes/database/database.inc).

pcambra’s picture

Status: Needs work » Active

Back to active then. Let's figure out how to reproduce and smash this buggies ;)

bibo’s picture

Seems the same error is generated under other circumstances too. For example a custom page callback that clears an users cart + adds one item to it sometimes throws this error under load.

pcambra’s picture

Status: Active » Postponed (maintainer needs more info)

I'm afraid I'm going to need a way to reproduce this, be aware that the module has been changed a lot.

meghanmary’s picture

I do not get an error but I am not able to remove the coupon from my cart. I am running 7.x-1.0-beta4+14-dev.

I add items to the cart and then add a coupon. I added a percentage based coupon.

I remove the items from the cart. My cart claims that 1 item remains but when I look at the cart it is empty.

If I then add another item to the cart, the previous coupon appears with the amount from the previous order. Is there any way to remove this coupon?

Thanks,
Meghan

adamgerthel’s picture

@meghanmary I'm afraid there's no such functionality. There is a patch in #1305242: Add a Remove coupon view button and Make a User used coupon rule condition but it's not working properly without admin rights.

sleepingmonk’s picture

Hi! I'm testing commerce_coupon-7.x-1.0-beta4+26-dev

Emptying the cart with a coupon in it gives me "The website encountered an unexpected error. Please try again later."

The logs show it's trying to use a column that doesn't exist. I'm assuming this query is checking for coupons to remove from the order when the cart is emptied.

Refreshing or going back shows the cart empty, but as others have mentioned, the coupon is still attached to the order. Adding more products to the order, reveals the coupon again.

Below is from the logs:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_commerce_coupon_reference0.commerce_coupon_reference_coupon_id' in 'where clause': SELECT field_data_commerce_coupon_reference0.entity_type AS entity_type, field_data_commerce_coupon_reference0.entity_id AS entity_id, field_data_commerce_coupon_reference0.revision_id AS revision_id, field_data_commerce_coupon_reference0.bundle AS bundle FROM {field_data_commerce_coupon_reference} field_data_commerce_coupon_reference0 INNER JOIN {commerce_line_item} commerce_line_item ON commerce_line_item.line_item_id = field_data_commerce_coupon_reference0.entity_id WHERE (field_data_commerce_coupon_reference0.commerce_coupon_reference_coupon_id = :db_condition_placeholder_0) AND (field_data_commerce_coupon_reference0.deleted = :db_condition_placeholder_1) AND (commerce_line_item.order_id = :db_condition_placeholder_2) AND (commerce_line_item.type = :db_condition_placeholder_3) AND (field_data_commerce_coupon_reference0.entity_type = :db_condition_placeholder_4) ; Array ( [:db_condition_placeholder_0] => 2 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => 64 [:db_condition_placeholder_3] => commerce_coupon [:db_condition_placeholder_4] => commerce_line_item ) in field_sql_storage_field_storage_query() (line 577 of .../public_html/sp/modules/field/modules/field_sql_storage/field_sql_storage.module).

sleepingmonk’s picture

Status: Postponed (maintainer needs more info) » Needs work
StatusFileSize
new601 bytes

EDITED: Disregard the attached patch. My initial tests weren't thorough enough. I realize now this is incorrect. Will investigate further.

sleepingmonk’s picture

Ok, I did some more digging and I'll admit, I'm pretty confused.

The commerce_coupon.module function on line 667:

function commerce_coupon_remove_coupon_from_order($order, $coupon) {
  // Make a EFQ to get coupon line items in that order that match to the coupon.
  $query = new EntityFieldQuery();
  $result = $query->entityCondition('entity_type', 'commerce_line_item')
      ->propertyCondition('order_id', $order->order_id)
      ->propertyCondition('type', 'commerce_coupon')
      ->fieldCondition('commerce_coupon_reference', NULL, $coupon->coupon_id, '=')
      ->execute();

  if (empty($result)) {
    return;
  }

  $line_item_ids = array_keys($result['commerce_line_item']);

  if (!empty($line_item_ids)) {
    // First remove the line items from the order and save it to avoid
    // conflicts.
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
      if (in_array($line_item_wrapper->line_item_id->value(), $line_item_ids)) {
        $order_wrapper->commerce_line_items->offsetUnset($delta);
      }
    }
    commerce_order_save($order);
    commerce_line_item_delete_multiple($line_item_ids);
  }

  // Also delete the coupon log.
  $coupon_log = commerce_coupon_log_load_by_order_and_coupon($order->order_id, $coupon->coupon_id);
  commerce_coupon_log_delete($coupon_log->log_id);
}

As far as I can see, field_data_commerce_coupon_reference doesn't contain anything after I add a coupon to an order, so there's nothing to delete from there. The only table that seems to matter is commerce_coupon_log. Deleting a row from there removes that coupon from an order.

Maybe these are leftovers from changes in the module, but can it be as simple as just deleting all rows from commerce_coupon_log for the order_id? The last part of the function attempts to do this, but doesn't work.

I'm sorry I don't fully grasp what's going on in this complex module. I'm just trying to do what I can to help. This is a very important feature for Drupal Commerce so I'd like to contribute to the best of my ability.

pcambra’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Status: Needs work » Fixed

Pushed a big change fixing #1547440: Kill coupon log entity and that should fix all emptying cart problems.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

greenavus’s picture

It seems i am having this same problem. When there is only one product in the shopping cart, it throws up this error

EntityFieldQueryException: Unknown field: commerce_coupon_reference in EntityFieldQuery->addFieldCondition() (line 770 of C:\wamp\www\Wellness\includes\entity.inc).

Does anyone know what i can do to solve this problem?

greenavus’s picture

Status: Closed (fixed) » Active
pcambra’s picture

Status: Active » Closed (fixed)

Please don't revive issues closed 5 months ago. Check the project page for the dedicated issue and the documentation for solving problems like yours, probably related with upgrading from beta4