You are here

public function CommerceDiscountControllerExportable::save in Commerce Discount 7

Overridden to handle embedded discount_offer update.

Overrides EntityAPIControllerExportable::save

File

includes/commerce_discount.controller.inc, line 59
The controller for the discount entity containing the CRUD operations.

Class

CommerceDiscountControllerExportable
Controller for discount entities; Overrides CRUD operations.

Code

public function save($entity, DatabaseTransaction $transaction = NULL) {

  // If overwriting an existing discount, delete the referenced
  // discount_offer.
  $wrapper = entity_metadata_wrapper('commerce_discount', $entity);
  if (!empty($entity->commerce_discount_offer['commerce_discount_fields'])) {
    $wrapper->commerce_discount_offer
      ->delete();
    $discount_offer = entity_create('commerce_discount_offer', $entity->commerce_discount_offer['commerce_discount_fields']);
    $discount_offer
      ->save();
    $wrapper->commerce_discount_offer
      ->set($discount_offer);
  }
  return parent::save($entity, $transaction);
}