Monday 28 November 2011

Add Date field with Datepicker in Magento Contact Form

Magento has a built in library for calendar functionalities. However the calendar library is available only on Admin pages like Custom Module, Customer Account view page, etc. We can extend the prototype Javascript library's calendar functions to frontend.

Edit the page.xml file in your current theme in the directory app/design/frontend/default/your-theme/layout/page.xml Around line 61 add the below lines in between

 
js_csscalendar/calendar-win2k-1.css
jscalendar/calendar.js
jscalendar/calendar-setup.js

This will include the calendar library functions in the page head of all front end pages.

Now add Date Field to your contact form

Next step would be to add Javascript code at bottom of contact form template file. The id of the date input field and calendar image should be the same. The javascript code shown below should be added below the contact form coding.


Sunday 27 November 2011

Magento Product Question

You wish to give users the option to quickly ask a question about a particular product then this simple extension will do the trick. This will present the user with a contact form with the product in question liked to at the top. You can download extension from here

Install the extension in the normal manner. To add the question you will need to edit your product page. Add the following where you wish to code to appear.

/app/design/frontend/default/your_theme/template/catalog/product/view.phtml

<?php if(Mage::getStoreConfigFlag('productquestion/productquestion/enabled')):
$url = $this->helper("productquestion")->getAddUrl($_product);
?>
        <?php echo $this->__('Ask a question about this product') ?>
 <?php endif; ?>

Tuesday 15 November 2011

Magento: Getting product attributes values and labels

I have found that it is very useful to be able to get attributes from the system and use them in places other than a products category page. This is how to get a drop down lists options. I don't think it will work for a mulit-select attribute. I stick the value/label pairs into an array to use how I please.
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id');

foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
 $attributeArray[$option['value']] = $option['label'];
}
I had a trickier time getting values for a multi-select attribute. I don't think that this is the best method, but it is one that worked for me. First the multi-select attribute must be set to be used in the advanced search. You can set this in the manage attributes area.
$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes();
$attributeArray=array();

foreach($attributes as $a){
 if($a->getAttributeCode() == 'desired_attribute_code'){
  foreach($a->getSource()->getAllOptions(false) as $option){
   $attributeArray[$option['value']] = $option['label'];
  }
 }
}
Here is a better way to get the multi-select attribute values.
$attributeId = Mage::getResourceModel('eav/entity_attribute')
->getIdByCode('catalog_product','attribute_code_here');

$attribute = Mage::getModel('catalog/resource_eav_attribute')
->load($attributeId);

$attributeOptions = $attribute ->getSource()->getAllOptions();
If you only need to retrieve a value for a product you can try this way
//Referenced from /app/code/core/Mage/Eav/Model/Config/php @ line 443
$_product->getResource()->getAttribute('club_type')
->getFrontend()->getValue($_product)
The code below will get an attribure collection. Set {entityType} to 4 to get attributes for products. You can remove the "setCodeFilters" line if you want to get all the attributes. To get anything really useful you will probably need to get the resulting attribute ids and do someting with them, like use them in a filter for the products collection or something.
$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter({entityType})
->setCodeFilter($attributes)
->addSetInfo()
->getData();

Delete an attribute associated with a configurable product?

Go to table catalog_product_super_attribute and search with the condition
product_id= < "id of your configurable product">.
This will list all the attributes associated with this particular configurable product. Find the record with the corresponding attribute_id and delete it.

Monday 14 November 2011

Magento – Get URL Paths for Skin, Media, JS, Base & Store URL

Tips to get Magento URL paths of skin, Media, JS, Base and Store URL in CMS pages for Magento customization or programming. How we can retrieve URL path from static blocks in CMS, PHP and phtml pages


To Retrieve URL path in STATIC BLOCK
To get SKIN URL
{{skin url='images/sampleimage.jpg '}}
To get Media URL
{{media url='/sampleimage.jpg'}}
To get Store URL
{{store url='mypage.html'}}
To get Base URL
{{base url='yourstore/mypage.html'}}


To Retrieve URL path in PHTML
Note: In editing PHTML don't forget to enclode the following code with PHP tag Not secure Skin URL
getSkinUrl('images/sampleimage.jpg') ?>
Secure Skin URL
getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>
Get Current URL
$current_url = Mage::helper('core/url')->getCurrentUrl();
Get Home URL
$home_url = Mage::helper('core/url')->getHomeUrl();
Get Magento Media URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
Get Magento Skin URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
Get Magento Store URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
Get Magento Js URL
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

Thursday 10 November 2011

How To Simultaneously Add Multiple Products To A Magento Shopping Cart

Magento's product list view lets customers add products to the shopping cart one at a time. I wanted customers to be able to add multiple products to the shopping cart simultaneously. I created an adhoc AJAX method to accomplish this feature request. Adding a product to a Magento shopping cart is accomplished through an HTTP GET request. It will look like or similar to this:
/path/to/app/checkout/cart/add?product=[id]&qty=[qty] 

That URL is output by the tem­plate helper:

$this->getAddToCartUrl($_product)

Since adding a product to the shopping cart is nothing more than a GET request, then all that needs to be done is queue up the URLs of the desired products, make each request in order, and then reload the page when done. First, in app/design/frontend/default/your-theme/template/catalog/product/list.html, I first added checkboxes to allow customers to select which products they want and also hidden fields for storing the URLs to add the product and text fields for the quantity.

<?php $_iterator = $_product->getId(); >?


<?php if(!$_product->isGrouped()): ?>

<?php endif; ?>

I added this code within the loop that generate the HTML for the product line items for the list. Next, I added the JavaScript that does the actual processing, also within the list section right after the script block that contains: decorateList('products-list', 'none-recursive').

At the bottom of the list I added a submit button.

Clicking the button calls the function addItemsToCart(). The function hides the button to prevent a double click and unhides the status message. Next, the function determines which checkboxes are checked. For each checked checkbox, the function finds the corresponding URL field and quantity field, concatenates the two values, and stores the new URL in an array. If the length of the array is greater than 0, then the function calls processNext(), otherwise it displays an error message and resets the submit button.

The function processNext() first updates the process­ing message. The function takes the array of URLs and an index, and then creates an AJAX GET request using the URL at the given index in the array. If the AJAX request completes, it calls processNext() with the same array but with an incremented index while the index is less than the array length. If the incremented index is greater than the array length, then that ends the processing and the function reloads the page.

 That's it.

Wednesday 9 November 2011

Magento: set number of products in new products

You can set number of products to be displayed in new product in your new.phtml file. Find:
 <?php $i=0; foreach ($_products->getItems() as $_product): ?>
and add above, so the code looks like this:
    <?php $_products->setOrder('news_from_date')->setPageSize(6)
  ->setCurPage(1);?>
    >?php $i=0; foreach ($_products->getItems() as $_product): ?>
Set the number (6) as you like. Or you can display all new product by $size = $_products->getSize(); set the number ($size). On the other hand you can set this number in administration on home cms page. Under Custom desing set the code for new products to look like this:

    
    8
    
    bundle
    bundle/catalog_product_price
    
    
    
    
Just set the number in tags.

Magento Cron error: /bin/sh: -c: line 0: syntax error near unexpected token `newline'

I got below error in my mail when i set up cron for magento.

/bin/sh: -c: line 0: syntax error near unexpected token `newline'
/bin/sh: -c: line 0: `php /home/pooja/public_html/magento/journal/cron1.php >'

I found solution for that is i remove newline space from my cron1.php file.
and its work.

Monday 31 October 2011

Magento: Add to cart button every where

Sometime you need to add “Add to cart” button outside the product details view. So, you can’t use
getAddToCartUrl($product)

Don’t worry, you can use this code instead for:
echo Mage::helper('checkout/cart')->getAddUrl($_item)

Monday 24 October 2011

Product images not uploading

When trying to upload an image for the product the section with the image name gets a red border and an error message appears.
When trying to upload something for the downloadable products same error found.


Here is what I did to fix it:
The problem seems to be caused by the prototype v1.7.
It works great with prototype 1.6
Get the 1.6 version from here http://prototypejs.org/assets/2009/8/31/prototype.js
or get it from older magento version.


Create this file: js/prototype/prototype1.6.js and put the contents from the link above in it.
Now edit app/design/adminhtml/default/default/layout/main.xml and change this line

prototype/prototype.js
with
prototype/prototype1.6.js


I don’t think it’s a problem if you edit this core file.  


I hope this helps someone

Friday 21 October 2011

Magento: this.images.toJSON is not a function

If you can’t upload your images to product. And you get this error: {Object}.toJSON is not a function in firebug console. This issue will be fix easily if you add $H() to your object.

var myData = this.images.toJSON();


replace by:
   
var myData = $H(this.images).toJSON();

Thursday 20 October 2011

Magento 1.5 admin - Categories are not appearing when editing products

I have similar pb in all my websites in 1.5 
app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Categories.php
i have changed it by the 1.4.2 code and yeahh; it works fine. Categories are auto expanded  change the last function by this code.
public function getSelectedCategoriesPathIds($rootId = false)
    {
        $ids = array();
        $collection = Mage::getModel('catalog/category')->getCollection()
            ->addFieldToFilter('entity_id', array('in'=>$this->getCategoryIds()));
        foreach ($collection as $item) {
            if ($rootId && !in_array($rootId, $item->getPathIds())) {
                continue;
            }
            foreach ($item->getPathIds() as $id) {
                if (!in_array($id, $ids)) {
                    $ids[] = $id;
                }
            }
        }
        return $ids;
    }

Wednesday 19 October 2011

Remove “+$” or “-$” price value in the drop down in configurable product

If you want to remove "+$" or "-$" price value in the drop down in configurable product.

STEP 1
app/code/core/Mage/Catalog/Block/Product/View/Type/ Configurable.php

change this line
'template'  => str_replace('%s', '#{price}', $store->getCurrentCurrency()->getOutputFormat()),
TO
'template'          => Mage::helper('catalog')->__(''),

STEP 2
js/varien/product.js
change this function
formatPrice: function(price, showSign){ 
    var str = ''; 
    price = parseFloat(price); 
    if(showSign){ 
    if(price<0){ 
    str+= '-'; 
    price = -price; 
    } 
    else{ 
    str+= '+'; 
    } 
} 
TO
formatPrice: function(price, showSign){ 
var str = ''; 
price = parseFloat(price); 
if(showSign){ 
if(price < 0){ 
str+= ''; 
price = -price; 
} 
else{ 
str+= ''; 
} 
}

Magento ParadoxLabs Gallery Lightbox not work on ie9

I used to spend a lot more time hacking websites to work with paradoxlabs gallery in Magento but won't work in – IE9. 

Finally i got solution for that. i just upgrade prototype.js to newer version which is located in to js/prototype/prototype.js

you can find the file from below link.

it work for me. its works like a charm.

Using collection in Magento for database manipulation

Basically a collection is a model type that contains other model.In other words we can say a collection is basically a set of models in magento. These Models are used to manipulate database as per our requirement.

With the collection we will get the data from database. Here is the simplest way to do this.
//  Creating model object on which we want to do manipulation
$model = Mage::getModel("customer/account_history");
 
// Generating Collection of above model.
 $collection = $model->getCollection();
 
//We are adding filter on collection that
// we want the data of currently logged in user only.
$collection->addCustomerFilter(Mage::registry('current_customer')->getId());
 
//Adding where condition into the query
 $collection->addFieldToFilter('status', array('neq' => '0'));
 
// Adding order by clause to the mysql query through collection
$collection->getSelect()->order(new Zend_Db_Expr('created_time DESC'));
 
// Adding limit to mysql query through collection
$collection->getSelect()->limit(100);
 
//Below code will  print full mysql query for you so that you can see it
echo $collection->getSelect();
 
// Now use your collection. Simply loop through it
$this->setCollection($collection);
Now you can use this above collection to get your intended data
// Looping collection to get data
foreach($collection as $product) {
var_dump($product->getData());
}

Tuesday 18 October 2011

Fatal error: Call to undefined method Mage_Adminhtml_Block_Widget::getrowurl()

If you getting blank pages or fatal errors on MANAGE CATEGORIES page, then here is the solution :
Go To app/code/core/Mage/Adminhtml/Block/Widget/Grid.php

Search function getRowUrl in the file.
public function getRowUrl($item)
{
$res = parent::getRowUrl($item);
return ($res ? $res : '#');
}
Replace this function with below function:
public function getRowUrl($row) 
{ 
return $this->getUrl('*/*/edit', array('instance_id' => $row->getId())); 
}

Permanently change the ‘view x items per page’ in the admin backend from the default of 20

In sections like CMS->Static Blocks, CMS->Pages, Catalog->Manage Product etc.  if you have more than 20 items magento will split them into multiple pages of results.

The fix itself is pretty easy, just open up:
app/code/core/Mage/Adminhtml/Block/Widget/Grid.php

Somewhere near the top of the file (around line 70) you'll find the following code:
protected $_defaultLimit    = 20;
Replace it with: 
protected $_defaultLimit    = 999;
As your updating a core file within Magento this change will be overwritten every time you upgrade your magento so you'll have to go back and alter it again after each upgrade. 

If you want to add new page no to pager than open file 
app\design\adminhtml\default\default\template\widget\grid.phtml

Somewhere in the file (around line 81) you'll find the select tag code and copy option line and paste with your desire page no.

Sunday 9 October 2011

Magento Code to get General Store Information


Most of the time we want to access Store Contact info at different places of our magento site to do this we have a very simple and useful code i.e
echo Mage::getStoreConfig('general/store_information');
This code will fetch you an array containing complete store which is provided at backend From System->Configuration->General->Store Information. use address
echo Mage::getStoreConfig('general/store_information/address'); 
use phone no
echo Mage::getStoreConfig('general/store_information/phone'); 
or you can get using
$info = Mage::getStoreConfig('general/store_information');
store name : $info['name']
store address : $info['address']
store Phone : $info['phone']

Monday 26 September 2011

Magento: Adding New attributes in Category General Information

Add Below code to any file and change with my_attribute to your attribute than run that file. so for example if you past it in category/view.phtml file than open any category page from frontside and Attribute was created. see in backend category page. it will be done dont forgot to remove this code from that file after attribute was created.
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', 'my_attribute', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'varchar',
    'label'         => 'My Attribute',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
you can use it If it is a text field (textbox or textarea), this is all you have to do:
echo $_product->getMyAttribute()
If you are using a dropdown or a multiple select, you have to call it a little differently:
echo $_product->getAttributeText('my_attribute')

Saturday 24 September 2011

Magento Jextn Faq SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store' in 'where clause'

When I installed  Jextn Faq  Extension I got the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store' in 'where clause'

I have just comment on three lines and works for me.
app\code\community\Jextn\Faq\Model\Mysql4\Faq\collection.php
after 
public function setFirstStoreFlag($flag = false)
{
    $this->$previewFlag = $flag;
    return $this;
}
 before
public function setFirstStoreFlag($flag = false)
{
//  $this->$previewFlag = $flag;
    return $flag;
}
In same file remove If condition from  function _afterLoad() and its look like this
protected function _afterLoad()
{
//        if ($this->$previewFlag) {
        $items = $this->getColumnValues('faq_id');
        if (count($items)) {
            $select = $this->getConnection()->select()
                    ->from($this->getTable('faq_store'))
                    ->where($this->getTable('faq_store').'.faq_id IN (?)', $items);
            if ($result = $this->getConnection()->fetchPairs($select)) {
                foreach ($this as $item) {
                    if (!isset($result[$item->getData('faq_id')])) {
                        continue;
                    }
                    if ($result[$item->getData('faq_id')] == 0) {
                        $stores = Mage::app()->getStores(false, true);
                        $storeId = current($stores)->getId();
                        $storeCode = key($stores);
                    } else {
                        $storeId = $result[$item->getData('faq_id')];
                        $storeCode = Mage::app()->getStore($storeId)->getCode();
                    }
                    $item->setData('_first_store_id', $storeId);
                    $item->setData('store_code', $storeCode);
                }
            }
        }
//        }
    parent::_afterLoad();
}
change in this file also app\code\community\Jextn\Faq\Model\Mysql4\faq.php change
after
$collection = Mage::getModel('faq/faq')->getCollection()
                ->addStoreFilter($storeId)
                ->addIsActiveFilter();
before
$collection = Mage::getModel('faq/faq')->getCollection()
                //->addStoreFilter($storeId)
                ->addIsActiveFilter();

Thursday 22 September 2011

Remove Category option from Layered Navigation options list

Try this:
1) open app\code\core\Mage\Catalog\Block\Layer\View.php
2) find
$categryBlock = $this->getLayout()->createBlock('catalog/layer_filter_category')
            ->setLayer($this->getLayer())
            ->init();

$this->setChild('layer_state', $stateBlock);
$this->setChild('category_filter', $categryBlock);
3) change with
$this->setChild('layer_state', $stateBlock);

Monday 19 September 2011

Magento: Login required for Add Review

If you want to restriction for adding review than add below condition to form which is located at.
app\design\frontend\base\default\template\review\form.phtml
add below code to before form start
if ((boolean) $this->helper('customer')->isLoggedIn() )
{ ?>
add below code to after form end and before script start
else //customer is NOT logged in
{
        echo $this->__('To prevent SPAM we ask our customers to login before posting a review. Thank you for your understanding!'); 
        echo 'Please Sign In to post review ';
} 
?>

Magento: Remove auto Breaks("br/") from product description

By Default Magento automatically adds

html tags to product descriptions for display on the customer interface.  If you have created a nice description with the WYSIWYG Editor or imported HTML descriptions you most likely want to remove this behavior.   Luckily this is not hard to do.
  1. Find the file "description.phtml" here:  app/design/frontend/default/ 
  2. Remove the "nl2br" tag
Before:
helper('catalog/output')->productAttribute($this->getProduct(), 
nl2br($this->getProduct()->getDescription()), 'description') ?>
After:
helper('catalog/output')->productAttribute($this->getProduct(),   
$this->getProduct()->getDescription()), 'description' ?>

Monday 12 September 2011

Magento how to add Date field with DatePicker

I have creating a form i'm using in the admin page on a custome module I have been writing, Im using addField to add text fields however now need to add a date field. I changed the type from text to date and add format. heres what I have done put below code to your admin block file.

$outputFormat = Mage::app()->getLocale()->
    getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
$fieldset->addField('created_time', 'date', 
            array('label' = > Mage::helper('schedulelist')->__('Created Date'),
            'required' => true,
            'name' => 'created_time',
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'format' => $outputFormat,
));

Wednesday 24 August 2011

Show All Product link to product list page in magento

To show "view all" product link in product list page than first of all goto backend

System->Configuration->Catalog->Frontend

enable Allow All Products per Page.

and than open app\design\frontend\base\default\template\page\html\pager.phtml

add this code to as you where display in page.

<?php 
$url = $this -> getLimitUrl('all');
echo 'View All';
?>

Tuesday 9 August 2011

Check if Cms Homepage

if(Mage::app() -> getFrontController() -> getRequest() -> getRouteName() == 'cms'  && Mage::getSingleton('cms/page') -> getIdentifier() == 'home') : 
 echo "home page";

Monday 8 August 2011

Search is not working in magento

If Search is not working in magento Then login to admin section of your site then goto -> System -> Index management. There clicked on Catalog Search Index and Reindex data.Clear your Cache and It worked .

Friday 29 July 2011

Improve the Speed of Your Magento Site

Caching is useful for files on a web server that very rarely change. Images, pdf files and other content can be cached, reducing the network traffic between the server, the client, and the HTTP proxies in between them.

Change in your .htaccess file and it will improve your site speed.

Note: first backup your htaccess file.

1.)
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
    # Insert filter on all content
    SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
2.)
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
    #ExpiresDefault "access plus 1 year"
3.)
Header unset Pragma
FileETag None
Header unset ETag
# cache images/pdf docs for 10 days

Header set Cache-Control "max-age=864000, public, must-revalidate"
Header unset Last-Modified

# cache html/htm/xml/txt diles for 2 days
Header set Cache-Control "max-age=7200, must-revalidate"  
4.)

Enable all catch from your site backend form System->Catch manegement

Tuesday 26 July 2011

Add Extra Fee Shopping Cart Price Rules Magento

Under the Promotions tab in your admin panel there is a shopping cart price rule int this you can't add minus value to for rule. But now it is possible to add minus value and this value was added as extra fee to cart and checkout.

Note: we are going to change Magento Core files. Please make a backup of your files before continuing.

1). Go to app/code/core/Mage/Rule/Model/Rule.php

Find this:

            if ((int)$this->getDiscountAmount() < 0) {
                        Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.'));
           }

Just add some bars // to comment the code: it look like this

            //if ((int)$this->getDiscountAmount() < 0) {
                        //Mage::throwException(Mage::helper('rule')->__('Invalid discount amount.'));
            //}

2). Now go to: app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php

find this

            'class' => 'validate-not-negative-number',

and coomment it

            //'class' => 'validate-not-negative-number',

3). Translate the discount word. Go to app/locale/es_ES (I'm using the Spainish translation so maybe yours would be en_US) Find a file called Mage_Sales.csv. Inside look for the word discount you will find something like:

            "Discount (%s)","Discount (%s)"

You can change the value in order to show your own text. For example:

            "Discount (%s)","Extra Fee (%s)"

4). If you want to apply this rule to whole cart than do this goto app\code\core\Mage\SalesRule\Model\validator.php find this below code it is near to line 280 to 300.

case 'cart_fixed':
            $cartRules = $address->getCartFixedRules();
             if (!isset($cartRules[$rule->getId()]) > 0) {
                        $cartRules[$rule->getId()] = $rule->getDiscountAmount();
             }
             if ($cartRules[$rule->getId()]) {

replace by

case 'cart_fixed':
            $cartRules = $address->getCartFixedRules();
            if (!isset($cartRules[$rule->getId()])) {
                        $cartRules[$rule->getId()] = $rule->getDiscountAmount();
            }
            if ($cartRules[$rule->getId()]) {

Monday 25 July 2011

Add WYSIWYG editor to admin custom field

To enable the editor for a certain editable textfield, just use 'wysiwyg' => true, instead of 'wysiwyg' => false. and add 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(). i.e.:

$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'wysiwyg' => false,
'required' => true,
));

After Change

$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'wysiwyg' => true,
'required' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
));

also add this to your controller initAction() before return.

if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
 $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}

That's all done.

Thursday 21 July 2011

Magento Category List

To display all root category list add this code to your file where you want display category.

$category = Mage::getModel('catalog/category')->load(2);
$subcategory = $category->getAllChildren(true);
array_shift($subcategory);
if($subcategory!=null)
{
 foreach ($subcategory as $sub)
    {
        $sub1 = Mage::getModel('catalog/category')->load( $sub);
        echo $sub1->getUrl();
        echo $sub1->getName();
        echo $sub1->getImageUrl();
    }
}