0

I want to display product same as magento displays in default when product is added. I added tab and when clicks on that tab it displays products but not with systematic design. I want to display product like this:

enter image description here

I added a tab in customer.xml

<customer_account>
        <reference name="customer_account_navigation">
            <action method="addLink">
                <name>offer_product</name>
                <path>user/index/index</path>
                <label>My Offer Product</label>
            </action>
        </reference>
<!--         <update handle="customer_account"/> -->
    </customer_account>

This is my phtml file through which I displayed my products when clicked on my customised tab:

<?php
  $products = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect('*') ->setOrder('entity_id', 'DESC')->setPageSize(10);
  foreach($products as $product):
    $_product = Mage::getModel('catalog/product')->load($product->getId());
    $attribute_value = $_product->getResource()->getAttribute('customerproduct')->getFrontend()->getValue($_product);
     if($attribute_value == 'Yes')
      {
       ?>
        <img alt="" class="img-responsive" src="<?php echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(200,200); ?>">
       <?php
       ?>
        <br />
       <?php
       echo $product->getName().'<br />';
       echo $product->getPrice();
      }
  endforeach;
?>

and this is my controller code :

<?php
class Test_User_IndexController extends Mage_Core_Controller_Front_Action
{
 public function indexAction()
    {
        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('catalog/session');

        $this->getLayout()->getBlock('content')->append(
            $this->getLayout()->createBlock('user/account_dashboard')
        );
        $this->getLayout()->getBlock('head')->setTitle($this->__('My Account'));
        $this->renderLayout();
    }
}
?>

I got idea that, I have to include list.phtml to display my products as magento displays in default after adding products. But I don'y know how to do it.Please help.

1

in your local.xml or xml file of your module

<user_index_index translate="label">
       <label>Custom Page</label>
          <reference name="head">
                 <action method="setTitle"><title>Custom Page</title></action> <!--Page Title-->
         </reference>
     <!-- Mage_Customer -->
     <update handle="customer_account"/>
      <reference name="my.account.wrapper">
        <block type="user/custom" 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"/>
          </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>
          <action method="setColumnCount"><columns>3</columns></action>
      </block>
    </reference>
</user_index_index>

Create block class for collection

<?php
class Excellence_User_Block_Custom extends Mage_Catalog_Block_Product_List{
    protected function _getProductCollection() {
        $this->_productCollection = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect('*') ->setOrder('entity_id', 'DESC')->setPageSize(10);
        return $this->_productCollection;
    }
}

your updated controller

<?php
class Excellence_User_IndexController extends Mage_Core_Controller_Front_Action
{
 public function indexAction()
    {
        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('catalog/session');
        $this->renderLayout();
    }
}
?>
  • Where should I call _getProductCollection() method that you defined on block file @Gopal Patel – Birju Mar 28 '17 at 10:38
  • it will call by default in product list template. just assign your product collection @Birju – Gopal Patel Mar 28 '17 at 10:39
  • its not working@Gopal Patel – Birju Mar 28 '17 at 11:00
  • any error? your route tag is user or anything else? – Gopal Patel Mar 28 '17 at 11:08
  • Its showing the output same without design – Birju Mar 28 '17 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.