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 that [...]
In: Magento
9 Feb 2011So, 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’; else [...]
In: Magento
1 Feb 2011Suppose 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 of [...]
In: Magento
18 Jan 2011It 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’ => $term)); [...]
In: Magento
24 Dec 2010When creating a Magento theme, one has to worry about all aspects. Some of the most important things when creating a theme is personalization. In order to personalize your website for a current user, you can do various things, but most important one is knowing your clients name. So, in order to get customer name [...]
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;
Before reading this article it is advised to read “How to run Magento in WordPress“, as it could help you overcome some basic problems that might emerge. This snippet shows you how to get Magento categories and show them in WordPress so you can use them as a menu. Copy following snippet into your WordPress [...]
In: Magento
19 Oct 2010If you are using a Magento and you want to know what is the current category in order to show it to your user, you can do it by using following snippet. 1 2 3 4 5 6 //if there is no current category return if(!Mage::registry(’current_category’)) return; //if current category is defined $magentoCurrentCategory = [...]
Many developers like combining Magento and WordPress, and there is many more out there that would like to. All snippets showing how to grab data from Magento don’t warn you that there is the function in Magento core that has the same name as WordPress function for translation “__()”. For this reason it is not [...]
Magento does not come with an option to actually delete existing order. You can “Cancel” it or put it on “Hold”, but not delete it for good. Lucky for us – there is a way to make Magento delete order by using a simple MySQL snippet. 1 2 3 4 SET @increment_id=’4400000002′; –replace with your [...]