vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.61k stars 993 forks source link

No price information was found for ProductVariant ID "8" in the Channel "british-isles" #2440

Open seminarian opened 11 months ago

seminarian commented 11 months ago

Describe the bug No price information was found for ProductVariant ID "8" in the Channel "british-isles". Error message when loading products in subchannel british-isles image

The cause was Product assigned to british-isles which has a custom field of type relation which has PVs configured that are not assigned to british-isles channel.

In our case I think the channel-aware custom fields would actually be the solution to use. Because up sell variants are actually channel dependent.

Product variant is not assigned to the channel: image

But that specific PV was assigned to a Product assigned to british-isles

product -> upsell variants custom field
2 -> 18 20
9 -> 2 18 20
14 -> 8 14
15 -> 2 11 20
16 -> 2 11 18

aggregated list 2 8 11 14 18 20

actually assigned PVs to channel:
2 11 17 18 19 20 21

**lacking pvs assigned to channel**: 8 14

To Reproduce Steps to reproduce the behavior:

  1. Add the following custom field config
    config.customFields.Product.push({
      name: 'upsellVariants',
      label: [{ languageCode: LanguageCode.en, value: 'Upsell variants' }],
      type: 'relation',
      entity: ProductVariant,
      list: true,
    });
  2. Generate the migrations and restart dev server
  3. In default channel add a few upsell variants to a product.
  4. In a subchannel add the Product to the channel but make sure some of the upsell variants are not assigned to the subchannel.
  5. Go to products page in admin UI for the subchannel

Environment (please complete the following information):

yasserlens commented 10 months ago

We're also seeing the same error after upgrading from v2.0.4 to v2.1.4. Nothing else has changed that could have caused the error to appear. The error we have is:

No price information was found for ProductVariant ID "99" in the Channel "default_channel”

The query that causes this is:

query ProductListQuery($options: ProductListOptions) {
  products(options: $options) {
    items {
      ...ProductListQueryProductFragment
      __typename
    }
    totalItems
    __typename
  }
}

fragment ProductListQueryProductFragment on Product {
  id
  createdAt
  updatedAt
  enabled
  languageCode
  name
  slug
  featuredAsset {
    id
    createdAt
    updatedAt
    preview
    focalPoint {
      x
      y
      __typename
    }
    __typename
  }
  variantList {
    totalItems
    __typename
  }
  customFields {
    canChooseColor
    __typename
  }
  __typename
}

Variables

{
  "options": {
    "skip": 0,
    "take": 10,
    "filter": {
      "name": {
        "contains": ""
      }
    },
    "sort": {
      "createdAt": "DESC"
    }
  }
}

And the error response is

{
  "errors": [
    {
      "message": "No price information was found for ProductVariant ID \"99\" in the Channel \"__default_channel__\".",
      "locations": [
        {
          "line": 32,
          "column": 3
        }
      ],
      "path": [
        "products",
        "items",
        4,
        "variantList"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      }
    }
  ],
  "data": null
}
seminarian commented 10 months ago

We're also seeing the same error after upgrading from v2.0.4 to v2.1.4. Nothing else has changed that could have caused the error to appear. The error we have is:

No price information was found for ProductVariant ID "99" in the Channel "default_channel”

The DefaultVariantPriceStrategy inside the core is not falling back anymore if a currency was requested which there is not a price for in the channel. Check that.

Or override the strategy with your own version which suits your business needs.

yasserlens commented 10 months ago

Hello! Thank you! I'm not sure I follow re:"currency was requested which there is not a price for in the channel" - could you please provide an example? Note that this is the default channel that it complains about - which, as far as I know, has access to all channel-specific variants/prices/currencies..etc.

yasserlens commented 10 months ago

tldr; the error happens when a currencyCode for a productVariant X channelId combo do not match the channelId's default currency code. Vendure doesn't know what to do with that so it throws an exception. To resolve this I deleted the products that had variants with incorrect currencyCodes and started over. In hindsight, I should have updated the currencyCode associated with the productVariant x channelId combination to match the channel's default currency.

Details below I did a quick investigation before that and I found:

In hindsight, I could have removed the association of those product variants to the channels that have currency issues then re-assigned them to those channels, hoping that would resolve the currency issues, but I didn't think of this at the time. Deleting the products seemed easier since that's all done in a development instance.