0

I Created one custom module and I want to fetch data from the system.xml file which is created in my module. so for fetching that data I create Model, Block and also .phtml file. But I get the Fatal error. Here is my Model File.

<?php

class Vrinsoft_Productlist_Model_Categorylist extends Mage_Core_Model_Abstract {
  public function getCategorylist() {
    echo "harshil";exit;     
    $categorylist=Mage::getStoreConfig('productlist/section_two/custom_field_nine');
    $result=explode(",",$categorylist);
    $category = Mage::getModel('catalog/category');

    foreach($result as $value )
    {
        $val=$category->load($value);   

        $productCollection = $val->getProductCollection();
        $productCollection
        ->addStoreFilter()
        ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addUrlRewrite();
    }
}

Here is Block File.

<?php
class Vrinsoft_Productlist_Block_Categorylist extends Mage_Core_Block_Template
{
  public function getCategorylist() 
    {
    echo "block";exit       
        $arr_products = array();
            $products = Mage::getModel("productlist/productlist")­->getCategorylist();

        foreach ($products as $product) 
        {
              $arr_products[] = array(
            'id' => $product-­>getId(),
            'name' => $product­->getName(),
            'url' => $product­->getProductUrl(),
            'image'=>$product­->getImageUrl(),
              );
            }

        return $arr_products;      
    }
}

Here is my .phtml file

<?php 

$products = $this­->getCategorylist();
foreach($products as $product) { ?>
      <div>
        <a href="<?php echo $product['url'] ?>"><?php echo $product['name'] ?></a>
      </div>
    <?php } ?>

And Here is my config.xml file

<?xml version="1.0"?>
<config>
    <modules>
        <Vrinsoft_Productlist>
            <version>0.0.1</version>
        </Vrinsoft_Productlist>
    </modules>
    <frontend>
        <routers>
          <productlist>
        <use>standard</use>
        <args>
          <module>Vrinsoft_Productlist</module>
          <frontName>productlist</frontName>
        </args>
          </productlist>
        </routers>
        <layout>
           <updates>
                <test>
                     <file>productlist.xml</file>
                 </test>
            </updates>
        </layout>
      </frontend>
    <global>
    <blocks>
        <productlist>
            <class>Vrinsoft_Productlist_Block</class>
        </productlist>
    </blocks>
        <helpers>
            <productlist>
                <class>Vrinsoft_Productlist_Helper</class>
            </productlist>
        </helpers>
        <models>
             <productlist>
                <class>Vrinsoft_Productlist_Model</class>
             </productlist>
        </models>
    </global>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <productlist>
                                            <title>Product Configuration Section</title>
                                        </productlist>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

so help me out for this problem. Any kind of help will appreciated

1 Answer 1

0

You code seems wrong,in a case.

You have try get product collection of your configuration selected categories.

You need to modify code at your model class Model File

<?php
class Vrinsoft_Productlist_Model_Categorylist extends Mage_Core_Model_Abstract {
  public function getCategorylist() {
    echo "harshil";exit;     
    $categorylist=Mage::getStoreConfig('productlist/section_two/custom_field_nine');
    $result=explode(",",$categorylist);
    $productCollection = Mage::getModel('catalog/product')
        ->getCollection()
        ->joinField(
        'category_id', 'catalog/category_product', 'category_id', 
        'product_id = entity_id', null, 'left'
        )->addAttributeToFilter('category_id', array(
        array('finset' => $result),
        ))
        ->addStoreFilter()
        ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addUrlRewrite();
    return $productCollection;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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