コード例 #1
0
ファイル: OrderForm.php プロジェクト: pedrocones/hydrotools
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $order = $this->entity;
     $original = clone $order;
     // Build list of changes to be applied.
     $panes = _uc_order_pane_list();
     foreach ($panes as $pane) {
         if (in_array('edit', $pane['show'])) {
             $pane['callback']('edit-process', $order, $form, $form_state);
         }
     }
     $log = array();
     foreach (array_keys($order->getFieldDefinitions()) as $key) {
         if ($original->{$key}->value !== $order->{$key}->value) {
             if (!is_array($order->{$key}->value)) {
                 $log[$key] = array('old' => $original->{$key}->value, 'new' => $order->{$key}->value);
             }
         }
     }
     if (\Drupal::moduleHandler()->moduleExists('uc_stock')) {
         $qtys = array();
         foreach ($order->products as $product) {
             $qtys[$product->order_product_id] = $product->qty;
         }
     }
     if (is_array($form_state->getValue('products'))) {
         foreach ($form_state->getValue('products') as $product) {
             if (!isset($product['remove']) && intval($product['qty']) > 0) {
                 foreach (array('qty', 'title', 'model', 'weight', 'weight_units', 'cost', 'price') as $field) {
                     $order->products[$product['order_product_id']]->{$field} = $product[$field];
                 }
                 if (\Drupal::moduleHandler()->moduleExists('uc_stock')) {
                     $product = (object) $product;
                     $temp = $product->qty;
                     $product->qty = $product->qty - $qtys[$product->order_product_id];
                     uc_stock_adjust_product_stock($product, 0, $order);
                     $product->qty = $temp;
                 }
             } else {
                 $log['remove_' . $product['nid']] = $product['title'] . ' removed from order.';
             }
         }
     }
     // Load line items again, since some may have been updated by the form.
     $order->line_items = $order->getLineItems();
     $order->logChanges($log);
     $order->save();
     drupal_set_message(t('Order changes saved.'));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL)
 {
     parent::buildComponents($build, $entities, $displays, $view_mode, $langcode);
     // TODO: Change the autogenerated stub
     foreach ($entities as $id => $order) {
         $panes = _uc_order_pane_list($view_mode);
         foreach ($panes as $pane) {
             if (in_array($view_mode, $pane['show'])) {
                 $func = $pane['callback'];
                 if (function_exists($func) && ($contents = $func($view_mode, $order)) != NULL) {
                     $title = isset($pane['display title']) ? $pane['display title'] : $pane['title'];
                     if ($title) {
                         $title = array('#markup' => $pane['title'] . ':', '#prefix' => '<div class="order-pane-title">', '#suffix' => '</div>');
                     } else {
                         $title = array();
                     }
                     $build[$id][$pane['id']] = array('#prefix' => '<div class="order-pane ' . $pane['class'] . '" id="order-pane-' . $pane['id'] . '">', '#suffix' => '</div>');
                     $build[$id][$pane['id']]['title'] = $title;
                     $build[$id][$pane['id']]['pane'] = $contents;
                 }
             }
         }
     }
 }