Magento: How to check if current page is homepage?

Here is a quick Magento code to check if the current page is homepage or not. If you are in template/page/html/header.phtml template file, then you can check for homepage with the following code: if($this->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } If you are elsewhere (in … Read more

Magento: Join, filter, select and sort attributes, fields and tables

In my previous article (Magento: Very Useful Collection Functions), I had written about database interaction functions present in class Varien_Data_Collection_Db. Here, I am going to explain some database interaction functions present in the class Mage_Eav_Model_Entity_Collection_Abstract. These collection functions are very useful to select data from Magento database. We need them almost all the time for … Read more

Magento: Convert Price from Current Currency to Base Currency and vice-versa

Here is a quick code to convert price amount from current currency of the shop to base currency. This is applicable when you have a multiple currency shop. From the code below, you can convert any currency you desire. You just need the ‘From Currency Code’ and ‘To Currency Code’. In the example below, I … Read more

PHP: How to get stock quote data from Yahoo! Finance? (Complete Code and Tutorial)

In this tutorial, I will be showing you how you can fetch any company’s data from Yahoo! Finance. INTRODUCTION First of all, let us see the stock quote data of top tech companies on Yahoo! Finance. View the basic Google stock chart on Yahoo! Finance: http://finance.yahoo.com/q?s=goog For eBay: http://finance.yahoo.com/q?s=EBAY For Amazon: http://finance.yahoo.com/q?s=AMZN For Apple: http://finance.yahoo.com/q?s=AAPL … Read more

PHP: Read Write CSV

In this article, I will be showing you how to read and write CSV file with PHP. I have used PHP function fgetcsv to read CSV fields and fputcsv to write on CSV file. fgetcsv — Gets line from file pointer and parse for CSV fields. fgetcsv() parses the line it reads for fields in … Read more

PHP: How to get Main or Base URL?

Suppose you are on a page : http://example.com/category/php/ Now, the base URL or the main URL for the above link is : http://example.com Similarly, in the case of local machine (localhost), Suppose you are in the page : http://localhost/myproject/index.php?id=8 Here, the base or main URL is : http://localhost/myproject Below is the code to get main … Read more

Magento: Get list of all Categories

Here, I will show you how you can get list of all categories of your Magento Shop. You might want to display all categories in homepage or any CMS page. There are different ways to get the category listing. Here are some:- Get all categories The following code will fetch all categories (both active and … Read more

Magento: How to change default page layout?

Here, I will show you how you can change the default page layout in Magento. By page layout, I mean all CMS page, category page, etc. There are different ways to change the page layout in Magento. Here are some of them:- Changing individual category page layout You can modify the page layout of each … Read more