public function testCheckoutAjax() { // Enable two payment methods and set a condition on one. $this->createPaymentMethod('check'); $other = $this->createPaymentMethod('other'); // $this->addPaymentZoneCondition($other['id'], 'KS'); // Specify that the billing zone should update the payment pane. $config = _uc_ajax_defaults('checkout'); $config['panes][billing][address][zone'] = array('payment-pane' => 'payment-pane'); \Drupal::configFactory()->getEditable('uc_cart.settings')->set('ajax.checkout', $config)->save(); // Go to the checkout page, verify that the conditional payment method is // not available. $product = $this->createProduct(array('shippable' => 0)); $this->addToCart($product); $this->drupalPostForm('cart', array('items[0][qty]' => 1), t('Checkout')); // @todo Re-enable when shipping quote conditions are available. // $this->assertNoEscaped($other['label']); // Change the billing zone and verify that payment pane updates. $edit = array(); $edit['panes[billing][zone]'] = 'KS'; $this->ucPostAjax(NULL, $edit, 'panes[billing][zone]'); $this->assertEscaped($other['label']); $edit['panes[billing][zone]'] = 'AL'; $this->ucPostAjax(NULL, $edit, 'panes[billing][zone]'); // Not in Kansas any more... // @todo Re-enable when shipping quote conditions are available. // $this->assertNoEscaped($other['label']); }
/** * {@inheritdoc} * * @param string $target_form * The form for which ajax behaviors are to be administered. Currently only * 'checkout' is supported. */ public function buildForm(array $form, FormStateInterface $form_state, $target_form = 'checkout') { module_load_include('inc', 'uc_store', 'includes/uc_ajax_attach'); switch ($target_form) { case 'checkout': $triggers = _uc_ajax_admin_checkout_trigger_options(_uc_ajax_admin_build_checkout_form()); $panes = \Drupal::service('plugin.manager.uc_cart.checkout_pane')->getDefinitions(); $wrappers = array(); foreach ($panes as $id => $pane) { $wrappers["{$id}-pane"] = $pane['title']; } break; default: throw new NotFoundHttpException(); } $form['#uc_ajax_target'] = $target_form; $config = $this->config('uc_cart.settings')->get('ajax.' . $target_form); $form['#uc_ajax_config'] = $config ?: _uc_ajax_defaults($target_form); $form['table'] = uc_ajax_admin_table($triggers, $wrappers, $form['#uc_ajax_config']); $form['actions'] = array('#type' => 'actions', 'submit' => array('#type' => 'submit', '#value' => $this->t('Submit'))); return $form; }