我是magento模块开发的新手,目前我正在开发一个模块,但我被困在一行,我也想学习观察者,但每次我都失败了。目前我想要获取所有产品列表但是没有结果并没有错误。任何帮助?
这是我的尝试
中的:app / etc / modules / Abc_Mymodule.xml
<?xml version="1.0"?>
<config>
<modules>
<Abc_Mymodule>
<active>true</active>
<codePool>local</codePool>
</Abc_Mymodule>
</modules>
</config>
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>
我的控制器是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();
}
?>
我的块是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);
}
?>
我想使用事件可以对观察者或事件有任何帮助吗?
这是我的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>
答案 0 :(得分:0)
好吧实际上没有答案我想知道为什么阻止不起作用的原因有一个小的拼写错误,现在我已经编辑了我的问题并且现在正确拼写并为我工作。