vendure-ecommerce / vendure

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

Channels #12

Closed michaelbromley closed 4 years ago

michaelbromley commented 6 years ago

Channels represent distinct sales outlets. Many web shops will just have a single, default channel, which is the website. However, there are cases when it would be desirable to be able to define distinct sales channels, such as:

Thus the following aspects could vary from one channel to the next:

Prior Art

Design

Adding Channels would quite significantly increase the complexity of the models. Here is a rough idea for an implementation:

michaelbromley commented 6 years ago

Some real-life use-cases for Channels:

I am a merchant that is on M2 commerce cloud edition. We have 5 websites, one with 2 separate store views. Moving to Magento from Volusion, the major draw was multi site. We have sites that sell the same product just to different audiences and marketed different. And one site is 100% a different product line. I can not imagine trying to manage those as separate stores. source

I will have store A, B and Each will have it's own url i.e www.a.com, www.b.com and www.c. Each of the stores will share some products and some products will be exclusive to each particular Each store will have it's own identity but will share physical addresses and general information. source

michaelbromley commented 6 years ago

Determining the active Channel

Consider the following:

  1. There are 2 Channels, "default" and "special".
  2. There are 100 products in total. All are assigned to "default" but only 50 are assigned to "special".
  3. A client makes a products() query. How do we decide which set of products to return?

In general: How do we determine the active channel for a request?

Possible solutions:

  1. Send a channelId (or token) argument with all API calls as an argument or a header, for example.
    • ✅ Relatively simple, familiar pattern (like passing an API key to a SaaS service)
    • 👎 It would be trivial for an end-user to change the channelId manually with possibly unwanted consequences.
  2. Generate distinct API endpoints for each Channel
    • 👎 This is functionally no different from #1 - it just uses a different way of encoding the same information. And is more complex.

Implementation ideas

  1. A Channel has a generated token property (a random hash)
  2. When a client makes a call, it must set a header containing this token. This sets the context of the request to be the specified Channel.
  3. At the Resolver layer, this token is resolved into a channelId and forwarded to the Service layer.
  4. The DB call is amended with a filter by channelId. E.g. "select products where product is assigned to channel with id channelId"
  5. In the case of Administrators, the role(s) of that User will be associated with one or more Channels (in the case of a "Channel Administrator" - someone in charge of one or more Channels only). The AdminUI should allow clear switching between Channels as a top-level UI control.
  6. For "Super Administrators" (or whatever we call them), they will be able to see all products since they always have access to the default Channel

determining-active-channel

michaelbromley commented 6 years ago

Concept for Channels in the Admin UI

channels admin ui

superadmin channels admin ui

michaelbromley commented 4 years ago

A lot of work has been done on Channels over the past week. Here's a current status report:

Outstanding tasks: