Magento Coding Solutions

how to get filterable attributes and options in magento programmatically

Add this code in Product List.phtml otherwise you should be assign category Id 
<?php
echo "<pre>";
$_category = Mage::registry('current_category');
$category_id= $_category->getId();
$layer = Mage::getModel("catalog/layer");
$category = Mage::getModel("catalog/category")->load($category_id);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach($attributes as $attribute){
if($attribute->getAttributeCode() == 'price'){
$filterBlockName = 'catalog/layer_filter_price';
}elseif($attribute->getBackendType() == 'decimal'){
$filterBlockName = 'catalog/layer_filter_decimal';
}else{
$filterBlockName = 'catalog/layer_filter_attribute';
}

$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();


$count = count($result->getItems());
echo "</br>";
if($count > 0){
echo $attribute->getFrontendLabel();
echo $attribute->getAttributeCode();
}
if($count > 0){

foreach($result->getItems() as $option) {


echo '<a href="'.$this->urlEscape($option->getUrl()).'">'.$option->getLabel().'</a>';
echo " ";
//echo $option->getValue();

echo "(".$option->getCount().")";
}
}
}
echo "</pre>";
?>

Magento module admin from.php




Reservation: is module
1) you can make new form 

$form = new Varien_Data_Form();


$fieldsetDesignImage = $form->addFieldset("designimage_form");


2) If Any Nots  as well HTML can you write
Location: " app/code/local/Mpb/Reservation/Block/Adminhtml/Reservation/Edit/Tab"

$table="design";
$fieldset->addField('note', 'note', array(
'label' => Mage::helper('reservation')->__('test'),
'text' => Mage::helper('reservation')->__($table),
));
3) you can add textarea with editor

$fieldset->addField("comments", "textarea", array(
"label" => Mage::helper("managedesign")->__("Comments"),
"name" => "comments",
"wysiwyg" => true,
));
4) add Link type in grid.php

 $this->addColumn('Download', array(
            'header'    => "Download Artwork",
            'index'     => 'Download Artwork',
            'type'      => 'link',
            'align'     => 'center',
           'renderer'  => 'managedesign/adminhtml_managedesign_renderer_Doenloadlink'
));


magento to get attribut option by option Code

Hear "quartier" is attribute code

$btkAdresses = Mage::getModel('eav/config')->getAttribute('catalog_product', 'quartier')->getSource()->getAllOptions(true, true);
foreach ($btkAdresses as $_adresse){
  array_push($btkAdresse , array('value'=>$_adresse['value'] , 'label'=> $this->htmlEscape($_adresse['label']) ) );
 }

How to acces one .phtml file in another .phtml file magento

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('page/boutiquemap.phtml')->toHtml();?>

How to redirect to previous page in magento


 previous page redirect
   return $this->_redirectReferer();

Redirect in same module
return $this->_redirect('*/*');

Import sql file by php

<?php

// Name of the file
$filename = 'logoagog.sql';
// MySQL host
$mysql_host = 'localhost';
// MySQL username
$mysql_username = 'root';
// MySQL password
$mysql_password = '';
// Database name
$mysql_database = 'logotest';

// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
// Select database
mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
    continue;

// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
    // Perform the query
    mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
    // Reset temp variable to empty
    $templine = '';
}
}
 echo "Tables imported successfully";
?>

How to redirect to previous page with message

In Module controllers/IndexController.php
Message:
Mage::getSingleton('core/session')->addSuccess('Query submit successfully');

Redirect
$this->_redirectReferer();

Redirect Fiex url:
boutiques is my module
$redirectUrl=Mage::getBaseUrl().'boutiques'; Mage::app()->getResponse()->setRedirect($redirectUrl);


get Design Skin url Magento

<?php echo Mage::getDesign()->getSkinUrl().'images/logo.png';?>

Get Base Url , Skin Url , Media Url , Js Url , Store Url and Current Url magento

Get Url in phtml files

Get Skin Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

Secure Skin Url :
$this->getSkinUrl('images/imagename.gif', array('_secure'=>true));

Get Media Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

Get Js Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Get Current Url
Mage::helper('core/url')->getCurrentUrl();

Get Url in cms pages or static blocks

Get Base Url :

{{store url=""}}

Get Skin Url :
{{skin url='images/imagename.jpg'}}

Get Store Url :
{{store url='mypage.html'}}

Get Magento skin URL

<?php echo $this->getSkinUrl();?>
example
<?php echo $this->getSkinUrl('images/abc.php');?>

$this->getSkinUrl('images/imagename.gif', array('_secure'=>true));