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
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 16 hours ago
Dhairya Shah
4077
4077
New contributor
asked 17 hours 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 16 hours ago
HelgeBHelgeB
3,0431322
3,0431322
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