function mailchimp_ecommerce_add_cart_line in Mailchimp E-Commerce 7
Adds a line to a cart in the current Mailchimp store.
Parameters
string $cart_id: The cart ID.
string $line_id: A unique identifier for the order line item.
array $product: Associative array of product information.
- product_id (string) The unique identifier for the product.
- product_variant_id (string) The unique identifier for the variant.
- quantity (int) The quantity of a cart line item.
- price (float) The price of a cart line item.
1 call to mailchimp_ecommerce_add_cart_line()
- mailchimp_ecommerce_commerce_commerce_cart_product_add in modules/
mailchimp_ecommerce_commerce/ mailchimp_ecommerce_commerce.module - Implements hook_commerce_cart_product_add().
File
- ./
mailchimp_ecommerce.module, line 577 - Mailchimp eCommerce core functionality.
Code
function mailchimp_ecommerce_add_cart_line($cart_id, $line_id, $product) {
try {
$store_id = mailchimp_ecommerce_get_store_id();
if (empty($store_id)) {
throw new Exception('Cannot add a cart line without a store ID.');
}
if (mailchimp_ecommerce_use_queue()) {
mailchimp_ecommerce_create_queue_item([
'op' => 'addCartLine',
'cart_id' => $cart_id,
'store_id' => $store_id,
'line_id' => $line_id,
'product' => $product,
]);
}
else {
/* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
$mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
$mc_ecommerce
->addCartLine($store_id, $cart_id, $line_id, $product);
}
} catch (Exception $e) {
mailchimp_ecommerce_log_error_message('Unable to add a cart line: ' . $e
->getMessage());
mailchimp_ecommerce_show_error($e
->getMessage());
}
}