Friday, December 10, 2010

Adding TInyMCE Editor in Magento Custom Module

I've created an custom module from module creator but i couldnot displayed tinymce wysiwyg editor in admin page ?

though modulecreator guys has added default field of "content" for editor:

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

but even i change wysiwyg to true it didnt worked. module creator has forgot that to enable wysiwyg we also needed js for that

so here is complete simple layout xml file :





1










js_cssprototype/windows/themes/default.css
js_cssprototype/windows/themes/magento.css










change getthelooks to your custom module name and enjoy!

Product grid Magento

$this->getLayout()->createBlock('adminhtml/catalog_product_grid', 'product.grid')->toHtml()

GET ATTRIBUTE VALUE MAGENTO

if($_product->getResource()->getAttribute('webexcusive')->getFrontend()->getValue($_product) == 'Yes') {

Tuesday, December 7, 2010

Magento Print your Static BLOCK

getLayout()->createBlock('cms/block')->setBlockId('BLOCK IDENTIFIER')->toHtml() ?>

Friday, December 3, 2010

static block in categories view magento

Display Any static Block of magento

$this->getLayout()->createBlock('cms/block')->setBlockId('YOUR BLOCK NAME')->toHtml()

categories view and product listin after particular cat level with quickview product details







$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$cat = Mage::getModel('catalog/category')->load($_category->getId());
$subcats = $cat->getChildren();
$subcat= explode(',',$subcats);
$_columnCount=3;
$_collectionSize = count($subcat);

$catlevel=$_category->getLevel();
// $_category->setDisplayMode('PAGE');


if($subcats!="" && $catlevel<4){>




{
$_subcategory = Mage::getModel('catalog/category')->load($subCatid);
if($_subcategory->getIsActive())
{
$caturl = $_subcategory->getURL();
$this_current_category = Mage::registry('current_category');
$parentCategory = Mage::getModel('catalog/category')->load($_category->getParentId());
$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_subcategory)->addAttributeToSelect('*');
?>










}
}
?>

elf Cosmetics

getImageUrl()):?>
" title="getName(); ?>">getImageUrl()?>" width="193" height="129">

" title="getName(); ?>">/skin/frontend/base/default/images/catalog/product/placeholder/small_image.jpg">



$subcats1 = $_subcategory->getChildren();
$subcat1= explode(',',$subcats1);
if($subcats1!=""){
foreach($subcat1 as $subCatid1) {
$_subcategory1 = Mage::getModel('catalog/category')->load($subCatid1);
?>
getURL()?>">getName()?>





}
else
{ //product display

$cat = Mage::getModel('catalog/category')->load($_category->getId());
$subcats = $cat->getChildren();
$subcat= explode(',',$subcats);
foreach($subcat as $subCatid){
$_subcategory = Mage::getModel('catalog/category')->load($subCatid);
if($_subcategory->getIsActive())
{
//Mage::register('current_category', $_subcategory);
echo '
'. $_subcategory->getName().'
';
$collection = $_subcategory->getProductCollection();

$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_subcategory)->addAttributeToFilter('visibility', 4)->addAttributeToSelect('*');
$products->getSelect()->order(new Zend_Db_Expr('RAND()'))->limit(3);
$products->load();
$_product = null;

////////////////////////////////////////////////
?>
count()): ?>

__('There are no products matching the selection.') ?>






count() ?>












elf Cosmetics
getId()?>);" onmouseover="show_sp_button(getId()?>);" class="depttitle dept_box">







$script='



////////////////////////////////////////////////
}
}

?>

$script.="";
echo $script;
?>

}
?>



Product collection magento

Get product list of any categories with "not visible individually" filter

Limit product listing to 3 only


$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_subcategory)->addAttributeToFilter('visibility', 4)->addAttributeToSelect('*');

$products->getSelect()->order(new Zend_Db_Expr('RAND()'))->limit(3);
$products->load();

Friday, August 20, 2010

magento set continueshoppingurl from any custom module

use this to set continue shopping url from any where in magento without editing any core files :-

Mage::getSingleton('checkout/session')->setContinueShoppingUrl(Mage::helper('core/url')->getCurrentUrl());

for more on magento visit:-

http://magentoexp.blogspot.com/

Thursday, August 19, 2010

Magento – Filter by multiple categories

create local copy of this modal:
app\code\local\Mage\Catalog\Model\Resource\Eav\Mysql4\Product
edit collection.php add this function:-

public function addCategoriesFilter(array $categories)
{
// print_r($categories);
//echo $this->getStoreId() ;
$this->_prepareProductLimitationFilters();
$this->_productLimitationJoinWebsite();
$this->_productLimitationJoinPrice();
$filters = $this->_productLimitationFilters;

$conditions = array(
'cat_index.product_id=e.entity_id',
$this->getConnection()->quoteInto('cat_index.store_id=?', $this->getStoreId())
);
if (isset($filters['visibility']) && !isset($filters['store_table'])) {
$conditions[] = $this->getConnection()
->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
}
$conditions[] = $this->getConnection()
->quoteInto('cat_index.category_id IN(?)',$categories);
if (isset($filters['category_is_anchor'])) {
$conditions[] = $this->getConnection()
->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
}

$joinCond = join(' AND ', $conditions);
$this->getSelect()->join(
array('cat_index' => $this->getTable('catalog/category_product_index')),
$joinCond,
array('cat_index_position' => 'position')
);


$this->_productLimitationJoinStore();

Mage::dispatchEvent('catalog_product_collection_apply_limitations_after', array(
'collection' => $this
));

return $this;
}




At your module block use this function to get products collection from multiple categories :-

public function _getProductCollection(){
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$categories=array(3,4,5,6,7,8);
$storeId = Mage::app()->getStore()->getId();
$this->_collection = Mage::getModel('catalog/resource_eav_mysql4_product_collection')
->setStoreId($storeId)
->addCategoriesFilter($categories)
->addAttributeToFilter('visibility', $visibility)
->addAttributeToSelect('*')
->setOrder('created_at', 'desc')
->addAttributeToSelect('*');
return $this->_collection;

}

get attribute value for configurable product

//this function will get the configurable products set
public function getprodco_without_visib(){
$categories=$this->get_categories();
$storeId = Mage::app()->getStore()->getId();
$this->_collection = Mage::getModel('catalog/resource_eav_mysql4_product_collection')
->setStoreId($storeId)
->addCategoriesFilter($categories)
->addAttributeToSelect('*')
->setOrder('created_at', 'desc')
->addAttributeToSelect('*');
return $this->_collection;
}


function getatt_label_basedoncode($attrb_code,$product){
$attributeValue = Mage::getModel('catalog/product')
->load($product->getId())
->getAttributeText($attrb_code);

return $attributeValue;
}

//GET all product id with their attribute selected value in an array

function getproduct_attrbset_array(){
$prodattarr=array();
$prods = $this->getprodco_without_visib();
foreach ($prods as $product) {
//$product = Mage::getModel('catalog/product')->load(14);
$prodattarr[] = array(
'attset' => $this->getatt_label_basedoncode('your_attrib_code',$product),
'prod_id' =>$product->getId(),
);
}
return $prodattarr;
}