co-cart / co-cart

πŸ›’ CoCart makes it easy to decouple your WooCommerce store via a customizable REST API that takes the pain out of developing – allowing you to build fast and flexible headless stores.

Home Page:https://cocartapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Price Ignored after Load Cart from Session

micksabox opened this issue Β· comments

Prerequisites

  • I have carried out troubleshooting steps and I believe I have found a bug.
  • I have searched for similar bugs in both open and closed issues and cannot find a duplicate.

Describe the bug

I submit a POST request to the cart/add-item endpoint. There is no authentication.

const res = await CoCart.post("cart/add-item", {
      id: product.sku,
      quantity: "1",
      price: "32",
    });

The return response I received indicates the custom price has been set. After this, I want to use the cart_key to load from session.

{
    "cart_hash": "aafc62fa0af276a1e49e7f5d0cacfa30",
    "cart_key": "2ec67e0a678a02e6bcaf726fd6dda7b8",
    "currency": {
        "currency_code": "CAD",
        "currency_symbol": "$",
        "currency_minor_unit": 2,
        "currency_decimal_separator": ".",
        "currency_thousand_separator": ",",
        "currency_prefix": "$",
        "currency_suffix": ""
    },
    "customer": {
        "billing_address": {
            "billing_first_name": "",
            "billing_last_name": "",
            "billing_company": "",
            "billing_country": "CA",
            "billing_address_1": "",
            "billing_address_2": "",
            "billing_city": "",
            "billing_state": "ON",
            "billing_postcode": "",
            "billing_phone": "",
            "billing_email": ""
        },
        "shipping_address": {
            "shipping_first_name": "",
            "shipping_last_name": "",
            "shipping_company": "",
            "shipping_country": "CA",
            "shipping_address_1": "",
            "shipping_address_2": "",
            "shipping_city": "",
            "shipping_state": "ON",
            "shipping_postcode": ""
        }
    },
    "items": [
        {
            "item_key": "ec8ce6abb3e952a85b8551ba726a1227",
            "id": 220,
            "name": "Folded Business Card 14pt + UV (High Gloss)",
            "title": "Folded Business Card 14pt + UV (High Gloss)",
            "price": "3200",
            "quantity": {
                "value": 1,
                "min_purchase": 1,
                "max_purchase": -1
            },
            "totals": {
                "subtotal": "3200",
                "subtotal_tax": 0,
                "total": 32,
                "tax": 0
            },
            "slug": "folded-business-card-14pt-uv-high-gloss",
            "meta": {
                "product_type": "simple",
                "sku": "foldedbusinesscards_14pt+uv(highgloss)",
                "dimensions": {
                    "length": "",
                    "width": "",
                    "height": "",
                    "unit": "cm"
                },
                "weight": 0,
                "variation": []
            },
            "backorders": "",
            "cart_item_data": [],
            "featured_image": "http://localhost:8080/wp-content/uploads/woocommerce-placeholder.png"
        }
    ],
    "item_count": 1,
    "items_weight": 0,
    "coupons": [],
    "needs_payment": true,
    "needs_shipping": false,
    "shipping": [],
    "fees": [],
    "taxes": [],
    "totals": {
        "subtotal": "3200",
        "subtotal_tax": "0",
        "fee_total": "0",
        "fee_tax": "0",
        "discount_total": "0",
        "discount_tax": "0",
        "shipping_total": "0",
        "shipping_tax": "0",
        "total": "3200",
        "total_tax": "0"
    },
    "removed_items": [],
    "cross_sells": [],
    "notices": {
        "success": [
            "“Folded Business Card 14pt + UV (High Gloss)” has been added to your cart."
        ]
    }
}

Expected behavior

I'm expecting the Load Cart from Session functionality to use the customized price that was set in the POST request.

Actual behavior

The cart is loaded with the correct product but an incorrect price.
Screen Shot 2022-11-04 at 9 41 56 AM

Steps to reproduce

  1. Set item price to 0 in WooCommerce
  2. Submit POST to cart/add-item with a custom price
  3. Load cart from sessions using the cocart-load-cart URL query param, passing in the cart_key from the response in step 2.
  4. The cart displayed to user doesn't have the custom price, but instead shows the price as 0.

WordPress Environment

`

WordPress Environment

WordPress address (URL): http://localhost:8080
Site address (URL): http://localhost:8080
WC Version: 7.0.0
REST API Version: βœ” 7.0.0
WC Blocks Version: βœ” 8.5.1
Action Scheduler Version: βœ” 3.4.0
Log Directory Writable: βœ”
WP Version: ❌ 6.0.3 - There is a newer version of WordPress available (6.1)
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: βœ”
Language: en_CA
External object cache: –

Server Environment

Server Info: Apache/2.4.54 (Debian)
PHP Version: 7.4.32
PHP Post Max Size: 8 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.74.0
OpenSSL/1.1.1n

SUHOSIN Installed: –
MySQL Version: 5.7.40
Max Upload Size: 2 MB
Default Timezone is UTC: βœ”
fsockopen/cURL: βœ”
SoapClient: ❌ Your server does not have the SoapClient class enabled - some gateway plugins which use SOAP may not work as expected.
DOMDocument: βœ”
GZip: βœ”
Multibyte String: βœ”
Remote Post: βœ”
Remote Get: βœ”

Database

WC Database Version: 7.0.0
WC Database Prefix: wp_
Total Database Size: 6.24MB
Database Data Size: 4.48MB
Database Index Size: 1.76MB
wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_actions: Data: 0.09MB + Index: 0.11MB + Engine InnoDB
wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_cocart_carts: Data: 0.09MB + Index: 0.02MB + Engine InnoDB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_options: Data: 3.03MB + Index: 0.08MB + Engine InnoDB
wp_postmeta: Data: 0.22MB + Index: 0.28MB + Engine InnoDB
wp_posts: Data: 0.09MB + Index: 0.06MB + Engine InnoDB
wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_term_relationships: Data: 0.08MB + Index: 0.02MB + Engine InnoDB
wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_admin_notes: Data: 0.05MB + Index: 0.00MB + Engine InnoDB
wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_product_meta_lookup: Data: 0.05MB + Index: 0.09MB + Engine InnoDB
wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB

Post Type Counts

attachment: 1
customize_changeset: 5
page: 8
post: 2
product: 206
revision: 4
shop_coupon: 1
woolentor-template: 1
wp_global_styles: 2

Security

Secure connection (HTTPS): ❌
Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
Hide errors from visitors: βœ”

Active Plugins (5)

CoCart - Headless ecommerce: by SΓ©bastien Dumont – 3.7.8
CoCart Beta Tester: by CoCart – 2.1.0
custom-product-sync-woocommerce: by Michael Nolivos – 1.0.0
WooCommerce: by Automattic – 7.0.0 (update to version 7.0.1 is available)
WooLentor - WooCommerce Elementor Addons + Builder: by HasThemes – 2.4.6

Inactive Plugins (2)

Akismet Anti-Spam: by Automattic – 5.0.1
Hello Dolly: by Matt Mullenweg – 1.7.2

Settings

API Enabled: –
Force SSL: –
Currency: CAD ($)
Currency Position: left
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: –
Enforce Approved Product Download Directories: βœ”

WC Pages

Shop base: #13 - /
Cart: #14 - /cart/
Checkout: #15 - /checkout/
My account: #16 - /my-account/
Terms and conditions: ❌ Page not set

Theme

Name: Storefront
Version: 4.1.3
Author URL: https://woocommerce.com/
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: βœ”

Templates

Overrides: –

Admin

Enabled Features: activity-panels
analytics
coupons
customer-effort-score-tracks
experimental-products-task
experimental-import-products-task
experimental-fashion-sample-products
experimental-product-tour
shipping-smart-defaults
shipping-setting-tour
homescreen
marketing
multichannel-marketing
mobile-app-banner
navigation
onboarding
onboarding-tasks
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
shipping-label-banner
subscriptions
store-alerts
transient-notices
woo-mobile-welcome
wc-pay-promotion
wc-pay-welcome-page

Disabled Features: minified-js
new-product-management-experience
settings

Daily Cron: βœ” Next scheduled: 2022-10-30 13:35:03 -04:00
Options: βœ”
Notes: 39
Onboarding: completed

Action Scheduler

Pending: 224
Oldest: -0001-11-29 18:42:28 -0517
Newest: 2022-11-04 09:02:34 -0400

CoCart

Version: 3.7.8
Database Version: 3.7.8
Install Date: 30 October 2022
Carts in Session: 26
Carts Active: 26 out of 26 in session.
Carts Expiring Soon: 0 out of 26 in session.
Carts Expired: 0 out of 26 in session.
Carts Source (by CoCart): 24
Carts Source (by Web): 2
Carts Source (by Other): 0

Status report information

Generated at: 2022-11-04 09:41:44 -04:00
`

Isolating the problem

  • I have deactivated other plugins and confirmed this bug occurs when only CoCart plugin is active.
  • I can reproduce this bug consistently using the steps above.

Thank you for reporting the bug @micksabox

A patch will be released today with it fixed.

I tried this while not being logged in to the Wordpress store and it worked as expected. The previous times, I had been trying it while logged in, and using the WooCommerce API keys as authentication.

The price was not setting for me logged out.