/** * {@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'); }
/** * {@inheritdoc} */ public function prepare(OrderInterface $order, array $form, FormStateInterface $form_state) { // If a quote was explicitly selected, add it to the order. if (isset($form['panes']['quotes']['quotes']['quote_option']['#value']) && isset($form['panes']['quotes']['quotes']['quote_option']['#default_value']) && $form['panes']['quotes']['quotes']['quote_option']['#value'] !== $form['panes']['quotes']['quotes']['quote_option']['#default_value']) { $quote_option = explode('---', $form_state->getValue(['panes', 'quotes', 'quotes', 'quote_option'])); $order->quote['method'] = $quote_option[0]; $order->quote['accessorials'] = $quote_option[1]; $order->data->uc_quote_selected = TRUE; } // If the current quote was never explicitly selected, discard it and // use the default. if (empty($order->data->uc_quote_selected)) { unset($order->quote); } // Ensure that the form builder uses the default value to decide which // radio button should be selected. $input = $form_state->getUserInput(); unset($input['panes']['quotes']['quotes']['quote_option']); $form_state->setUserInput($input); $order->quote_form = uc_quote_build_quote_form($order, !$form_state->get('quote_requested')); $default_option = _uc_quote_extract_default_option($order->quote_form); if ($default_option) { $order->quote['rate'] = $order->quote_form[$default_option]['rate']['#value']; $quote_option = explode('---', $default_option); $order->quote['method'] = $quote_option[0]; $order->quote['accessorials'] = $quote_option[1]; $methods = uc_quote_methods(); $method = $methods[$quote_option[0]]; $label = $method['quote']['accessorials'][$quote_option[1]]; $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']); } } else { unset($order->quote); } }
/** * {@inheritdoc} */ public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); if (is_array($values['line_items'])) { foreach ($values['line_items'] as $line) { if (is_numeric($line['li_id']) && intval($line['li_id']) > 0 && isset($line['title']) && isset($line['amount'])) { uc_order_update_line_item($line['li_id'], $line['title'], $line['amount']); } } } }
/** * 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); } } }