Magento get controller name module name action name and route name

You can find the Magento Controller Name, Route Name, Module Name, and Action Name in any where in Magento . You just simple paste the below code and refresh the browser and see the Magento Controller NameRoute NameModule Name, and Action Name in your browser screen.


// Getting the Module Name in Magento
<?php echo  Mage::app()->getRequest()->getModuleName(); ?>


// Getting the Controller Name in Magento
<?php echo  Mage::app()->getRequest()->getControllerName(); ?>

// Getting the Action Name in Magento
<?php echo  Mage::app()->getRequest()->getActionName(); ?>


// Getting the Route Name in Magento
<?php echo  Mage::app()->getRequest()->getRouteName(); ?>


How to get all cart items from cart session in magento

If you want to get the cart session product in magento. Than use below code and This code will also help you to show the cart product quantity and price on header section.

<?php

$session= Mage::getSingleton('checkout/session');
foreach($session->getQuote()->getAllItems() as $item)
{
   echo $productid = $item->getProductId();
  echo  $productsku = $item->getSku();
  echo  $productname = $item->getName();
  echo   $productqty = $item->getQty();
}


?>.

how to display the Number of sold products in magento?

By default magento does not show sold product count. if we want to show the sold product count in product description page than we need to do custom work . This Magento Blog or Magento Tutorial will tell you how to show sold product in product description page.


<?php 
                             
$items = Mage::getModel('sales/order_item')
    ->getCollection()
    ->addFieldToFilter('product_id', $_product->getId());
if ($_product->isAvailable()){
$ga_cnt = 0;
foreach ($items as $item) {
    $ga_cnt += $item->getQtyOrdered() - $item->getQtyCanceled() - $item->getQtyRefunded();
}
if($ga_cnt > 0){
    echo $ga_cnt.' people have purchased this product';
} else {
    echo 'Be the first to buy this product!';
}
 } else {
    echo 'Product out of stock';

                

?>

magento get product attribute value

If you do not know how to get the simple product , Bundle product, configurable product and Grouped product attribute value in magento than don't worry this magento blog  or magento tutorial will tell you how to get the product Attribute value in magento.
Using this code You can get custom Attribute or default attribute value and label.

Open the template file “view.phml” from path template/catalog/product/

Find below code in the file.
<?php $_product = $this->getProduct(); ?>

Put below code and check on frontend.

<?php 
echo '<pre>';
$attributes = $_product->getAttributes();
foreach ($attributes as $attribute) 
{
    //if ($attribute->getIsVisibleOnFront()) {

        echo "<br/>".$attribute->getName();

       echo "<br/>Apply To = ".$attribute->getData('apply_to'); 
      
      // print_r($attribute->getData()); // get All product attribute value

        echo "<br/>Attribute Value = ".$attribute->getFrontend()->getValue($_product); // get product Attribute value

         echo "<br/>Attribute Label value = ".$_product->getAttributeText($attribute->getAttributeCode()) ; 
         // display value only select checkbox and drop down only         
        
        echo "<br/>";
        
    //}
}
echo '</pre>';
?> 

error in SetData method in magento

if you got the problem in setData method in magento. Than follow some step to slove this problem.

Step1:- Check your resource table name in config.xml file,and Clear your cache folder inside /var folder and than check.

Step2:- If step 1 is not working than reindex your project and than check.

Step3:- If step 1 and 2 is not working, than check your table Engine type if it's InnoDB than change it to MyISAM and than check.  
             
Hopefully your problem has been solved.
Note:-  Please take a back up before using this steps.

Clck here To know how to set data through model .