Executing cron tasks manually in Magento

Usually I’ve been asked about how to run a cron task manually. A cron task defined in Magento is not anything else than a function that belongs to a model that is loaded and executed. For example, we have this cron task on a config.xml file of a specific module: <catgento_sap_sync_nonimages> <schedule> <cron_expr>*/15 * * * *</cron_expr> </schedule> <run> <model>sap/cron_sync_nonimages::run</model> </run> </catgento_sap_sync_nonimages> It’s easy to identify the model and function that is being loaded and Read more…

How to use Solr as a search engine for Magento

We recently upgraded a Magento Community Edition 1.4 to a Magento Enterprise Edition 1.11. Once the upgraded was done and everything was working fine, our client started complaining about the fact that the search results where not good in comparison to the previous version they had (with Magento CE 1.4). After doing some research we found no specific reason for this: we changed the order criteria: tested it using relevance or name, but the results Read more…

Empty the cart programatically in Magento

One of the last things I had to implement in Magento was a function to empty the customer cart. At first I found this great extension made by the Inchoo people, but it did much more than I needed. Having a controller to do this is fair enough, and the only code you need to put in that controller is the following: $quote = Mage::getSingleton(‘checkout/session’)->getQuote(); $quote->delete();

How to create a custom setup script in Magento

During the past days we have had some problems when updating our Magento custom modules. Oddly, even though we created the mysql4-upgrade file and edited the config.xml with the new version, the upgrade script wouldn’t run. Why? We don’t know. But we needed a quick solution because there was an important issue in the production server. We finally decided to create a custom setup script to edit one of the attributes. So here is how Read more…

Magento search not working properly, how to improve search results?

My experience has shown me that the default Magento search is really bad, it doesn’t matter if you’re using the Community version or the Enterprise one: search results are always bad, even if you don’t have too many products in your catalogue (less than 200). Here are some tips on how to improve the search: First of all, check the search type in your backoffice (System » Configuration » Catalog » Catalog search). By default, Read more…

Browser language auto-detection in Magento

By default, Magento shows the store that has been configured «by default». Adding browser language auto-detection is pretty easy editing the Magento index.php file. We just need to check what’s the user browser main language and then try to load the store that uses that code. It’s important to note that maybe the user has already selected a preferred language before. In that case, we just check that the variable $_SERVER[‘MAGE_RUN_CODE’] is set. Make a copy Read more…

Solr: 413 Status: FULL head and Magento (hits but no results)

A few days ago we tried to install and set Solr as a Magento default search system. We run into a weird problem: once we checked that Solr was working we enabled it in Magento. Everything seemed to work well: when reindexing products the log would show the changes and the button for testing whether Solr was connected with Magento said that it all was OK. But when searching for products in Magento there were Read more…

Magento Professional Edition no longer exists

February 1st: Magento announces that Magento Professional edition will disappear (they’ll phase it out, they said). This means that people who have recently bought the professional edition have been left hanging. In our case, we have 3 clients that have recently paid for a Magento PE license and now we have to explain to them that they won’t get any updates unless they upgrade to Magento Enterprise edition. For most of them that won’t be Read more…

Programmatically update product price per website in Magento

If you want to programmatically update product prices per website (this means that you have many websites and have set a website scope for price in the configuration), then you can use this script: public function updateProductPrices ($sku, $newPrice) { Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $websites = Mage::app()->getWebsites(); $product = Mage::getModel(‘catalog/product’) $productId = $product->getIdBySku($sku); foreach ($websites as $_eachWebsite) { $_websiteId = $_eachWebsite->getWebsiteId(); $websiteObj = new Mage_Core_Model_Website(); $websiteObj->load($_websiteId); $storeIds = $websiteObj->getStoreIds(); if (count($storeIds)) { foreach ($storeIds as $_eachStoreId) { $product->setStoreId($_eachStoreId) Read more…

Adding configurable product options to category list in Magento

At this moment we’re working on 3 projects, all of them require a category list with products that are only configurable and the customer has to be able to choose the options from the configurable and add it directly to the cart without going to the product page. Step by Step How can we add all this to the product category list? Sadly it’s not that easy. The configurable.js only works with one product at Read more…