wpsc_set_cart_item

Located in: cart.class.php

Functions that call this hook: set_item
Arguments Accepted: $product_id , $parameters , $this
Version Introduced: 3.8

Description: This hook is triggered just before the item gets set into the wpsc_cart_item and then added to the cart.

Code in context:
[php firstline=”822″ highlight=”835″]
/**
* Set Item method, requires a product ID and the parameters for the product
* @access public
*
* @param integer the product ID
* @param array parameters
* @return boolean true on sucess, false on failure
*/
function set_item($product_id, $parameters, $updater = false) {
// default action is adding

if(($parameters[‘quantity’] > 0) && ($this->check_remaining_quantity($product_id, $parameters[‘variation_values’], $parameters[‘quantity’]) == true)) {
$new_cart_item = new wpsc_cart_item($product_id,$parameters, $this);
do_action_ref_array( ‘wpsc_set_cart_item’ , array( $product_id , $parameters , &$this ) );
$add_item = true;
$edit_item = false;
if((count($this->cart_items) > 0) && ($new_cart_item->is_donation != 1)) {
//loop through each cart item
foreach($this->cart_items as $key => $cart_item) {
// compare product ids and variations.
if(($cart_item->product_id == $new_cart_item->product_id) &&
($cart_item->product_variations == $new_cart_item->product_variations) &&
($cart_item->custom_message == $new_cart_item->custom_message) &&
($cart_item->custom_file == $new_cart_item->custom_file)) {
// if they are the same, increment the count, and break out;
if(!$updater){
$this->cart_items[$key]->quantity += $new_cart_item->quantity;
} else {
$this->cart_items[$key]->quantity = $new_cart_item->quantity;

}
$this->cart_items[$key]->refresh_item();
$add_item = false;
$edit_item = true;
}
}

}
// if we are still adding the item, add it
if($add_item === true) {
$this->cart_items[] = $new_cart_item;
}

}

// if some action was performed, return true, otherwise, return false;
$status = false;
if(($add_item == true) || ($edit_item == true)) {
$status = true;
}
$this->cart_item_count = count($this->cart_items);
$this->clear_cache();
return $status;
}

[/php]