【问题标题】:rewrite cart url is not working in magento重写购物​​车 url 在 magento 中不起作用
【发布时间】:2015-07-08 01:45:53
【问题描述】:

我想重写结帐购物车网址。我创建了一个模块,但它不工作。我在模型中创建了 config.xml 和 Url.php 但没有成功。我的代码是:etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Ghrix_Newcart>
          <version>1.0.0</version>
        </Ghrix_Newcart>
    </modules>
  <global>
    <rewrite>
      <ghrix_newcart_checkout_cart>
        <from><![CDATA[#^/checkout/winkelwagen#]]></from>
        <to><![CDATA[#^/checkout/cart#]]></to>
      </ghrix_newcart_checkout_cart>
    </rewrite>
   <models>
      <ghrix_newcart>
        <class>Ghrix_Newcart_Model</class>
      </ghrix_newcart>
      <core>
        <rewrite>
          <url>Ghrix_Newcart_Model_Url</url>
        </rewrite>
      </core>
    </models>
  </global> 
</config>

在模型/Url.php中

<?php
class Ghrix_Newcart_Model_Url extends Mage_Core_Model_Url {
    /**
    * Build url by requested path and parameters
    *
    * @param string|null $routePath
    * @param array|null $routeParams
    * @return string
    */
    public function getUrl($routePath = null, $routeParams = null) {
    if(strstr($routePath,'checkout')){
        //echo $routePath.'--ss--<br />';
    }
        if ( $routePath == 'checkout/cart' ) {          

                $routePath = 'checkout/cart';
            }
            return parent::getUrl($routePath, $routeParams);
        }
} 
?>

我已经正确创建了一个函数,但它对我不起作用。我希望我的结帐/购物车 url 应该是 checkout/winkelwagen 请建议我该怎么做。

【问题讨论】:

  • 你能解释一下你想要完成什么吗?为什么需要将客户发送到checkout/winkelwagen 而不是checkout/cart

标签: magento url-rewriting module


【解决方案1】:

我可能会使用 Magento 的事件观察器系统以一种不那么侵入性的方式来处理这个问题。您可以做的是将所有请求重定向到 checkout/cart 路由到您的新路由 checkout/winkelwagen,如下所示:

etc/config.xml

<frontend>
    <events>
        <controller_action_predispatch_checkout_cart_index>
            <observers>
                <redirectCart>
                    <class>Ghrix_Newcart_Model_Observer</class>
                    <method>redirectCart</method>
                </redirectCart>
            </observers>
        </controller_action_predispatch_checkout_cart_index>
    </events>
</frontend>

模型/观察者.php

public function redirectCart(Varien_Event_Observer $observer)
{
    Mage::app()->getResponse()->setRedirect('/checkout/winkelwagen')->sendResponse();
    exit;
}

【讨论】:

  • 我编辑了我的代码及其重定向,但没有得到购物车页面内容。
  • 我在 config.xml 中的代码 1.0.0/checkout/cartGhrix_Newcart_ModelGhrix_Newcart_Model_Url
  • and Url.php "; if(strstr($routePath,'checkout')){ //echo $routePath.'--ss--
    '; } if ( $routePath == 'checkout/cart' ) { $routePath = 'checkout/winkelwagen'; } 返回父级::getUrl($routePath, $routeParams); } } ?>
  • 建议我如何在我的 url 上获取购物车页面数据。它重写了结帐/winkelwagen 的 url,但没有得到购物车页面的内容。如何获取内容?
  • 请建议我该怎么做?
猜你喜欢
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 2016-11-26
相关资源
最近更新 更多