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

                    Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

                    Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form