Make-Lemonade / lemonsqueezy-wp

The official Lemon Squeezy WordPress plugin
https://wordpress.org/plugins/lemon-squeezy/
6 stars 3 forks source link

Configurable Store option #7

Closed patrickposner closed 2 years ago

patrickposner commented 3 years ago

@gilbitron mentioned this important point:

One other thing I've just realised, the products dropdown in the block is loading all products across all of the Lemon Squeezy stores that belong to the user. I think we should add a second "stores" dropdown above the products dropdown if the API key has access to multiple stores. That way products can be filtered by store.

CleanShot 2021-11-02 at 10 41 36@2x

Originally posted by @gilbitron in https://github.com/Make-Lemonade/lemonsqueezy-wp/issues/3#issuecomment-957320826

patrickposner commented 3 years ago

@gilbitron Could you check the feature branch here: https://github.com/Make-Lemonade/lemonsqueezy-wp/tree/select-store

I integrated the select option for stores and modified the endpoints so that the products are getting updated as soon as you select a store.

One problem I faced yesterday (maybe I was simply too tired..):

If I make a request to: https://api.lemonsqueezy.com/v1/products?store_id=123 I get all products from that store.

If I do the same with: https://api.lemonsqueezy.me/v1/products?store_id=123

I get all products from all stores.

patrickposner commented 3 years ago
gilbitron commented 2 years ago

@patrickposner The JSON:API format for filters is filter[store_id]=. So the URL would need to be:

https://api.lemonsqueezy.com/v1/products?filter[store_id]=123

The other (cleaner) way to do it is:

https://api.lemonsqueezy.com/v1/stores/123/products

gilbitron commented 2 years ago

@patrickposner I've commited some changes to the select-store branch which fixes the API request and adds some better state handling. I'll let you clean it up a bit.

I noticed that changing the product in the block settings in the sidebar doesn't change the product in the dropdown in the block editor itself, and vice versa.