Ubercart 2.0 - 允许小数数量的代码更改列表?

发布于 2024-08-11 17:03:31 字数 114 浏览 1 评论 0 原文

我正在为客户开发 Ubercart 2.0 项目。这是一家布料店。他们希望客户能够添加小数数量(或小数数量),例如 1.75 m。有没有人有一个可以实现此功能的代码更改的完整列表

I am working on an Ubercart 2.0 project for a client. It is for a fabric store. They want the ability for customers to add fractional quantities (or decimal quantity) like 1.75 m. Does anyone have a comprehensive list of code changes that will allow for this functionality?

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

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

发布评论

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

评论(5

臻嫒无言 2024-08-18 17:03:31

我认为改变 ubercart 核心来实现你的意思是一个坏主意。当有安全修复程序时,您基本上注定自己无法更新/升级,并且可能其他一些模块会假设您正在使用整数,从而让位于难以跟踪的错误和 php 异常。

我没有像上一张海报那样进行广泛的搜索,但如果我必须自己实现您的需求,我会立即:

  1. 使用厘米(整数)作为后端的逻辑测量单位。
  2. 通过在验证/提交时更改 add_to_cart 表单来“屏蔽”小数功能,以供用户输入,以便在提交时 1,75 m 将转换为 175 厘米
  3. 更改产品、目录和订单页面模板,以便它们以米为单位显示价格信息,以便值 0.05 €/cm(存储在数据库中)显示为5 €/m

只是我的两分钱,但考虑到 ubercart 正在积极开发中,尽管最近退出了候选版本状态,但它仍然存在很多错误:您确实希望能够在修复程序出现时更新您的代码库。

编辑:只是为了强调上面的内容:自从我在不到一周前写下这个答案以来,已经发布了两个 UC 更新,其中一个修复了一个关键的安全问题...

希望这会有所帮助!

I think changing ubercart core to achieve what you mean is a bad idea. You are basically dooming yourself not to have the ability to update/upgrade when there are security fixes and probably some other module would assume you are using integer, giving way to difficult-to-track bugs and php exceptions.

I did not make an extensive search as the previous poster, but if I had to implement your need myself, off the top of my head I would:

  1. Use centimeters (integer) as logical measurement unit in the back-end.
  2. "Mask" the decimal functionality by altering the add_to_cart forms at validation/submit time, for the user input, so that on submit 1,75 m would get converted in 175 cm.
  3. Alter the product, catalog and order page templates in order for them to display price information in metres, so that the value 0.05 €/cm (stored in the DB) would be displayed as 5 €/m.

Just my two cents, but consider that ubercart is in active development and - despite the recent exit from release candidate state - it still has plenty of bugs: you really want to be able to update your codebase when fixes come out.

EDIT: just to stress what above: since I wrote this answer less than a week ago, two UC updates have come out, of which one fixing a critical security issue...

Hope this helps!

孤君无依 2024-08-18 17:03:31

当前的 Uberart(v 2.0)不允许其数量使用小数。

如果您在 Ubercart 论坛中搜索“十进制数量”、“数量分数”和“十进制数量”,您会得到一些结果。本文旨在概述可能对您安装的 Ubercart 系统进行的一些更改,以允许向您的购物车添加“小数数量”。

感谢莱尔和他的帖子回复,帮助我开始写这篇文章

添加到Ubercart Core?

我希望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/abilility_have_decimal_quantities

http://www.ubercart.org/forum/ideas_and_suggestions/3283/comma_values_quantity_field

The current Uberart (v 2.0) does not allow decimals for their quantities.

If you seach the Ubercart forums for “quantity as decimal”, “fractions for quantity”, and “decimal quantities” you get some hits. This article is an effort to outline some changes that may be made to your installed Ubercart system to allow addition of "fractional quantities" to your cart.

Thank you to Lyle and his post reply that helped me get started on this article.

Add To Ubercart Core?

I hope that the Ubercart developers can find a way to implement the ability for “fractional quantities” to Ubercart Core. I hope that this document / article will help make that happen!

Database Changes

Changing Ubercart to accept fractional quantities means the datatype of some table columns must be changed from INTEGER to FLOAT(M,D). The FLOAT data type allows for the decimal to be stored. Here is a description from http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

Here, “(M,D)” means than values can be
stored with up to M digits in total,
of which D digits may be after the
decimal point. For example, a column
defined as FLOAT(7,4) will look like
-999.9999 when displayed. MySQL performs rounding when storing values,
so if you insert 999.00009 into a
FLOAT(7,4) column, the approximate
result is 999.0001.

Below are the changes to the tables to be made to allow 2 decimal places and 6 total digits. Applying the following database table changes should not affect existing data, unless you have quantities greater than 6 digits – in which case you could increase the M value.

// # 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;

Code Changes

// # uc_cart.module (line 1445)
db_query("UPDATE {uc_cart_products} SET qty = %d, changed = UNIX_TIMESTAMP(), data = '%s' WHERE cart_item_id = %d",

to...

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));

to...

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', "

to...

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);

to...

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,

with...

'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));

to...

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));

--

Thoughts - Additional Changes

It would probably be a good idea to add some functionality to allow a choice as to whether or not a certain product type / class is allowed to accept “fractional quantities”. Maybe the addition of a boolean column (like “allow_frac_qty”) in the uc_product_classes table or the uc_products table. Then of course, there would be more code additions / changes to allow for this. Also, the “pkg_qty” column in the uc_products table may also need to be changed

Other Ubercart Forum Posts

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

耶耶耶 2024-08-18 17:03:31

以防万一有人需要 robnardo 消息中的解决方案,但要申请 drupal 7、ubercart 3 - 我在这里描述了在 Drupal 7、Ubercart 3.1 中对我有用的内容:
http://www.ubercart.org/project/uc_decimal_quantities#comment-68750

Just in case somebody needs the solution from robnardo's message but to apply for drupal 7, ubercart 3 - I described what had worked for me in Drupal 7, Ubercart 3.1 here:
http://www.ubercart.org/project/uc_decimal_quantities#comment-68750

所谓喜欢 2024-08-18 17:03:31

麦克说得对。这种方法更加简单并且不易出现维护问题。

它还可以轻松支持任何类型的测量,使用 JavaScript 生成测量系统的下拉列表并在提交时进行转换。

mac's got it right. That approach is much simpler and less prone to maintenance problems.

It would also make it trivial to support any type of measurement using JavaScript to generate a drop down of measurement system and doing a conversion on submit.

绅刃 2024-08-18 17:03:31

I have posted a module I am working on at http://www.ubercart.org/issue/6044/abiility_have_decimal_quantities ... Please leave your feedback.

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