Thursday, November 8, 2012
How to redirect in magento
>> Pass the url in this function :
public function redirect($url)
{
return Mage::app()->getFrontController()
->getResponse()
->setRedirect($url);
}
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>
</reference>
>> 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.
<layout>
<PRODUCT_TYPE_custom>
<reference name="product.info">
<action method="setTemplate">
<template>path/to/your/view.phtml</template>
</action>
</reference>
</PRODUCT_TYPE_custom>
</layout>
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.
config.xml
<global>
<catalog>
<product>
<type>
<classified translate="label" module="vendor">
<label>Classified</label>
<model>vendor/product_type_classified</model>
<composite>0</composite>
<index_priority>50</index_priority>
<is_qty>1</is_qty>
</classified>
</type>
</product>
</catalog>
</global>
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 tabl
e. We will discuss later for update Sql. <?php
$installer = $this;
/* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup */
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$fieldList = array(
'price',
'special_price',
'special_from_date',
'special_to_date',
'minimal_price',
'cost',
'tier_price',
'weight',
'tax_class_id'
);
// 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));
}
}
$installer->endSetup();
?>
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.
<?php
$_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(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH
);
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToFilter('visibility' , $visibility);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productCollection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
$productCollection->getSelect()->limit(12);
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
Subscribe to:
Posts (Atom)