Jump to content

Custom add to cart with tax


Recommended Posts

Hi there,

 

I have a giftcard module and when a giftcard is customized and added to cart the tax is not included in the total price..

 

This is the code to add product to cart:

$card = new GiftCardProduct ( (int)Tools::getValue ( 'id_product' ) );

/* add new card if not exist */
if (! $this->context->cart->id)
{
	if (Context::getContext ()->cookie->id_guest)
	{
	       $guest = new Guest ( Context::getContext ()->cookie->id_guest );
	       $this->context->cart->mobile_theme = $guest->mobile_theme;
	}
	$this->context->cart->add ();
	if ($this->context->cart->id)
		$this->context->cookie->id_cart = (int)$this->context->cart->id;
	}
}
$this->context->cart->addTextFieldToProduct ( $card->id, $id_cfield_from, Product::CUSTOMIZE_TEXTFIELD, $from );
$this->context->cart->addTextFieldToProduct ( $card->id, $id_cfield_lastname, Product::CUSTOMIZE_TEXTFIELD, $lastname );
$this->context->cart->addTextFieldToProduct ( $card->id, $id_cfield_message, Product::CUSTOMIZE_TEXTFIELD, $message );
$this->context->cart->addTextFieldToProduct ( $card->id, $id_cfield_template, Product::CUSTOMIZE_TEXTFIELD, $template_id );
$this->context->cart->addTextFieldToProduct ( $card->id, $id_cfield_mailto, Product::CUSTOMIZE_TEXTFIELD, $mailto );
$this->context->cart->addTextFieldToProduct ( $card->id, $id_cfield_deliverydate, Product::CUSTOMIZE_TEXTFIELD, $delivery_date );
$update_quantity = $this->context->cart->updateQty ( 1, $card->id );

There is no documentation about adding tax programatically so please help!
How can I add tax to it ?
 
Link to comment
Share on other sites

thanks for the reply Scully,

 

Could you please suggest some examples of handling the taxes code ? I am affraid the misconfiguration is not the issue here , as I've debuged custom products and all the related values to tax are the same...

 

I am asking for examples as the core code is very unfamilliar...

Link to comment
Share on other sites

Maybe first set the tax method

 

protected $_taxCalculationMethod = PS_TAX_EXC;
 

and then call

 

setTaxCalculationMethod

and

getCartRules

 

from Cart class. Not tested. But the main goal for your approach is: you shouln't need to calculate prices or taxes on your own but call the related methods.

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...