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]: Automatic promotion % off on a product seems to not be working ok #10539

Open
Lzok opened this issue Dec 10, 2024 · 0 comments
Open

[Bug]: Automatic promotion % off on a product seems to not be working ok #10539

Lzok opened this issue Dec 10, 2024 · 0 comments

Comments

@Lzok
Copy link

Lzok commented Dec 10, 2024

Package.json file

"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"
  },

Node.js version

v22

Database and its version

16.2

Operating system name and version

Mac OS Sequoia

Browser name

Chrome

What happended?

Context first

My objective is to create a promotion where the customer automatically get for example 10% OFF in a product if they buy 3 or more of that particular product.
While I don't see any option for this in the Admin UI, I read the docs and also asked KapaAI in the discord and I tried creating the promotion through the Admin API using the following payload

// POST http://localhost:9000/admin/promotions

{
     "code": "BUY_3_BCN_EVENING_X_GET_10_PERCENT_OFF",
     "type": "standard",
     "is_automatic": true,
     "application_method": {
       "description": "Buy 3 or more, get 10% off",
       "value": 10,
       "currency_code": "eur",
       "type": "percentage",
       "target_type": "items",
       "allocation": "each",
       "max_quantity": 100
     },
     "rules": [
       {
         "attribute": "items.product.id",
         "operator": "eq",
         "values": ["prod_01JCH0YZJ4043EPYQ9J03QQCRX"]
       },
       {
         "attribute": "quantity",
         "operator": "gte",
         "values": ["3"]
       }
     ]
   }

After hitting the endpoint, this is what I see in the Admin UI. Small note here, initially what is in the purple rectangle was empty, but neither empty or adding the things manually there seems to work.
image

Here is the whole JSON I see when I click on it in case it is useful for you. I collapsed it here because it is too long.
{
  "id": "promo_01JERRW9RT6N0B78JJ2BBG8R5R",
  "code": "BUY_3_BCN_EVENING_X_GET_10_PERCENT_OFF",
  "is_automatic": true,
  "type": "standard",
  "created_at": "2024-12-10T17:11:43.651Z",
  "updated_at": "2024-12-10T17:11:43.651Z",
  "deleted_at": null,
  "campaign_id": null,
  "application_method": {
    "id": "proappmet_01JERRW9RYBFCKF615DXK2JPHK",
    "raw_value": {
      "value": "10",
      "precision": 20
    },
    "currency_code": "eur",
    "max_quantity": 100,
    "apply_to_quantity": 0,
    "buy_rules_min_quantity": 0,
    "type": "percentage",
    "target_type": "items",
    "allocation": "each",
    "created_at": "2024-12-10T17:11:43.651Z",
    "updated_at": "2024-12-10T17:29:10.678Z",
    "deleted_at": null,
    "target_rules": [
      {
        "id": "prorul_01JERSW88EYMZPHQH21GPFWH6D",
        "description": null,
        "attribute": "items.product.id",
        "operator": "in",
        "created_at": "2024-12-10T17:29:10.671Z",
        "updated_at": "2024-12-10T17:29:10.671Z",
        "deleted_at": null,
        "values": [
          {
            "value": "prod_01JCH0YZJ4043EPYQ9J03QQCRX"
          },
          {
            "value": "prod_01JCNC9Z5225PWPG2PR25BAEJN"
          }
        ]
      }
    ],
    "buy_rules": [],
    "value": 10
  },
  "rules": [
    {
      "id": "prorul_01JERRW9RWJCNPVBH8B029D849",
      "attribute": "items.product.id",
      "operator": "eq",
      "values": [
        {
          "value": "prod_01JCH0YZJ4043EPYQ9J03QQCRX"
        }
      ]
    },
    {
      "id": "prorul_01JERRW9RXGCB88FBMKJGRNKG4",
      "attribute": "quantity",
      "operator": "gte",
      "values": [
        {
          "value": "3"
        }
      ]
    }
  ],
  "campaign": null
}

Here's the product as I see it in the Admin UI:
image

Please do not hesitate to contact me if you need further information or help on this one.
Thank you very much.

Expected behavior

The expected behavior here is, when the customer selects 3 or more quantity of that particular product, they should see that item with a 10% OFF.
To clarify here, that 10% OFF will be applied over the whole 3 quantity, not just the "last one".

Actual behavior

The actual behavior here is that I don't see any promotion being applied. I can't even see any promotion in the cart body response:

image
Here's the full cart JSON response in case it is useful for you
{
    "cart": {
        "id": "cart_01JEMG7DJ8PK196RMQ48ZV779C",
        "currency_code": "eur",
        "email": null,
        "region_id": "reg_01JCG7R4T52SCPB39DVKJE35B2",
        "created_at": "2024-12-09T01:23:33.064Z",
        "updated_at": "2024-12-10T17:31:56.236Z",
        "completed_at": "2024-12-10T17:31:56.209Z",
        "total": 440,
        "subtotal": 440,
        "tax_total": 0,
        "discount_total": 0,
        "discount_subtotal": 0,
        "discount_tax_total": 0,
        "original_total": 440,
        "original_tax_total": 0,
        "item_total": 440,
        "item_subtotal": 440,
        "item_tax_total": 0,
        "original_item_total": 440,
        "original_item_subtotal": 440,
        "original_item_tax_total": 0,
        "shipping_total": 0,
        "shipping_subtotal": 0,
        "shipping_tax_total": 0,
        "original_shipping_tax_total": 0,
        "original_shipping_subtotal": 0,
        "original_shipping_total": 0,
        "metadata": null,
        "items": [
            {
                "thumbnail": "",
                "id": "cali_01JERSWHXQCYXWQJ12GZEJ815Q",
                "variant_id": "variant_01JCH12FHXF7EGAAS8BSC7NCRG",
                "product_id": "prod_01JCH0YZJ4043EPYQ9J03QQCRX",
                "product_type_id": null,
                "product_title": "BCN | Evening",
                "product_description": null,
                "product_subtitle": null,
                "product_type": null,
                "product_collection": null,
                "product_handle": "evening-bcn",
                "variant_sku": null,
                "variant_barcode": null,
                "variant_title": "Mondays and Wednesdays",
                "requires_shipping": true,
                "metadata": {},
                "created_at": "2024-12-10T17:29:20.567Z",
                "updated_at": "2024-12-10T17:31:06.133Z",
                "title": "Mondays and Wednesdays",
                "quantity": 4,
                "unit_price": 110,
                "compare_at_unit_price": null,
                "is_tax_inclusive": false,
                "tax_lines": [],
                "adjustments": [],
                "product": {
                    "id": "prod_01JCH0YZJ4043EPYQ9J03QQCRX",
                    "collection_id": null,
                    "type_id": null,
                    "categories": [],
                    "tags": []
                }
            }
        ],
        "sales_channel_id": "sc_01JBHJYEYD0S09GPPBSEKW98SA",
        "customer_id": null,
        "shipping_methods": [],
        "shipping_address": null,
        "billing_address": null,
        "region": {
            "id": "reg_01JCG7R4T52SCPB39DVKJE35B2",
            "name": "Global",
            "currency_code": "eur",
            "automatic_taxes": false,
            "countries": []
        },
        "promotions": [],
        "payment_collection": {
            "id": "pay_col_01JEMG7HYP1E3FXTZ9SHPYTJ0E",
            "amount": 440,
            "payment_sessions": [
                {
                    "id": "payses_01JERSZTZMPS2WTZMG0HGWRP5D",
                    "currency_code": "eur",
                    "raw_amount": {
                        "value": "440",
                        "precision": 20
                    },
                    "provider_id": "pp_stripe_stripe",
                    "data": {
                        "id": "pi_3QUXH6CCrOntVla41fsUtGBJ",
                        "amount": 44000,
                        "object": "payment_intent",
                        "review": null,
                        "source": null,
                        "status": "requires_payment_method",
                        "created": 1733851868,
                        "invoice": null,
                        "currency": "eur",
                        "customer": "cus_RNHqBMxtK6KTYO",
                        "livemode": false,
                        "metadata": {
                            "session_id": "payses_01JERSZTZMPS2WTZMG0HGWRP5D"
                        },
                        "shipping": null,
                        "processing": null,
                        "application": null,
                        "canceled_at": null,
                        "description": null,
                        "next_action": null,
                        "on_behalf_of": null,
                        "client_secret": "pi_3QUXH6CCrOntVla41fsUtGBJ_secret_WZvQYJWhqcidDUR0asnzGSMg0",
                        "latest_charge": null,
                        "receipt_email": null,
                        "transfer_data": null,
                        "amount_details": {
                            "tip": {}
                        },
                        "capture_method": "automatic",
                        "payment_method": null,
                        "transfer_group": null,
                        "amount_received": 0,
                        "amount_capturable": 0,
                        "last_payment_error": null,
                        "setup_future_usage": null,
                        "cancellation_reason": null,
                        "confirmation_method": "automatic",
                        "payment_method_types": [
                            "card",
                            "bancontact",
                            "eps",
                            "giropay",
                            "ideal",
                            "p24",
                            "sepa_debit",
                            "sofort",
                            "alipay",
                            "klarna",
                            "wechat_pay",
                            "link",
                            "mobilepay"
                        ],
                        "statement_descriptor": null,
                        "application_fee_amount": null,
                        "payment_method_options": {
                            "eps": {},
                            "p24": {},
                            "card": {
                                "network": null,
                                "installments": null,
                                "mandate_options": null,
                                "request_three_d_secure": "automatic"
                            },
                            "link": {
                                "persistent_token": null
                            },
                            "ideal": {},
                            "alipay": {},
                            "klarna": {
                                "preferred_locale": null
                            },
                            "sofort": {
                                "preferred_language": null
                            },
                            "giropay": {},
                            "mobilepay": {},
                            "bancontact": {
                                "preferred_language": "en"
                            },
                            "sepa_debit": {},
                            "wechat_pay": {
                                "app_id": null,
                                "client": null
                            }
                        },
                        "automatic_payment_methods": {
                            "enabled": true,
                            "allow_redirects": "always"
                        },
                        "statement_descriptor_suffix": null,
                        "payment_method_configuration_details": {
                            "id": "pmc_1KYwoXCCrOntVla4rGyHDB0X",
                            "parent": null
                        }
                    },
                    "context": {},
                    "status": "authorized",
                    "authorized_at": "2024-12-10T17:31:55.737Z",
                    "payment_collection_id": "pay_col_01JEMG7HYP1E3FXTZ9SHPYTJ0E",
                    "metadata": null,
                    "created_at": "2024-12-10T17:31:08.148Z",
                    "updated_at": "2024-12-10T17:31:56.121Z",
                    "deleted_at": null,
                    "amount": 440
                }
            ]
        }
    }
}

Link to reproduction repo

https://github.com/medusajs/nextjs-starter-medusa

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