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]: calculated_price context works only with price lists and does not take other prices into consideration. #10613

Open
Deroswent opened this issue Dec 16, 2024 · 1 comment

Comments

@Deroswent
Copy link

Deroswent commented Dec 16, 2024

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",
    "1c_integration": "github:Deroswent/1c_integration",
    "awilix": "^8.0.1",
    "exceljs": "^4.4.0",
    "managers": "github:Deroswent/managers",
    "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

v20.15.0

Database and its version

PostgreSQL 16.4

Operating system name and version

WIndows 11

Browser name

No response

What happended?

The product variants have prices set with the region rule, and a price for each currency. These prices are "default" prices, which we create in the admin when creating a standard product. It's looks like:

2024-12-16_07-11

Then create a valid price list (any type of price list) for the same product variant. Set the price in the price list higher than the “default” prices for the product (these “default” prices are described above).

Finally, try to get prices for this product variant using *variants.calculated_price and the official manual or Store API GetProduct - you will always get the price from the price list, despite the fact that the "default" price is lower and the price request contains region_id, currency_code and also the user is authorized. It's a bug.

Experimentally it was found out that if there is at least one valid price list - calculated_price context will not take into account any “default” prices at all. Despite the fact that “default” prices are lower than prices from price lists and “default” prices are also valid for selection, because the query contains region_id and currency_code for these prices.

(Actually calculated_price does not work with “default” prices at all if there is at least one valid price list. But if you specify prices lower than "default" prices in the price list, then everything looks correct, because the lowest price will be returned. Just thought I'd mention it, since it's also part of the bug, although the result is returned correctly.)

Expected behavior

It is expected that calculated_price will return the minimum of available and valid prices.

Actual behavior

calculated_price returns the minimum price, but only from the price lists (if there are several valid price lists - calculated_price will choose the minimum price from the price lists without taking into account the “default” prices).

Link to reproduction repo

https://github.com/medusajs/medusa/

@erickirt
Copy link
Contributor

I am having this issue with order edits for shipping prices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants