You are here

public function ShipmentController::makeShipment in Ubercart 8.4

Default method to create a shipment from packages.

Parameters

\Drupal\uc_order\OrderInterface $uc_order: The order object.

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

array|\Symfony\Component\HttpFoundation\RedirectResponse A render array, or a redirect response if there are selected packages.

1 string reference to 'ShipmentController::makeShipment'
uc_fulfillment.routing.yml in shipping/uc_fulfillment/uc_fulfillment.routing.yml
shipping/uc_fulfillment/uc_fulfillment.routing.yml

File

shipping/uc_fulfillment/src/Controller/ShipmentController.php, line 48

Class

ShipmentController
Controller routines for shipments.

Namespace

Drupal\uc_fulfillment\Controller

Code

public function makeShipment(OrderInterface $uc_order, Request $request) {
  $method_id = $request->query
    ->get('method_id');
  $request->query
    ->remove('method_id');
  $package_ids = $request->query
    ->all();
  if (count($package_ids) > 0) {

    //      $breadcrumb = drupal_get_breadcrumb();
    //      $breadcrumb[] = Link::createFromRoute($this->t('Shipments'), 'uc_fulfillment.shipments', ['uc_order' => $uc_order->id()]);
    //      drupal_set_breadcrumb($breadcrumb);
    // Find FulfillmentMethod plugins.
    $manager = \Drupal::service('plugin.manager.uc_fulfillment.method');
    $methods = FulfillmentMethod::loadMultiple();
    if (isset($methods[$method_id])) {
      $method = $methods[$method_id];
    }
    else {

      // The selected fulfullment isn't available, so use built-in "Manual" shipping.
      $method = $methods['manual'];
    }
    $plugin = $manager
      ->createInstance($method
      ->getPluginId(), $method
      ->getPluginConfiguration());
    return $plugin
      ->fulfillOrder($uc_order, $package_ids);
  }
  else {
    $this
      ->messenger()
      ->addWarning($this
      ->t('There is no sense in making a shipment with no packages on it, right?'));
    return $this
      ->redirect('uc_fulfillment.new_shipment', [
      'uc_order' => $uc_order
        ->id(),
    ]);
  }
}