Magento 1.5.1:新的客户仪表板块

发布于 2024-11-13 14:03:19 字数 3046 浏览 1 评论 0原文

我正在努力尝试在我的客户仪表板上创建一个新的非常简单的部分。类似 www.mymagentosite.com/customer/rid(rid 仅包含静态链接)。但是,当我尝试访问 www.mymagentosite.com/customer/rid 时,我总是收到 404 Magento 页面(日志文件中没有异常或系统消息)

我错过了什么?

谢谢

到目前为止我所做的是:

- 在 /app/code/local/Mage/Customer/Block/Account/Dashboard/Rid.php 下创建一个新块 -

class Mage_Customer_Block_Account_Dashboard_Rid extends Mage_Core_Block_Template
{ 
  public function getCustomer()
  {
      return Mage::getSingleton('customer/session')->getCustomer();
  } 

}

在 /app/code/local/Mage 下创建一个新控制器/Customer/controllers/RidController.php

class Mage_Customer_RidController extends Mage_Core_Controller_Front_Action
{
  protected function _getSession()
  {
    return Mage::getSingleton('customer/session');
  }

  public function preDispatch()
  {
    parent::preDispatch();

    if (!Mage::getSingleton('customer/session')->authenticate($this)) {
        $this->setFlag('', 'no-dispatch', true);
    }
  }

  public function indexAction()
  {
    if (count($this->_getSession()->getCustomer()->getAddresses())) {
        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('catalog/session');

        $block = $this->getLayout()->getBlock('rid');
        if ($block) {
            $block->setRefererUrl($this->_getRefererUrl());
        }
        $this->renderLayout();
    } else {
        $this->getResponse()->setRedirect(Mage::getUrl('*/*/new'));
    }
  }
}

- 在 /app/code/local/Mage/Customer/Helper/Rid.php 下创建一个新的助手

class Mage_Customer_Helper_Rid extends Mage_Core_Helper_Abstract
{

  public function getRenderer($renderer)
  {
    if(is_string($renderer) && $className = Mage::getConfig()->getBlockClassName($renderer)) {
        return new $className();
    } else {
        return $renderer;
    }
  }

}

- 编辑文件/app/design/frontend/default/MYTHEME/layout/customer.xml

<customer_account_index translate="label">
    <label>Customer My Account Dashboard</label>
    <update handle="customer_account"/>
    <!-- EXISTING CODE -->
    <reference name="my.account.wrapper">
    <!-- EXISTING CODE -->
   <block type="customer/account_dashboard_rid" name="rid" as="rid" 
              template="customer/account/dashboard/rid.phtml"></block>
        </block>
    </reference>
</customer_account_index>

<customer_rid_index translate="label">
    <label>RID</label>
    <!-- Mage_Customer -->
    <update handle="customer_account"/>
    <reference name="my.account.wrapper">
        <block type="customer/rid" name="address_book" 
               template="customer/account/dashboard/rid.phtml"/>
    </reference>
</customer_rid_index>

-create /app/design/frontend/default/MYTHEME/template/customer/account/dashboard/rid.phtml

I am going mental trying to create a new very simple section on my customer dashboard. Something like www.mymagentosite.com/customer/rid (rid includes only static links). However, when I try to access www.mymagentosite.com/customer/rid, I always get a 404 Magento page (no exceptions or system message in the log files)

What am I missing?

Thank you

What I have done so far is:

-create a new Block under /app/code/local/Mage/Customer/Block/Account/Dashboard/Rid.php

class Mage_Customer_Block_Account_Dashboard_Rid extends Mage_Core_Block_Template
{ 
  public function getCustomer()
  {
      return Mage::getSingleton('customer/session')->getCustomer();
  } 

}

-create a new controller under /app/code/local/Mage/Customer/controllers/RidController.php

class Mage_Customer_RidController extends Mage_Core_Controller_Front_Action
{
  protected function _getSession()
  {
    return Mage::getSingleton('customer/session');
  }

  public function preDispatch()
  {
    parent::preDispatch();

    if (!Mage::getSingleton('customer/session')->authenticate($this)) {
        $this->setFlag('', 'no-dispatch', true);
    }
  }

  public function indexAction()
  {
    if (count($this->_getSession()->getCustomer()->getAddresses())) {
        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->_initLayoutMessages('catalog/session');

        $block = $this->getLayout()->getBlock('rid');
        if ($block) {
            $block->setRefererUrl($this->_getRefererUrl());
        }
        $this->renderLayout();
    } else {
        $this->getResponse()->setRedirect(Mage::getUrl('*/*/new'));
    }
  }
}

-create a new helper under /app/code/local/Mage/Customer/Helper/Rid.php

class Mage_Customer_Helper_Rid extends Mage_Core_Helper_Abstract
{

  public function getRenderer($renderer)
  {
    if(is_string($renderer) && $className = Mage::getConfig()->getBlockClassName($renderer)) {
        return new $className();
    } else {
        return $renderer;
    }
  }

}

-edit the file /app/design/frontend/default/MYTHEME/layout/customer.xml

<customer_account_index translate="label">
    <label>Customer My Account Dashboard</label>
    <update handle="customer_account"/>
    <!-- EXISTING CODE -->
    <reference name="my.account.wrapper">
    <!-- EXISTING CODE -->
   <block type="customer/account_dashboard_rid" name="rid" as="rid" 
              template="customer/account/dashboard/rid.phtml"></block>
        </block>
    </reference>
</customer_account_index>

<customer_rid_index translate="label">
    <label>RID</label>
    <!-- Mage_Customer -->
    <update handle="customer_account"/>
    <reference name="my.account.wrapper">
        <block type="customer/rid" name="address_book" 
               template="customer/account/dashboard/rid.phtml"/>
    </reference>
</customer_rid_index>

-create /app/design/frontend/default/MYTHEME/template/customer/account/dashboard/rid.phtml

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2024-11-20 14:03:19

您需要告诉 Magento 使用您的控制器而不是核心:

“这里需要注意的一个重要关键是,对于控制器,Magento 不会像块和模型那样自动加载它们。”

http://prattski.com/ 2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/

etc/config.xml

<config>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                         <My_Module before="Mage_Checkout">My_Module_Checkout</My_Module>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

You need to tell Magento to use your controller and not the core:

"An important key to note here is that with controllers, Magento does not autoload them like it does with blocks and models."

http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/

etc/config.xml

<config>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                         <My_Module before="Mage_Checkout">My_Module_Checkout</My_Module>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文