Google+

Pages

Tuesday, February 14, 2017

How to download a Magento extension directly

Note: This post is written for Magento version 1.x.x. This post does not target Magento versions 2.x.x.

Sometimes there are situations when we can't install extension via Magento Connect Manager in Magento. In such situations we may need to download the extension's files directly.

Below are some easy ways by which we can download Magento extension directly (without Magento Connect Manager):


http://connect20.magentocommerce.com/community/{PACKAGE NAME}/{VERSION}/{PACKAGE NAME}-{VERSION}.tgz

where {PACKAGE NAME} can be found from extension's key's last part and {VERSION} can be found under release notes tab on extension's page.

For example, you want to download the "Order Delivery Date" module as TGZ (.tar.gz) archive from Magento Connect.

1. Open Magento Connect page of the module: https://www.magentocommerce.com/magento-connect/order-delivery-date.html

2. Note down last release version number from the 'Release Notes' tab.

In our sample last version of the module is "0.1.9".

3. Check an Extension key for "Magento Connect 2.0".

For our module the Extension key is:
http://connect20.magentocommerce.com/community/order_delivery_date

4. Configure URL for downloading and open it in your browser: http://connect20.magentocommerce.com/community/order_delivery_date/0.1.9/order_delivery_date-0.1.9.tgz

Please try above ways and let me know if you find any trouble.

Thanks for visiting 😊

Thursday, January 12, 2017

Custom CMS field showing widget calling code in frontend in Magento

Scenario:
I added custom field for CMS pages and wanted to show its value in sidebar.

Field type: Textarea
Wysiwyg: Enabled
Field Name: content_custom

I wanted to call a widget in content of this custom field.

For reference, I added below code to call widget:

{{widget type="cms/widget_page_link" anchor_text="My Custom Link" title="My Custom Link" template="cms/widget/link/link_block.phtml" page_id="153"}}

When I tried to show field's value in frontend, it displayed content as it was inputted from cms page:

{{widget type="cms/widget_page_link" anchor_text="My Custom Link" title="My Custom Link" template="cms/widget/link/link_block.phtml" page_id="153"}}

instead of rendering its html.

Solution: To render html instead of code calling widget, use below code:

echo Mage::helper('cms')->getBlockTemplateProcessor()->filter(Mage::getBlockSingleton('cms/page')->getPage()->getContentCustom());

Please try this code and let me know if you find any problem.

Thanks for visiting.

Monday, July 4, 2016

How to add a datetime picker input field in admin module form in magento 1.x

To add a date/time input field in admin form in magento 1.x, you need to simply use code like below:

$dateFormatIso = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField(‘time_from’, ‘date’, array(
‘name’ => ‘time_from’,
‘class’ => ‘required-entry’,
‘required’ => true,
‘label’ => Mage::helper(‘event’)->__(‘Time From’),
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘input_format’ => Varien_Date::DATETIME_INTERNAL_FORMAT,
‘format’ => $dateFormatIso,
‘time’ => true, //if you don’t want time, then simply set ‘time’ => false,
));

Friday, January 1, 2016

Eliminate render-blocking JavaScript and CSS in above-the-fold content in Magento

To remove render-blocking JavaScript issue in Magento using layout xml directly simply add either <params>defer</params> or <params>defer</params> before </action> tag.

For example:

<action method="addJs"><script>prototype/prototype.js</script></action>

Replace it with following:

<action method="addJs"><script>prototype/prototype.js</script><params>defer</params></action>

or

<action method="addJs"><script>prototype/prototype.js</script><params>async</params></action>

Saturday, December 26, 2015

Delete mysql user and revoke all privileges properly in mysql

If you want to remove all the privileges and start totally from scratch do the following:

    Revoke all privileges on database level:

    REVOKE ALL PRIVILEGES ON dbname.* FROM 'username'@'hostname';

    Drop the user:

    DROP USER 'username'@'hostname';

Above procedure will entirely remove mysql user from your instance, this means you can recreate him from scratch.

Wednesday, December 16, 2015

Attribute options are not deleting in magento

It may happen due to lesser php value of max_input_variable.

To fix this problem open .htaccess file of magento's document root and write this in it:

php_value max_input_vars 2500
You can also do the same by adding/changing max_input_vars value from active php.ini of your server.
example:
max_input_vars = 2500

Thursday, September 10, 2015

Add link to category page by id from cms static block/cms page in Magento

If you want to add a link for category page from cms page or cms static block, simply use the category link widget inline link code:


{{widget type="catalog/category_widget_link" anchor_text="Displayed Text" title="Title attribute text" template="catalog/category/widget/link/link_block.phtml" id_path="category/22"}}

There is no need to add <a> tag from cms pages or static blocks.

Sunday, July 6, 2014

Magento: Set page layout on specific pages programmatically

If you want to set page layout on specific pages programmatically; for example you need to change layout from 1column.phtml to 2columns-left.phtml in some condition or so, then you need to create a simple module for it.

Steps to do so are given below:


Under app/etc/modules folder create your module's definition file (Package_Module.xml) and put this code in it:

<?xml version="1.0"?>
<config>
    <modules>
        <Package_Module>
            <codePool>local</codePool>
            <active>true</active>
        </Package_Module>
    </modules>
</config>
 
Now create config.xml file under 
app/code/local/Your/Module/etc folder and put this code in it:
 
<?xml version="1.0"?>
<config>
    <modules>
        <Package_Module>
            <version>0.1.0</version>
        </Package_Module>
    </modules> 
    <global> 
        <models>
            <module>
                <class>Package_Module_Model</class>
            </module>
        </models>
        <events> 
            <controller_action_layout_generate_blocks_after>
                <observers>
                    <any_unique_name>
                        <type>singleton</type>
                        <class>Module/Observer</class>
                        <method>controllerActionLayoutGenerateBlocksAfter</method>
                    </any_unique_name>
                </observers>
            </controller_action_layout_generate_blocks_after>
        </events>
    </global>
</config>
 
Now create Observer.php under app/code/local/Your/Module/Model folder and put this 
code in it:
 
<?php
class Package_Module_Model_Observer
{
    public function controllerActionLayoutGenerateBlocksAfter ($observer)
    {
        $controller = $observer->getAction();

        if ($controller->getFullActionName() == 'catalog_product_view') {
            $layout = $controller->getLayout();
            $rootBlock = $layout->getBlock('root');

            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                $rootBlock->setTemplate('page/1-column.html');
            } else {
                $rootBlock->setTemplate('page/2-columns.html');
            }
        }
    }
}
 
That's it. Cheers.. :) 

Friday, May 30, 2014

Magento: admin/admin in path in magento admin

Are you facing problem of getting 'admin/admin/' instead of 'admin/' in Magento admin URLs. Don't worry..

Here are some easy steps to get your admin URLs back to original.
  1. Check the values in /magentofolder/app/etc/local.xml and ensure all is good.
  2. Log in and check the values at System > configuration > Web > Unsecure URL (and Secure URL) - make sure they are good (they should be, otherwise you’d not be able to log in very easily.
  3. Go to System > configuration > Advanced > Admin and set the value of use custom admin url to 'No' and remove any values, if any, in the URL box underneath it. Then save config.
  4. If all these settings are correct, and you’re seeing admin/admin, then check:
System > Configuration > General > Web > URL options > Add store code to URL

There you must have set its value 'Yes'.

What this does is on the front end it includes the store code (actually store view code) to the URL for mutli-store setups, so that you can access a store like this : http://url/index.php/storecode1/ or http://url/index.php/storecode2/ ... etc.

But unfortunately it also does it for the admin (which has store code admin) - therefore, the path to your admin is now admin/admin - the first being the store code, the second being the path to serve the application. And so, some extensions that don’t use dynamic admin URL path won’t work - probably you’ll get a 404 where you expect your content to be in the main body of the page.

Enabling the second option in that admin (System > configuration > General > Web > URL options), i.e. "Redirect to Base URL if requested URL doesn’t match it" should fix all the problem.

If it still does not fix your problem then the last option to fix it to turn 'No' for 'Add Store Code to URLs'  option.

Hope this will help.. :)

Wednesday, May 28, 2014

How to reset admin password in Magento

If you have forgot your admin login password in Magento, there is an easy way to reset it.
Let's first find all users in 'admin_user' table.To do so, either you can view 'admin_user' table contents or fire below query:

SELECT * FROM admin_user;

Now to change password, you need to fire below query:

UPDATE `admin_user` SET `password` = CONCAT(MD5('qXpassword'), ':qX') WHERE `username` = 'USERNAME';

where 'qX' is salt value for encryption and it can be any other string and 
'USERNAME' is the desired user name for which you want to reset password.

For example:

user name is 'admin' for which you want to reset password.

Suppose after reset you want to set password 123456 and salt value you like is 'mK', 
then query to be fired will be:

UPDATE admin_user SET password=CONCAT(MD5('mK123456'), ':mK') WHERE username='admin';

Hope it will help. :)

Tuesday, June 4, 2013

Catalog Search not returning expected results in Magento

Many customers complain about Magento's default catalog search results. Here is the solution to get better results from Magento Catalog Search.

1. Copy app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php to app/code/local/Mage/CatalogSearch/Model/Resource/ folder and open file.

2. Navigate to function prepareResult() and find below set of code:

$words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
foreach ($words as $word) {
$like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
}

and replace it with:

$like[] = '`s`.`data_index` LIKE :likew';
$bind[':likew'] = '%' . $queryText . '%';

Next replace

$likeCond = '(' . join(' OR ', $like) . ')';

with

$likeCond = '(' . join(' AND ', $like) . ')';

3. Login to Admin Panel of your magento. Navigate to System --> Configuration.

4. Now click on  Catalog --> Catalog tab on left. In Catalog Search panel, set Search Type to like.

5. Just reindex all data and your store's search should be working fine now.
 
This process was tested on magento version 1.7.0 and  above.

Saturday, February 16, 2013

Magento: Redirect to login page if user not login

Here is simple magento code to redirect to login page, if user is not logged in:

<?php
    $redirect_url = Mage::getUrl('customer/account/login/');
    $current_url = Mage::helper('core/url')->getCurrentUrl();
    if((!$this->helper('customer')->isLoggedIn()) && ($current_url != $redirect_url)){
        Mage::app()->getFrontController()->getResponse()->setRedirect($redirect_url);
    }
?>

Use this code and enjoy.. :)

Wednesday, December 5, 2012

Magento: How to setup multiple currency shop

To setup Multiple currencies for magento store is very easy. To do so, just follow below steps:


1. Login to admin panel of your website.
2. Go to System --> Configuration, then select Currency Setup from General tab.



        Then select values for Base currency, Default display currency and Allowed currencies and Save Config button.



Note: Press Control key of key board while selecting multiple options from Allowed Currencies section.

Magento still does not know about currency rates for newly selected currencies. To let magento know about currency interchange rates, follow step #3.

3. Go to System --> Manage Currency --> Rates.



        Just click on Import button on top right side. Now click on Save Currency Rates button.



Note: You can provide values manually also, but it is recommended to import rates from web service.

That's all.. refresh magento cache and you are done. Now on frontend prices of products can be displayed in the currencies you configured.

Magento: How To Set Up Multiple Languages in Magento


In order to configure a different language for your store, you need to follow a simple procedure:

1. First go to http://www.magentocommerce.com/translations, where you will find various language translations packs for default Magento interface.
        Download the language pack for the desired language, extract and paste the extracted files to respective places in your Magento directory.
         or
You can install it directly by searching and installing through Magento Connect.

2. Now go to Admin Panel, then go to System --> Manage Stores.



        Click on Create Store View button.
Select Store, provide appropriate value for Name and code, and select Enabled from Status dropdown. Click on Save Store View button.

3. Now go to System --> Configuration and Select Store View (which you created in step #2).
Clicking on General tab (on left side), you will see Locale Options on right side. Select installed Language from Locale dropdown. Save Config.



and you are done. Just Clear Magento Cache Storage and see reflection on frontend of you website.

Monday, December 3, 2012

Magento: Upgrading mysql setup of module


Suppose, you are working on a module, and you need to:

* Add a new table, or
* Modify current tables, or
* Insert some default data in existing table, or
* Add/ modify some attributes

In every case, either you will
1. goto core_resource table
2. delete module's entry
3. and delete current tables of module

which is a poor solution, because sometimes, you don't have direct access to database, so you can't delete/ modify data in db in that case.
There is a simple solution for this. You can do it by simply upgrading you module version and write a new mysql upgrade file.


Suppose, you have a module named Mymodule. Its version is 0.1.1. You have the mysql setup file (mysql install file) mysql4-install-0.1.1.php in Mymodule/sql/mymodule_setup folder of your module.

You don’t need to make direct changes to database. To fulfill any of the above tasks in your module,


1) First create a new mysql upgrade file inside Mymodule/sql/mymodule_setup folder.

Let us suppose that you are going to change the version of your module from 0.1.1 to 0.1.2.

The name of mysql upgrade file should be mysql4-upgrade-0.1.1-0.1.2.php

2) Write necessary sql statements in this mysql upgrade file.

3) Now, you have to change the version in config.xml in Mymodule/etc folder as well.

Change the version like 0.1.2. Which is the new version for our module.

4) Reload your site. And you are done!


Note: The upgrade format is like mysql4-upgrade-CURRENT_VERSION-UPGRADED_VERSION.php


Enjoy.. :)

Monday, October 29, 2012

Magento: How to remove parent category path from sub category url in Magento

Hi friends,

Today I would like to tell you, how you can remove parent category path from sub category url in Magento.

To do so, Go to:
app/code/core/Mage/Catalog/Model folder and copy Url.php file to override it in your local package.

Open this file (Url.php) and find the following:
         public function getCategoryRequestPath($category, $parentPath)

With in this function, find the following code:

        if (null === $parentPath) {
            $parentPath = $this->getResource()->getCategoryParentPath($category);
        }
        elseif ($parentPath == '/') {
            $parentPath = '';
        }
and comment it like this:

 //     if (null === $parentPath) {
 //         $parentPath = $this->getResource()->getCategoryParentPath($category);
 //     }
 //     elseif ($parentPath == '/') {
            $parentPath = '';
 //       }
and save the file.

Note: It should be noted that the code $parentPath = ''; in else part should not be commented.
Now login to admin panel of your site, and go to:
System->Config->Index Management and click on "select all" then select Reindex Data from the Action Dropdown, then click on submit.

That's all.. Enjoy.. :)


Tuesday, October 23, 2012

Magento: How to view Magento version

Hi friends,

Have you faced problem when you were working on a complete customized theme and you were unable to know current magento version.

Just try this solution to find current Magento version of your website:

Create file versionTest.php parallel to index.php in root folder.
Now copy and paste following code in versionTest.php:
<?php
      include_once(‘App/Mage.php’);
      Mage::app();
      echo Mage::getVersion();
?>


Now just access this file using browser. Enjoy.. :)

Magento: Difference between Mage::getSingleton() and Mage::getModel() in Magento


Hi friends,
Some people ask about the difference between Mage::getModel() and Mage::getSingleton() in Magento.
Here is the difference between these two:

Mage::getModel('module/model') will create a new instance of the model object (if such object exists in configuration)
So if we write:
Mage::getModel('catalog/product'), it will create new instance of the object product each time. So,

$p1 = Mage::getModel('catalog/product');
$p2 = Mage::getModel('catalog/product');
Then $p1 is a one instance of product and $p2 is another instance of product.

While Mage::getSingleton('catalog/product') will create reference on existing object (if object does not exist then this method will create an instance using ::getModel() and returns reference to it).
So, if
$p1 = Mage::getSingleton('catalog/product');
$p2 = Mage::getSingleton('catalog/product');
Then $p1 and $p2 both refer to the same instance of product as reference $p2.

That's all.. Cheers.. :)

Friday, August 10, 2012

Magento: Get all related products of current product

Obviously, we can get all related products of current product by calling related.phtml. But there are many cases, in which we can not call related.phtml. For example:let us assume that we are showing two or more products on a page and we may want to show small image and name of these two products at a time.

Many other situations can be there, when we may not have option, but to write custom code to get related products of currently loaded product.

For such situations, try this code:

$collection = Mage::getModel('catalog/product_link')
                    ->getCollection()
                    ->addFieldToFilter('product_id',$product_id)
                    ->addFieldToFilter('link_type_id','1');

$related_products = $collection->getData();

This will give you list of all related products of a product.

Note: Here $product_id is the id of currently loaded product.

That's all.. Cheers.. :)

COURTESY: Mr. Neeraj Gupta (My dear Friend)

Wednesday, August 8, 2012

Magento: How to get last order id

There are many ways to get last order id:
 
1.  From checkout session:

    $lastOrderId = Mage::getSingleton('checkout/session')
                   ->getLastRealOrderId();

    $orderId = Mage::getModel('sales/order')
               ->loadByIncrementId($lastOrderId)
               ->getEntityId();


Above solution will not work, if you want to get last order id in admin.
For this you can try this solution:

2.  From model:
 

$orders = Mage::getModel('sales/order')->getCollection()
     ->setOrder('increment_id','DESC')
     ->setPageSize(1)
     ->setCurPage(1);


$orderId = $orders->getFirstItem()->getEntityId();
 

But this method will not work, if there are multi store in a single magento setup. So a better solution would be:

$orders = Mage::getModel('sales/order')->getCollection()
     ->setOrder('created_at','DESC')
     ->setPageSize(1)
     ->setCurPage(1);

$orderId = $orders->getFirstItem()->getEntityId();
 
 
That's all.. Enjoy.. :)