You are here

public function CommerceDiscountControllerExportable::export in Commerce Discount 7

Override export, to allow embedding the commerce discount offer inside the export of the commerce discount.

Overrides EntityAPIControllerExportable::export

File

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

Class

CommerceDiscountControllerExportable
Controller for discount entities; Overrides CRUD operations.

Code

public function export($entity, $prefix = '') {
  $vars = get_object_vars($entity);

  // Add commerce_discount_offer full entity export.
  $wrapper = entity_metadata_wrapper('commerce_discount', $entity);
  $discount_offer = $wrapper->commerce_discount_offer
    ->value();
  if (!empty($discount_offer)) {
    unset($discount_offer->discount_offer_id);
    $vars['commerce_discount_offer'] = get_object_vars($discount_offer);
  }
  unset($vars[$this->statusKey], $vars[$this->moduleKey], $vars['is_new']);
  if ($this->nameKey != $this->idKey) {
    unset($vars[$this->idKey]);
  }
  return entity_var_json_export($vars, $prefix);
}