Is There A Function To Change Product Price In Cart?

I add orders remotely. I need to change price of product in cart. Is there a function to change product price in cart before placing?

You add orders remotely but want to change price of items in cart? A bit confusing since an order is created from a cart and after order is created, cart is no longer used.



If you mean that you are adding items to the cart remotely in preparation for checkout and want to use a different price, then you'd need to describe HOW you are adding remotely so I could help. Generally you'd just update the product 'price' in the cart along with 'saved_price' so that your price will be maintained through recalculations.

Hi, You can hook to


fn_set_hook('pre_add_to_cart', $product_data, $cart, $auth, $update);



and change the price before is added to the cart



I hope that helps,





Valentin

[color=#808080][size=2]part of hungryweb.net[/size][/color]

Assuming he is using the fn_add_product_to_cart() function, then yes, that is one way to do it. If he's adding it manually then the hook would never be triggered. But if he's calling that function, he already has the ability to set the price in the $product_data.



But I believe a recalculation will override the price if the 'stored_price' element is not set. But I have an error above. The 'stored_price' takes a 'Y' or 'N' value, not the actual stored price. It will then leave the price alone upon calculation (or recalculation).

[color=#282828][font=arial, verdana, tahoma, sans-serif]I sell my products at an another website [/font][/color]apart from my own website. But product prices are different from my own website. [color=#282828][font=arial, verdana, tahoma, sans-serif]I am adding items to the cart remotely in preparation for checkout and want to use a different price for items in the cart. I am getting products from that another source/web site that ordered in different prices. [/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]So, I am getting and saving these orders in CS Cart. But I need to change product prices before placing.[/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]I use [/font][/color][color=#282828][font=arial, verdana, tahoma, sans-serif]fn_add_product_to_cart() function and [/font][/color][color=#282828][font=arial, verdana, tahoma, sans-serif]$product_data variable to add products to the cart.[/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]I think I need to update price after adding to cart or add price to [/font][/color][color=#282828][font=arial, verdana, tahoma, sans-serif]$product_data variables before adding to cart.[/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]Which one is correct way? And which function should I use according to the method?[/font][/color]

Just do this for each item you are adding (assuming you've already retrieved the product data for the item):


$product_data['price'] = $price_from_remote_site;
$product_data['stored_price'] = 'Y';
fn_add_product_to_cart(array($product_id =>$product_data), $cart, $auth, true);


And you should be all set. The 'stored_price' = 'Y' will force it to always use the price you specify rather than what's in the database.

I modified the code according to the info you gave. But the product price and stored_price didn't changed.



Here is the code part that I modified. Please check it. Where is my mistake?




....

$product_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE);

$product_data = array (
$product_id => array (
'product_id' => $product_data['product_id'],
'amount' => $quantity[1] || 1,
'price' => $sellerInvoiceAmount[1],
'stored_price' => 'Y'
)
);

//fn_print_r($product_data);


if ($combination) { // add option inventory info
$product_data[$product_id]['product_options'] = fn_get_product_options_by_combination($combination);
}



$cart['user_id'] = $user_data['user_id'];
$auth['user_id'] = $cart['user_id'];
$cart['user_data'] = fn_get_user_info($cart['user_id']);


$auth['referer'] = 'http://localhost/index.php?dispatch=checkout.checkout';
$auth['points'] = 0;

$cart['payment_id'] = 2;

$cart['shipping_id'] = 6;

$cart['payment_surcharge'] = 0;
$cart['chosen_shippings'] = array();
$cart['chosen_shippings'][0] = fn_get_shipping_params(6);


fn_checkout_update_shipping($cart, array(6));
fn_add_product_to_cart($product_data, $cart, $auth, true);
$cart['recalculate'] = true;
fn_save_cart_content($cart, $auth['user_id']);
$cart['change_cart_products'] = true;
fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true);

....

Have no idea what you're trying to do with this code:


$product_data = array (
$product_id => array (
'product_id' => $product_data['product_id'],
'amount' => $quantity[1] || 1,
'price' => $sellerInvoiceAmount[1],
'stored_price' => 'Y'
)
);



I would use:

$product_data = fn_get_product_data($product_id, $auth);
$product_data['price'] = $sellerInvoiceAmount[1];
$product_data['stored_price'] = 'Y';
fn_add_product_to_cart(array($product_data['product_id'] => $product_data), $cart, $auth, true);
// do this after all products are added to cart.
$cart['change_cart_products'] = true;
fn_calculate_cart_content($cart, $auth, 'S', true, 'F', true);