Wednesday, February 27, 2013

Product or Catgeorty List Page With Layered Navigation on Home Page or Any CMS Page Or Custom Module In Magneto

Hi,
if You have to call Product List page or category page with Left Layered Navigation on CMS Page or Custom Module
for Attached text File steps
1. Override Mage_Catalog_Block_Category_View to your local


class Sugarcode_Catalog_Block_Category_View extends Mage_Catalog_Block_Category_View
{
   public function getCurrentCategory()
    {
        if (!$this->hasData('current_category')) {
            $category = Mage::registry('current_category');
            if (!$category)
            {
                //get the root category
                $id = $this->getCategoryId();
                $category = Mage::getModel('catalog/category')->load($id);
            }
            $this->setData('current_category', $category);
        }
        return $this->getData('current_category');
    
    }
}



2. Override Sugarcode_Catalog_Block_Layer_View to your local


class Sugarcode_Catalog_Block_Layer_View extends Mage_Catalog_Block_Layer_View
{
   
 
 protected $categoryId;
 protected $fromHomePage = false;
   
    protected function _construct()
    {
        parent::_construct();

        $this->_initBlocks();
    }

   public function setCategoryId($id)
    {
 
        $category = Mage::getModel('catalog/category')->load($id);
        if ($category->getId()) {
            Mage::getSingleton('catalog/layer')->setCurrentCategory($category);
   $this->setData('current_category', $category);
   $this->categoryId=$id;
   $filterableAttributes =   Mage::getSingleton('catalog/layer')->getFilterableAttributes();
   
   $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
            ->setLayer(Mage::getSingleton('catalog/layer'));

        $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
            ->setLayer(Mage::getSingleton('catalog/layer'))
            ->init();

        $this->setChild('layer_state', $stateBlock);
        $this->setChild('category_filter', $categoryBlock);

        $filterableAttributes = $this->_getFilterableAttributes();
        foreach ($filterableAttributes as $attribute) {
            if ($attribute->getAttributeCode() == 'price') {
                $filterBlockName = $this->_priceFilterBlockName;
            } elseif ($attribute->getBackendType() == 'decimal') {
                $filterBlockName = $this->_decimalFilterBlockName;
            } else {
                $filterBlockName = $this->_attributeFilterBlockName;
            }

            $this->setChild($attribute->getAttributeCode() . '_filter',
                $this->getLayout()->createBlock($filterBlockName)
                    ->setLayer(Mage::getSingleton('catalog/layer'))
                    ->setAttributeModel($attribute)
                    ->init());
        }

        Mage::getSingleton('catalog/layer')->apply();

  
  
        }
 
    }
 
 
    /**
     * Prepare child blocks
     *
     * @return Mage_Catalog_Block_Layer_View
     */
    public function _prepareLayout()
    {
 //parent::_prepareLayout();
  if (!Mage::registry('current_category'))
        {
  
            $this->fromHomePage = true;
            $category = Mage::getModel('catalog/category')
                ->setStoreId(Mage::app()->getStore()->getId())
                ->load($this->categoryId);

            if (!Mage::helper('catalog/category')->canShow($category)) 
            {
                return false;
            }
    
            Mage::getSingleton('catalog/session')->setLastVisitedCategoryId($category->getId());
            Mage::register('current_category', $category); 
    Mage::getSingleton('catalog/layer')->setCurrentCategory($category);
   
        }
        $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
            ->setLayer($this->getLayer());

        $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
            ->setLayer($this->getLayer())
            ->init();

        $this->setChild('layer_state', $stateBlock);
        $this->setChild('category_filter', $categoryBlock);

        $filterableAttributes = $this->_getFilterableAttributes();
        foreach ($filterableAttributes as $attribute) {
            if ($attribute->getAttributeCode() == 'price') {
                $filterBlockName = $this->_priceFilterBlockName;
            } elseif ($attribute->getBackendType() == 'decimal') {
                $filterBlockName = $this->_decimalFilterBlockName;
            } else {
                $filterBlockName = $this->_attributeFilterBlockName;
            }

            $this->setChild($attribute->getAttributeCode() . '_filter',
                $this->getLayout()->createBlock($filterBlockName)
                    ->setLayer($this->getLayer())
                    ->setAttributeModel($attribute)
                    ->init());
        }

        $this->getLayer()->apply();

        return parent::_prepareLayout();
    }
}



3. In CMS design->custom XMl make
Custom Layout:- 2 columns with left bar
XML add below code


<reference name="left">
            <block type="catalog/layer_view" name="catalog.leftnav33" after="-"  template="catalog/layer/view.phtml">
   <action method="setCategoryId"><category_id>3</category_id></action>
   </block>
        </reference>
        <reference name="content">
            <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml" >
                <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                    <!-- <action method="addReviewSummaryTemplate"><type>default</type><template>review/helper/su.phtml</template></action> -->
     <action method="setCategoryId"><category_id>3</category_id></action>
                    <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"/>
                   
                    </block>
                    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
                    <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
                    <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
                </block>
            </block>
        </reference>

 
Note :- 3 in XML Set You category Id
For More got to here http://www.magentocommerce.com/boards/viewthread/308574/

Tuesday, January 8, 2013

SQLSTATE[HY000]: General error: 126 Incorrect key file for table Error in Magento

Hi,

If you face error some thing like “SQLSTATE[HY000]: General error: 126 Incorrect key file for table ‘/var/tmp/#sql_41ac_0.MYI’; try to repair it” error its because of MySQL tmp folder space issue

there is not enough space in /tmp for the temporary table, so this error will through
I fixed this by setting “tmpdir = /home/tmp” (which has lots of space on my host) in my.cnf
just create a folder tmp which has enough space and give tmpdir in my.cnf in my case i used home/tmp where i had enough space for tmp directory but in your case it may change
Enjoy :-)
http://www.magentocommerce.com/boards/viewthread/302400/

Sunday, January 6, 2013

Redirect back to page after logged-in in Magento

If you need to go back to same page once it logged in ,
that is
your in list page and clicked to sign in link and then you logged in it has to go back to list page its self

Magento has default setting for not to redirect account page if you logged in from default page by defult it will redirect to account dash board

but you need to go page to list page
for that follow the below steps
Open header.phtml add this code at top of the file
 if(!Mage::helper('customer')->isLoggedIn()) {
 $loginback=$this->helper('core/url')->getCurrentUrl();
 $check=strstr($loginback, 'customer/account/login');
 if(!strlen($check)){
 Mage::getSingleton('core/session')->setLoginBackUrl($loginback);
 }
}

override app\\code\\core\\Mage\\Customer\\controllers\\AccountController.php to you local or custom module and add this function
 public function _loginPostRedirect()
    {
        $session = $this->_getSession();

        if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) {

            // Set default URL to redirect customer to
            $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
            // Redirect customer to the last page visited after logging in
            if ($session->isLoggedIn()) {
   $backUrlcustom=Mage::getSingleton('core/session')->getLoginBackUrl();
                if (!Mage::getStoreConfigFlag('customer/startup/redirect_dashboard')) {
                    $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
                    if ($referer) {
                        $referer = Mage::helper('core')->urlDecode($referer);
                        if ($this->_isUrlInternal($referer)) {
                            $session->setBeforeAuthUrl($referer);
                        }
                    }
                } else if ($session->getAfterAuthUrl()) {
                    $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
                } else if (strlen($backUrlcustom)) {
     Mage::getSingleton('core/session')->setLoginBackUrl('');
                    $session->setBeforeAuthUrl($backUrlcustom);
                }
            } else {
                $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl());
            }
        } else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) {
            $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl());
        } else {
            if (!$session->getAfterAuthUrl()) {
                $session->setAfterAuthUrl($session->getBeforeAuthUrl());
            }
            if ($session->isLoggedIn()) {
                $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
            }
        }
        $this->_redirectUrl($session->getBeforeAuthUrl(true));
    }

or check it this post
http://www.magentocommerce.com/boards/viewthread/301762/

Wednesday, December 19, 2012

Order Edit or Update From Front End in Magneto

Hi,
I done with module called order update where you can edit a pending order from front-end in your account section it will work same as like order edit in admin any help needed contact me

Tuesday, December 18, 2012

Store Credit Or Customer Balance Module in Magneto

Hi,
I Done with Store Credit module any help need please contact me i can help you out
in this once order is invoiced and made credit memo at that time customer can re use that balance to buy other product

Tuesday, October 16, 2012

Get Magento Version in Magento Programmatically


If you need to get your Magento project version Programmatically use below code



$m= new Mage;
$version=$m->getVersion();
echo $version;


Wednesday, August 29, 2012

Buy X Product get least price product Free in magneto


Hi,
We can write a module which will give option in Shopping Cart Price Rules where if customer buys X product and he will get very least or minimum price product as free

i explained clear in my Magento post  please go to below link

http://www.magentocommerce.com/boards/member/356269/