Beispiel #1
0
 /**
  * Ajax callback: Manually applies a shipping quote to an order.
  */
 public function applyQuote($form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue(['quotes', 'quote_option'])) {
         if ($order = $form_state->get('order')) {
             $quote_option = explode('---', $form_state->getValue(['quotes', 'quote_option']));
             $order->quote['method'] = $quote_option[0];
             $order->quote['accessorials'] = $quote_option[1];
             $method = ShippingQuoteMethod::load($quote_option[0]);
             $label = $method->label();
             $quote_option = $form_state->getValue(['quotes', 'quote_option']);
             $order->quote['rate'] = $form_state->getValue(['quotes', $quote_option, 'rate']);
             $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [':id' => $order->id(), ':type' => 'shipping']);
             if ($lid = $result->fetchField()) {
                 uc_order_update_line_item($lid, $label, $order->quote['rate']);
                 $form_state->set('uc_quote', array('lid' => $lid, 'title' => $label, 'amount' => $order->quote['rate']));
             } else {
                 uc_order_line_item_add($order->id(), 'shipping', $label, $order->quote['rate']);
             }
             // Save selected shipping
             uc_quote_uc_order_update($order);
             // Update line items.
             $order->line_items = $order->getLineItems();
             // @todo Still needed?
             $form_state->set('order', $order);
             $form_state->setRebuild();
             $form_state->set('quote_requested', FALSE);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $paypal_config = $this->config('uc_paypal.settings');
     $session = \Drupal::service('session');
     $order = Order::load($session->get('cart_order'));
     if (!$form_state->isValueEmpty('shippable')) {
         $quote_option = explode('---', $form_state->getValue(['quotes', 'quote_option']));
         $order->quote['method'] = $quote_option[0];
         $order->quote['accessorials'] = $quote_option[1];
         $method = ShippingQuoteMethod::load($quote_option[0]);
         $label = $method['quote']['accessorials'][$quote_option[1]];
         //      $label = $method->label();
         $quote_option = $form_state->getValue(['quotes', 'quote_option']);
         $order->quote['rate'] = $form_state->getValue(['quotes', $quote_option, 'rate']);
         $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [':id' => $order->id(), ':type' => 'shipping']);
         if ($lid = $result->fetchField()) {
             uc_order_update_line_item($lid, $label, $order->quote['rate']);
         } else {
             uc_order_line_item_add($order->id(), 'shipping', $label, $order->quote['rate']);
         }
     }
     if ($paypal_config->get('ec_review_company')) {
         $order->delivery_company = $form_state->getValue('delivery_company');
     }
     if ($paypal_config->get('ec_review_phone')) {
         $order->delivery_phone = $form_state->getValue('delivery_phone');
     }
     if ($paypal_config->get('ec_review_comment')) {
         db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
         uc_order_comment_save($order->id(), 0, $form_state->getValue('order_comments'), 'order');
     }
     $order->save();
     $form_state->setRedirect('uc_paypal.ec_submit');
 }