当前的 Uberart (v 2.0) 不允许使用小数表示数量。
如果您在 Ubercart 论坛中搜索“数量为十进制”、“分数为数量”和“十进制数量”,您会获得一些点击率。本文旨在概述可能对您安装的 Ubercart 系统进行的一些更改,以允许将“小数”添加到您的购物车中。
感谢 Lyle 和他的帖子回复,帮助我开始使用 this article。
添加到 Ubercart 核心?
我希望 Ubercart 开发人员能够找到一种方法来实现 Ubercart Core 的“分数”功能。我希望这篇文档/文章能帮助实现这一目标!
数据库更改
将 Ubercart 更改为接受小数意味着某些表列的数据类型必须从 INTEGER 更改为 FLOAT(M,D)。 FLOAT 数据类型允许存储小数。这是来自http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html的描述
这里,“(M,D)”表示值可以是
总共存储最多 M 个数字,
其中 D 位可能在
小数点。例如,一列
定义为 FLOAT(7,4) 看起来像
-999.9999 显示时。 MySQL 在存储值时执行舍入,
因此,如果您将 999.00009 插入
FLOAT(7,4) 列,近似值
结果是 999.0001。
以下是对表格进行的更改,以允许保留 2 个小数位和 6 个总位数。应用以下数据库表更改不应影响现有数据,除非您的数量大于 6 位——在这种情况下,您可以增加 M 值。
// # UC_CART_PRODUCTS
ALTER TABLE `uc_cart_products` MODIFY COLUMN `qty` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 0;
UC_ORDERS
// # UC_ORDERS
ALTER TABLE `uc_orders` MODIFY COLUMN `product_count` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 0;
// # UC_PRODUCTS
ALTER TABLE `uc_products` MODIFY COLUMN `default_qty` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 1.00;
// # UC_ORDER_PRODUCTS
ALTER TABLE `uc_order_products` MODIFY COLUMN `qty` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 0;
代码更改
// # uc_cart.module (line 1445)
db_query("UPDATE {uc_cart_products} SET qty = %d, changed = UNIX_TIMESTAMP(), data = '%s' WHERE cart_item_id = %d",
到...
db_query("UPDATE {uc_cart_products} SET qty = %f, changed = UNIX_TIMESTAMP(), data = '%s' WHERE cart_item_id = %d",
--
// # uc_cart.module (line 1509)
db_query("INSERT INTO {uc_cart_products} (cart_id, nid, qty, changed, data) VALUES ('%s', %d, %d, %d, '%s')", $cid, $node->nid, $qty, time(), serialize($data));
到...
db_query("INSERT INTO {uc_cart_products} (cart_id, nid, qty, changed, data) VALUES ('%s', %d, %f, %d, '%s')", $cid, $node->nid, $qty, time(), serialize($data));
--
// # uc_order.module (line 1043)
db_query("UPDATE {uc_orders} SET uid = %d, order_status = '%s', order_total = %f, product_count = %d, primary_email = '%s', "
到...
db_query("UPDATE {uc_orders} SET uid = %d, order_status = '%s', order_total = %f, product_count = %f, primary_email = '%s', "
--
// # uc_order.module (line 1143)
db_query("UPDATE {uc_orders} SET product_count = %d WHERE order_id = %d", $count, $order->order_id);
到...
db_query("UPDATE {uc_orders} SET product_count = %f WHERE order_id = %d", $count, $order->order_id);
--
// # uc_order.install (replace lines 48 to 51)
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
与...
'type' => 'float',
'precision' => '6',
'scale' => '2',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.00,
--
// # uc_product.module (line 1207)
db_query("UPDATE {uc_cart_products} SET qty = %d, changed = %d WHERE nid = %d AND cart_id = '%s' AND data = '%s'", $qty, time(), $nid, $cid, serialize($data));
到...
db_query("UPDATE {uc_cart_products} SET qty = %f, changed = %d WHERE nid = %d AND cart_id = '%s' AND data = '%s'", $qty, time(), $nid, $cid, serialize($data));
--
想法 - 其他变化
添加一些功能以允许选择是否允许某个产品类型/类别接受“分数”可能是个好主意。可能会在 uc_product_classes 表或 uc_products 表中添加一个布尔列(如“allow_frac_qty”)。那么当然,会有更多的代码添加/更改来实现这一点。此外,uc_products 表中的“pkg_qty”列可能也需要更改
其他 Ubercart 论坛帖子
http://www.ubercart.org/forum/support/4651/use_fractions_quantity_15_yards
http://www.ubercart.org/forum/support/6074/decimal_quantities_items
http://www.ubercart.org/issue/6044/abiility_have_decimal_quantities
http://www.ubercart.org/forum/ideas_and_suggestions/3283/comma_values_quantity_field