public function CartController::addToCart in Basic cart 8.6
Same name and namespace in other branches
- 8 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::addToCart()
- 8.0 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::addToCart()
- 8.2 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::addToCart()
- 8.3 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::addToCart()
- 8.4 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::addToCart()
- 8.5 src/Controller/CartController.php \Drupal\basic_cart\Controller\CartController::addToCart()
Add node to cart.
Parameters
int $nid: Node id of the cart content.
Return value
Object Json Object response with html div text *
1 string reference to 'CartController::addToCart'
File
- src/
Controller/ CartController.php, line 75
Class
- CartController
- Contains the cart controller.
Namespace
Drupal\basic_cart\ControllerCode
public function addToCart($nid) {
\Drupal::service('page_cache_kill_switch')
->trigger();
$query = \Drupal::request()->query;
$config = Utility::cartSettings();
$param['entitytype'] = $query
->get('entitytype') ? $query
->get('entitytype') : "node";
$param['quantity'] = $query
->get('quantity') ? is_numeric($query
->get('quantity')) ? (int) $query
->get('quantity') : 1 : 1;
Utility::addToCart($nid, $param);
if ($config
->get('add_to_cart_redirect') != "<none>" && trim($config
->get('add_to_cart_redirect'))) {
}
else {
$this
->messenger()
->all();
$response = new \stdClass();
$response->status = TRUE;
$response->count = Utility::cartCount();
$response->text = '<p class="messages messages--status">' . t($config
->get('added_to_cart_message')) . '</p>';
$response->id = 'ajax-addtocart-message-' . $nid;
$response->block = Utility::render('basic_cart_cart_template');
return new JsonResponse($response);
}
}