I get this error:

Notice: Undefined index: discount_name in commerce_discount_remove_discount_components() (line 74 of /Applications/MAMP/htdocs/losencantes.es/profiles/commerce_kickstart/modules/contrib/commerce_discount/commerce_discount.module).
DatabaseTransactionOutOfOrderException: in DatabaseConnection->rollback() (line 1052 of /Applications/MAMP/htdocs/losencantes.es/includes/database/database.inc).

I created a rule to run a discount action. In actions I choose:

Subtract an amount from the unit price
and the setting for the action are:
Parameter: Line item: [commerce_line_item], Amount: 500, Price component type: Discount

CommentFileSizeAuthor
#3 issue-1817394-3.patch680 byteslsolesen
#2 issue-1817394.patch536 byteslsolesen

Comments

m.ioannidis’s picture

Just a "quick&dirty" solution while we wait the official fix is the following:

function commerce_discount_remove_discount_components($price_wrapper) {
  $data = $price_wrapper->data->value();
  $component_removed = FALSE;
  // Remove price components belonging to order discounts.
  foreach ($data['components'] as $key => $component) {
     if(!empty($component['price']['data'])){
      if ($component['name'] != 'discount') {
        continue;
      }
      $discount_name = $component['price']['data']['discount_name'];
      $wrapper = entity_metadata_wrapper('commerce_discount', $discount_name);
      if ($wrapper->type->value() == 'order_discount') {
        unset($data['components'][$key]);
        $component_removed = TRUE;
      }
    }
  }

File: commerce_discount.module (located: /profiles/commerce_kickstart/modules/contrib/commerce_discount/
I actually added a check if the $component['price']['data'] is empty.

I know this is NOT the prettiest solution, but saved my Weekend! :)

lsolesen’s picture

StatusFileSize
new536 bytes

@m.ioannidis solution expressed as a patch.

lsolesen’s picture

StatusFileSize
new680 bytes

Though it does not seem to fix the actual issue. Workaround patch attached.

soundexcel’s picture

Same error here. Using commerce kickstart 2.0 rc4.

Error appears when adding a product to the cart.
There is a active pricing rule which uses a custom field as discount parameter:

{ "rules_product_discount" : {
    "LABEL" : "Product discount",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
    "ON" : [ "commerce_product_calculate_sell_price" ],
    "IF" : [
      { "AND" : [
          { "data_is" : { "data" : [ "commerce-line-item:type" ], "value" : "product" } },
          { "data_is" : { "data" : [ "commerce-line-item:commerce-product:type" ], "value" : "product" } },
          { "entity_has_field" : { "entity" : [ "commerce-line-item:commerce-product" ], "field" : "field_product_discount" }
          }
        ]
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_multiply" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "amount" : [ "commerce-line-item:commerce-product:field-product-discount" ],
          "component_name" : "discount",
          "round_mode" : "1"
        }
      }
    ]
  }
}

When i switch the price component type to "base price", everything works ok.
Unfortunately the patch provided in comment 3 doesn't work. I am looking in to this but haven't found a solution yet.

bojanz’s picture

Status: Active » Fixed

Pushed a fix.

Status: Fixed » Closed (fixed)

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