Magento - Remove tax from all products quote. (Update)












0















I saw there are some post like this but I tried that answer and dit not work.



I am learning how to use magento, and What I wan to try is remove all the tax from the cliente when them have add 3 products to the cart.



I am using an observer event. And the function it run is:



Here is the config.xml



<events>
<checkout_cart_add_product_complete> <!-- identifier of the event we want to catch -->
<observers>
<checkout_cart_add_product_complete_handler> <!-- identifier of the event handler -->
<type>model</type> <!-- class method call type; valid are model, object and singleton -->
<class>descuentoiva/observer</class> <!-- observers class alias -->
<method>addCheckout</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</checkout_cart_add_product_complete_handler>
</observers>
</checkout_cart_add_product_complete>
<events>


And this is my actual code for the fuction:



public function addCheckout(Varien_Event_Observer $observer)
{
$cart = Mage::getModel('checkout/cart')->getQuote();
if (count($cart->getAllItems()) >= 3) {
$products = $cart->getAllVisibleItems();
foreach($products as $item) {
echo $item->getPriceInclTax()."<br>";
if ($item->getTaxAmount() > 0) {
$item->setTaxPercent(0);
$item->setTaxAmount(0);
$item->setBaseTaxAmount(0);
$item->save();
}
}
$cart->save();
}
#die("patata");
}


But when I look the checkout it did not work.










share|improve this question





























    0















    I saw there are some post like this but I tried that answer and dit not work.



    I am learning how to use magento, and What I wan to try is remove all the tax from the cliente when them have add 3 products to the cart.



    I am using an observer event. And the function it run is:



    Here is the config.xml



    <events>
    <checkout_cart_add_product_complete> <!-- identifier of the event we want to catch -->
    <observers>
    <checkout_cart_add_product_complete_handler> <!-- identifier of the event handler -->
    <type>model</type> <!-- class method call type; valid are model, object and singleton -->
    <class>descuentoiva/observer</class> <!-- observers class alias -->
    <method>addCheckout</method> <!-- observer's method to be called -->
    <args></args> <!-- additional arguments passed to observer -->
    </checkout_cart_add_product_complete_handler>
    </observers>
    </checkout_cart_add_product_complete>
    <events>


    And this is my actual code for the fuction:



    public function addCheckout(Varien_Event_Observer $observer)
    {
    $cart = Mage::getModel('checkout/cart')->getQuote();
    if (count($cart->getAllItems()) >= 3) {
    $products = $cart->getAllVisibleItems();
    foreach($products as $item) {
    echo $item->getPriceInclTax()."<br>";
    if ($item->getTaxAmount() > 0) {
    $item->setTaxPercent(0);
    $item->setTaxAmount(0);
    $item->setBaseTaxAmount(0);
    $item->save();
    }
    }
    $cart->save();
    }
    #die("patata");
    }


    But when I look the checkout it did not work.










    share|improve this question



























      0












      0








      0








      I saw there are some post like this but I tried that answer and dit not work.



      I am learning how to use magento, and What I wan to try is remove all the tax from the cliente when them have add 3 products to the cart.



      I am using an observer event. And the function it run is:



      Here is the config.xml



      <events>
      <checkout_cart_add_product_complete> <!-- identifier of the event we want to catch -->
      <observers>
      <checkout_cart_add_product_complete_handler> <!-- identifier of the event handler -->
      <type>model</type> <!-- class method call type; valid are model, object and singleton -->
      <class>descuentoiva/observer</class> <!-- observers class alias -->
      <method>addCheckout</method> <!-- observer's method to be called -->
      <args></args> <!-- additional arguments passed to observer -->
      </checkout_cart_add_product_complete_handler>
      </observers>
      </checkout_cart_add_product_complete>
      <events>


      And this is my actual code for the fuction:



      public function addCheckout(Varien_Event_Observer $observer)
      {
      $cart = Mage::getModel('checkout/cart')->getQuote();
      if (count($cart->getAllItems()) >= 3) {
      $products = $cart->getAllVisibleItems();
      foreach($products as $item) {
      echo $item->getPriceInclTax()."<br>";
      if ($item->getTaxAmount() > 0) {
      $item->setTaxPercent(0);
      $item->setTaxAmount(0);
      $item->setBaseTaxAmount(0);
      $item->save();
      }
      }
      $cart->save();
      }
      #die("patata");
      }


      But when I look the checkout it did not work.










      share|improve this question
















      I saw there are some post like this but I tried that answer and dit not work.



      I am learning how to use magento, and What I wan to try is remove all the tax from the cliente when them have add 3 products to the cart.



      I am using an observer event. And the function it run is:



      Here is the config.xml



      <events>
      <checkout_cart_add_product_complete> <!-- identifier of the event we want to catch -->
      <observers>
      <checkout_cart_add_product_complete_handler> <!-- identifier of the event handler -->
      <type>model</type> <!-- class method call type; valid are model, object and singleton -->
      <class>descuentoiva/observer</class> <!-- observers class alias -->
      <method>addCheckout</method> <!-- observer's method to be called -->
      <args></args> <!-- additional arguments passed to observer -->
      </checkout_cart_add_product_complete_handler>
      </observers>
      </checkout_cart_add_product_complete>
      <events>


      And this is my actual code for the fuction:



      public function addCheckout(Varien_Event_Observer $observer)
      {
      $cart = Mage::getModel('checkout/cart')->getQuote();
      if (count($cart->getAllItems()) >= 3) {
      $products = $cart->getAllVisibleItems();
      foreach($products as $item) {
      echo $item->getPriceInclTax()."<br>";
      if ($item->getTaxAmount() > 0) {
      $item->setTaxPercent(0);
      $item->setTaxAmount(0);
      $item->setBaseTaxAmount(0);
      $item->save();
      }
      }
      $cart->save();
      }
      #die("patata");
      }


      But when I look the checkout it did not work.







      magento-1.9 code code-analysis






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      Teja Bhagavan Kollepara

      3,01241949




      3,01241949










      asked Jun 9 '16 at 11:21









      mohamet montemohamet monte

      66




      66






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You also have to config your event in config.xml. Learn here



          Now, we need to use this event checkout_cart_product_add_after and checkout_cart_product_update_after.



          In your config.xml



          <global>
          ..
          ..
          <events>
          <checkout_cart_product_add_after>
          <observers>
          <my_module_product_add_after>
          <type>singleton</type>
          <class>modulename/observer</class>
          <method>checkout_cart_product_add_after</method>
          </my_module_product_add_after>
          </observers>
          </checkout_cart_product_add_after>
          </events>
          ..
          ..
          </global>


          Now function checkout_cart_product_add_after() in model/observer.php



          public function checkout_cart_product_add_after(Varien_Event_Observer $observer)
          {
          $quote = $observer->getEvent()->getQuote();
          if (count($quote->getAllItems()) >= 3) {
          $items = $quote->getAllVisibleItems();
          foreach($items as $item) {
          $item
          ->setTaxAmount(0)
          ->setBaseTaxAmount(0)
          ->save();
          }
          }
          Mage::log('my log', null, 'my-log.log'); //creates log file if this function is called
          }


          This will set tax to 0 for all items that are in cart. You would want to check sales_flat_quote_item table.



          Because you would also want to check this event on item update on cart, so you have to set another event for this checkout_cart_product_update_after.



          you can call same function for this event too.



          I haven't tested, but this should work.






          share|improve this answer


























          • I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

            – mohamet monte
            Jun 9 '16 at 12:36











          • It did not work Adarsh

            – mohamet monte
            Jun 10 '16 at 7:09











          • Any error? And did it create a log fine called my-log?

            – Adarsh Khatri
            Jun 10 '16 at 7:28











          • Yes it create the log

            – mohamet monte
            Jun 10 '16 at 7:39













          • Check your var/log folder

            – Adarsh Khatri
            Jun 10 '16 at 7:43












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f120158%2fmagento-remove-tax-from-all-products-quote-update%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You also have to config your event in config.xml. Learn here



          Now, we need to use this event checkout_cart_product_add_after and checkout_cart_product_update_after.



          In your config.xml



          <global>
          ..
          ..
          <events>
          <checkout_cart_product_add_after>
          <observers>
          <my_module_product_add_after>
          <type>singleton</type>
          <class>modulename/observer</class>
          <method>checkout_cart_product_add_after</method>
          </my_module_product_add_after>
          </observers>
          </checkout_cart_product_add_after>
          </events>
          ..
          ..
          </global>


          Now function checkout_cart_product_add_after() in model/observer.php



          public function checkout_cart_product_add_after(Varien_Event_Observer $observer)
          {
          $quote = $observer->getEvent()->getQuote();
          if (count($quote->getAllItems()) >= 3) {
          $items = $quote->getAllVisibleItems();
          foreach($items as $item) {
          $item
          ->setTaxAmount(0)
          ->setBaseTaxAmount(0)
          ->save();
          }
          }
          Mage::log('my log', null, 'my-log.log'); //creates log file if this function is called
          }


          This will set tax to 0 for all items that are in cart. You would want to check sales_flat_quote_item table.



          Because you would also want to check this event on item update on cart, so you have to set another event for this checkout_cart_product_update_after.



          you can call same function for this event too.



          I haven't tested, but this should work.






          share|improve this answer


























          • I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

            – mohamet monte
            Jun 9 '16 at 12:36











          • It did not work Adarsh

            – mohamet monte
            Jun 10 '16 at 7:09











          • Any error? And did it create a log fine called my-log?

            – Adarsh Khatri
            Jun 10 '16 at 7:28











          • Yes it create the log

            – mohamet monte
            Jun 10 '16 at 7:39













          • Check your var/log folder

            – Adarsh Khatri
            Jun 10 '16 at 7:43
















          0














          You also have to config your event in config.xml. Learn here



          Now, we need to use this event checkout_cart_product_add_after and checkout_cart_product_update_after.



          In your config.xml



          <global>
          ..
          ..
          <events>
          <checkout_cart_product_add_after>
          <observers>
          <my_module_product_add_after>
          <type>singleton</type>
          <class>modulename/observer</class>
          <method>checkout_cart_product_add_after</method>
          </my_module_product_add_after>
          </observers>
          </checkout_cart_product_add_after>
          </events>
          ..
          ..
          </global>


          Now function checkout_cart_product_add_after() in model/observer.php



          public function checkout_cart_product_add_after(Varien_Event_Observer $observer)
          {
          $quote = $observer->getEvent()->getQuote();
          if (count($quote->getAllItems()) >= 3) {
          $items = $quote->getAllVisibleItems();
          foreach($items as $item) {
          $item
          ->setTaxAmount(0)
          ->setBaseTaxAmount(0)
          ->save();
          }
          }
          Mage::log('my log', null, 'my-log.log'); //creates log file if this function is called
          }


          This will set tax to 0 for all items that are in cart. You would want to check sales_flat_quote_item table.



          Because you would also want to check this event on item update on cart, so you have to set another event for this checkout_cart_product_update_after.



          you can call same function for this event too.



          I haven't tested, but this should work.






          share|improve this answer


























          • I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

            – mohamet monte
            Jun 9 '16 at 12:36











          • It did not work Adarsh

            – mohamet monte
            Jun 10 '16 at 7:09











          • Any error? And did it create a log fine called my-log?

            – Adarsh Khatri
            Jun 10 '16 at 7:28











          • Yes it create the log

            – mohamet monte
            Jun 10 '16 at 7:39













          • Check your var/log folder

            – Adarsh Khatri
            Jun 10 '16 at 7:43














          0












          0








          0







          You also have to config your event in config.xml. Learn here



          Now, we need to use this event checkout_cart_product_add_after and checkout_cart_product_update_after.



          In your config.xml



          <global>
          ..
          ..
          <events>
          <checkout_cart_product_add_after>
          <observers>
          <my_module_product_add_after>
          <type>singleton</type>
          <class>modulename/observer</class>
          <method>checkout_cart_product_add_after</method>
          </my_module_product_add_after>
          </observers>
          </checkout_cart_product_add_after>
          </events>
          ..
          ..
          </global>


          Now function checkout_cart_product_add_after() in model/observer.php



          public function checkout_cart_product_add_after(Varien_Event_Observer $observer)
          {
          $quote = $observer->getEvent()->getQuote();
          if (count($quote->getAllItems()) >= 3) {
          $items = $quote->getAllVisibleItems();
          foreach($items as $item) {
          $item
          ->setTaxAmount(0)
          ->setBaseTaxAmount(0)
          ->save();
          }
          }
          Mage::log('my log', null, 'my-log.log'); //creates log file if this function is called
          }


          This will set tax to 0 for all items that are in cart. You would want to check sales_flat_quote_item table.



          Because you would also want to check this event on item update on cart, so you have to set another event for this checkout_cart_product_update_after.



          you can call same function for this event too.



          I haven't tested, but this should work.






          share|improve this answer















          You also have to config your event in config.xml. Learn here



          Now, we need to use this event checkout_cart_product_add_after and checkout_cart_product_update_after.



          In your config.xml



          <global>
          ..
          ..
          <events>
          <checkout_cart_product_add_after>
          <observers>
          <my_module_product_add_after>
          <type>singleton</type>
          <class>modulename/observer</class>
          <method>checkout_cart_product_add_after</method>
          </my_module_product_add_after>
          </observers>
          </checkout_cart_product_add_after>
          </events>
          ..
          ..
          </global>


          Now function checkout_cart_product_add_after() in model/observer.php



          public function checkout_cart_product_add_after(Varien_Event_Observer $observer)
          {
          $quote = $observer->getEvent()->getQuote();
          if (count($quote->getAllItems()) >= 3) {
          $items = $quote->getAllVisibleItems();
          foreach($items as $item) {
          $item
          ->setTaxAmount(0)
          ->setBaseTaxAmount(0)
          ->save();
          }
          }
          Mage::log('my log', null, 'my-log.log'); //creates log file if this function is called
          }


          This will set tax to 0 for all items that are in cart. You would want to check sales_flat_quote_item table.



          Because you would also want to check this event on item update on cart, so you have to set another event for this checkout_cart_product_update_after.



          you can call same function for this event too.



          I haven't tested, but this should work.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 13 '17 at 12:55









          Community

          1




          1










          answered Jun 9 '16 at 12:10









          Adarsh KhatriAdarsh Khatri

          6,78511644




          6,78511644













          • I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

            – mohamet monte
            Jun 9 '16 at 12:36











          • It did not work Adarsh

            – mohamet monte
            Jun 10 '16 at 7:09











          • Any error? And did it create a log fine called my-log?

            – Adarsh Khatri
            Jun 10 '16 at 7:28











          • Yes it create the log

            – mohamet monte
            Jun 10 '16 at 7:39













          • Check your var/log folder

            – Adarsh Khatri
            Jun 10 '16 at 7:43



















          • I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

            – mohamet monte
            Jun 9 '16 at 12:36











          • It did not work Adarsh

            – mohamet monte
            Jun 10 '16 at 7:09











          • Any error? And did it create a log fine called my-log?

            – Adarsh Khatri
            Jun 10 '16 at 7:28











          • Yes it create the log

            – mohamet monte
            Jun 10 '16 at 7:39













          • Check your var/log folder

            – Adarsh Khatri
            Jun 10 '16 at 7:43

















          I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

          – mohamet monte
          Jun 9 '16 at 12:36





          I will try but I thinked that prove i done and dit not work. And config.xml is configured. When I use again my own computer I will update all data with config.xml and the prove. Ty Adarsh

          – mohamet monte
          Jun 9 '16 at 12:36













          It did not work Adarsh

          – mohamet monte
          Jun 10 '16 at 7:09





          It did not work Adarsh

          – mohamet monte
          Jun 10 '16 at 7:09













          Any error? And did it create a log fine called my-log?

          – Adarsh Khatri
          Jun 10 '16 at 7:28





          Any error? And did it create a log fine called my-log?

          – Adarsh Khatri
          Jun 10 '16 at 7:28













          Yes it create the log

          – mohamet monte
          Jun 10 '16 at 7:39







          Yes it create the log

          – mohamet monte
          Jun 10 '16 at 7:39















          Check your var/log folder

          – Adarsh Khatri
          Jun 10 '16 at 7:43





          Check your var/log folder

          – Adarsh Khatri
          Jun 10 '16 at 7:43


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f120158%2fmagento-remove-tax-from-all-products-quote-update%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Berlina muro

          Last logged in always never, not logging

          Berlina aerponto