You are here

public static function Utility::quantityPrefixData in Basic cart 8

Same name and namespace in other branches
  1. 8.6 src/Utility.php \Drupal\basic_cart\Utility::quantityPrefixData()
  2. 8.0 src/Utility.php \Drupal\basic_cart\Utility::quantityPrefixData()
  3. 8.2 src/Utility.php \Drupal\basic_cart\Utility::quantityPrefixData()
  4. 8.3 src/Utility.php \Drupal\basic_cart\Utility::quantityPrefixData()
  5. 8.4 src/Utility.php \Drupal\basic_cart\Utility::quantityPrefixData()
  6. 8.5 src/Utility.php \Drupal\basic_cart\Utility::quantityPrefixData()
1 call to Utility::quantityPrefixData()
CartForm::buildForm in src/Form/CartForm.php
Form constructor.

File

src/Utility.php, line 299
Contains \Drupal\basic_cart\Utility

Class

Utility

Namespace

Drupal\basic_cart

Code

public static function quantityPrefixData($nid) {
  global $base_url;
  $langcode = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $url = new Url('basic_cart.cartremove', array(
    "nid" => $nid,
  ));
  $cart = Utility::getCart($nid);
  $basic_cart = array();
  $basic_cart['delete_url'] = $url
    ->toString();
  $basic_cart['delete_image_url'] = $base_url . '/' . drupal_get_path('module', 'basic_cart') . '/images/delete2.png';
  $basic_cart['notempty'] = false;
  if (!empty($cart['cart'])) {
    $basic_cart['notempty'] = true;
    $unit_price = $cart['cart']
      ->getTranslation($langcode)
      ->get('add_to_cart_price')
      ->getValue();
    $unit_price = isset($unit_price[0]['value']) ? $unit_price[0]['value'] : 0;
    $title = $cart['cart']
      ->getTranslation($langcode)
      ->get('title')
      ->getValue()[0]['value'];

    // Price and currency.
    $url = new Url('entity.node.canonical', array(
      "node" => $nid,
    ));
    $link = new Link($title, $url);
    $unit_price = isset($unit_price) ? $unit_price : 0;
    $unit_price = Utility::formatPrice($unit_price);
    $basic_cart['unit_price'] = $unit_price;
    $basic_cart['title_link'] = $link
      ->toString();
  }
  return $basic_cart;
}