Articles for Magento

Tweet If you ever find a need to, as a result of your custom action, display the 404 page to customer, you can do it by using the following code inside your controller class 1 2 3 $this->getResponse()->setHeader(’HTTP/1.1′,’404 Not Found’); $this->getResponse()->setHeader(’Status’,’404 File not found’); $this->_forward(’defaultNoRoute’); This way you’ll be calling the default Magento dispatcher and [...]

Tweet Suppose you want to display all the attributes of one product. You can easily get the id of the value by call the unversal method 1 $attributeValueId = $_product->getResource()->getColor(); where color is the name of the attribute. If you’ve already loaded the whole product into the variable $_product then you don’t need the getResource() [...]

Tweet Sometimes you need to get product by its attribute SKU. To do this, you can simply use following snippet and you will have Magento to load product by SKU. $productSku = ‘my-product-sku’; $_product = Mage::getModel(’catalog/product’)->load($productSku, ‘sku’);

Tweet It happens from time to time to forget Magento admin password. When it happens you should be able to recover from it with no problems. Use this simple MySQL script to reset admin password in Magento. Magento reset admin password: UPDATE admin_user SET password=CONCAT(MD5(’random_stringyour_new_password’), ‘:random_string’) WHERE username=’admin’;

Tweet Can be easily activated through couple of SQL queries. First time you can enable it by running INSERT INTO core_config_data (scope, scope_id, path, value) VALUES (’default’, 0, ‘dev/debug/template_hints’, 1), (’default’, 0, ‘dev/debug/template_hints_blocks’, 1); If you want to disable it, just run UPDATE core_config_data SET value = 0 WHERE scope = ‘default’ AND scope_id = [...]

Tweet Simple question that developers in Magento sometimes ask is: “How can I add custom attribute to customers when using Magento”. The answer is simple – it is shown in the snippet below. But before you use it lets imagine what we want to do… Lets say that we want to give discount to users [...]

Tweet So, there is a simple way to access the running Magento session from outside the installation folder. The magic happens here: 1 2 3 4 5 6 7 8 9 10 11 12 $mageFilename = realpath(‘mymagentoshop/app/Mage.php’); require_once( $mageFilename ); umask(0);   Mage::app(); Mage::getSingleton(‘core/session’, array(‘name’ => ‘frontend’)); $session = Mage::getSingleton(‘customer/session’);   if($session->isLoggedIn()) echo ‘LOGGED IN’; [...]

Tweet Suppose you have to access your Magento session from outside the Magento system (and it’s folders), and also, you want to put some relevant data into session and retrieve it on the other side. The following procedure on the Magento side will allow you to do that: 1 Mage::getSingleton(’core/session’)->setMyData(’exampleString’); where MyData is the name [...]

Magento search

In: Magento

18 Jan 2011

Tweet It is easy to use Magento search, even if outside of your Magento installation. First, we shall write a function to use Magento search: 1 2 3 4 5 6 7 8 9 10 11 function getCatalogSearch($term) { $mageFilename = realpath(’../shop/app/Mage.php’); require_once( $mageFilename ); umask(0);   // Initialize Magento Mage::app(); $search = Mage::getSingleton(’catalogsearch/advanced’)->addFilters(array(’name’ => [...]

Magento static block

In: Magento|PHP

23 Dec 2010

Tweet Have you ever wondered how to display Magento static block inside your app/store? It is an easy task, so just use following snippet. First, you have to create your static block in Magento admin, and than use its name to load it in your web application. 1 2 $block = Mage::getModel(’cms/block’)->setStoreId(Mage::app()->getStore()->getId())->load("Magento_static_block_name"); echo $block;

Make Magento Checkout Awesome