/**
  * Called to save the final product from the edit form.
  */
 function edit_save_form($form_state)
 {
     $item =& $form_state['item'];
     $export_key = $this->plugin['export']['key'];
     $result = ctools_export_crud_save($this->plugin['schema'], $item);
     field_attach_submit('ms_products_plan', $item, $form_state['saved_form'], $form_state);
     field_attach_update('ms_products_plan', $item);
     if ($result) {
         $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['success']);
         drupal_set_message($message);
     } else {
         $message = str_replace('%title', check_plain($item->{$export_key}), $this->plugin['strings']['confirmation'][$form_state['op']]['fail']);
         drupal_set_message($message, 'error');
     }
 }
 /**
  * Overrides EntityInlineEntityFormController::entityFormSubmit().
  *
  * Fixes some of the custom entity values, similar to
  * fieldable_panels_panes_entity_edit_form_submit().
  */
 public function entityFormSubmit(&$entity_form, &$form_state)
 {
     $info = entity_get_info($this->entityType);
     list(, , $bundle) = entity_extract_ids($this->entityType, $entity_form['#entity']);
     $entity = $entity_form['#entity'];
     $entity_values = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);
     // Some additional adjustments necessary for FPP to save correctly.
     if (!empty($entity_values['link']['path'])) {
         $entity_values['path'] = $entity_values['link']['path'];
     }
     if (isset($entity_values['link']['link'])) {
         $entity_values['link'] = $entity_values['link']['link'];
     } else {
         $entity_values['link'] = 0;
     }
     // The 'reusable' option contains several sub fields.
     if (isset($entity_values['reusable']['reusable'])) {
         $reusable = $entity_values['reusable'];
         $entity_values['reusable'] = FALSE;
         $entity_values['category'] = '';
         $entity_values['admin_title'] = '';
         $entity_values['admin_description'] = '';
         foreach (array('reusable', 'category', 'admin_title', 'admin_description') as $field) {
             if (isset($reusable[$field])) {
                 $entity_values[$field] = $reusable[$field];
             }
         }
     }
     // Only fix the revision log if a revision is being saved.
     $entity_values['log'] = '';
     if (isset($entity_values['revision']['revision'])) {
         if (isset($entity_values['revision']['log'])) {
             $entity_values['log'] = $entity_values['revision']['log'];
         }
         $entity_values['revision'] = $entity_values['revision']['revision'];
     } else {
         $entity_values['revision'] = 0;
     }
     // Copy top-level form values that are not for fields to entity properties,
     // without changing existing entity properties that are not being edited by
     // this form. Copying field values must be done using field_attach_submit().
     $values_excluding_fields = $info['fieldable'] ? array_diff_key($entity_values, field_info_instances($this->entityType, $bundle)) : $entity_values;
     foreach ($values_excluding_fields as $key => $value) {
         $entity->{$key} = $value;
     }
     if ($info['fieldable']) {
         field_attach_submit($this->entityType, $entity, $entity_form, $form_state);
     }
 }
Example #3
0
 $form_state = array();
 $form_state['values'] = '';
 $form = array();
 $form['#parents'] = array();
 $new_product = commerce_product_new('product');
 $new_product->status = 1;
 $new_product->uid = 1;
 $new_product->sku = $item->Ид;
 $new_product->title = $item->Наименование;
 $new_product->type = 'product';
 $new_product->created = $new_product->changed = time();
 $new_product->language = LANGUAGE_NONE;
 $new_product->commerce_price['und'][0]['amount'] = $item->Цены->Цена->ЦенаЗаЕдиницу * 100;
 $new_product->commerce_price['und'][0]['currency_code'] = 'RUB';
 $new_product->commerce_price['und'][0]['data']['component'] = array();
 field_attach_submit('product', $new_product, $form, $form_state);
 commerce_product_save($new_product);
 $node = new stdClass();
 $node->type = 'product';
 node_object_prepare($node);
 $node->title = $item->Наименование;
 $node->language = LANGUAGE_NONE;
 $node->field_id['und'][0]['value'] = $item->Ид;
 $node->field_id['und'][0]['safe_value'] = $item->Ид;
 $node->field_id['und'][0]['format'] = NULL;
 $node->body[$node->language][0]['value'] = 'описание товара';
 $node->body[$node->language][0]['summary'] = 'описание товара';
 $node->body[$node->language][0]['format'] = 'filtered_html';
 $node->field_product['und'][0]['product_id'] = $new_product->product_id;
 $node->uid = 1;
 node_save($node);