Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Prices from price lists are not applicable when adding to cart. #10490

Open
Deroswent opened this issue Dec 7, 2024 · 2 comments · Fixed by #10493
Open

[Bug]: Prices from price lists are not applicable when adding to cart. #10490

Deroswent opened this issue Dec 7, 2024 · 2 comments · Fixed by #10493

Comments

@Deroswent
Copy link

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "latest",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "latest",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

20.15.0

Database and its version

PostgreSQL 16.4

Operating system name and version

Windows 11

Browser name

No response

What happended?

Clean installation of Medusa 2.1 + official storefront, without any changes in the code.

Problem:
The price of an item in the cart = always the full price of the product variand, not including the price list.

How to reproduce the problem:

  1. Register as a customer on the storefront and authorize on the storefront.

  2. In medusa backend, create a Customer group and add our customer to it.

  3. In medusa backend, create two price lists: Sale type and Override type, make both price lists active by date and apply them to our Customer group. Assign prices to any product variant: sale = 7 eur, override = 5 eur.

  4. On the storefront (being an authorized customer) we look at the prices for our product variant - everything works fine and we see the price of 5 eur. Add this variant to the cart.

  5. Go to the cart and we see that the price of the cart is 10 eur (the full price of the product variant without price lists). This is the bug.

2024-12-07_21-22

2024-12-07_21-01

If we check the database, we see that
1)Cart is linked to our user

2024-12-07_21-23

  1. The price of line item in the unit_price field is 10 eur and not 5.

2024-12-07_21-24

So this is not a storefront bug, but a bug in the core of Medusa.

Expected behavior

The price of the item in the shopping cart should match the price on the storefront.

Actual behavior

The price in the shopping cart is always the full price of the product without any price lists.

Link to reproduction repo

https://github.com/medusajs/medusa

@sergiocampama
Copy link

I was looking into this today too. Was able to find that adding a product to a cart uses the add-to-cart.ts workflow which does not take into account the pricingContext coming in from the request.

Was trying to develop locally but it hasn't been super easy setting a reproducible development stack.

sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

Price lists may sometimes be bound to certain customer groups. The
addToCartWorkflow and updateLineItemInCartWorkflow workflows were indeed
accounting for the pricing context based on the cart's region, customer
id and currency code, but, unlike in the setPricingContext middleware
for the store/products route, it was not expanding the customer into its
customer groups. For this reason, the pricing module was not calculating
the correct price for the variants.

Fixes medusajs#10490
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

Price lists may sometimes be bound to certain customer groups. The
addToCartWorkflow and updateLineItemInCartWorkflow workflows were indeed
accounting for the pricing context based on the cart's region, customer
id and currency code, but, unlike in the setPricingContext middleware
for the store/products route, it was not expanding the customer into its
customer groups. For this reason, the pricing module was not calculating
the correct price for the variants.

Fixes medusajs#10490
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 8, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
@sergiocampama
Copy link

apologies for the notification spam, had the ticket id in the commit and did some pushes

sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 10, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
sergiocampama added a commit to sergiocampama/medusa that referenced this issue Dec 10, 2024
… lists

*What*

* Fixes medusajs#10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.
riqwan added a commit that referenced this issue Dec 12, 2024
… lists (#10493)

*What*

* Fixes #10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants