kilbot / WooCommerce-POS

:bangbang: All development now at https://github.com/wcpos.
http://wcpos.com
GNU General Public License v3.0
353 stars 125 forks source link

Rounding is different in POS then in Store #107

Closed gruntlord6 closed 8 years ago

gruntlord6 commented 8 years ago

In the webstore, I have a product set to appear as 14.99 after tax. In the POS mode however, the product appears as 14.98 after tax. I have attached screenshots below.

image

image

kilbot commented 8 years ago

Thanks for posting the bug! There's something going wrong here :confused:

Can you post the raw API output for that product, then I will have everything I need to reproduce the issue. To get the raw output:

  1. Go to your POS and hover over the Ultra-Pro Black Satin, this will give you the product ID
  2. Then go to this URL: YOURDOMAIN/wc-api/v3/products/ID?pos=1 (substitute YOURDOMAIN and ID)

This should return a JSON object, just copy and paste that in a comment.

gruntlord6 commented 8 years ago

from what I can see this is what you are looking for.

{
    "title": "Ultra-Pro Black Satin Tower Deck Box",
    "id": 1641,
    "created_at": "2015-10-03T02:20:00Z",
    "updated_at": "2015-10-03T02:45:24Z",
    "type": "simple",
    "status": "publish",
    "downloadable": false,
    "virtual": false,
    "sku": "074427841737",
    "price": "13.26",
    "regular_price": "13.26",
    "sale_price": null,
    "price_html": "<span class=\"amount\">&#36;13.26<\/span> <small class=\"woocommerce-price-suffix\">(<span class=\"amount\">&#36;14.99<\/span> after tax)<\/small>",
    "taxable": true,
    "tax_status": "taxable",
    "tax_class": "",
    "managing_stock": true,
    "stock_quantity": 0,
    "in_stock": false,
    "backorders_allowed": false,
    "backordered": false,
    "sold_individually": false,
    "purchaseable": true,
    "featured": false,
    "visible": true,
    "on_sale": false,
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": null,
    "parent_id": 0,
    "categories": ["Deck Boxes", "Ultra-Pro"],
    "featured_src": "https:\/\/duelkingdom.ca\/wp-content\/uploads\/2015\/10\/Black-Satin-Tower-180x180.png",
    "attributes": [{
        "name": "Condition",
        "slug": "condition",
        "position": 0,
        "visible": true,
        "variation": false,
        "options": ["Sealed"]
    }],
    "purchase_note": "",
    "total_sales": 1,
    "variations": [],
    "barcode": "074427841737"
}
kilbot commented 8 years ago

That's it, thanks.

So, what's happening here is the REST API is giving a rounded price for the product. The actual values for the product are:

price13.2654867257
13% tax1.72451327434
total14.99

Because the WC REST API returns a rounded value the calculated tax is wrong. I will post an issue to WooCommerce to try and get the bug resolved. As a test you could remove the rounding done by WooCommerce, ie: change the following to:

'price'              => $product->get_price(),
'regular_price'      => $product->get_regular_price(),

If you clear your local cache and redownload the products you should get the right price in the POS.

gruntlord6 commented 8 years ago

Took me a bit of digging to find the lines I needed to fix, but it works exactly as you say, the price in the POS is now correct. Not sure who at WC thought it was a good idea to round the result returned to the API, but I'm once again very impressed at your turn around time :)

Once my store takes off I'll have to go Pro ;)

kilbot commented 8 years ago

Closed via https://github.com/woothemes/woocommerce/commit/5b0a5d15a8832197caf8f5418a4e3fbaa980ef6e