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

Doing something right before you need it - expression for this?

Is the Joker left-handed?

Blender 2.8 I can't see vertices, edges or faces in edit mode

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

How to show the equivalence between the regularized regression and their constraint formulas using KKT

How do I write bicross product symbols in latex?

What's the difference between 'rename' and 'mv'?

90's TV series where a boy goes to another dimension through portal near power lines

Is "remove commented out code" correct English?

Should I tell management that I intend to leave due to bad software development practices?

How much of data wrangling is a data scientist's job?

What exploit are these user agents trying to use?

How to model explosives?

Why are electrically insulating heatsinks so rare? Is it just cost?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

How can I tell someone that I want to be his or her friend?

I Accidentally Deleted a Stock Terminal Theme

Forgetting the musical notes while performing in concert

Will google still index a page if I use a $_SESSION variable?

I'm flying to France today and my passport expires in less than 2 months

Intersection of two sorted vectors in C++

Why does Kotter return in Welcome Back Kotter

SSH "lag" in LAN on some machines, mixed distros



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






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom: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.


























    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 2 days 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 2 days 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 2 days ago









                HelgeBHelgeB

                3,0631322




                3,0631322




















                    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

                    Sum ergo cogito? 1 nng

                    三茅街道4182Guuntc Dn precexpngmageondP