Cart::add_line_item( int $product_id, array $options = array(), int $quantity = 1, array $modifiers = array() )
Summary
No summary available.Parameters
- $product_id
-
(int) (Required) The BigCommerce ID of the product
- $options
-
(array) (Optional) All options and modifiers for the line item
Default value: array()
- $quantity
-
(int) (Optional) How many to add to the cart
Default value: 1
- $modifiers
-
(array) (Optional) Deprecated in 1.7.0, all values should be passed in $options
Default value: array()
Return
(BigCommerceApiv3ModelCart)
Source
File: src/BigCommerce/Cart/Cart.php
public function add_line_item( $product_id, $options = [], $quantity = 1, $modifiers = [] ) { $request_data = new CartRequestData(); $option_selections = []; foreach ( $options as $option_key => $option_value ) { if ( $option_value !== 0 ) { $option_selections[] = new ProductOptionSelection( [ 'option_id' => $option_key, 'option_value' => $option_value, ] ); } } /* * Kept for backwards compatibility. Modifiers are treated * the same as options when submitting a line item. */ foreach ( $modifiers as $modifier_key => $modifier_value ) { $option_selections[] = new ProductOptionSelection( [ 'option_id' => $modifier_key, 'option_value' => $modifier_value, ] ); } $request_data->setLineItems( [ new LineItemRequestData( [ 'quantity' => $quantity, 'product_id' => $product_id, 'option_selections' => $option_selections, ] ), ] ); $request_data->setGiftCertificates( [] ); return $this->add_request_to_cart( $request_data ); }