You are here

class FlexiformFormEntityNewCommerceLineItem in Flexiform 7

Form Entity Class for getting new commerce line items.

Hierarchy

Expanded class hierarchy of FlexiformFormEntityNewCommerceLineItem

1 string reference to 'FlexiformFormEntityNewCommerceLineItem'
flexiform_flexiform_entity_getter_info in ./flexiform.flexiform.inc
Implements hook_flexiform_entity_getter_info().

File

includes/form_entity/commerce_line_item.form_entity.inc, line 10
Contains class for a basic entity getter.

View source
class FlexiformFormEntityNewCommerceLineItem extends FlexiformFormEntityBase {

  /**
   * {@inheritdoc}
   */
  public function getEntity() {
    parent::getEntity();

    // Get the base order
    $order = $this
      ->getParam('base');

    // Check we have enough information to load the entity.
    if (!$order) {
      return FALSE;
    }
    $target_entity = commerce_line_item_new($this->settings['bundle'], $order->order_id);
    return $this
      ->checkBundle($target_entity) ? $target_entity : FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function saveEntity($entity) {

    // If the entity is still false do not save it!
    if ($entity === FALSE) {
      return;
    }
    $order = $this
      ->getParam('base');
    if (empty($entity->order_id)) {
      if (empty($order->order_id)) {
        commerce_order_save($order);
      }
      $entity->order_id = $order->order_id;
    }

    // Make sure commerce_unit_price has components.
    if (!empty($entity->commerce_unit_price[LANGUAGE_NONE][0]) && empty($entity->commerce_unit_price[LANGUAGE_NONE][0]['data']['components'])) {
      $price =& $entity->commerce_unit_price[LANGUAGE_NONE][0];
      $price['data'] = commerce_price_component_add($price, 'base_price', $price, TRUE);
    }
    commerce_line_item_save($entity);
    $order->commerce_line_items[LANGUAGE_NONE][] = array(
      'line_item_id' => $entity->line_item_id,
    );
    commerce_order_save($order);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlexiformFormEntityBase::$entity_namespace public property The namespace of this entity.
FlexiformFormEntityBase::$entity_type public property The type of this entity.
FlexiformFormEntityBase::$getter public property Details of the getter.
FlexiformFormEntityBase::$manager public property The Flexiform Entity Manager
FlexiformFormEntityBase::$settings public property The settings for this entity on the flexiform.
FlexiformFormEntityBase::checkBundle public function Check bundle.
FlexiformFormEntityBase::configForm public function Get the Configuration Form. Overrides FlexiformFormEntityInterface::configForm 3
FlexiformFormEntityBase::configFormSubmit public function Submit the Configuration Form. Overrides FlexiformFormEntityInterface::configFormSubmit
FlexiformFormEntityBase::configFormValidate public function Validate the configuration form. Overrides FlexiformFormEntityInterface::configFormValidate
FlexiformFormEntityBase::getParam public function Get a Parameter From the Entity Manager.
FlexiformFormEntityBase::getParamSettings public function Get a Parameter's entity settings from the Entity Manager.
FlexiformFormEntityBase::getParamType public function Get the entity type of a parameter.
FlexiformFormEntityBase::__construct public function Construct a Flexiform Form Entity class.
FlexiformFormEntityNewCommerceLineItem::getEntity public function Get the entity for the form. Overrides FlexiformFormEntityBase::getEntity
FlexiformFormEntityNewCommerceLineItem::saveEntity public function Save the entity upon submission of the form. Overrides FlexiformFormEntityBase::saveEntity