Problem/Motivation

Payment accepts only integer quantities for line items at this moment. This can lead to undesired roundings. E.g. if the unit price is per square meter and it should be possible to order decimal quantities (e.g. 1.5 m2).

This problem has two sources. In the payment_line_item table the quantity field is of type int. And on several places in the code the quantity on a line item is type casted to an int explicitly.

Proposed resolution

The quantity field in the payment_line_item table should be of type float. Also in code the quantity should be type casted to a float.

Remaining tasks

I've fixed this problem in a local 7.x-1.15 version for a client. I'll re-roll the patch for that fix against 7.x-1.x-dev. After that I'll upload the patch here for review.

User interface changes

This would not affect the user interface.

API changes

This won't affect the API.

Data model changes

The quantity field in the payment_line_item table will be of type float instead of type int after the proposed resolution has been implemented.

Comments

ricovandevin created an issue. See original summary.

ricovandevin’s picture

Status: Needs work » Needs review
StatusFileSize
new2.14 KB

This patch should do the trick.

bucefal91’s picture

Hello!

I also upvote this issue and the patch enclosed within. Without this patch on pgsql I wasn't able even to successfully pay with "Payment" module a quantity of 1 (in PHP it was generated as float 1.00 by Commerce module and then my Postgres DB would reject the INSERT statement due to type mismatch).

Thank you for the patch, ricovandevin :) I also conducted code review and have no objections about the proposed changes in the patch.

xano’s picture

Version: 7.x-1.15 » 7.x-1.x-dev
StatusFileSize
new339 bytes
new2.34 KB

Thanks for writing and reviewing the patch! I fixed one default value that was still an integer. Otherwise this is good to go.

xano’s picture

Assigned: ricovandevin » Unassigned
Status: Needs review » Fixed

The tests will not pass on PHP 7 because of #2554339: Plan for CTools 7.x-1.10 release. The maintainers have been contacted about this.

Because the tests pass on PHP 5.6, I will commit this. Thanks for the work!

  • Xano committed 15da9aa on 7.x-1.x authored by ricovandevin
    Issue #2607266 by Xano, ricovandevin, bucefal91: Payment should accept...
bucefal91’s picture

Thanks! :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.