我正在使用一个为 Drupal Commerce 项目构建价格表的模块。有一个格式化表格标题的函数:
/**
* Helper function that takes care of the quantity displayed in the headers of
* the price table.
*/
function commerce_price_table_display_quantity_headers($item) {
// Set the quantity text to unlimited if it's -1.
$max_qty = $item['max_qty'] == -1 ? t('Unlimited') : $item['max_qty'];
// If max and min qtys are the same, only show one.
if ($item['min_qty'] == $max_qty) {
$quantity_text = $item['min_qty'];
}
else {
$quantity_text = $item['min_qty'] . ' - ' . $max_qty;
}
return $quantity_text;
}
如您所见,这不是一个主题函数,我可以在 template.php 中覆盖它,但我可以调整一些输出。
我怎样才能重新定义这个函数,以便我可以砍掉和改变一些东西?
到目前为止我的工作...
到目前为止,我尝试将它创建为一个单独的模块,并进行一些细微的更改以显示它是否正常工作,但它并没有覆盖任何输出。
信息文件
; $id$
name = Price Table: Tweaked Display
description = A different layout for the price table as shown on the product display nodes
package = Commerce (contrib)
core = 7.x
dependencies[] = commerce_product
dependencies[] = commerce_price
dependencies[] = commerce_price_table
模块文件
/**
* Override of the helper function that takes care of the quantity displayed in the headers of
* the price table.
*/
function commerce_table_tweak_display_quantity_headers($item) {
// Set the quantity text to unlimited if it's -1.
$max_qty = $item['max_qty'] == -1 ? t('Unlimited gnhh') : $item['max_qty'];
// If max and min qtys are the same, only show one.
if ($item['min_qty'] == $max_qty) {
$quantity_text = $item['min_qty'];
}
else {
$quantity_text = $item['min_qty'] . ' - this is working - ' . $max_qty;
}
return $quantity_text;
}