Wiki source code of Build your own shop system

Last modified by Shop Team on 2023/02/13 22:56

Show last authors
1 = Intro =
2
3 If a standalone or [[JavaScript Integrated Shop>>url:https://help.spreadshirt.com/hc/en-us/articles/207487815-Website-Integration-with-JavaScript||shape="rect"]] does not fulfill your requirements and you absolutely must have a custom shop this tutorial aims to be a starting point for your journey.
4
5 Before we start you can take a look at a **[[working (minimal) example>>url:https://github.com/spreadshirt/shop-api-example-integration||shape="rect"]]** that we have built in order to demonstrate the capabilities of the Public Shop API. It shows a draft of a shop system written in php that might be helpful to understand the (list-page -> detail-page -> add-to-basket) workflow.
6
7 [[image:attach:image2019-8-2_14-10-37.png]][[image:attach:image2019-8-2_14-11-14.png]][[image:attach:image2019-8-2_14-9-28.png]]
8
9 = Prerequisites =
10
11 We have to stress that you have to have a certain amount of time and technical knowledge in order to build your own shop based on the Public Shop API.
12
13 The following topics will not be covered by this tutorial and will be treated as given:
14
15 1. A Spreadshop with one or more ideas which you configured in the Partner Area
16 1. An API Key
17 1. (((
18 A solid understanding of HTTP, HTML, CSS, client-side and server-side programming.
19 )))
20
21 = Step by step =
22
23 == (% style="font-size: 20.0px;letter-spacing: -0.008em;" %) 1. Manage your assets in the Partner Area(%%) ==
24
25 There are no endpoints available that allow uploading or changing the content of your shop. Use the partner area to upload designs and manage your assortment. Note that not only the content you upload in the Partner Area, but also the shop settings affect the output of the [[sellable resources>>doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.Sellables.WebHome||style="letter-spacing: 0.025em;" shape="rect"]]. For example, enabling model images affects the image URLs returned by the API.
26
27 == (% style="font-size: 20.0px;letter-spacing: -0.008em;" %) 2. Build a scheduled sellable data import(%%) ==
28
29 To use the full potential of a custom shop implementation it is recommended to import the entries of the [[sellable list>>doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.Sellables.WebHome]] resource into your own database every 24 hours. The example integration uses the Public Shop API as a direct data source for simplicity, but that is not the recommended approach. The import based solution yields better performance and allows you to introduce all kinds of filtering and sorting options (which are NOT built into the Public Shop API). Once you have imported this data you can build a frontend that meets your requirements.
30
31 == 3. Build the list page ==
32
33 Using the sellable data from your data base, you can now build your own list page giving an overview over the available sellables. Use the "previewImage.url" field directly in your <img> tags. You are free to build any navigational structure and filtering mechanisms you deem necessary. Depending on your needs, the [[doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.ProductType Departments and Categories.WebHome]] resource might be useful.
34
35 == 4. Build the detail page ==
36
37 When assembling a detail page on your server, request the [[sellable detail resource>>doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.Sellables.WebHome]] allowing you to render all available images as well as sizes. If you want to display things like name and description of the product type, appearance names and colors, etc., the [[doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.ProductType.WebHome]] resource is useful. The response of that resource is slow and rarely changes, so it is a good candidate for caching. In a somewhat generic implementation, the [[doc:API.Spreadshirt Public Shop API Documentation.API Tutorials.Build your own shop system.Price Formatting Guide.WebHome]] might be helpful.
38
39 == 5. Build a basket ==
40
41 Once a user clicks the add-to-basket button, use the "[[Create a basket>>doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.Baskets.WebHome]]" resource to create a Spreadshirt basket with the selected sellable in it. Associate the returned basket id with the customer's session. You can now use the fields from the basket payload to assemble a drop-down UI component or something similar. Use the "Update a basket" resource for subsequent customer interactions.
42
43 == 6. (Optional) Support promotions ==
44
45 If you want to show promotion banners in your shop system and enable promotion discounts provided by SpreadShop, we recommend to check out the [[doc:API.Spreadshirt Public Shop API Documentation.API REST Resources.Current Promotion.WebHome]] resource.
46
47 == 7. Redirect to the Spreadshirt checkout ==
48
49 Finally, you can redirect the customer to the Spreadshirt checkout using the "shop checkout" link from the basket response. We will take over from there.
50
51 \\
52
53 \\