How to set a cookie on add to cart and remove it when cart is empty?Setting cookie on loginErratic cookie-related login problemChrome and SSL: problem with login and cartCan't login to second store on subdomainShopping Cart total percentage discount when specific item is in cartMagento customer login and admin login session/cookie issueRWD mini-cart: How to reload cart page if product removed via mini cart?Customer can't log in - redirect to login pageset and get cookie in same functionmultistore customer login and add to cart failsMagento 1.9 soap API : Totals and subtotals always equal 0 after adding products to cart

Does int main() need a declaration on C++?

Does marriage to a non-Numenorean disqualify a candidate for the crown of Gondor?

What is the most common color to indicate the input-field is disabled?

Implication of namely

Can someone clarify Hamming's notion of important problems in relation to modern academia?

Blending or harmonizing

How to stretch the corners of this image so that it looks like a perfect rectangle?

What Exploit Are These User Agents Trying to Use?

Are British MPs missing the point, with these 'Indicative Votes'?

Finding the reason behind the value of the integral.

How can a day be of 24 hours?

If a warlock makes a Dancing Sword their pact weapon, is there a way to prevent it from disappearing if it's farther away for more than a minute?

What is the opposite of "eschatology"?

What historical events would have to change in order to make 19th century "steampunk" technology possible?

How obscure is the use of 令 in 令和?

In the UK, is it possible to get a referendum by a court decision?

Send out email when Apex Queueable fails and test it

What is an equivalently powerful replacement spell for the Yuan-Ti's Suggestion spell?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

Where would I need my direct neural interface to be implanted?

Machine learning testing data

Is it a bad idea to plug the other end of ESD strap to wall ground?

Notepad++ delete until colon for every line with replace all

How do I exit BASH while loop using modulus operator?



How to set a cookie on add to cart and remove it when cart is empty?


Setting cookie on loginErratic cookie-related login problemChrome and SSL: problem with login and cartCan't login to second store on subdomainShopping Cart total percentage discount when specific item is in cartMagento customer login and admin login session/cookie issueRWD mini-cart: How to reload cart page if product removed via mini cart?Customer can't log in - redirect to login pageset and get cookie in same functionmultistore customer login and add to cart failsMagento 1.9 soap API : Totals and subtotals always equal 0 after adding products to cart













0















As in title - I'd like to set a cookie when any product is added to the cart and remove it if cart is empty.



I found a somewhat similar answer for setting cookies on login, which is perfect, cause I'd like to do that as well, but have no clue how to set equivalent for chart items (I'm new to Magento).



version 1.9.2.4










share|improve this question









New contributor




MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    0















    As in title - I'd like to set a cookie when any product is added to the cart and remove it if cart is empty.



    I found a somewhat similar answer for setting cookies on login, which is perfect, cause I'd like to do that as well, but have no clue how to set equivalent for chart items (I'm new to Magento).



    version 1.9.2.4










    share|improve this question









    New contributor




    MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      As in title - I'd like to set a cookie when any product is added to the cart and remove it if cart is empty.



      I found a somewhat similar answer for setting cookies on login, which is perfect, cause I'd like to do that as well, but have no clue how to set equivalent for chart items (I'm new to Magento).



      version 1.9.2.4










      share|improve this question









      New contributor




      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      As in title - I'd like to set a cookie when any product is added to the cart and remove it if cart is empty.



      I found a somewhat similar answer for setting cookies on login, which is perfect, cause I'd like to do that as well, but have no clue how to set equivalent for chart items (I'm new to Magento).



      version 1.9.2.4







      magento-1.9 cookie






      share|improve this question









      New contributor




      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 16 hours ago









      Dhairya Shah

      4077




      4077






      New contributor




      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 17 hours ago









      MarcinWolnyMarcinWolny

      1056




      1056




      New contributor




      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      MarcinWolny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use the event controller_front_send_response_before in the frontend area, check if there are items in cart (using the checkout/cart helper) and set or delete cookie. A possible function for that observer could be the following:



          public function setCartDataCookie($observer)

          $cookieName = "YOUR_COOKIE_NAME";
          $cookie = Mage::getSingleton("core/cookie");
          $cookieData = $cookie->get($cookieName);

          $cart = Mage::helper('checkout/cart')->getItemsQty();

          if ($cart > 0)
          //set cookie, when items are in cart
          $cookie->set($cookieName,"YOUR DATA");
          else
          //cart is empty -> remove cookie
          if ($cookieData)
          $cookie->delete($cookieName);





          If you need data about the cart items in the cookie you may use Mage::helper('checkout/cart')->getQuote()->getAllVisibleItems() to get that information.






          share|improve this answer























            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
            );



            );






            MarcinWolny is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f268297%2fhow-to-set-a-cookie-on-add-to-cart-and-remove-it-when-cart-is-empty%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 can use the event controller_front_send_response_before in the frontend area, check if there are items in cart (using the checkout/cart helper) and set or delete cookie. A possible function for that observer could be the following:



            public function setCartDataCookie($observer)

            $cookieName = "YOUR_COOKIE_NAME";
            $cookie = Mage::getSingleton("core/cookie");
            $cookieData = $cookie->get($cookieName);

            $cart = Mage::helper('checkout/cart')->getItemsQty();

            if ($cart > 0)
            //set cookie, when items are in cart
            $cookie->set($cookieName,"YOUR DATA");
            else
            //cart is empty -> remove cookie
            if ($cookieData)
            $cookie->delete($cookieName);





            If you need data about the cart items in the cookie you may use Mage::helper('checkout/cart')->getQuote()->getAllVisibleItems() to get that information.






            share|improve this answer



























              0














              You can use the event controller_front_send_response_before in the frontend area, check if there are items in cart (using the checkout/cart helper) and set or delete cookie. A possible function for that observer could be the following:



              public function setCartDataCookie($observer)

              $cookieName = "YOUR_COOKIE_NAME";
              $cookie = Mage::getSingleton("core/cookie");
              $cookieData = $cookie->get($cookieName);

              $cart = Mage::helper('checkout/cart')->getItemsQty();

              if ($cart > 0)
              //set cookie, when items are in cart
              $cookie->set($cookieName,"YOUR DATA");
              else
              //cart is empty -> remove cookie
              if ($cookieData)
              $cookie->delete($cookieName);





              If you need data about the cart items in the cookie you may use Mage::helper('checkout/cart')->getQuote()->getAllVisibleItems() to get that information.






              share|improve this answer

























                0












                0








                0







                You can use the event controller_front_send_response_before in the frontend area, check if there are items in cart (using the checkout/cart helper) and set or delete cookie. A possible function for that observer could be the following:



                public function setCartDataCookie($observer)

                $cookieName = "YOUR_COOKIE_NAME";
                $cookie = Mage::getSingleton("core/cookie");
                $cookieData = $cookie->get($cookieName);

                $cart = Mage::helper('checkout/cart')->getItemsQty();

                if ($cart > 0)
                //set cookie, when items are in cart
                $cookie->set($cookieName,"YOUR DATA");
                else
                //cart is empty -> remove cookie
                if ($cookieData)
                $cookie->delete($cookieName);





                If you need data about the cart items in the cookie you may use Mage::helper('checkout/cart')->getQuote()->getAllVisibleItems() to get that information.






                share|improve this answer













                You can use the event controller_front_send_response_before in the frontend area, check if there are items in cart (using the checkout/cart helper) and set or delete cookie. A possible function for that observer could be the following:



                public function setCartDataCookie($observer)

                $cookieName = "YOUR_COOKIE_NAME";
                $cookie = Mage::getSingleton("core/cookie");
                $cookieData = $cookie->get($cookieName);

                $cart = Mage::helper('checkout/cart')->getItemsQty();

                if ($cart > 0)
                //set cookie, when items are in cart
                $cookie->set($cookieName,"YOUR DATA");
                else
                //cart is empty -> remove cookie
                if ($cookieData)
                $cookie->delete($cookieName);





                If you need data about the cart items in the cookie you may use Mage::helper('checkout/cart')->getQuote()->getAllVisibleItems() to get that information.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 16 hours ago









                HelgeBHelgeB

                3,0431322




                3,0431322




















                    MarcinWolny is a new contributor. Be nice, and check out our Code of Conduct.









                    draft saved

                    draft discarded


















                    MarcinWolny is a new contributor. Be nice, and check out our Code of Conduct.












                    MarcinWolny is a new contributor. Be nice, and check out our Code of Conduct.











                    MarcinWolny is a new contributor. Be nice, and check out our Code of Conduct.














                    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%2f268297%2fhow-to-set-a-cookie-on-add-to-cart-and-remove-it-when-cart-is-empty%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?