co-cart / co-cart

🛒 CoCart is a free REST API designed to decouple your slow WooCommerce storefront and convert it blazing-fast, build in any web framework, and save you countless hours.

Home Page:https://cocartapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Totals calculations are not right when a custom price is set for the product

voodoobg opened this issue · comments

Overriding the product price is not working properly as the calculations are made with base price from WC, not with the custom price. The custom price is showing in the "items" array, but in the totals the price if from WC.

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest trunk branch of CoCart on GitHub.
  • The issue still exists against the latest dev branch of CoCart on GitHub (this is not the same version as on WordPress.org!).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional)
  • I have installed the requirements to run this plugin.

Steps to reproduce the issue

  1. Set custom price with request "id" : "491", "quantity" : "1", "price" : "25"
  2. Price in WC in the main inventory is set to 1
  3. Custom price shows in the Items array, but not in the totals calculations.

Expected/actual behavior

Totals should be calculated with the custom price, not with the price from WC

When I follow those steps, I see wrong totals calculated.

I was expecting to see totals calculated with the custom price.

Screenshots

screenshot-1

screenshot-2

Isolating the problem

  • This bug happens with only WooCommerce and CoCart plugin are active.
  • This bug happens with a default WordPress theme active.
  • This bug happens with the WordPress theme Storefront active.
  • This bug happens with the latest release of WooCommerce active.
  • This bug happens only when I authenticate as a customer.
  • This bug happens only when I authenticate as administrator.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment

``` ### WordPress Environment ###

WordPress address (URL): https://store.---.bg
Site address (URL): https://store.---.bg
WC Version: 6.2.2
REST API Version: ✔ 6.2.2
WC Blocks Version: ✔ 6.7.3
Action Scheduler Version: ✔ 3.4.0
WC Admin Version: ✔ 3.1.0
Log Directory Writable: ✔
WP Version: 5.9.3
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: en_US
External object cache: –

Server Environment

Server Info: Apache
PHP Version: 7.4.29
PHP Post Max Size: 50 MB
PHP Time Limit: 1800
PHP Max Input Vars: 5000
cURL Version: 7.81.0
OpenSSL/1.1.1n

SUHOSIN Installed: –
MySQL Version: 5.5.5-10.3.34-MariaDB-log
Max Upload Size: 50 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

Database

WC Database Version: 6.2.2
WC Database Prefix: wpet_
Total Database Size: 8.43MB
Database Data Size: 6.61MB
Database Index Size: 1.82MB
wpet_woocommerce_sessions: Data: 0.01MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_api_keys: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
wpet_woocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_order_items: Data: 0.03MB + Index: 0.01MB + Engine MyISAM
wpet_woocommerce_order_itemmeta: Data: 0.26MB + Index: 0.12MB + Engine MyISAM
wpet_woocommerce_tax_rates: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_woocommerce_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_actionscheduler_actions: Data: 0.19MB + Index: 0.09MB + Engine MyISAM
wpet_actionscheduler_claims: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_actionscheduler_groups: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_actionscheduler_logs: Data: 0.16MB + Index: 0.11MB + Engine MyISAM
wpet_additional_supplier_info: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_atum_inventories: Data: 0.02MB + Index: 0.04MB + Engine MyISAM
wpet_atum_inventory_files: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_atum_inventory_locations: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
wpet_atum_inventory_meta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_atum_inventory_orders: Data: 0.07MB + Index: 0.01MB + Engine MyISAM
wpet_atum_inventory_regions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_atum_inventory_reserved_stock: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_atum_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine MyISAM
wpet_atum_order_items: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_atum_product_data: Data: 0.01MB + Index: 0.02MB + Engine MyISAM
wpet_cocart_carts: Data: 0.32MB + Index: 0.01MB + Engine MyISAM
wpet_commentmeta: Data: 0.02MB + Index: 0.02MB + Engine MyISAM
wpet_comments: Data: 0.03MB + Index: 0.02MB + Engine MyISAM
wpet_dokan_advertised_products: Data: 0.02MB + Index: 0.08MB + Engine InnoDB
wpet_dokan_announcement: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_delivery_time: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wpet_dokan_distance_rate_shipping: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wpet_dokan_follow_store_followers: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_dokan_orders: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wpet_dokan_product_map: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_refund: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_report_abuse_reports: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_dokan_rma_conversations: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_rma_request: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_rma_request_product: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_shipping_tracking: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wpet_dokan_shipping_zone_locations: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_table_rate_shipping: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wpet_dokan_vendor_balance: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_dokan_withdraw: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wpet_duplicator_packages: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_e_events: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_links: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_options: Data: 3.12MB + Index: 0.12MB + Engine MyISAM
wpet_order_inventory: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_files: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_hash: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_history: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_images: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_imports: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_posts: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_pmxi_templates: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_podsrel: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_postmeta: Data: 1.21MB + Index: 0.45MB + Engine MyISAM
wpet_posts: Data: 0.31MB + Index: 0.13MB + Engine MyISAM
wpet_redirection_404: Data: 0.03MB + Index: 0.01MB + Engine MyISAM
wpet_redirection_groups: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_redirection_items: Data: 0.00MB + Index: 0.02MB + Engine MyISAM
wpet_redirection_logs: Data: 0.02MB + Index: 0.01MB + Engine MyISAM
wpet_snippets: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_termmeta: Data: 0.04MB + Index: 0.03MB + Engine MyISAM
wpet_terms: Data: 0.01MB + Index: 0.02MB + Engine MyISAM
wpet_term_relationships: Data: 0.02MB + Index: 0.05MB + Engine MyISAM
wpet_term_taxonomy: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
wpet_usermeta: Data: 0.23MB + Index: 0.07MB + Engine MyISAM
wpet_users: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
wpet_wc_admin_notes: Data: 0.03MB + Index: 0.00MB + Engine MyISAM
wpet_wc_admin_note_actions: Data: 0.01MB + Index: 0.00MB + Engine MyISAM
wpet_wc_category_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_wc_customer_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_wc_download_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_wc_order_coupon_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_wc_order_product_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_wc_order_stats: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_wc_order_tax_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_wc_product_meta_lookup: Data: 0.01MB + Index: 0.03MB + Engine MyISAM
wpet_wc_rate_limits: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_wc_reserved_stock: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_wc_tax_rate_classes: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
wpet_wc_webhooks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
wpet_wt_iew_action_history: Data: 0.07MB + Index: 0.00MB + Engine MyISAM
wpet_wt_iew_mapping_template: Data: 0.00MB + Index: 0.00MB + Engine MyISAM

Post Type Counts

acf-field: 8
acf-field-group: 1
attachment: 224
atum_inventory_log: 3
atum_po_delivery: 5
atum_purchase_order: 96
atum_supplier: 2
custom-css-js: 3
customize_changeset: 4
custom_css: 1
dokan_announcement: 1
elementor_library: 1
manufacturer: 1
page: 14
post: 4
producer: 3
product: 133
product_variation: 2
revision: 100
shop_coupon: 2
shop_order: 235
supplier: 1
wp_global_styles: 6
_pods_field: 5
_pods_group: 2
_pods_pod: 2

Security

Secure connection (HTTPS): ✔
Hide errors from visitors: ✔

Active Plugins (27)

WP Admin Customize: by Svet – 1.0
Wooop Manufacturer: by Svet – 1.0
ATUM Multi-Inventory: by Stock Management Labs™ – 1.6.9
ATUM Purchase Orders PRO: by Stock Management Labs™ – 1.0.2
ATUM Inventory Management for WooCommerce: by Stock Management Labs™ – 1.9.14
CoCart Lite: by Sébastien Dumont – 3.4.0
CoCart - Cart Enhanced: by Sébastien Dumont – 3.2.0
CoCart Pro: by Sébastien Dumont – 1.0.0-rc.5
Simple Custom CSS and JS: by SilkyPress.com – 3.39
Disable Gutenberg: by Jeff Starr – 2.6
Dokan: by weDevs – 3.3.9
Dokan Pro: by weDevs – 3.5.2
Duplicator: by Snap Creek – 1.4.5
Elementor: by Elementor.com – 3.6.4
Essential Addons for Elementor: by WPDeveloper – 5.1.0
Maintenance: by WebFactory Ltd – 4.05
Maintenance: by WebFactory Ltd – 4.05
Pods - Custom Content Types and Fields: by Pods Framework Team – 2.8.15
Post Meta View and Export: by Matej Kravjar – 1.0
Product CSV Import Export (BASIC): by WebToffee – 2.1.9
Redirection: by John Godley – 5.2.3
Simple-JWT-Login: by Nicu Micle – 3.4.2
UpdraftPlus - Backup/Restore: by UpdraftPlus.Com
DavidAnderson – 1.22.11

User Role Editor: by Vladimir Garagulya – 4.61.2
Order Weight for WooCommerce: by Andreas Karman – 0.5.5
WooCommerce: by Automattic – 6.2.2 (update to version 6.4.1 is available)
WP Clean Admin Menu: by P. Roy – 2.0

Inactive Plugins (1)

Code Snippets: by Code Snippets Pro – 2.14.3

Settings

API Enabled: –
Force SSL: –
Currency: BGN (лв.)
Currency Position: right_space
Thousand Separator:
Decimal Separator: ,
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)

Connected to WooCommerce.com: –

WC Pages

Shop base: #103 - /shop/
Cart: #104 - /cart/
Checkout: #105 - /checkout/
My account: #106 - /
Terms and conditions: ❌ Page not set

Theme

Name: --- Child
Version: 1.0.0
Author URL: https://wooop.bg
Child Theme: ✔
Parent Theme Name: Astra
Parent Theme Version: 3.7.9 – 3.8.0 is available
Parent Theme Author URL: https://wpastra.com/about/?utm_source=theme_preview&utm_medium=author_link&utm_campaign=astra_theme
WooCommerce Support: ✔

Templates

Overrides: /home/woopbg13/store.wooop.bg/wp-content/plugins/atum-multi-inventory/views/email-templates/email-mi-order-items.php

Action Scheduler

Canceled: 7
Oldest: 2022-04-24 00:33:06 +0000
Newest: 2022-05-09 06:49:45 +0000

Complete: 773
Oldest: 2022-04-28 07:19:43 +0000
Newest: 2022-05-10 13:06:55 +0000

Pending: 4
Oldest: 2022-05-11 00:00:00 +0000
Newest: 2022-05-11 12:43:56 +0000

CoCart

Version: 3.4.0
Database Version: 3.4.0
Install Date: 18/03/2022
Carts in Session: 17
Carts Active: 17 out of 17 in session.
Carts Expiring Soon: 0 out of 17 in session.
Carts Expired: 0 out of 17 in session.
Carts Source (by CoCart): 14
Carts Source (by Web): 2
Carts Source (by Other): 1

Status report information

Generated at: 2022-05-10 15:16:32 +02:00

</details>

## Additional context

<!--Any additional context or details you think might be helpful.-->

So just to clarify @voodoobg

  • Product is set as 1
  • Coupon takes off 10 (Fixed)
  • Item added to the cart is set as 25
  • Subtotal still shows as original price
  • But the total is 90

Product is set to 1 - Correct
Coupon is 10% off
Item added at 25
It appears the total is 0.9 (10%off 1) should be calculated based on 25

Tried without the coupon applied and it calculates again on the price taken from WC that is 1.

Not been able to replicate the issue with just CoCart & CoCart Pro so it's defiantly a plugin compatibility issue.

I've managed to find the problem and its the one I feared. The plugin is ATUM Multi-Inventory that is installed with ATUM Inventory Management for WooCommerce. It manages multiple inventories and this is the functionality that my clients wants. When I disable this plugin the custom price is calculated properly in the totals.
What will be the next step? I need this functionality working with the CoCart. Can you point me of what to search for or help you figure this out and what can cause this problem?

@voodoobg I don't have the add-on for ATUM so I can't go any further at this point. I would ask them if they can contribute in supporting overriding the price. I don't see anything in the free core version of ATUM causing the isue so it's realted to the add-on of theirs.

The function that ATUM would need to look at is: https://github.com/co-cart/co-cart/blob/trunk/includes/class-cocart-cart-cache.php#L94,L110

I'm currently making preparations to making CoCart 4.0 so if it's small patch that can be added, their best place to add the contribution would be to add it to this package: https://github.com/co-cart/cocart-third-party

I don't have yet any instructions added but it should be straight forward to follow if they reviev the code.

Thank you. I have contacted the devs of Atum and told them about this compatibility issue. I hope they will take a look and figure it out.