简体   繁体   中英

magento module block not working and how to use observer

I am new to magento module development,currently I am developing an module but I am stuck in one line and I want to learn observer also but every time i failed.Currently i want to fetch all products list but there are no results and no errors. any help?

this is my try

in : app/etc/modules/Abc_Mymodule.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Abc_Mymodule>
    <active>true</active>
    <codePool>local</codePool>
    </Abc_Mymodule>
  </modules>
</config>  

My config file in app/code/local/Abc/Mymodule/etc/config.xml

 <?xml version="1.0"?>
 <config>
<modules>
    <Abc_Mymodule>
        <version>0.4.0</version>    <!-- Version number of your module -->
    </Abc_Mymodule>
</modules>
 <global>
    <models>
        <catalog>
            <rewrite>
                <product_type>Abc_Mymodule_Model_Product_Type</product_type>
            </rewrite>
        </catalog>  
      <Mymodule>
           <class>Abc_Mymodule_Model</class>
            <resourceModel>Mymodule_Mysql4</resourceModel>
      </Mymodule>
    </models>
    <resources>

        <Mymodule_setup>
            <setup>
                <module>Abc_Mymodule</module>
                <class>Abc_Mymodule_Model_Resource_Setup</class>
            </setup>                
        </Mymodule_setup>            

    </resources>
    <blocks>
        <Mymodule>
            <class>Abc_Mymodule_Block</class>
        </Mymodule>
    </blocks>
</global>       
<frontend>
    <routers>
        <mymodule>
            <use>standard</use>
            <args>
                <module>Abc_Mymodule</module>
                <frontName>Mymodule</frontName>
            </args>
        </mymodule>
    </routers>
    <layout>
        <updates>
            <Mymodule>
                <file>Mymodule.xml</file>
            </Mymodule>
        </updates>
    </layout>
</frontend>
</config>

My controller is app/code/local/Abc/Mymodule/controllers/PpController.php

<?php
class Abc_Mymodule_PpController extends Mage_Core_Controller_Front_Action
{
 public function productlistAction(){
 /*
     $block = $this->getLayout()->createBlock('Mymodule/Productlist');
    $cole1 =         $block->getCollection();    
     print_r($cole1);
 die;*/
    $this->loadLayout();     
    $this->renderLayout();
 }

 public function postcategoryAction(){
  $userid = Mage::getSingleton('customer/session')->getCustomer()->getId();  
  $parentId = '64';
  $title = $this->getRequest()->getPost('category_name');
   $url=$this->getRequest()->getPost('category_url');

 try{
$category = Mage::getModel('catalog/category');
$category->setName($title);
$category->setUrlKey($url);
$category->setcuid($userid);
$category->setIsActive(0);
$category->setDisplayMode('PRODUCTS');
$category->setIsAnchor(0); //for active achor
$category->setStoreId(Mage::app()->getStore()->getId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
$category->setPath($parentCategory->getPath());
$category->save();
    } catch(Exception $e) {
        var_dump($e);
    }

 Mage::getSingleton('core/session')->addSuccess('Category has been successfully added');


 $this->_redirect('customer/account');

 }

 public function categorylistAction(){

     $this->loadLayout();     
    $this->renderLayout();
 }


?>

My block is app/code/local/Abc/Mymodule/Block

<?php
class Abc_Mymodule_Block_Productlist extends Mage_Core_Block_Template
{
private $cuserid = null;
private $store_id = null;

protected function _construct()
{
//          $cat33 = $this->getCurrentCategory();

$this->store_id = Mage::app()->getStore()->getId();
  //parent::__construct();
$this->cuserid  = Mage::getSingleton('customer/session')->getCustomer()->getId();


    $collection = Mage::getModel('catalog/product')->getCollection();

  /*$collection =   Mage::getModel('catalog/product')
                    ->getCollection()
        ->addAttributeToSelect('*')
                    ->addAttributeToFilter('mmuserid', array('eq' => $this->cuserid))
                    ->load();*/

    $this->setCollection($collection);
  }
?>

I want to use events can any help regarding observer or events?

this is my mymodul

<?xml version="1.0"?>
<layout version="0.1.0">

<mymodule_pp_product>
<reference name="root">
        <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        <action method="addBodyClass"><class>customer-account</class></action>

    </reference>
<reference name="content" >

      <block type="Mymodule/Productadd"  name="productadd"  template="mymodule/productadd.phtml"  />

</reference>
 <reference name="left">
        <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
            <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
            <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
            <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>

        </block>
    </reference>
    </mymodule_pp_product>
     </layout>

好的,没有答案。实际上,我指出了阻止不起作用的原因,这是一个小的拼写错误,现在我已经编辑了问题,现在可以正确拼写并为我工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM