Tuesday, November 6, 2012

Change default sort by order for one category in Magento

>> If you want to change default sort by value "position" to "name", change admin category setting. see the screen-shot.


    you can change default direction by providing the following code in Custom Layout Update section in admin category "Custom Design" Tab
    <reference name="product_list_toolbar">
          <action method="setDefaultDirection"><dir>desc</dir></action>

>> Add "created_at" in sort by dropdown.

    update eav_attribute set frontend_label = "Date" where attribute_code = "created_at" AND entity_type_id = 4; // Ensure about the entity_type_id
    update catalog_eav_attribute set used_for_sort_by = 1 where attribute_id = (select attribute_id from eav_attribute where attribute_code = "created_at" AND entity_type_id = 4);
    Now You can see the Date in admin default sort by configuration.
    Admin=>System=>Configuration=>Catalog=>Frontend=> change value here "Product Listing Sort by"

>> If you want to add another attribute, go to the attribute setting and set "yes" for use for default sort by, see the screen-shot.

    Admin=>Attributes=>Manage Attributes

Thursday, October 25, 2012

add custom product view page for custom product type in magento

>> Suppose you've created a new Product Type "custom". I've posted how to add new product type in magento. You want to use a different template for those product. follow the instruction ::

  You can directly update in the catalog.xml or you can create a custom module by using Module Creator.

    <reference name="product.info">
      <action method="setTemplate">

How to add custom product type in Magento

>> Basically You can't create a product type from Admin. You need to modify config.xml and sql in your module.


                <classified translate="label" module="vendor">

Here classified is my custom product type and vendor is my custom module.

Now you need to update price type attributes for new type : To run your sql file of your module for next time you need to delete the row created for the module "vendor" in core_resource table. We will discuss later for update Sql.

$installer = $this;
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */


$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$fieldList = array(

// make these attributes applicable to downloadable products
foreach ($fieldList as $field) {
    $applyTo = split(',', $setup->getAttribute('catalog_product', $field, 'apply_to'));
    if (!in_array('classified', $applyTo)) {
        $applyTo[] = 'classified';
        $setup->updateAttribute('catalog_product', $field, 'apply_to', join(',', $applyTo));



Wednesday, October 17, 2012

How to get attribute set name in Magento

>> $prodAttributeSet = Mage::getModel('eav/entity_attribute_set')->load($_product->getAttributeSetId())->getAttributeSetName();

>> To get the attributeset name in cart page see the following..
app/design/frontend/base/default/template/checkout/cart/item/default.phtml (or in your theme folder.)

Here you can see the cart item object $_item = $this->getItem(); at line 28. Then you have to load the product with product id.
    $_product = Mage::getModel('catalog/product')->load($_item->getProductId());
    $prodAttributeSet = Mage::getModel('eav/entity_attribute_set')->load($_product->getAttributeSetId())->getAttributeSetName();

Friday, October 12, 2012

Get Product collection in Magento

 There are many way to get product collection.
 >> First preferable way to get Collection of Magento products :

   $visibility = array(
   $productCollection = Mage::getModel('catalog/product')->getCollection()
                                        ->addAttributeToFilter('visibility' , $visibility);



Wednesday, October 10, 2012

Remove next elements in jQuery

>>  This peace of code will remove Next input fields :

          jQuery("#selector").nextAll('input:hidden').remove();        // Input type "hidden"
          jQuery("#selector").nextAll('input:text').remove();            // Input type "text"

// By the above code All the input field after the selector will remove

          jQuery("#selector").next('input:hidden').remove();        // Input type "hidden"
          jQuery("#selector").next('input:text').remove();            // Input type "text"

// By the above code only the next input field of the selector will remove

Wednesday, October 3, 2012

How to get a html output through xml in Magento

>> Basically we use to get the content page like :

         <reference name="content">
            <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml" />

  It'll return html output with header, footer content. If you want to get only the content of list.phtml
Then you have to modify the code with following:

        <block type="core/text_list" name="root" output="toHtml">
              <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml" />

The above code will return only the content of list.phtml.