- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
首先,我为在这里提出另一个“magento 核心覆盖”问题而道歉,但我遵循了大约 10 个教程并通读了此处发布的几乎所有类似问题,但没有成功。
我必须重写一堆核心模型和类。代码有效,因为我已经更改了核心(在测试 magento 站点中)并且它运行完美。但是时不时会有 magento 更新可用,如果我们应用更新,我的所有更改都会丢失。所以我必须改写基本代码。我想制作我自己的模块来放入所有必需的代码,因为我只需要在每个类中重写 1 或 2 个函数,其余的应该像 Magento 预期的那样工作。
我的第一次尝试是覆盖 Mage_Sales_Model_Order_Pdf_Invoice 类。好的,所以我制作了我的模块。文件结构为:
app/code/local/[namespace]/Sales/etc/config.xml
app/code/local/[命名空间]/Sales/Helper/Data.php(这个类什么都不做,它只是一个空类。我之所以这样做是因为我在某处读到如果没有 Helper 类,Magento 有时无法识别模块)
app/code/local/[namespace]/Sales/Model/Order/Pdf/Invoice.php
app/etc/modules/[命名空间]_Sales.xml
[命名空间]_Sales.xml 文件看起来是这样的:
<?xml version="1.0"?>
<config>
<modules>
<[namespace]_Sales>
<active>true</active>
<codePool>local</codePool>
</[namespace]_Sales>
</modules>
</config>
config.xml 文件如下所示:
< ?xml version="1.0"?>
<config>
<modules>
<[namespace]_Sales>
<version>0.1.0</version>
</[namespace]_Sales>
</modules>
<global>
<helpers>
<sales>
<class>[namespace]_Sales_Helper</class>
</sales>
</helpers>
<models>
<sales>
<rewrite>
<order_pdf_invoice>[namespace]_Sales_Model_Order_Pdf_Invoice</order_pdf_invoice>
</rewrite>
</sales>
</models>
</global>
</config>
Invoice.php 文件如下所示:
<?php
/****I'm adding some different classes here*******************************/
include_once Mage::getBaseDir('lib')."/myclass.php";
include_once Mage::getBaseDir('lib')."/another_library.php";
/********************************************************/
class [namespace]_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
{
public function getPdf($invoices = array())
{
//my code
}
}
我想先测试一下,然后再覆盖我必须更改的所有其他 Controller 和模型。
问题是,它仍然使用原始模型。
我认为模块代码和路径是正确的,因为 magento 找到了我的自定义模型。我通过进入后端进行检查并查看了System->configuration->advanced
我完全清除了缓存,所以不是这样。
我使用 get_class 来确定在 Controller 中返回什么模型:get_class(Mage::getModel('sales/order_pdf_invoice')),这返回 Mage_Sales_Model_Order_Pdf_Invoice/p>
我不知道我在哪里犯了错误,但我确定我犯了一个错误:(
最佳答案
有些错误是我从字面上发现的。请更正这些错误:-
您在“local
”代码池中的问题中提到的所有文件结构,在“”中都缺少文件夹名称“
”文件夹。所以你的本地模块的每个文件结构都必须像:“code
” >appapp/code/local/[namespace]/Sales/...
”。
如果此文件夹结构错误,那么您的 [namespace]_Sales
模块也可能无法按预期工作。
其次,文件“config.xml
”的内容有点不对。正确的是:-
<?xml version="1.0"?>
<config>
<modules>
<[namespace]_Sales>
<version>0.1.0</version>
</[namespace]_Sales>
</modules>
<global>
<helpers>
<!--
This node will be the unique identifier of your module,
and it will be used every time your code requires referencing your own module.
This shouldn't clash with other unique identifiers used in your Magento system.
Normally all the characters are kept in small case for this,
however, I haven't tried with the upper case.
But it will be best to keep your unique identifier in small case only.
-->
<[namespace]sales>
<class>[namespace]_Sales_Helper</class>
</[namespace]sales>
</helpers>
<models>
<!--
If this is not provided, then Magento will not know your module's starting part of Model Class Names.
-->
<[namespace]sales>
<class>[namespace]_Sales_Model</class>
</[namespace]sales>
<sales>
<rewrite>
<order_pdf_invoice>[namespace]_Sales_Model_Order_Pdf_Invoice</order_pdf_invoice>
</rewrite>
</sales>
</models>
</global>
</config>
此外,我认为您不需要在此处添加不同的类(您已在“[namespace]_Sales_Model_Order_Pdf_Invoice
”类 PHP 页面中完成)。这是因为 Magento 会自动加载相关库的所有定义(库类的一些示例是“Varien
”和“Zend
”)。您只需要创建这些库类的对象,您就可以充分使用这些方法。
希望对您有所帮助。
关于php - magento 无法覆盖核心模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8961737/
Linux 有许多跨(假设是 2 个)CPU 内核执行的线程和进程。我希望我的单线程 C/C++ 应用程序成为 CPU0 上的唯一线程。我如何“移动”所有其他线程以使用 CPU1? 我知道我可以使用
我有一个类似于下图的数据库表 Table with 2 columns (UserId and value) 我将传递 UserId 和 2 个字符串。例如:userId: 1, key1: h1,
我想在我的新项目中使用 ASP.NET Core,因为我听说它更快。但是,该项目将使用广泛的数据库访问功能,Entity Framework Core 不支持其中一些功能。我想知道,是否可以使用 En
我已经使用 EntityFrameworkCore.SqlServer 2.0 开发了 asp .net core wep api 2.0 应用程序。它是使用数据库优先方法开发的。当尝试使用 dbco
我已经阅读了很多关于这个主题的文章,但我仍然无法处理这个问题。对不起,如果它是重复的,无论如何! 所以基本上,我正在从头开始构建一个 Angular 应用程序,并且我想按照最佳约定来组织我的代码。我有
我对MPI还是陌生的,所以如果这是一个琐碎的问题,请原谅我。我有一个四核CPU。我想运行一个在单个内核上使用两个进程的OpenMPI C++程序。有什么办法吗?如果是这样,那又如何?我提到了this
下面是一个传播异常处理机制的类问题,所需的输出是异常。任何人都可以解释为什么输出是异常,在此先感谢。 Class Question { public void m1() throws Excep
我想打印每个获得 CPU 时间片的进程的 name 和 pid。可能吗? 最佳答案 对于单个流程,您可以在以下位置获取此信息: /proc//stat 第14和第15个字段分别代表在用户态和内核态花费
我想知道是否可以识别具有特定 thread-id 的线程使用的物理处理器(核心)? 例如,我有一个多线程应用程序,它有两 (2) 个线程(例如,thread-id = 10 和 thread-id =
我有一个需要身份验证的 Solr 核心。假设我有一个用户,密码为password。当我现在尝试在控制台中创建一个 Solr 核心时 bin\solr create -c test 我收到 HTTP 错
我想为与使用它的项目不同的类库中的第二个和后续数据库创建迁移。有皱纹。我永远不会知道连接字符串,直到用户登录并且我可以从目录数据库 (saas) 中获取它。 对于目录数据库,我使用了来自 this 的
我想为一种可以产生 GHC Core 的简单语言创建一个前端。然后我想获取这个输出并通过正常的 GHC 管道运行它。根据this page , 不能直接通过 ghc 命令实现。我想知道是否有任何方法可
阅读文档,我构建了 2 个使用 BLE 连接 2 个 iDevices 的应用程序。 一个设备是中央设备,另一个是外围设备。 Central在寻找Peripheral,当找到它时,探索它的服务和特性,
在我的网络应用程序中,我对长时间运行的任务进行了操作,我想在后台调用此任务。因此,根据文档 .net core 3.1 Queued background tasks我为此使用这样的代码: publi
Solr 1.4 Enterprise Search Server 建议对核心副本进行大量更新,然后将其换成主核心。我正在按照以下步骤操作: 创建准备核心:http://localhost:8983/
它们是否存在,如果存在,文档和代码在哪里? 最佳答案 它们位于 Git 的 test 目录中。 https://github.com/jquery/jquery/tree/master/test 关于
我有一个 Lisp (SBCL 1.0.40.0.debian) 应用程序 (myfitnessdata),它使用以下代码来处理命令行参数: (:use :common-lisp) (:export
Core是GHC的中间语言。阅读Core可以帮助你更好地了解程序的性能。有人向我索要有关阅读 Core 的文档或教程,但我找不到太多。 有哪些文档可用于阅读 GHC Core? 这是我迄今为止发现的内
我有一个核心 WebJob 部署到 Azure Web 应用程序中。我正在使用WebJobs version 3.0.6 . 我注意到,WebJob 代码不会立即拾取对连接字符串和应用程序设置的更改(
我有一个在内部构造和使用 SqlConnection 类的第三方库。我可以从该类继承,但它有大量重载,到目前为止我一直无法找到合适的重载。我想要的是将参数附加到正在使用的连接字符串。 有没有办法在 .
我是一名优秀的程序员,十分优秀!