且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

结帐时的Magento自定义字段

更新时间:2023-11-30 11:32:28

我通常的座右铭是找到(并根据需要购买)已经具有所需功能的模块.特别是在该项目的生命周期涉及版本升级时,因为这样您就可以从提供商那里寻求预打包的解决方案.

My usual motto is to find (and buy if needed) a module that already has the functionality you seek. Especially when the life of this project involves version upgrades because then you can seek a pre-packaged solution from the provider.

我很遗憾我在Magento安装中添加的所有自定义代码.因为现在除了弄清楚我的hacks之外,我还必须维护该站点以使其继续工作.是时候花更多的时间来用现成的扩展来替换hack了,而这些扩展本来会更快.

I regret every bit of custom code I have added to our Magento install. Because now I've got to maintain the site to just keep working in addition to figuring out my hacks. Time to devote more time to replacing hacks with off-the-shelf extensions, which would have been much faster in the first place.

我知道这种态度在一定程度上与堆栈溢出相反,认为我可以做任何事情,但实际上,Magento的工作是使某人减少工作量.

I know this attitude goes somewhat against the stack overflow thinking of I can do anything, but really, Magento's job is to enable someone to do less work.

两年后,进行了更新:在轻率地投票(可能是为了摆脱问题)之后,我会重新审视并分享一些我学到的东西.附加字段的编程方面是数据持久性的概念.

Two years later, an update: after the gentle poke of a downvote (probably for appearing to shrug off the question), I am back to revisit and share some of what I've learned. The programming aspect of additional fields is the concept of persistence of the data.

如果您对自定义字段没问题,请 Magento SE可以通过编程方式创建自定义变量.

If you're ok with the custom fields only appearing in the transactional emails following the order, then the task is as "simple" as adding the fields to the form somewhere and then updating the controller to to catch and insert the post data into the email. You can use a custom variable in the back end to readily expose this to the email templates. And a Magento SE on programatically creating a custom variable.

要在后端获得持久性,就需要通过模块中的安装程序来添加数据库字段. iCoreThink博客清楚地说明了步骤并解释了原因,如何确认您的工作,然后提供实际的实施方式,例如向客户显示其帐户中的内容. "

Getting persistence into the back end requires adding database fields via an installer in your module. The iCoreThink blog lays out the steps clearly and explains why, how to confirm your work, and then provides real-world implementation, like displaying to the customer in their account. The "other blog" mentioned below has a great example of this, though his example is specifically related to billing and shipping.

我的投票和书签资源:
»到目前为止,这篇 iCoreThink博客帖子是我最喜欢的参考以及我现在正在关注的内容.

Resources from my upvotes and bookmarks:
» This iCoreThink blog post is my favorite reference so far and what I'm following now.

»我使用的是Templates Master的 FireCheckout ,其中包括他们自己的 checkoutfields 模块,但是我已经放弃了他们的单一视图签出,以应对Magento的一页签出流程.我现在正在尝试将他们的结帐字段(并使用他们的控制器)调整到我的模板中以进行结帐.

» I was using Templates Master's FireCheckout which includes their own checkoutfields module, but I've abandoned their single view checkout for the flow of Magento's one page checkout. I'm now trying to adapt their checkout fields (and use their controller) into my template for checkout.

»我想肯定 Alan Storm 写了一篇有关Checkout自定义字段的文章,但我没有看不到.

» I thought for sure Alan Storm wrote an article about Checkout custom fields, but I don't see one.

»此Magento SE 列出了几个博客和一个付费扩展.卓越博客还可以,但是他的风格对我来说太死板了,我什么也没学.

» This Magento SE lists a couple blogs and a paid extension. The excellence blog is ok, but his style is too rote for me and I don't learn anything. The other blog discusses the procedure for building your module and installing the database fields.

»意外的IT博客演示了如何非正式地将代码添加到核心文件中(但可悲的是没有显示如何通过将它们复制到app/code/local来覆盖这些文件)以及手动执行以获取添加到数据库中的列和字段的步骤.显然,对于1.4及以下版本来说是完美的选择,但评论似乎可以解释1.5及以上版本的处理方法.

» The unexpected-IT blog demonstrates and informal hack to add the code to core files (but sadly doesn't show how to override those files by copying them to app/code/local) and the steps to manually perform to get the column and fields added in the database. Apparently is perfect for 1.4 and below, but comments seem to explain what to do for 1.5 and up.

这是我个人最喜欢的更改,因为它无缝地将多余的部分添加到现有的Magento管理页面中,并减少了工作量.注意事项:如果不使用版本控制,我不会这么做,如果在版本升级之间发生任何核心代码更改,它将绝对中断.