Magento Themes and Magento Extensions

magento check for secure unsecure urls in code

Posted on March 9th, 2013 | Posted by admin

magento check for secure unsecure urls in code
Here’s a quick way to check if you are in a secure URL, such as would happen if you have “Use Secure URLs in Frontend” enabled. This code can be placedwithin phtml files to check the URL.

if (Mage::app()->getStore()->isCurrentlySecure()) {
//you are on a secured page
else {
//normal, unsecure, http:// URL

Add Sort by “Date” to Magento Catalog Products List

Posted on March 8th, 2013 | Posted by admin

Magento has only 3 pre-defined sort methods for catalog products list, namely by Position, Name, and Price. It’s not unusual that the customers or catalog editors would want to sort the products by creation date so that the newest products are displayed at the forefront. We will make this happen in this article.

Step 1

Find file /app/code/core/Mage/Catalog/Model/Config.php and copy it to /app/code/local/Mage/Catalog/Model/Config.php. Open the copied file (open it still if it already exists before the copy) and find this function.

Add the bolded line:

public function getAttributeUsedForSortByArray()
    $options = array(
        'position'  => Mage::helper('catalog')->__('Position'),
        // This line that adds the 'Date' option to the Sort By dropdown methods.
        'created_at' => Mage::helper('catalog')->__('Date')
    foreach ($this->getAttributesUsedForSortBy() as $attribute) {
        /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
        $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();

    return $options;

Magento: Get Collection of Special Offer Products

Posted on March 7th, 2013 | Posted by admin

Magento: Get Collection of Special Offer Products

I recently had to create a collection of special offer products to list on the clients homepage. There’s a few different attributes that we need to filter to get the proper results.

1. The products visibility must NOT be set to 1. This means that the product is going to be visible individually. If we tried to link to a product that was not visible individually we might get a 404 or even worse, the mage error screen! See this post for a list of visibility options ->addAttributeToFilter(‘visibility’, array(‘neq’=>1))
2. In my case I don’t want to show products that have an empty special price field. ->addAttributeToFilter(‘special_price’, array(‘neq’=>”))
4. I want to set the number of products returned to 8. ->setPageSize(8)
5. Finally I set up my date filters.

Magento : how to set the same order increment id for all stores

Posted on March 6th, 2013 | Posted by admin

Magento in default sets different order increment id for each of you magento store or store views.
Here is simple fix to set the same order increment id for all your store.
Run the following code once from anywhere within your site.


Unit Testing & Magento’s Autoloader

Posted on March 5th, 2013 | Posted by admin

If code written for Magento is executed outside of Magento—as occurs when running unit tests—Magento’s normal startup process (which registers its autoload functionality) is not run. Without the autoloader in place, the first time PHP encounters a request to initialize a class which it doesn’t recognize, it will error out with a “class not found” error. Also, without Magento’s startup process running, PHP doesn’t know about the Mage family of singleton methods (e.g. Mage::getModel(), Mage::helper()) which are commonly used to create class instances.


Include/require (perhaps using require_once) app/Mage.php in the code you execute from outside of Magento. When Mage.php is included, the code in that file will register Magento’s autoloader with PHP. Also, Mage.php contains the method definitions for the Mage singleton methods.

Page 5 of 6« First...«23456»