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

Admin UI : bug when displaying the price of a variant from another channel #1392

Closed
christopheblin opened this issue Feb 2, 2022 · 12 comments
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@christopheblin
Copy link
Contributor

Describe the bug
Slack thread.

To Reproduce

  1. set default channel to euros
  2. define a channel in dollars and switch to it
  3. create a product + variant with $5.00
  4. go back to default channel and look at the variant -> it says €5.00

Expected behavior
Because the prices of a variant are per channel, we should see N/A (or anything else) to indicate that this variant has no price in the current channel

Environment (please complete the following information):

  • @vendure/core version: 1.4.5
@christopheblin christopheblin added the type: bug 🐛 Something isn't working label Feb 2, 2022
@michaelbromley
Copy link
Member

The relevant code is here:

// When creating a ProductVariant _not_ in the default Channel, we still need to
// create a ProductVariantPrice for it in the default Channel, otherwise errors will
// result when trying to query it there.
await this.createOrUpdateProductVariantPrice(
ctx,
createdVariant.id,
input.price,
defaultChannelId,
);
}

Removing this line will most likely have unintended consequences, e.g. listing products in the default channel will throw. Furthermore, the graphql ProductVariant.price field is of type Int!, which means we cannot currently represent a "no price set" state for the price in a given channel. The assumption made is that if a ProductVariant is assigned to a Channel, then it must have a price in that Channel.

I'm open to suggestions on how to better handle this in a non-breaking way.

@christopheblin
Copy link
Contributor Author

@michaelbromley would it be possible to have const NO_PRICE = Infinity (or -1 or whatever) and use NO_PRICE here instead of input.price ?

if you already made the assumption that a variant must have a price in a channel, it should not break, right ?

Bonus : in the admin_ui, display N/A instead of Infinity 😄

I see that there is already a priceFactor in the assignProductToChannelInput so this should also work here

Additionally, an error should be thrown when addItemToOrder if variant.price == NO_PRICE

WDYT ?

@christopheblin
Copy link
Contributor Author

also, to not break mono-currency setups, you could check the default channel currency is the same

     this.getDefaultChannelCurrency() == this.getCurrentChannelCurrency() ? input.price : NO_PRICE,

@michaelbromley
Copy link
Member

Thanks for the suggestions!

Well, Infinity is not supported by GraphQL, so we wouldn't be able to use that.

-1 could work but still feels like a hack to me. Currently -1 is a valid value for a ProductVariantPrice. So that would actually be a breaking change. It's an edge-case, I know, and maybe we could get away with it.

Can we back up a bit here and help me to understand your workflow. You are adding a product to a non-default channel first, and then want it to not have a price in the default channel.

Do you plan to, at some future point, assign it a price in the default channel? Or do you wish it to remain "N/A"?

@christopheblin
Copy link
Contributor Author

Sure -1 is a hack (as well as any other int)

In a more general way, my use case is to NOT allow orders/customers/products/anything in the default channel

If I step back again in am ore general way, what I'd like is to restrict an administrator to some channels

@michaelbromley
Copy link
Member

Ah ok. Now we are drilling down to the X in this XY problem!

First thing: everything is always in the default channel. It is actually a parent of all other channels. Illustration here: https://www.vendure.io/docs/developer-guide/channels/

So in order to restrict admins so they cannot access the default channel, you would use the built-in role-based access control. When you create a role in the admin ui, you can limit it to specified channels:
image

Then you'd create an administrator, and assign it that newly-created role.

@christopheblin
Copy link
Contributor Author

I'm going to test that, thanks for pointers !

@michaelbromley
Copy link
Member

Please be sure to update this thread if you managed to resolve the issue using the channel permissions approach 👍

@christopheblin
Copy link
Contributor Author

Restricting admins to their respective channels by adding a "shop admin xxx" role for each channel (so not so easy if you have many channels) "solved" the problem (i.e because no one except super admin has access to the default channel, no one actually sees the problem except super admin)

In fact, we decided to NEVER use the default channel because not only there is this problem with possible different prices, but there is the "same" problem with currencies

That is, if I create a "eu-shop" channel in € while my "default" channel is in $, the prices in € of the "eu-shop" are just shown in $ in the "default" channel !

Here is an illustration of the problem

The order was made in eu-shop in €
Capture d’écran 2022-02-11 à 08 50 42
But the same order appears consolidated in $ in the default channel
You can see however that "latest orders" correctly display the order in euros 😄
Capture d’écran 2022-02-11 à 08 51 33

This is also the case for variants, the variant was 1€ when created in eu-shop but appears $1 in default shop ...
Capture d’écran 2022-02-11 à 09 08 13

So, I think that it is just a matter of being aware of these subtleties when you use vendure

  1. Each channel have a currency (including the default one)
  2. Each variant has a price in each channel (including the default one)
  3. If you create a variant in a channel, it is copied in the default channel with same "raw" price (i.e without taking care of currency)
  4. The default channel should NOT be used if you use different currencies (unless you know what you are doing)

Somehow, I see 3 distincts use cases that could be described in the docs

  1. mono-shop -> simply use the default channel for everything
  2. multi-shops / multi-catalogs -> never use default channel (each shop has its currency, its catalog, its orders, its roles, ... -> this is more or less my use case)
  3. multi-shops / mono-catalog / multi-currencies (seems the hardest use case to me) -> define product in default channel with -1 price (or whatever), share it in all other channels, adjust the price in each channel, manage orders / promotions separately in each channel

At the end, it just shows how flexible vendure is (and with great flexibility comes great responsibilities :) )

Anyway, thanks for your time and your pointers, I close this issue since "this is not a bug but a feature" :)

@michaelbromley
Copy link
Member

Thanks for your detailed write-up and summary. I'll see how I can somehow communicate this better in the docs based on those use-cases you mentioned, so other people don't get confused by the behaviour.

Regarding that "total orders" widget - yeah that's probably just an impossible problem to solve - displaying the order totals from all channels, possibly with several different currencies, in a single number! If I were the super admin of a multi channel, multi-currency setup, I'd probably want a widget which summarizes order totals in each channel or something like that. Anyway, luckily that is all configurable and people can build whatever widgets they need.

michaelbromley added a commit that referenced this issue Feb 11, 2022
@michaelbromley
Copy link
Member

Added this section to the Channels docs: https://www.vendure.io/docs/developer-guide/channels/#channels-currencies--prices

@christopheblin
Copy link
Contributor Author

@michaelbromley that seems clear to me (at least now that I am very familiar with this stuff :)

if I may just add that you should also update https://www.vendure.io/docs/developer-guide/multi-tenant/ with a link to https://www.vendure.io/docs/developer-guide/channels/#use-case-multiple-separate-shops

Capture d’écran 2022-02-11 à 11 01 51

Something like :

Take extra care if you log in with a super admin in the default channel, especially with prices and currencies.

See more details at developer-guide/channels and especially in #use-case-multiple-separate-shops

michaelbromley added a commit that referenced this issue Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants