public function AjaxCartHelper::ajaxAddToCartAjaxResponse in Ajax Add to Cart 8
Ajax add to cart response.
Parameters
string $form_id: Form id.
object $response: Response object to store information.
Return value
object Return response object.
File
- src/
Helper/ AjaxCartHelper.php, line 178
Class
- AjaxCartHelper
- Class AjaxCartHelper.
Namespace
Drupal\ajax_add_to_cart\HelperCode
public function ajaxAddToCartAjaxResponse($form_id, $response) {
// Adding modal window.
$options = [
'width' => $this->configFactory
->get('ajax_add_to_cart.ajaxconfig')
->get('ajax_modal_width'),
'height' => $this->configFactory
->get('ajax_add_to_cart.ajaxconfig')
->get('ajax_modal_height'),
];
$title = t('Successfully Added');
$message = [
'#theme' => 'status_messages',
'#message_list' => [
'status' => $this->messenger
->deleteByType('status'),
],
];
if (!empty($this->cartBlock)) {
$response
->addCommand(new OpenModalDialogCommand($title, $message, $options));
}
else {
$customblock = $this->container
->get('plugin.manager.block')
->createInstance('commerce_cart', []);
$render = $customblock
->build();
$response
->addCommand(new OpenModalDialogCommand($title, $render, $options));
}
$response
->addCommand(new ReplaceCommand('.block-commerce-cart', $this->cartBlock));
$response
->addCommand(new ReloadCommand());
return $response;
}