如何从我的模块动态更改 ubercart 的默认消息

发布于 2024-08-28 11:33:40 字数 195 浏览 5 评论 0原文

对于某些产品,我希望有一个与默认值不同的特殊结账完成消息。

我知道我可以通过将默认重定向页面更改为其他内容来做到这一点。 [我不确定这是否会引入另一个问题]

但是,我想知道是否有标准/更好的方法来解决这个问题。

谢谢!,

D

There are some products for which I would like to have a special checkout complete message that would differ from the default.

I know that I could probably do this by changing the default redirect page to something else. [And I'm not sure if that would introduce another problem]

However, I would like to know if there is a standard/better way of approaching this problem.

Thanks!,

D

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

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

发布评论

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

评论(2

南笙 2024-09-04 11:33:40

考虑字符串覆盖模块。这是关于它的引用(来自模块的项目页面):

提供了一种快速、简单的方法来替换网站上的任何文本。

特点:

  • 轻松替换通过 t() 传递的任何内容
  • 区域设置支持,允许您覆盖任何语言的字符串
  • 能够导入/导出 *.po 文件,以便从区域设置模块轻松迁移
  • 请注意,这并不是 Locale 的替代品,因为数以千计的覆盖可能会带来更多的痛苦而不是好处。仅当您需要进行一些简单的文本更改时才使用此选项。

Consider the String Overrides module. Here is a quote about it (from the module's project page):

Provides a quick and easy way to replace any text on the site.

Features:

  • Easily replace anything that's passed through t()
  • Locale support, allowing you to override strings in any language
  • Ability to import/export *.po files, for easy migration from the Locale module
  • Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
横笛休吹塞上声 2024-09-04 11:33:40

我想做我正在考虑的事情的唯一其他可能的方法是覆盖 ubercart 用于显示消息的主题函数。这似乎是最有意义的。

在这种情况下,我将覆盖 theme_uc_cart_complete_sale

我可以设置 a

$_SESSION['is_special_product'] == TRUE;

,然后将 $message 设置为我的 $special_message(如果已设置)。

if ($_SESSION['special_product']) {
      $special_message = t('This is my special message');
      $message = variable_get('special_product_message', $special_message;
    }

最后,要从我的模块覆盖,我需要挂钩预处理挂钩:

function $modulename_prepocess_$hook(&$message) {
      if ($_SESSION['special_product']) {
      $special_message = t('This is my special message');
      $message = variable_get('special_product_message', $special_message;
    }
}

重要的是要注意在模块中拥有此函数是不够的。仅当调用覆盖主题函数的模板文件时,才会调用预处理函数。

更多详细信息请访问 http://drupal.org/node/223430

I guess the only other possible way of doing what I am thinking of is to override the theme function that ubercart uses to display the message. And this probably seems like it would make the most sense.

In this case I would override theme_uc_cart_complete_sale

I could set a

$_SESSION['is_special_product'] == TRUE;

and then set $message to my $special_message if it's been set.

if ($_SESSION['special_product']) {
      $special_message = t('This is my special message');
      $message = variable_get('special_product_message', $special_message;
    }

Finally, to override from my module I will need to hook into the pre-process hook:

function $modulename_prepocess_$hook(&$message) {
      if ($_SESSION['special_product']) {
      $special_message = t('This is my special message');
      $message = variable_get('special_product_message', $special_message;
    }
}

It is important to note that it is not enough to have this function in your module. The preprocess functions are only invoked when the template file that overrides the theme function is called.

More details can be found at http://drupal.org/node/223430

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