Tuesday 25 June 2013

Get all Product type's price show in homepage in magento

Get Simple Product Price in Homepage

<?php echo $_product->getFormatedprice(); ?>

Get Group Product Price in Homepage


<?php  
    $aProductIds = $_product->getTypeInstance()->getChildrenIds($_productl->getId());
    $prices = array();
    foreach ($aProductIds as $ids) {
           foreach ($ids as $id) {
                  $aProduct = Mage::getModel('catalog/product')->load($id);
                  $prices[] = $aProduct->getPriceModel()->getPrice($aProduct);
            }
     }
     //krsort($prices);
     asort($prices);
     echo $_product->setPrice(array_shift($prices));
   ?>


Get Bundle Product (Maximum and Minimum) Price in Homepage


      $_product_id            = $_product->getId();  //Here bundle Product id


//$return_type  select which you want to get price. If you want to get Max Price, you will add $return_type = ‘max’. And if you want to get minimum Price of product, you will add $return_type = ‘min’


      // highest possible price for this bundle product
      //$return_type            = 'max';
     
            // lowest possible price for this bundle product
       $return_type         = 'min';
     
      $model_catalog_product  = Mage::getModel('catalog/product'); // getting product model
      $_product               = $model_catalog_product->load( $_product_id );
      $TypeInstance           = $_product->getTypeInstance(true);
$Selections             = $TypeInstance->getSelectionsCollection($OptionIds, $_product );
$Options                = $TypeInstance->getOptionsByIds($OptionIds, $_product);
$bundleOptions          = $Options->appendSelections($Selections, true);
     
$minmax_pricevalue  = 0; // to sum them up from 0
     
foreach ($bundleOptions as $bundleOption) {
      if ($bundleOption->getSelections()) {
          $bundleSelections       = $bundleOption->getSelections();
          $pricevalues_array  = array();
          foreach ($bundleSelections as $bundleSelection) {
              $pricevalues_array[] = $bundleSelection->getPrice();
          }
          if ( $return_type == 'max' ) {
              rsort($pricevalues_array); // high to low
          } else {
              sort($pricevalues_array);   // low to high
          }
          // sum up the highest possible or lowest possible price
          $minmax_pricevalue += $pricevalues_array[0];
      }
  }
// echo $minmax_pricevalue;  //Get minimum price value
echo 'As low as '.Mage::helper('core')->currency($minmax_pricevalue, true, false);   //Get minimum price value with store currency.


Get Configurable Product Price in Homepage


$product = Mage::getModel('catalog/product')->load($_product->getId());
//load all children
$childProducts = Mage::getModel('catalog/product_type_configurable')
           ->getUsedProducts(null,$product);
$childPrice = array();
foreach($childProducts as $child){
    $_child = Mage::getModel('catalog/product')->load($child->getId());
    $childPrice[] =  $_child->getPrice();
}
//If you want to minimum price of product use this
echo min($childPrice);


//If you want to maximum price of product use this
echo max($childPrice);

Add Multiple Items in cart in Magento


$product_id = 32;  //Here is first Product id
$warranty_id = 35;  //Here is second Product id
//You can also pass multiple product id.
$someQty = 1; //Here is quantity
//You can add different quantity for different product.


$cart = Mage::getModel("checkout/cart");
$cart->addProduct($product_id, $someQty);
$cart->addProduct($warranty_id, $someQty);
            $cart->save();

Monday 24 June 2013

Get Realted, Upsell, Cross sell Product collection in magento

Get Related Product Collection


$related_product_collection = $_product->getRelatedProductCollection();
$related_product_collection->AddStoreFilter();
foreach($related_product_collection as $pdt)
{
    $pdt_id=$pdt->getId();
    $model_rel = Mage::getModel('catalog/product'); //getting product model
    $_product_rel = $model_rel->load($pdt_id); //getting product object for particular product id
    $rel_name= $_product_rel->getName();
    $rel_price= number_format($_product_rel->getPrice(),2);
    $rel_img_url = $this->helper('catalog/image')->init($_product_rel, 'image')->keepFrame(false)->resize(156,107);   //Image resize code
?>


Get Upsell Product Collection


<?php
$upsell_product_collection = $_product->getUpSellProductCollection();
$upsell_product_collection->AddStoreFilter();
foreach($upsell_product_collection as $pdt)
{
    $pdt_id=$pdt->getId();
    $model_upsell = Mage::getModel('catalog/product');
    $_product_upsell = $model_upsell->load($pdt_id);
    $upsell_name= $_product_upsell->getName();
    $upsell_price= number_format($_product_upsell->getPrice(),2);
    $upsell_img_url = $this->helper('catalog/image')->init($_product_upsell, 'image')->keepFrame(false)->resize(100,100);
?>


Get Cross Sell Product Collection


<?php
$crossselll_product_collection = $_product->getCrossSellProducts(); $crossselll_product_collection>AddStoreFilter();
foreach($crossselll_product_collection as $pdt)
{
    $pdt_id=$pdt->getId();
    $model_crosssell = Mage::getModel('catalog/product');
    $_product_crosssell = $model_crosssell>load($pdt_id);
    $crosssell_name= $_product_crosssell->getName();
    $crosssell_price= number_format($_product_crosssell->getPrice(),2);
    $crosssell_img_url = $this->helper('catalog/image')->init($_product_crosssell, 'image')->keepFrame(false)->resize(100,100);
?>

Get Current Page Detail in magento

Get title
<?=Mage::getSingleton(‘cms/page’)->getTitle()?>
Get Identifier
<? echo Mage::getBlockSingleton(‘cms/page’)->getPage()->getIdentifier()?>
Get Page ID
<? echo Mage::getBlockSingleton(‘cms/page’)->getPage()->getId();  ?>