Sunday, 25 August 2013

Magento Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH), Short Open Tag Error

This error you can solved by your end. Please find the following solutions.

Go to C:\xampp\php\php.ini

Then set
short_open_tag = on

And restart your Apache Server.













Wednesday, 21 August 2013

magento get all products with child products


$collection = Mage::getModel('catalog/product')->getCollection();
foreach($collection as $assProducts)
{
$product = Mage::getModel('catalog/product')->load($assProducts->getId());
echo $product->getName().'<br>';
if($assProducts->getTypeId() == "configurable") {
       $product = Mage::getModel('catalog/product')->load($assProducts->getId());
$childProducts = Mage::getModel('catalog/product_type_configurable')
                    ->getUsedProducts(null,$product);  
foreach($childProducts as $child) {
    echo '---------'.$child->getName().$child->getId().'<br>';
}
}

}






php first element of array


$array = array( 2 => 'orange', 4 => 'banana', 9 => 'apple' )
echo reset($array); //Output : "orange"














Magento get store list from all websites


$allWebsites = Mage::app()->getWebsites();
<select id="store" name="stire" onChange="">
<?php
foreach ($allWebsites as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach($stores as $_eachStoreId => $val)
{
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
$webid = $website->getId();
?>
<option value="<?php echo $webid; ?>"><?php echo $_storeName;?></option>
<?php
}
}
}
?>
</select>








Thursday, 8 August 2013

Magento Passing data between a controller and a block

In the controller write the bellow code
Mage::register('demodata', $demodata);
In the controller write the bellow code 
$data = Mage::registry('demodata');
Hope it will help you.