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;
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
magento-1.9 cookie
New contributor
New contributor
edited 2 days ago
Dhairya Shah
4077
4077
New contributor
asked 2 days ago
MarcinWolnyMarcinWolny
1056
1056
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered 2 days ago
HelgeBHelgeB
3,0631322
3,0631322
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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