Adding a new product attribute to magento and changing the default sort by option in magento

The magento screencast on adding a new product attribute is really what would give a clear idea on adding prodcut attribute.

Step 1: Follow the screencast and add new attribute
http://www.magentocommerce.com/media/screencasts

Step 2: Since you want this attribute to be used for sorting on list view, make sure the option “Used for sorting in product listing” is set to YES.

Step 3: Add the new attribute to the required attribute set.

Step 4: Go to System > configuration > Catalog > Catalog > Frontend

Step 5: Set the “Product listing sort by” option to the new field you added.

Click on the screenshot above for details.

That’s all, save the configuration, clear cache (if enabled) and relaod the list view. You should see the new attribute.

NOTE:
If you are using a custom template /package, chances are that you may have to change the code manually to view the new sort by field in the selection list.
The code is usually located in in catalog/product/list/toolbar.phtml

Felogin logout redirect does not work

When we try to logout from an access restricted page, we will see either a 404 (Page not found) or a 401 (Authorization required) error.
This issue seems quite old, but unfortunately there are still some bugs when we use the Logout template of the felogin.

The issue is reproduceable even on Typo3 4.2.8, I am not sure if this is fixed on 4.3 onwards.

There is a patch that we can use to patch felogin as given on the following URL:
http://bugs.typo3.org/view.php?id=8677

Due to various reasons it may not always be possible to patch.
In such circumstances it is wiser to use an alternate technique, such as creating the Logout link manually.
One such example is:

[loginUser = *]  

lib.logoutbox = COA
lib.logoutbox {
    20 = TEXT
    20 {
       data = TSFE:fe_user|user|username
       # link to account edit page
       stdWrap.typolink.parameter = 60
    }
    30 = IMAGE
    30 {
        file = fileadmin/templates/images/logout.gif
        stdWrap {
             
             # Let us link to home page for logging out
             typolink.parameter = 1
             typolink.additionalParams = &logintype=logout
             wrap =  |
         }
    }
}

[end]

In this example I am displaying the logged in username (which links to user account page) followed by a working logout button.

Note:
– Here we are not using the felogin plugin.
– Do not link the logout button to any access restricted page.

The following page from Typo3wizard might be useful for displaying more user-details if needed:
http://www.typo3wizard.com/en/snippets/cool-stuff-typoscript/userinfo-for-currently-logged-in-user.html

Dividers to Tabs in Extensions

This article explains how easily we can get Tabs in the content elements of type “insert records”.

Generally we will need to edit tca.php and ext_tables.php.

To be more specific it involves adding two parameters.

1. Specify that you are using dividers to tabs “dividersstabs”
2. Mark all tabs using –div–

Let us see how.

1. Specify that you are using dividers to tabs “dividersstabs”

In the TCA array first look at the start of table definition. Generally this is located

EX:

$TCA['tx_myext_table] = array ( 
        'ctrl' => array ( 
                'title' => 'LLL:EXT:myext/locallang_db.xml:tx_myext_table, 
                'label' => 'title', 
                'tstamp' => 'tstamp', 
                'crdate' => 'crdate', 
                'cruser_id' => 'cruser_id', 
                'languageField' => 'sys_language_uid', 
                'transOrigPointerField' => 'l10n_parent', 
                'transOrigDiffSourceField' => 'l10n_diffsource', 
                'sortby' => 'sorting', 
                'delete' => 'deleted', 
                'dividers2tabs' => TRUE, 
                'enablecolumns' => array ( 
                        'disabled' => 'hidden', 
                ), 
                'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php', 
                'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_myext_table.gif', 
        ), 
);

                

In the above config you can see that ‘dividers2tabs’ is set to TRUE

2. Mark all tabs using --div--

This is the step in which you would group all fields into different Tabs. This generally involves editing the TCA config usually locatd in tca.php.

In tca.php, look the section showitem, and add --div--;Tab Name,
EX: 
'types' => array ( 
        '0' => array(
                'showitem' => '--div--;General,
                                sys_language_uid;;;;1-1-1, l10n_parent, 
                                l10n_diffsource, hidden;;1,
                                --div--;Content,title;;;;3-3-3, parentid,top_page,content,
                                --div--;Header and Footer,footer,
                                background_image,background_align'
                ) 
),

As you can see I have added 3 tabs, General, Content, Header and Footer.

The idea is to add --div--; (two hypen followed by div and two hyphen and semicolon)

After semicolon add the “Title of your tab” and followed by a comma.

This section --div--;Tab Name, must be added just before a field, or after a field ends.

That should be it.

Happy coding.

Adding search by Category feature to Magento Advanced search and catlog search in Product list view

I recently had to add a search form in the Magento product list view and I found the following Wiki article:

http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search

This article would work 100% perfect, however the steps given in article is not really upgrade safe.

There were hence two options either to include these steps in a seperate magento module, or to follow the steps I have given here.
This is not really a perfect practice, however, if we are not aware of writing a magento module then this can be a very quick alternative.
This step also protects us from our work being over-written when we make a magento upgrade.

Step 1:
Create a new folder called “Mage” inside app/code/local

Now we have anew folder app/code/local/Mage

Step 2:
If I see the steps given in Magento wiki, we notice that the they are extending the features of the CatalogSearch module that is located in the namespace Mage,
So just go to “app/code/core/Mage” and copy the entire folder named “CatalogSearch” into app/code/local/Mage

Now we have the entire “CatalogSearch” module located in app/code/local/Mage/CatalogSearch

Step 3:
Now all we need to do is follow the exact steps given in the wiki article, however make sure to edit files located in app/code/local/Mage/CatalogSearch only.

Link to the wiki: http://www.magentocommerce.com/wiki/how-to/how_to_add_search_by_category_to_advanced_search

How to add catalog search in Magento product list view or the Search by category feature in Magento product list view.

This simply involves adding a search form in prodcut list view we however need to ensure that the category id is passed to the advanced search form using a hidden input.

Add the following code to

“app\design\frontend\YOURPACKAGENAME\default\template\catalog\product\list\toolbar.phtml”
OR
“app\design\frontend\YOURPACKAGENAME\default\template\catalog\product\list.phtml”

<?php if( !isset($_GET[‘category’]) ): ?>
<form action=”<?echo $this->getUrl(‘catalogsearch/advanced/result’)?>” method=”get” id=”category_search_form”>
<?php

if ($this->helper(‘catalog/data’)->getCategory()) {
$_ccat = $this->helper(‘catalog/data’)->getCategory();
} else {
$_ccats = $this->helper(‘catalog/data’)->getProduct()->getCategoryIds();
$_ccat = Mage::getModel(‘catalog/category’)->load($_ccats[0]);
};
$_ccatID = $_ccat->getId();
?>
<input type=”hidden” id=”category_search_field” name=”category” value=”<?php echo $_ccatID ?>” />
<div class=”left”>
<input name=”name” id=”searchcat” value=”<?php echo $this->__(‘Search Category’) ?>” title=”Name” class=”input-text ” type=”text” />
<input type=”image” alt=”<?php echo $this->__(‘Search’) ?>” src=”<?php echo $this->getSkinUrl(images/ico_s_search.png’)?>” class=”cw_buttonicon” />
</div>
</form>
<script type=”text/javascript”>
//<![CDATA[
var searchForm = new Varien.searchForm(‘category_search_form’, ‘searchcat’, ‘<?php echo $this->__(‘Search Category’) ?>’);
searchForm.initAutocomplete(‘<?php echo $this->helper(‘catalogSearch’)->getSuggestUrl() ?>’, ‘search_autocomplete’);
//]]>
</script>
<?php endif ?>

Note:
1.The first if statement <?php if( !isset($_GET[‘category’]) ): ?> makes sure that we will not have two forms in the advanced search result page.
You should retain this if statement because when we are in advanced search we will no longer be in the previously selected category!

2.
You may need to change the path of search image.

3. I have also included the autocomplete feature, so be careful if you are changing the name or ID attribute of the form or the input tags.

Hope this article would be useful, kindly do not forget to write your comments here. Thank you.