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

Shopify wishlist implementation #724

Conversation

chemmanouilidis
Copy link

@chemmanouilidis chemmanouilidis commented Mar 31, 2022

Wishlist implementation for the Shopify provider. You can Add, Remove products to your customer wishlist as well as their variants. Also Added the possibility to add a specific product variant to your wishlist if its not available for sale (due to no stock etc)...

  1. changed shopify fetch and graphQL fetch types and also the fetcher functions to include useAdminApiFlag in order to seperate graphql storefront API operations from Admin API ones,

  2. generated shopify admin api schema(documentation for code generation is outdated and not working as per readme instructions - yarn generate:shopify script not present),

  3. changed RemoveItemHook of commerce/types/wishlist,

  4. created shopify wishlist api routes (addItem, removeItem, getWishlist),

  5. added shopify api operation getCustomerWishlist,

  6. updated index files of api/operations, utils and api/wishlist,

  7. created shopify wishlist types ,

  8. created getCustomerId function as a util in shopify ,

  9. added customerUpdate mutation (Admin API operation), customer query (Admin API operation),

  10. added getCustomerId query,

  11. modified commerce wishlist endpoint to extract item variable from req/body,

  12. added useAdminApi flag to commerce fetcherOptions,

  13. updated wishlist api constants,

  14. modified shopify fetcher,

  15. added wishlist handlers to shopify provider ,

  16. Polished frontend UI so that you can now correctly add product to wishlist if variant is not available for sale

  17. modified .env.template files to correctly refer that you also need shopify admin access token

…flag, generated shopify admin api schema, changed RemoveItemHook of commerce/types/wishlist, created shopify wishlist api routes (addItem, removeItem, getWishlist), added shopify api operation getCustomerWishlist, updated index files of api/operations, utils and api/wishlist, created shopify wishlist types created getCustomerId function as a util in shopify added customerUpdate mutation, added customer query with admin api, added getCustomerId query
…/body, added useAdminApi flag to commerce fetcherOptions, updated wishlist api constants, modified shopify fetcher, added wishlist handlers to shopify provider Polished frontend UI so that you can now correctly add product to wishlist if variant is not available for sale
@vercel
Copy link

vercel bot commented Mar 31, 2022

@chemmanouilidis is attempting to deploy a commit to the Vercel Solutions Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Mar 31, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

commerce-local – ./site

🔍 Inspect: https://vercel.com/vercel-solutions-vtest314/commerce-local/4tMM9t6GzHEvFbqwnFRiJJELBWAH
✅ Preview: Failed

[Deployment for e81c0fb failed]

commerce-bigcommerce – ./site

🔍 Inspect: https://vercel.com/vercel-solutions-vtest314/commerce-bigcommerce/J7v1CDEWHcfBgAZGGqm1msGfWepN
✅ Preview: Failed

[Deployment for 594b3ef failed]

commerce-ordercloud – ./site

🔍 Inspect: https://vercel.com/vercel-solutions-vtest314/commerce-ordercloud/2pPXTFgZt6ZQe6FFwmdsXv83TePB
✅ Preview: Failed

…e shopify admin access token to use shopify Admin API
Copy link
Member

@dominiksipowicz dominiksipowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. It looks awesome and is a lot of work. Please see my comments and requests for changes.

Additional notes:

  • we use yarn for this project, please remove package-lock.json
  • the main "local" build is failing

site/commerce.config.json Outdated Show resolved Hide resolved
packages/shopify/.env.template Outdated Show resolved Hide resolved
packages/commerce/src/types/wishlist.ts Outdated Show resolved Hide resolved
packages/commerce/src/api/endpoints/wishlist.ts Outdated Show resolved Hide resolved
packages/commerce/src/api/endpoints/wishlist.ts Outdated Show resolved Hide resolved
site/.env.template Outdated Show resolved Hide resolved
site/components/wishlist/WishlistCard/WishlistCard.tsx Outdated Show resolved Hide resolved
@vercel
Copy link

vercel bot commented Apr 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
commerce-kibocommerce ❌ Failed (Inspect) Apr 21, 2022 at 8:43AM (UTC)
commerce-local ✅ Ready (Inspect) Visit Preview Apr 21, 2022 at 8:43AM (UTC)

@chemmanouilidis
Copy link
Author

Corrections Commit includes the following changes:

### Commerce API

  1. reverted commerce/api/endpoints/wishlist & commerce/types/wishlist to source implementation to avoid problems with other providers and major breaking changes

### Shopify provider

  1. Modified shopify/api/endpoints/wishlist/add-item property destructuring to be compatible with the types used,
  2. remove-item also has the same destructuring method plus new filtering method that correctly filters the wishlist by productId AND variantID
  3. Modified shopify/types/wishlist. RemoveItemHook type now correctly extends the core type from commerce/types/wishlist by adding an optional property itemVariantId, modified WishlistSchema type to be compatible with the new functions used in wishlist/endpoints (add-item, remove-item etc) by adding variables type property for the body.
  4. minor changes to use-add-item specifically in the way properties are being handed to the fetcher.
  5. use-remove-item hook now complies with the new types declared passing through itemId and itemVariantId
  6. modified env.template and const files to "hide" admin access token variable.

Site Components

  1. Modified WishlistButton removeItem function to be compatible across all providers
  2. Modified WishlistCard removeItem function (same as above) and also added variant options labels for each product in your wishlist. This all summarizes my goal from the begining being a user should be able to add more variants of the same product in his wishlist and not just the main product. One, can desire both the blue and the red version of that T-Shirt that is currently out of stock in those colors.
  3. Wishlist page midifications are mainly reverts to previous changes I have made. Now wishlist page should be the same as origin.

@chemmanouilidis
Copy link
Author

Thank you for your contribution. It looks awesome and is a lot of work. Please see my comments and requests for changes.

Additional notes:

  • we use yarn for this project, please remove package-lock.json
  • the main "local" build is failing

package lock removed.
local build was failing to me because it could not resolve the wishlist hooks from the "local" framework. wishlist folder of local package didn't have an index file with default exports. Should I add it and commit? adding the file to me, solves the problem.

…kage, reverted tsconfig changes I made for develop testing.
…rd components as the default option for provider compatibility
@chemmanouilidis
Copy link
Author

now the main "local" build succeeds.

@robinglen
Copy link

@chemmanouilidis thanks for this PR. Is there any progress here, did you ever use this in production?

@chemmanouilidis
Copy link
Author

@chemmanouilidis thanks for this PR. Is there any progress here, did you ever use this in production?

I don't think any further progress is required. I currently use it in production and it seems stable.

})!
metafieldInput = { id: wishlist?.id! }
} else {
metafieldInput = { namespace: 'my_fields', key: 'wishlist' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chemmanouilidis just a heads up, I believe you need a type: 'json' on this metafieldInput, otherwise the initial metafield API call will quietly fail and the Wishlist is never created.

Copy link
Author

@chemmanouilidis chemmanouilidis Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. It has been tested "as is" and works as intended. I use this implementation live without any problems so far.

The reason why you don't need this is because you don't actually create the Metafield. The metafield is created inside the settings section of your shopify store. By going to Settings > Metafields and choosing customers you define a Metafield for the customers field which is of json type. So every customer created already has the Wishlist metafield by default and it is of type JSON.

In the code block you mention, in order to add an item to the wishlist, I must first check if this customer's wishlist is already populated or not. There is a slight difference in the mutation if the list is already populated.

@leerob
Copy link
Member

leerob commented Apr 18, 2023

Hey there! Thank you for your contribution. We have decided to take Next.js Commerce in a new direction and will be closing out current PRs and issues due to this change. Please see this PR for more details: #966

@leerob leerob closed this Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants