/** * {@inheritdoc} */ public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state) { $pane = $this->pluginDefinition['id']; $address = $order->getAddress($pane); foreach ($form_state->getValue($pane) as $key => $value) { if (uc_address_field_enabled($key)) { $address->{$key} = $value; } } $order->setAddress($pane, $address); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, array $addresses = [], OrderInterface $uc_order = NULL) { $form['#attached']['library'][] = 'uc_fulfillment/uc_fulfillment.scripts'; $form['origin'] = array('#type' => 'fieldset', '#title' => t('Origin address'), '#weight' => -2); $form['origin']['pickup_address_select'] = $this->selectAddress($addresses); $form['origin']['pickup_address_select']['#weight'] = -2; $form['origin']['pickup_email'] = array('#type' => 'email', '#title' => t('E-mail'), '#default_value' => uc_store_email(), '#weight' => -1); $form['origin']['pickup_email']['#weight'] = -1; $form['origin']['pickup_address']['#tree'] = TRUE; $form['origin']['pickup_address']['pickup_address'] = array('#type' => 'uc_address', '#default_value' => reset($addresses), '#required' => FALSE); $form['destination'] = array('#type' => 'fieldset', '#title' => t('Destination address'), '#weight' => -1); if ($form_state->hasValue('delivery_country')) { $uc_order->delivery_country = $form_state->getValue('delivery_country'); } $form['destination']['delivery_email'] = array('#type' => 'email', '#title' => t('E-mail'), '#default_value' => $uc_order->getEmail(), '#weight' => -1); $form['destination']['delivery_email']['#weight'] = -1; $form['destination']['delivery_address'] = array('#type' => 'uc_address', '#default_value' => $uc_order->getAddress('delivery'), '#required' => FALSE, '#key_prefix' => 'delivery'); return $form; }
/** * {@inheritdoc} */ public function review(OrderInterface $order) { $pane = $this->pluginDefinition['id']; $address = $order->getAddress($pane); $review[] = array('title' => t('Address'), 'data' => $address); if (uc_address_field_enabled('phone') && !empty($address->phone)) { $review[] = array('title' => t('Phone'), 'data' => SafeMarkup::checkPlain($address->phone)); } return $review; }
/** * {@inheritdoc} */ public function buildRedirectForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL) { $country = \Drupal::service('country_manager')->getCountry($order->getAddress('billing')->country); $data = array('sid' => $this->configuration['sid'], 'mode' => '2CO', 'card_holder_name' => Unicode::substr($order->getAddress('billing')->first_name . ' ' . $order->getAddress('billing')->last_name, 0, 128), 'street_address' => Unicode::substr($order->getAddress('billing')->street1, 0, 64), 'street_address2' => Unicode::substr($order->getAddress('billing')->street2, 0, 64), 'city' => Unicode::substr($order->getAddress('billing')->city, 0, 64), 'state' => $order->getAddress('billing')->zone, 'zip' => Unicode::substr($order->getAddress('billing')->postal_code, 0, 16), 'country' => $country ? $country->getAlpha3() : 'USA', 'email' => Unicode::substr($order->getEmail(), 0, 64), 'phone' => Unicode::substr($order->getAddress('billing')->phone, 0, 16), 'purchase_step' => 'payment-method', 'demo' => $this->configuration['demo'] ? 'Y' : 'N', 'lang' => $this->configuration['language'], 'merchant_order_id' => $order->id(), 'pay_method' => 'CC', 'x_receipt_link_url' => Url::fromRoute('uc_2checkout.complete', ['cart_id' => \Drupal::service('uc_cart.manager')->get()->getId()], ['absolute' => TRUE])->toString(), 'total' => uc_currency_format($order->getTotal(), FALSE, FALSE, '.'), 'currency_code' => $order->getCurrency(), 'cart_order_id' => $order->id()); $i = 0; foreach ($order->products as $product) { $i++; $data['li_' . $i . '_type'] = 'product'; $data['li_' . $i . '_name'] = $product->title->value; // @todo: HTML escape and limit to 128 chars $data['li_' . $i . '_quantity'] = $product->qty->value; $data['li_' . $i . '_product_id'] = $product->model->value; $data['li_' . $i . '_price'] = uc_currency_format($product->price->value, FALSE, FALSE, '.'); } if ('direct' == $this->configuration['checkout_type']) { $form['#attached']['library'][] = 'uc_2checkout/2checkout.direct'; } $form['#action'] = $this->configuration['server_url']; foreach ($data as $name => $value) { $form[$name] = array('#type' => 'hidden', '#value' => $value); } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit order')); return $form; }