How do I save value in my own session variable in Magento?

Let’s say you want to save the value “Hello world” to the “welcome message” variable in the session. The code would be : $inputMessage=”Hello World”; Mage::getSingleton(‘core/session’)->setWelcomeMessage($inputMessage); Now you want to echo the “welcome message” somewhere else in your code/site. $outputMessage = Mage::getSingleton(‘core/session’)->getWelcomeMessage(); echo $this->__($outputMessage);

ALTER TABLE in Magento setup script without using SQL

You can use such methods within your setup script: Use Varien_Db_Ddl_Table class to create new tables, where you can configure all the fields, keys, relations in combination with $this->getConnection()->createTable($tableObject) Example: /* @var $this Mage_Core_Model_Resource_Setup */ $table = new Varien_Db_Ddl_Table(); $table->setName($this->getTable(‘module/table’)); $table->addColumn(‘id’, Varien_Db_Ddl_Table::TYPE_INT, 10, array(‘unsigned’ => true, ‘primary’ => true)); $table->addColumn(‘name’, Varien_Db_Ddl_Table::TYPE_VARCHAR, 255); $table->addIndex(‘name’, ‘name’); $table->setOption(‘type’, … Read more

Where are Magento’s log files located?

You can find them in /var/log within your root Magento installation There will usually be two files by default, exception.log and system.log. If the directories or files don’t exist, create them and give them the correct permissions, then enable logging within Magento by going to System > Configuration > Developer > Log Settings > Enabled … Read more

Current user in Magento?

Found under “app/code/core/Mage/Page/Block/Html/Header.php”: public function getWelcome() { if (empty($this->_data[‘welcome’])) { if (Mage::app()->isInstalled() && Mage::getSingleton(‘customer/session’)->isLoggedIn()) { $this->_data[‘welcome’] = $this->__(‘Welcome, %s!’, Mage::getSingleton(‘customer/session’)->getCustomer()->getName()); } else { $this->_data[‘welcome’] = Mage::getStoreConfig(‘design/header/welcome’); } } return $this->_data[‘welcome’]; } So it looks like Mage::getSingleton(‘customer/session’)->getCustomer() will get your current logged in customer 😉 To get the currently logged in admin: Mage::getSingleton(‘admin/session’)->getUser();

Programmatically add product to cart with price change

After digging a bit into Magento’s core code, I found that you need to use $item->getProduct()->setIsSuperMode(true) in order to make $item->setCustomPrice() and $item->setOriginalPrice() work. Here is some sample code you can use within an Observer that listens for the checkout_cart_product_add_after or checkout_cart_update_items_after events. The code is logically the same except checkout_cart_product_add_after is called for only … Read more

How to get data from Magento System Configuration

$configValue = Mage::getStoreConfig(‘sectionName/groupName/fieldName’); sectionName, groupName and fieldName are present in etc/system.xml file of your module. The above code will automatically fetch config value of currently viewed store. If you want to fetch config value of any other store than the currently viewed store then you can specify store ID as the second parameter to the … Read more

“Error 404 Not Found” in Magento Admin Login Page [closed]

Finally, I found the solution to my problem. I looked into the Magento system log file (var/log/system.log). There I saw the exact error. The error is as below:- Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website, null given, called in YOUR_PATH\app\code\core\Mage\Core\Model\App.php on line 555 and defined in YOUR_PATH\app\code\core\Mage\Core\Model\Store.php on line … Read more

Apache: edit to .conf file produces “Invalid command ‘Header'”

In order to use Header directive in apache you have to load mod_header module. You can test if module is loaded or not by :- apache2ctl -M | grep headers_module find / -name mod_headers.so If it is loaded you will see something like :- headers_module (shared) /usr/lib/apache2/modules/mod_headers.so If you see no output of find command … Read more