How to use Cookie with Magento?
magento

How to use Cookie with Magento?

KrikaSoft
10 Sep 2014 17:07

Some time developer gets stuck with how to pass variable value from PHP to JavaScript (server side to client side). We can found a solution with cookie. Because cookie is the feature which is available at both side (PHP & JavaScript / Server side & Client side).

In Magento it has in-built JS library for cookie that his js\mage\cookies.js and for php side it has cookie model (core/cookie). So in magento we do not need to write core function for cookie.

 

How to use cookie in JS?

Set cookie value.

Mage.Cookies.set(‘somename’,’somevalue’);

Get Cookie value

Mage.Cookies.get(‘somename’);

Delete Cookie / Cleare Cookie

Mage.Cookies.clear(‘somename’);

 

How to use cookie with magento model?

Set Cookie value.

Mage::getModel(‘core/cookie’)->set(‘somename’,’somevalue’);

Get Cookie Value.

Mage::getModel(‘core/cookie’)->get(‘somename’);

Delete Cookie

Mage::getModel(‘core/cookie’)->delete(‘somename’);

Author

KrikaSoft
Hello, I'm
KrikaSoft

KrikaSoft offers innovative IT solutions and services to businesses worldwide. Specializing in Web development, Web customization, and Website design, we excel in Magento, WordPress, and other PHP frameworks. From Hybrid Application Development to seamless user experiences, trust us as your technology partner for reliable and cutting-edge solutions. Experience excellence with KrikaSoft!

Latest Post