Jump to content

Add custom price to product during 'add to cart' process


agshoward

Recommended Posts

Hi All,

 

I'm looking for methods that are better than the current solution I have. The issue I have is that I wish clients to order and customize a product, any customisations are an additional cost (in this instance $2), however on some instances of this process I see the additional fee product added and then it is automatically removed, thereby changing the price. (To demonstrate try http://www.itsapreemiething.com and look at the print on demand shirts and using the T-Shirt Wizard use any double sided setup)

 

Today, I do the following in AJAX-CART.JS, it works well enough by adding to products into the cart for the customer one of which is the custom fee product. You'll notice the product id = 80 and I do two instances of the ajaxCart.add function to get them into the cart.

 

 

var pid = 80;

var idcomb = "";

var qtywant = $('#quantity_wanted').val();

var si_customcost = " <strong>Additional Customization Ordered</strong>";

ajaxCart.add( pid, idcomb, true, null, qtywant, null, si_customcost);

var si_instructions = "<br /><strong>*** Double Sided *** </strong><br /><br /><strong>Custom Front: </strong>" + si_FBCC_F + "<br /> <strong>Front Text Color: </strong>" + si_ColourFBF + "<br /><br /> <strong>Custom Back: </strong>" + si_FBCC_B + "<br /> <strong>Back Text Color: </strong>" + si_ColourFBB;

//Additional Fee setup

//End Additional Fee setup

ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null, si_instructions);

 

So the question is???

 

Is there a better way than what I'm doing above, if the above is the only way how would I add a delay so that I can ensure that both items are added to the cart and minimize the removal piece that happens?

 

thanks

Andre

Edited by agshoward (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 1 month later...
  • 1 year later...
  • 7 years later...

You could use specificPrice in your project:

$specific_price = new SpecificPrice();

$specific_price->id_cart = (int)$this->context->cookie->id_cart;

$id_shop=(int)($this->context->cookie->id_shop);

$id_group=(int)($this->context->cookie->id_group);

$id_country=(int)($this->context->cookie->id_country);

$id_currency=(int)($this->context->cookie->id_currency);

$id_customer=(int)($this->context->cookie->id_customer);

$from_quantity = 1;



//here i saved data from front ajax controller using dbstitch class, which handles the save, get data
$stitch_data_row=DbStitch::getStitch($specific_price->id_cart);

if(!empty($stitch_data_row)){

$new_price_without_tax=$stitch_data_row['final_price'];

$id_product=$stitch_data_row['id_product'];

$id_product_attribute=$stitch_data_row['id_product_attribute'];

}



$specific_price->id_product = (int)$id_product; // choosen product id

$specific_price->id_product_attribute = (int)$id_product_attribute; // optional or set to 0

$specific_price->id_specific_price_rule = 0;

$specific_price->id_shop = $id_shop;//there is only one shop in this site

$specific_price->id_currency = $id_currency;

$specific_price->id_country = $id_country;

$specific_price->id_group = $id_group;

$specific_price->id_shop_group = $id_shop_group;

$specific_price->id_customer = $id_customer;

$specific_price->from_quantity = $from_quantity;

$specific_price->price = $new_price_without_tax;

$specific_price->reduction_type = 'amount';

$specific_price->reduction = 0;

$specific_price->reduction_tax = 1;

$specific_price->from = date("Y-m-d H:i:s");

$specific_price->to = date("Y-m-d H:i:s", strtotime('1 day')); // or set date x days from now



$is_exists=$specific_price->stitch_exists(

$id_product,

$id_product_attribute,

$id_shop,

$id_group,

$id_country,

$id_currency,

$id_customer,

$from_quantity,

date("Y-m-d H:i:s"),

date("Y-m-d H:i:s", time()+300));

if($is_exists==0)$specific_price->add();

else{

//when update, primary key is id, but not id_specific_price

$specific_price->id = $is_exists;

$specific_price->update();

}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...