Skip to content

Commit 5131905

Browse files
authored
Better setup docs (#310)
1 parent bce96ed commit 5131905

File tree

10 files changed

+79
-45
lines changed

10 files changed

+79
-45
lines changed

config/shopify.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717
*/
1818
'storefront_token' => env('SHOPIFY_STOREFRONT_TOKEN'),
1919

20-
/**
21-
* Admin API Auth Key
22-
*/
23-
'auth_key' => env('SHOPIFY_AUTH_KEY'),
24-
25-
/**
26-
* Admin API Auth Password
27-
*/
28-
'auth_password' => env('SHOPIFY_AUTH_PASSWORD'),
29-
3020
/**
3121
* Admin Access Token
3222
*/
@@ -56,7 +46,7 @@
5646
/**
5747
* Admin API version - Set this to a fixed value (eg 2023-07) or null to let the library decide
5848
*/
59-
'api_version' => env('SHOPIFY_API_VERSION', null),
49+
'api_version' => env('SHOPIFY_API_VERSION', '2025-04'),
6050

6151
/**
6252
* Admin connection is a private app, defaults to false
@@ -80,7 +70,7 @@
8070
* Asset Container to Store the imported Assets
8171
*/
8272
'asset' => [
83-
'path' => env('SHOPIFY_ASSET_PATH', 'shopify'),
73+
'path' => env('SHOPIFY_ASSET_PATH', ''),
8474
'container' => env('SHOPIFY_ASSET_CONTAINER', 'shopify'),
8575
],
8676

@@ -137,4 +127,16 @@
137127
* (ensure this matches exactly)
138128
*/
139129
'sales_channel' => env('SHOPIFY_SALES_CHANNEL', 'Online Store'),
130+
131+
/**
132+
* Your App's Admin API Auth Key
133+
* Note: this is not required unless you are doing custom integrations using the RestApi
134+
*/
135+
'auth_key' => env('SHOPIFY_AUTH_KEY', 'api-key'),
136+
137+
/**
138+
* Admin API Auth Password
139+
* Note: this is not required unless you are doing custom integrations using the RestApi
140+
*/
141+
'auth_password' => env('SHOPIFY_AUTH_PASSWORD', 'api-password'),
140142
];

docs/content/en/CMS/customers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you want Shopify and Statamic to sync users and customers you need to change
88

99
## Link Statamic customers from Shopify
1010

11-
To create a link between Shopify customers and Statamic users you need to ensure your Shopify app has `customer read` and `customer write` permissions.
11+
To create a link between Shopify customers and Statamic users you need to ensure your Private Shopify app has `customer read` and `customer write` permissions.
1212

1313
You then need to set up the following webhooks:
1414

docs/content/en/CMS/webhooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ There is a built method to listen for webhooks sent by Shopify back to your appl
1313
3. Scroll down to **Webhooks** and click **Create Webhook**
1414
4. Enter the URL as shown in the sections below.
1515
5. Leave the type as `JSON` and on the latest API.
16+
6. If this is your first webhook, you will be provided a secret which you should add to your .env as `SHOPIFY_WEBHOOK_SECRET`
1617

1718
<alert type="info">
1819

docs/content/en/env.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ position: 3
66

77
## Required For Admin
88

9-
| Value | Description |
10-
| -------------------| ------------- |
11-
| `SHOPIFY_APP_URL` | The url to your store (no https://) |
12-
| `SHOPIFY_ADMIN_TOKEN` | The Admin API access token you received when generating your app |
13-
| `SHOPIFY_AUTH_KEY` | The Admin API key found when creating your private app |
14-
| `SHOPIFY_AUTH_PASSWORD` | The Admin API password found when creating your private app |
9+
| Value | Description |
10+
| -------------------|-----------------------------------------------------------------------------------------------------------------------------|
11+
| `SHOPIFY_APP_URL` | The url to your store (no https://) |
12+
| `SHOPIFY_ADMIN_TOKEN` | The Admin API access token you received when generating your app |
13+
| `SHOPIFY_AUTH_KEY` | The Admin API key found when creating your private app. This is optional and only required if you want to use the REST API. |
14+
| `SHOPIFY_AUTH_PASSWORD` | The Admin API password found when creating your private app. This is optional and only required if you want to use the REST API. |
1515

1616
## Required For Frontend
1717

1818
If you are using the JavaScript publishable in the addon you'll need to set the following.
1919

20-
| Value | Description |
21-
| -------------------| ------------- |
22-
| `SHOPIFY_APP_URL` | The url to your myshopify.com store (no https://) |
23-
| `SHOPIFY_STOREFRONT_URL` | The custom url to your store if you have one (no https://) |
24-
| `SHOPIFY_STOREFRONT_TOKEN` | Found when enabling the Storefront API whilst creating your private app |
20+
| Value | Description |
21+
| -------------------|-------------------------------------------------------------------------------------------------------------------|
22+
| `SHOPIFY_APP_URL` | The url to your myshopify.com store (no https://) |
23+
| `SHOPIFY_STOREFRONT_URL` | The custom url to your store if you have one (no https://) |
24+
| `SHOPIFY_STOREFRONT_TOKEN` | Found in the configuration section of your Headless Sales Channel |
2525

2626
## Required For Webhooks
2727

@@ -35,8 +35,15 @@ If you are using the webhook handlers you'll need the following.
3535

3636
These allow you to tweak how the system works. Please check out the `config/shopify.php` for a full list of options.
3737

38-
| Value | Description |
39-
| -------------------|-------------------------------------------------------------------------------------------------|
40-
| `SHOPIFY_JOB_QUEUE` | The queue to run the shopify jobs on. Allows you to set it to a different one than the default. |
41-
| `SHOPIFY_COLLECTION_HANDLE` | The handle of the collection that contains your Shopify products, defaults to 'products'. |
42-
| `SHOPIFY_SALES_CHANNEL` | The Sales Channel to use for product availability, defaults to 'Online Store'. |
38+
| Value | Description |
39+
|---------------------------|-------------------------------------------------------------------------------------------------|
40+
| `SHOPIFY_API_VERSION` | The version of the storefront and admin APIs you want to target (defaults to '2025-04'). |
41+
| `SHOPIFY_ASSET_CONTAINER` | The asset container you want to use to store assets (defaults to 'shopify') |
42+
| `SHOPIFY_ASSET_PATH` | The path in the container you want to use to store assets (defaults to ''). |
43+
| `SHOPIFY_COLLECTION_HANDLE` | The handle of the collection that contains your Shopify products, defaults to 'products'. |
44+
| `SHOPIFY_JOB_QUEUE` | The queue to run the shopify jobs on. Allows you to set it to a different one than the default. |
45+
| `SHOPIFY_SALES_CHANNEL` | The Sales Channel to use for product availability, defaults to 'Online Store'. |
46+
| `SHOPIFY_TAXONOMY_COLLECTIONS` | The taxonomy handle to use for shopify collections (defaults to 'collections'). |
47+
| `SHOPIFY_TAXONOMY_TAGS` | The taxonomy handle to use for 'tags' of product (defaults to 'tags'). |
48+
| `SHOPIFY_TAXONOMY_TYPE` | The taxonomy handle to use for 'types' of product (defaults to 'type'). |
49+
| `SHOPIFY_TAXONOMY_VENDOR` | The taxonomy handle to use for 'vendors' of product (defaults to 'vendor'). |

docs/content/en/setup.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,52 @@ composer require statamic-rad-pack/shopify
2424

2525
If you are on a Windows environment, please set the `SHOPIFY_SESSION_STORAGE_PATH` .env value to a writeable path.
2626

27-
## Creating a Shopify App
2827

29-
To set up a private app on Shopify for this add-on to use, use the following steps:
28+
### Step 1: Using Shopify's Headless app for front end Storefront integration
29+
30+
In you are using the front end code to access the Storefront API we recommend you set up [Shopify's Headless](https://apps.shopify.com/headless) on your store. This app lets you create a new sales channel that you can use to determine which of your products are available on your Statamic site.
31+
32+
Once you have installed the app you should create a new sales channel, with a meaningful name (eg "Statamic").
33+
34+
In the Sales Channel Credentials screen you should now be able to copy your keys as follows:
35+
36+
```bash
37+
SHOPIFY_APP_URL="your-store.myshopify.com"
38+
SHOPIFY_STOREFRONT_TOKEN="{Public access token}"
39+
SHOPIFY_SALES_CHANNEL="{Sales channel name}"
40+
```
41+
42+
43+
### Step 2: Create a private app for Admin API integration
44+
Set up a private app on Shopify for this add-on using the following steps:
3045

3146
1. Visit the "Apps" section in your Shopify admin by clicking on the sidebar menu link, then in the modal that appears "App and sales channel settings".
3247
2. Click "Develop Apps" in the top right.
3348
3. Click "Create an app" in the top right to make a new one.
34-
4. Set a nice name to remember as well as your email.
49+
4. Set a nice name to remember (eg "Statamic Admin") as well as your email.
3550
5. Click the "Configuration" Tab.
3651
1. Click "Configure" next to Admin API Integration.
3752
2. Enable `read_inventory`, `read_metaobjects`, `read_orders`, `read_products`, `read_product_listings`, `read_publications`, `read_translations` and `write_customers`
38-
3. Click "Configure" next to Storefront API Integration.
39-
4. Enable `unauthenticated_read_product_listings`, `unauthenticated_read_product_tags`, `unauthenticated_read_product_inventory`, `unauthenticated_write_customers`, `unauthenticated_write_checkouts`, `unauthenticated_read_customers`, `unauthenticated_read_checkouts`, `unauthenticated_read_metaobjects`
4053
5. Click "Save" in the top right.
41-
6. Click the "API Credentials" tab. Add the `Admin API access token` to your `.env` as `SHOPIFY_ADMIN_TOKEN`, add `API key` as `SHOPIFY_AUTH_KEY`, add `API secret key` as `SHOPIFY_AUTH_PASSWORD`, and add `Storefront API access token` as `SHOPIFY_STOREFRONT_TOKEN`.
54+
6. Click the "API Credentials" tab. Add the `Admin API access token` to your `.env` as `SHOPIFY_ADMIN_TOKEN`.
4255
7. If you've configured the app properly you should see a button that says "Install App". Click this.
4356

57+
### 3. Shopfront redirection
58+
If you are not intending to use the Shopify storefront you should perform redirection from any Shopify URLs to your website.
59+
60+
We recommend installing Shopify's [Hydrogen Redirect Theme](https://github.com/Shopify/hydrogen-redirect-theme), and following their setup instructions.
4461

45-
## Environment Variables
62+
### 4. Finalise your .env
63+
After completing steps 1 and 2 your .env should look as follows:
64+
65+
```bash
66+
SHOPIFY_APP_URL="your-store.myshopify.com"
67+
SHOPIFY_STOREFRONT_TOKEN="{Public access token}"
68+
SHOPIFY_SALES_CHANNEL="{Sales channel name}"
69+
SHOPIFY_ADMIN_TOKEN="{Admin API access token}"
70+
```
4671

47-
Ensure you've set the necessary environment variables as defined in the ["Env Values"](/env) section.
72+
You may also wish to add some of the option values defined in the ["Env Values"](/env) section.
4873

4974
## Publishable Assets
5075

src/Jobs/ImportSingleProductJob.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ public function handle()
261261

262262
$entry->set(config('shopify.taxonomies.collections'), $collections)->save();
263263
} catch (\Throwable $e) {
264-
dd($e);
265264
Log::error('Could not retrieve collections for product '.$this->data['id']);
266265
Log::error($e->getMessage());
267266
}

src/ServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,17 @@ private function createNavigation(): void
162162

163163
private function setShopifyApiConfig(): void
164164
{
165-
if (! $key = config('shopify.auth_key')) {
165+
if (! $key = config('shopify.admin_token')) {
166166
return;
167167
}
168168

169169
Context::initialize(
170-
apiKey: $key,
170+
apiKey: config('shopify.auth_key'),
171171
apiSecretKey: config('shopify.auth_password'),
172172
scopes: ['read_metaobjects', 'read_products'],
173173
hostName: config('shopify.url'),
174174
sessionStorage: new FileSessionStorage(config('shopify.session_storage_path', '/tmp/php_sessions')),
175-
apiVersion: config('shopify.api_version') ?? '2025-04',
175+
apiVersion: config('shopify.api_version'),
176176
isEmbeddedApp: false,
177177
isPrivateApp: config('shopify.api_private_app') ?? false,
178178
);

src/Tags/Shopify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function productPrice()
7575
public function tokens()
7676
{
7777
return "<script>
78-
window.shopifyConfig = { url: '".(config('shopify.storefront_url') ?? config('shopify.url'))."', token: '".config('shopify.storefront_token')."', apiVersion: '".(config('shopify.api_version') ?? '2024-07')."' };
78+
window.shopifyConfig = { url: '".(config('shopify.storefront_url') ?? config('shopify.url'))."', token: '".config('shopify.storefront_token')."', apiVersion: '".config('shopify.api_version')."' };
7979
</script>";
8080
}
8181

src/Traits/SavesImagesAndMetafields.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private function importImages(array $image)
2424
// Check if it exists first - no point double importing.
2525
$asset = Asset::query()
2626
->where('container', config('shopify.asset.container'))
27-
->where('path', config('shopify.asset.path').'/'.$name)
27+
->where('path', Str::replaceStart(config('shopify.asset.path').'/', '/', '').$name)
2828
->first();
2929

3030
if ($asset) {
@@ -104,7 +104,7 @@ private function cleanupFakeFile(string $name): void
104104
*/
105105
private function getPath(UploadedFile $file): string
106106
{
107-
return Path::assemble(config('shopify.asset.path').'/', $file->getClientOriginalName());
107+
return Path::assemble(config('shopify.asset.path'), $file->getClientOriginalName());
108108
}
109109

110110
/**

tests/Unit/TagsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function outputs_shopify_tokens()
2424
config()->set('shopify.storefront_token', '1234');
2525

2626
$this->assertEquals(str_replace(["\r", "\n"], '', "<script>
27-
window.shopifyConfig = { url: 'abcd', token: '1234', apiVersion: '2024-07' };
27+
window.shopifyConfig = { url: 'abcd', token: '1234', apiVersion: '2025-04' };
2828
</script>"),
2929
str_replace(["\r", "\n"], '', $this->tag('{{ shopify:tokens }}'))
3030
);

0 commit comments

Comments
 (0)