vlasin Posted August 14, 2017 Share Posted August 14, 2017 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 More sharing options...
Scully Posted August 15, 2017 Share Posted August 15, 2017 I'd guess some misconfiguration with your products tax since the code above does not handle taxes nor any other kind of pricing information. Link to comment Share on other sites More sharing options...
vlasin Posted August 16, 2017 Author Share Posted August 16, 2017 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 More sharing options...
Scully Posted August 16, 2017 Share Posted August 16, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now