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();  ?>

Friday, 24 May 2013

Get Page detail by page id in magento

Get Page tilte


echo Mage::getModel('cms/page')->load(3)->getTitle();  // Here 3 is page id


Get Page content


echo Mage::getModel('cms/page')->load(3)->getContent(); // Here 3 is page id


Get Page Url


echo Mage::helper('cms/page')->getPageUrl(3) ; // Here 3 is page id


Get excerpt


$full_content = Mage::getModel('cms/page')->load(3)->getContent(); // Here 3 is page id
$excerpt = strip_tags(substr($full_content,0,200));  // Here 200 is character length.
echo $excerpt;

Friday, 17 May 2013

Get All Product Collection in magento

Get All Product Collection
 
<?php
       $product_collection = Mage::getModel('catalog/product')->getCollection()->setOrder('name', 'asc'); 
      
       //getting the product collection, results are ordered by product name
       
      foreach($product_collection as $_product)
       {
           echo $_product->getId() . "<br />";
       }
?>


Get Limitation product


       <?php
       $limit = 5;
       $starting_from = 0;
       $product_collection = Mage::getModel('catalog/product')->getCollection()->setOrder('name', 'asc'); 
       //getting the product collection, results are ordered by product name

       $product_collection->getSelect()->limit($limit,$starting_from);   
       
       //where $limit will be the number of results we want, $starting_from will be the index of the result set to be considered as starting point (note 0 is the index of first row)
       //this will ouptput 5 records starting from 1rd record

       foreach($product_collection as $_product)
       {
           echo $_product->getName().'<br/>';
           echo $_product->getId() . "<br />";
       }
       ?>


Get Latest Product Collection


       <?php
          $_productCollection = Mage::getResourceModel('reports/product_collection')
                           ->addAttributeToSelect('*')
                           ->setOrder('created_at', 'desc')
                           ->setPage(1, 5);
       ?>
       <h2>Latest Products</h2>
       <?php foreach($_productCollection as $_product) : ?>
        <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></br>
       <?php endforeach; ?>


Tuesday, 14 May 2013

Get excerpt by post id in wordpress

// Function add in function.php

function get_excerpt_by_id($post_id){
   $the_post
= get_post($post_id);
   $the_excerpt
= $the_post->post_content;
   $excerpt_length
= 35;    //Sets excerpt length by word count
   $the_excerpt
= strip_tags(strip_shortcodes($the_excerpt));
   $words
= explode(' ', $the_excerpt, $excerpt_length + 1);

   
if(count($words) > $excerpt_length) :
       array_pop
($words);
       array_push
($words, '…');
       $the_excerpt
= implode(' ', $words);
   endif
;

   $the_excerpt
= '<p>' . $the_excerpt . '</p>';

   
return $the_excerpt;
}

// Call in template files

echo get_excerpt_by_id($post_id);   // you will get excerpt by post id