Magento 1.5.1: новый блок панели пользователя - PullRequest
1 голос
/ 06 июня 2011

Я схожу с ума, пытаясь создать новый очень простой раздел на панели пользователя.Что-то вроде www.mymagentosite.com/customer/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

1 Ответ

0 голосов
/ 06 июня 2011

Вы должны указать Magento использовать ваш контроллер, а не ядро:

"Здесь важно отметить, что с контроллерами Magento не загружает их автоматически, как это происходит с блоками и моделями."

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

и т. Д. / Config.xml

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