You are here

protected function CommerceAddToCartLinkViewsField::getUrl in Commerce Add To Cart Link 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/field/CommerceAddToCartLinkViewsField.php \Drupal\commerce_add_to_cart_link\Plugin\views\field\CommerceAddToCartLinkViewsField::getUrl()

Get URL.

Parameters

int $id: The product variation id.

Return value

\Drupal\Core\Url The URL.

1 call to CommerceAddToCartLinkViewsField::getUrl()
CommerceAddToCartLinkViewsField::getUrlInfo in src/Plugin/views/field/CommerceAddToCartLinkViewsField.php
Returns the URI elements of the link.

File

src/Plugin/views/field/CommerceAddToCartLinkViewsField.php, line 84

Class

CommerceAddToCartLinkViewsField
Defines a Views field that adds an add to cart link.

Namespace

Drupal\commerce_add_to_cart_link\Plugin\views\field

Code

protected function getUrl($id) {
  $url = AddToCartLink::fromVariationId($id)
    ->url();
  $query = (array) $url
    ->getOption('query');
  if ($this->options['destination']) {
    $query += $this
      ->getDestinationArray();
  }
  if ($this->options['quantity'] != 1) {
    $query += [
      'quantity' => $this->options['quantity'],
    ];
  }
  if (!$this->options['combine']) {
    $query += [
      'combine' => 0,
    ];
  }
  $url
    ->setOption('query', $query);
  return $url;
}