Showing posts with label magento. Show all posts
Showing posts with label magento. Show all posts

Tuesday, 29 September 2015

Show Categories Which Are not Included in Navigation Menu in Magento


Get categories list which are not include in Navigation in magento.

Some time you want that are not added in navigation but categories active and you want to
get or listing.

<ul class="full_category">
<?php $_categories = Mage::getResourceModel('catalog/category_collection')
    ->addAttributeToFilter('is_active', 1) //only active categories
    ->addAttributeToFilter('include_in_menu', 0)
    ->addAttributeToSort('position');//sort by position

foreach ($_categories as $_category) { ?>
<li class="cat">
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>" title="<?php echo $_category->getName() ?>"><strong class="strongsm"><?php echo $_category->getName() ?></strong></a>
<?php }?>

Monday, 28 September 2015

Get All Cms Page in magento


Some Time You need to add Cms page in your site map. you need your page page link and name.
I have same issue. I getting for query and use it's working. you can try it.

Get all Cms Page in Magento

$storeId = $this->helper('core')->getStoreId(); // thanks to drawandcode for this
$cms = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('identifier',array(array('nin' => array('no-route','enable-cookies'))))
$url = Mage::getBaseUrl();
$html = "";
foreach($cms as $cmspage):
$page = $cmspage->getData();
if($page['identifier'] == "home"){
echo  "<li><a href=\"$url\" title=\"".$page['title']."\">".$page['title']."</a></li>\n";
} else {
echo "<li><a href=\"$url".$page['identifier']."\" title=\"".$page['title']."\">".$page['title']."</a></li>\n";

Thursday, 24 September 2015

Filtering a Magento product collection by multiple categories and Stock item and filter current product in product detail page


I  Want to create section to get same product of different categories of products with Stock or quantity.

after i want get product of minimum of product quantity 50%.

for that i will join 'cataloginventory/stock_item', and  'catalog/category_product'  get this collection.

this section create in product detail page that why i am filter current product using it product id.

Please Below Code it help to you.

$product_id = Mage::registry('current_product')->getId();
    $category_ids = $_product->getCategoryIds();
$collection = Mage::getModel('catalog/product')->getCollection()
 ->addAttributeToFilter('entity_id', array('neq' => $product_id))
 ->addAttributeToFilter('status', 1)
$conditions = array();
foreach ($category_ids as $categoryId) {
 if (is_numeric($categoryId)) {
  $conditions[] = "{{table}}.category_id = $categoryId";
->joinField('category_id', 'catalog/category_product', null, 'product_id = entity_id', implode(" OR ", $conditions), 'inner');
 foreach ($collection as $_item) {
    //echo $_item->getName()."</br>";
     $product_qty = $_item->getQty();
     $product_qty = round($product_qty);
    $product_qty = $product_qty/100;
    if($product_qty >= 0.5){
        echo $_item->getName()."</br>";

Please Below code it help getting products.

Thursday, 17 September 2015

Price LessThan 1000 Get Products in Magento


Here I am Create Custom Query for Product list. I want to get all product that price
less than 1000 in magento. I am Giving Example for that

First Create Cms page goto Cms=>page

in cms page
goto design=>Layout Update XML

Write below code in xml

<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
 <action method="unsetChild"><alias>breadcrumbs</alias></action>    
    <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
        <action method="addCrumb">
        <action method="addCrumb">
            <crumbName>Custom Page</crumbName>
            <crumbInfo><label>1000 Under</label><title>1000 Under</title></crumbInfo>

<reference name="left">
     <block type="catalog/navigation" name="catalog.categorymenu" before="catalog.leftnav" template="catalog/product/categorymenu.phtml"/>

<reference name="content">
<block type="catalog/product_new" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>

after create block in your app\code\local\Mage\Catalog\Block\Product\new.php

Write this code for that


class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_List 
   function get_prod_count() 
      //unset any saved limits 
      return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;//set your page limit 
   }// get_prod_count 

   function get_cur_page() 
      return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1; 
   }// get_cur_page 

    * Retrieve loaded category collection 
    * @return Mage_Eav_Model_Entity_Collection_Abstract 
   protected function _getProductCollection() 

      $collection = Mage::getModel('catalog/product')
                        ->setOrder('price', 'ASC')
                        ->addAttributeToFilter('price', array('lt' => '1001'))
                        ->addFieldToFilter('status', array('eq' => '1')


      return $collection; 
   }// _getProductCollection 
}// Mage_Catalog_Block_Product_New 


Tuesday, 15 September 2015

Magento Category Product Listing Sort by Most Viewed Product


You Just want to orverride app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php

paste in code\local\Mage\Catalog\Block\Product\List\Toolbar.php


first add your most viewed in sort by product select box

 public function getAvailableOrders()


       $this->addOrderToAvailableOrders('mostviewd', 'MOST POPULAR');

        return $this->_availableOrder;\\you can add this code here

 public function setCollection($collection)


if ($this->getCurrentOrder()) {

               if($this->getCurrentOrder()=='mostviewd') {
joinInner('report_event AS _table_views',
' _table_views.object_id = e.entity_id',
'COUNT(_table_views.event_id) AS views')->
group('e.entity_id')->order('views DESC');



add this code and check the result.

Monday, 14 September 2015

Magento Product View Count in Product List Page and Product View Page


Some Time You Want to display how many time product view count in magento

I am Give Simple Code it can be used in both product list page it can paste in loop then

it will display every product totoal view count. and product view page current product view

$id = $id=$_helper->productAttribute($_product, $_product->getId(), 'id');

$mostviewedProducts = Mage::getResourceModel('reports/product_collection')->addViewsCount();

            foreach($mostviewedProducts as $product) {
    echo $id."<br/>";
    echo $_product->getId()."<br/>";
   echo $product->getData('entity_id')."<br/>";
    echo  "Total View Count: " . $product->getData('views');

You can add time duration in

$fromDate = '2013-12-10';
$toDate   = now();

$id = $id=$_helper->productAttribute($_product, $_product->getId(), 'id');

$mostviewedProducts = Mage::getResourceModel('reports/product_collection')->addViewsCount($fromDate,$toDate);

            foreach($mostviewedProducts as $product) {
    echo $id."<br/>";
    echo $_product->getId()."<br/>";
   echo $product->getData('entity_id')."<br/>";
    echo  "Total View Count: " . $product->getData('views');

Sunday, 13 September 2015

Get Most view products of current product categories in product detail page(view.phtml) in magento


Here Qurery for Create Most View product of current product of categories

This Section Query used Most view Product view in magento. it's difficult to get because

I am seaching but to get proper result. after i get solution from different different reference

site. i am will give proper guide for that. it success to use it.

    $storeId = Mage::app()->getStore()->getId();
            $category_ids = $_product->getCategoryIds();
            /** date range product view count */
            $toDate   = now();
           $product_id = Mage::registry('current_product')->getId();

$products = Mage::getResourceModel('reports/product_collection')
    ->setPageSize(5)//set the pae size
    ->addAttributeToFilter('category_id', array('in' => $category_ids ));


here one problem you face if current product detail page in this section then you have

I have issue when I go to  section on product detail page; the current product is also getting displayed on this. I just need to remove the current product from  section.

it's soultion is that without change query

foreach($products as $_item){

    $myid =  $_item->getId();

    if ($myid !=  $product_id ){

<?php echo $_item->getProductUrl() ?>



Wednesday, 9 September 2015

When On Particular Category adding a product in admin side then product name should be created automatically using product attributes like weight,sizing Magento


I am Adding Product Admin Side. But When Particular category then it can be automatically
generate Product name. like it's Attributes. I Give Reference for that I give Example For That.

Create Simple Module.


Create Easylife_Meta.xml Here.

<?xml version="1.0"?>
                <Mage_Catalog />


Create config.xml

<?xml version="1.0"?>


Create File Observer.php


class Easylife_Meta_Model_Observer
    public function createName($observer)
        $product = $observer->getEvent()->getProduct();
       $data = $observer->getEvent()->getCategory();
        $product_category_id = $product['category_ids'];
        $productColor = $product->getWeight('weight');
        $productsizing = $product->getAttributeText('sizing');
       if (!empty($product_category_id)) {
        if (in_array("9", $product_category_id)){ // Here 9 in My Category ID
            $productSku = $productColor." ".$productsizing;

Here You can generate name for particular category. you can also change all product remoce if
contion  $product->setName($productSku); set here your value. here 9 is my category
you can check your category id then check it.

Monday, 7 September 2015

Magento Admin Password Reset in Localhost or Local Machine (Magento Password Reset is not Working)


How To Reset Magento Password In Localhost and Magento Site Using Phpmyadmin

I am changing Magento password reset. I Follow The tutorial but in my magento it's not working.

Simple How to reset Password in magento Check this.

You can reset your Magento admin password directly through the database related to your website.

You can use Phpmyadmin Tool.

UPDATE `admin_user` SET `password` = MD5('NEWPASSWORD') WHERE `username` = 'ADMINUSERNAME';

some time you don't know your magento database then you can check you database


<![CDATA[test_magento]]> =>//it's your database name.

you can reset your password using php myadmin ui 

check out below step 

Step 1:

Step :2 

Step 3:

I am Set this but some time it's not Working it make issue in localhost

You can remove Cache and session Folder Var Folder

otherwise not woking then 
follow below Step


$cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath() //,
            // 'domain'   => $cookie->getConfigDomain(),
            // 'secure'   => $cookie->isSecure(),
            // 'httponly' => $cookie->getHttponly()

commet this display in code.

Friday, 29 May 2015

magento on hover change product image in catalog.


I am One Issue. I am change image in product listing page. when i am hover the image it can be change image after mouse out then default image can be see.

I am Writing code for that you can check that can help you.

 <?php $defaultSelectedImage = basename($this->helper('catalog/image')->init($_product, 'small_image')->resize(215));?>
            <?php  $defaultSelectedImage_url = $this->helper('catalog/image')->init($_product, 'small_image')->resize(215);  ?>
                   <?php $_galleryImages = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
                        foreach($_galleryImages as $_gimages){
                            $gallerySelectedImage = basename($this->helper('catalog/image')->init($_product, 'small_image',$_gimages->getFile())->resize(215));
                           if($defaultSelectedImage != $gallerySelectedImage){
                             $_hover_image = $this->helper('catalog/image')->init($_product, 'small_image',$_gimages->getFile())->resize(215);
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">

 <img onmouseover="this.src = '<?php echo $_hover_image; ?>';"  src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(215); ?>"
                onmouseout="this.src = '<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(215) ?>';"
                 alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />

check this code it can be Look Good.

Thursday, 28 May 2015

Remove Default Magneto Block Like News letter,Paypal Logo,Popular Tag

I here Remove this Magneto default block

Remove Poll,
Remove Popular Tags,
Remove Paypal logo Sample Data,
Remove Layered navigation on search result page,
Remove Reorder Sidebar When User Logged, in Dashboard,
Remove Customer Navigation,
Remove Cart Sidebar,
Remove Related products sidebar,
Remove Wishlist Sidebar,
Remove Compare Items Sidebar,
Remove Right Callout Sample Data,
Remove Left Callout Sample Data,
Remove Viewed Products,
Remove Compared Products,
Remove Layered Navigation,
Remove Sidebar Newsletter,

I can give reference of all block.

Chcek Below Code.

you can remove block using xml. here you can remove block using

remove after it 's block name.

<?xml version="1.0"?>
            <!--Magento's Default Sidebar Blocks-->
        <remove name="right.poll"/>                     <!--Poll-->
        <remove name="tags_popular"/>                   <!--Popular Tags-->
        <remove name="paypal.partner.right.logo"/>      <!--Paypal logo Sample Data-->
        <remove name="catalogsearch.leftnav"/>          <!--Layered navigation on search result page-->
        <remove name="sale.reorder.sidebar"/>           <!--Reorder Sidebar When User Logged, in Dashboard-->
        <remove name="customer_account_navigation"/>    <!--Customer Navigation-->
        <remove name="cart_sidebar"/>                   <!--Cart Sidebar-->
        <remove name="catalog.product.related"/>        <!--Related products sidebar-->
        <remove name="wishlist_sidebar"/>               <!--Wishlist Sidebar-->
        <remove name=""/>        <!--Compare Items Sidebar-->
        <remove name="right.permanent.callout"/>        <!--Right Callout Sample Data-->
        <remove name="left.permanent.callout"/>         <!--Left Callout Sample Data-->
        <remove name="right.reports.product.viewed"/>   <!--Viewed Products-->
        <remove name="right.reports.product.compared"/> <!--Compared Products-->
        <remove name="catalog.leftnav"/>                <!--Layered Navigation-->
        <remove name="left.newsletter"/>                <!--Sidebar Newsletter-->


Monday, 25 May 2015

Color Image Swicher in Magento

Hello Friends,

One site i see that when click on image icon in then change image color.
i am searching that any extension  in magneto but mostlly find paid.

then i am try to make simple image swicher or color swicher in magneto.

Check it my code that can help it.

GoTo Admin->manageproduct->addnewproduct(or edit product).

Check Below image we can create custom option in product. here check image for it.

Step1 :  Create custom option

color swicher

Step2: Add Image and also give the label to images

color swicher

After your current theme header.phtml file.

add this script in this your header.phtml

<script type="text/javascript">
jQuery(document).ready(function() {

    jQuery("#select_3").change(function() {
    var optionValueText = jQuery.trim(jQuery('#select_3 :selected').text());
    if(optionValueText != "-- Please Select --")
        alert("#image" + optionValueText);
        var image = "image" + optionValueText;
        jQuery("#image" + optionValueText).show();


in this script comment alert. 

also check id of selectbox

image swicher

I am added Moo_Cloudzoom Extention for so you can added it.

Here it's Media.phtml file it path is in template\moo\catalog\product\view\

Here replace  this code.

foreach ($galleryImages as $_image) {
        $id =  $this->htmlEscape($_image->getLabel());
        $gallery .= '<a id="cloud-zoom-gallery' . $i . ' " href="' . $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) . '" '
                . 'rel="useZoom: \'cloudZoom\', smallImage: \'' . $this->getCloudImage($this->getProduct(), $_image) . '\'" class="cloud-zoom-gallery image'.$id.'" title="' . $this->htmlEscape($_image->getLabel()) . '">'
                . '<img src="' . $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56) . '" width="56" height="56" alt="' . $this->htmlEscape($_image->getLabel()) . '"  />'
                . '</a>';

In this i am added on $id. here I am getting image label. this is added in class in a tag.

i am making with back color. this code added in your media.phtml file. check it
the output.

I am adding after addind code you can change selectbox color value you can change color of image

Thursday, 21 May 2015

Magento Add Breadcrumbs For CMS Page


I am issue in magento breadcrumbs.

issue is that i am create shop page in magento cms page. i am added all product in default category.
it's working fine. but it can not show Breadcrumbs in this page. i am searching on internet
i am checking in admin panel
admin -> system ->config-> web -> default pages -> Show Breadcrumbs for CMS Pages ->yes
but only shop page cms page not display breadcrumbs. other cms page display breadcrumbs.

that i am search for how to add breadcrumbs using xml in cms page i am found that we can
added breadcrumbs manully i am added this code it's working properlly

I am added this code in you cms page. edit your cmspage ->design->Layout Update XML->

I am adding this code

       <reference name="root">
<action method="setTemplate"><template>page/category.phtml</template></action>
 <action method="unsetChild"><alias>breadcrumbs</alias></action>    
    <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
        <action method="addCrumb">
        <action method="addCrumb">
            <crumbName>About us</crumbName>

this code for breadcrumbs my page name is shop add title shop and also change label shop

    <action method="unsetChild"><alias>breadcrumbs</alias></action>    
    <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
        <action method="addCrumb">
        <action method="addCrumb">
            <crumbName>About us</crumbName>

I think you can help this code.

Wednesday, 20 May 2015

how can add span in breadcrumbs in magneto?


I have Issue in My magento. i have add span beetween description.

Here Only I want to change in magento result page (search page).

THis In My Question

Here My breadcrumbs html

  • Home

i want span at 

between search and ring 

i like this 

result.php my breadcrumbs code 

$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
        if ($breadcrumbs) {
            $title = $this->__("Search > %s",$this->helper('catalogsearch')->getQueryText());

            $breadcrumbs->addCrumb('home', array(
                'label' => $this->__('Home'),
                'title' => $this->__('Go to Home Page'),
                'link'  => Mage::getBaseUrl()
            ))->addCrumb('search', array(
                'label' => $title,
                'title' => $title


I Found Solution From magento.stackexchange site.

The text you put in the breadcrumbs is escaped before printing so you won't be a victim of XSS. So any tag you put in the breadcrumbs label will be shown as a tag in the frontend and won't be interpreted.
But you can achieve what you need like this
You need to add after this line:

$title = $this->__("Search > %s",$this->helper('catalogsearch')->getQueryText());

$label = $this->__('Search <span></span>');//span add here
$label .= Mage::helper('core')->escapeHtml($this->helper('catalogsearch')->getQueryText());

This will make your query string escaped before sending it to the breadcrumbs template.

You will also have 2 variables instead of one. $title will still have the original text so you can use it as title for the span element (this will be escaped) and $label that you can use as the span innerHTML.
Now you need to tell the template not to escape the $label again.

So replace this

 ->addCrumb('search', array(
     'label' => $title,
     'title' => $title


->addCrumb('search', array(
     'label' => $label,
     'title' => $title,
     'no_escape' => true

Now you need to edit the breadcrumbs template an remove the htmlEscape when the no_escape element is true.

Replace this section

    echo $this->htmlEscape($_crumbInfo['label']) 
    echo $this->htmlEscape($_crumbInfo['label']) 
    echo $this->htmlEscape($_crumbInfo['label']) 
with this

if (isset($_crumbInfo['no_escape']) && $_crumbInfo['no_escape']) : 
    $label = $_crumbInfo['label'];
else : 
    $label = $this->htmlEscape($_crumbInfo['label']) ;
    echo $label 
    echo $label 
    echo $label 


Monday, 18 May 2015

Magento Search Catalog Not Working : Fixed


I am search in magento but it's not give me poper result.

I am Seaching on net many of solution i get but not working.

after i can found one wordpress blog there is set this type of line

i can follow that instruction it's working properlly.

First i am do some instruction.

If your magento search is not working by Your search returns no results.  the solution is right bellow.

go to System->Configuration->Catalog and check that in Catalog Search the Search Type field is like. it change to Combine (Like and Fulltext) select and save it.

after Go to System->Index Management and reindex Catalog Search Index and all indexes that require indexing.

System->Cache Management and clear your cache, or disable it.

you can do this step also if it can be give the result.
Go to Catalog->Manage Products and select visible products.
Choose the Update Attributes action form the right panel and click Submit button.
Click on the Websites tab from the left and check the Main Website.

below step is search page not give any result that follow upper step.

IF Your Magento search not give proper result then follow step here.

goto -> app/code/core/mage/catalogsearch/block/Result.php
set in your local file

in set your Result.php change some code in your file

step 1 ) Uncomment lines 149 and 150


step 2 ) Modify this  the line 172

change this line
$this->_productCollection = $this->getListBlock()->getLoadedProductCollection();


$this->_productCollection = Mage::getSingleton(‘catalogsearch/layer’)->getProductCollection();

goto the admin  panel (System -> Index Management) and select all the

Indexes > Pick action is “Reindex data” > and the press “submit” button.

And also one thing in admin panel is catalog search setting

Goto the System -> Config -> Catalog -> “Catalog Search”

Here, you can change your search type like, fulltext or both as you need.

i work this code you can check i hope it's working you give proper result.

Monday, 27 April 2015

How to Show popular search terms in sidebar Magento

How to Show popular search terms in sidebar Magento

Hello In you need to add popular search in your sidebar.

if you add code this code in local.xml file or catalog.xml file when to add block for side bar.

<block type="catalogsearch/term" after="tags_popular" name="catalogsearch.term" template="catalogsearch/term.phtml"/>

here i am added left sidebar in code

<reference name="left">
   <block type="catalogsearch/term" after="tags_popular" name="catalogsearch.term" template="catalogsearch/term.phtml"/>

Please use it. 

Thursday, 23 April 2015

how to get store information in magento?

how to get store information in magento?

Hello Herer Some Function To use how to get store value in your phtml file.


Get Current page URL of Store



Get store data



Store Id



Get  Store code



Get Website Id



Is Active store get 



Get Homepage URL of Store


Sunday, 19 April 2015

how to get new root category of sub category in magento and display navigation in menu

how to get new root category of sub category in magento

$root_category = Mage::getModel('catalog/category')->load(7); // Put your root category ID here.

  $subcategories = $root_category->getChildren();?>


  <ul class="cat_list">
  <?php foreach(explode(',',$subcategories) as $subcategory) {

        $category = Mage::getModel('catalog/category')->load($subcategory);?>

echo $category->getName()?></a></li>

 <?php }?>


this will help you new root category get child cateogry check it

if you want to add new root category in your menu then 
just do and follow step

Go to Admin -> Catalog -> Manage Categories -> "Select Category" -> Display Settings -> Is Anchor = "Yes"


Admin -> System -> Index Management -> "Select All" -> "Reindex data" -> "Submit"

get defualt root category any where


any new root category then


Friday, 17 April 2015

remove index.php in url in magento

remove index.php in url in magento 


Here simple to remove index.php in your url in magento.

just follow few step it's done.

here you want to remove index.php in frontend url

step 1 goto Configuration
step 2 goto  Web 
step3 goto Search Engines Optimizations and select yes

simple Configuration -> Web -> Search Engines Optimizations, select YES
it's working 
second is System -> Configuration -> Web -> Secure -> Use secure URLs select yes.

i hope it's working give suggest i any new thing.

remove index.php in magento

Monday, 13 April 2015

Set your custom temple in your cms page or using xml file magento

Set your custom temple in your cms page or using xml file


In Cms Page

Step 1: Goto Cms -> Pages

In add new page or edit your page

Step 2 : In cms page goto -> Design tab

in layout upadate

step3. save


cms page tempalte