Skip to content

Commit

Permalink
Merge branch '4.0' into feature/user-package-retries
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
lukeholder committed Nov 2, 2023
2 parents 4c0f2e9 + 828e0d7 commit 49ac028
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 53 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Release Notes for Shopify

### Unreleased

## 4.0.0 - WIP
- Shopify now requires `shopify/shopify-api` 5.2.0 or later.
- Shopify now the related custom app to be created with event version set to `2023-10`.
- Syncing meta fields is no longer performed in a job.
- Fixed a bug where the template routing setting would not save.
- Deprecated the `craft\shopify\jobs\UpdateProductMetadata` job.
- Fixed a bug where the template routing setting would not save.

## 3.2.0 - 2023-06-12

Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Before upgrading ensure that the **Admin API access scopes** match the [requirem

After upgrading, ensure that all required webhooks have been created by clicking the “Create” button on the **Shopify** → **Webhooks** screen in your project’s control panel page in the CP. If the “Create” button is not visible, all required webhooks have been created.

#### From `3.x` to `4.x`

In version `4.0.0` the plugin changed its Shopify API requirement to version `2023-10`. Any Shopify custom apps created before this version will need to update their webhook event version to `2023-10`.

This can be done by visiting your Shopify store and going to **Settings** → **Apps and sales channels** → **Develop apps** clicking you app and then **Configuration** → **Webhook version**.

### Create a Shopify App

The plugin works with Shopify’s [Custom Apps](https://help.shopify.com/en/manual/apps/custom-apps) system.
Expand All @@ -58,7 +64,7 @@ Follow [Shopify’s directions](https://help.shopify.com/en/manual/apps/custom-a
- `read_product_listings`
- `read_inventory`

Additionally (at the bottom of this screen), the **Webhook subscriptions** → **Event version** should be `2022-10`.
Additionally (at the bottom of this screen), the **Webhook subscriptions** → **Event version** should be `2023-10`.

3. **Admin API access token**: Reveal and copy this value into your `.env` file, as `SHOPIFY_ADMIN_ACCESS_TOKEN`.
4. **API key and secret key**: Reveal and/or copy the **API key** and **API secret key** into your `.env` under `SHOPIFY_API_KEY` and `SHOPIFY_API_SECRET_KEY`, respectively.
Expand Down Expand Up @@ -124,7 +130,7 @@ Once the plugin has been configured, perform an initial synchronization via the
### Native Attributes

In addition to the standard element attributes like `id`, `title`, and `status`, each Shopify product element contains the following mappings to its canonical [Shopify Product resource](https://shopify.dev/api/admin-rest/2022-10/resources/product#resource-object):
In addition to the standard element attributes like `id`, `title`, and `status`, each Shopify product element contains the following mappings to its canonical [Shopify Product resource](https://shopify.dev/api/admin-rest/2023-10/resources/product#resource-object):

| Attribute | Description | Type |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
Expand All @@ -137,8 +143,8 @@ In addition to the standard element attributes like `id`, `title`, and `status`,
| `tags` | Tags associated with the product in Shopify. | `Array` |
| `templateSuffix` | [Liquid template suffix](https://shopify.dev/themes/architecture/templates#name-structure) used for the product page in Shopify. | `String` |
| `vendor` | Vendor of the product. | `String` |
| `metaFields` | [Metafields](https://shopify.dev/api/admin-rest/2022-10/resources/metafield#resource-object) associated with the product. | `Array` |
| `images` | Images attached to the product in Shopify. The complete [Product Image resources](https://shopify.dev/api/admin-rest/2022-10/resources/product-image#resource-object) are stored in Craft. | `Array` |
| `metaFields` | [Metafields](https://shopify.dev/api/admin-rest/2023-10/resources/metafield#resource-object) associated with the product. | `Array` |
| `images` | Images attached to the product in Shopify. The complete [Product Image resources](https://shopify.dev/api/admin-rest/2023-10/resources/product-image#resource-object) are stored in Craft. | `Array` |
| `options` | Product options, as configured in Shopify. Each option has a `name`, `position`, and an array of `values`. | `Array` |
| `createdAt` | When the product was created in your Shopify store. | `DateTime` |
| `publishedAt` | When the product was published in your Shopify store. | `DateTime` |
Expand All @@ -147,7 +153,7 @@ In addition to the standard element attributes like `id`, `title`, and `status`,
All of these properties are available when working with a product element [in your templates](#templating).

> **Note**
> See the Shopify documentation on the [product resource](https://shopify.dev/api/admin-rest/2022-10/resources/product#resource-object) for more information about what kinds of values to expect from these properties.
> See the Shopify documentation on the [product resource](https://shopify.dev/api/admin-rest/2023-10/resources/product#resource-object) for more information about what kinds of values to expect from these properties.
### Methods

Expand Down Expand Up @@ -347,7 +353,7 @@ Filter by the vendor information from Shopify.

#### `images`

Images are stored as a blob of JSON, and only intended for use in a template in conjunction with a loaded product. Filtering directly by [image resource](https://shopify.dev/api/admin-rest/2022-10/resources/product-image#resource-object) values can be difficult and unpredictable—you may see better results using [the `.search()` param](https://craftcms.com/docs/4.x/searching.html#development).
Images are stored as a blob of JSON, and only intended for use in a template in conjunction with a loaded product. Filtering directly by [image resource](https://shopify.dev/api/admin-rest/2023-10/resources/product-image#resource-object) values can be difficult and unpredictable—you may see better results using [the `.search()` param](https://craftcms.com/docs/4.x/searching.html#development).

```twig
{# Find products that have an image resource mentioning "stripes": #}
Expand Down Expand Up @@ -414,13 +420,13 @@ Products behave just like any other element, in Twig. Once you’ve loaded a pro
### Variants and Pricing

Products don’t have a price, despite what the Shopify UI might imply—instead, every product has at least one
[Variant](https://shopify.dev/api/admin-rest/2022-10/resources/product-variant#resource-object).
[Variant](https://shopify.dev/api/admin-rest/2023-10/resources/product-variant#resource-object).

You can get an array of variant objects for a product by calling [`product.getVariants()`](#productgetvariants). The product element also provides convenience methods for getting the [default](#productgetdefaultvariant) and [cheapest](#productgetcheapestvariant) variants, but you can filter them however you like with Craft’s [`collect()`](https://craftcms.com/docs/4.x/dev/functions.html#collect) Twig function.

Unlike products, variants in Craft…

- …are represented exactly as [the API](https://shopify.dev/api/admin-rest/2022-10/resources/product-variant#resource-object) returns them;
- …are represented exactly as [the API](https://shopify.dev/api/admin-rest/2023-10/resources/product-variant#resource-object) returns them;
- …use Shopify’s convention of underscores in property names instead of exposing [camel-cased equivalents](#native-attributes);
- …are plain associative arrays;
- …have no methods of their own;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require": {
"php": "^8.0.2",
"craftcms/cms": "^4.3.0",
"shopify/shopify-api": "^4.1"
"shopify/shopify-api": "^5.2.0"
},
"require-dev": {
"craftcms/ecs": "dev-main",
Expand Down
71 changes: 39 additions & 32 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/controllers/WebhooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use craft\shopify\Plugin;
use craft\web\assets\admintable\AdminTableAsset;
use craft\web\Controller;
use Shopify\Rest\Admin2022_10\Webhook;
use Shopify\Rest\Admin2023_10\Webhook;
use Shopify\Webhooks\Registry;
use Shopify\Webhooks\Topics;
use yii\web\ConflictHttpException;
Expand Down
2 changes: 1 addition & 1 deletion src/events/ShopifyProductSyncEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use craft\events\CancelableEvent;
use craft\shopify\elements\Product as ProductElement;
use Shopify\Rest\Admin2022_10\Product as ShopifyProduct;
use Shopify\Rest\Admin2023_10\Product as ShopifyProduct;

/**
* Event triggered just before a synchronized product element is going to be saved.
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Metafields.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace craft\shopify\helpers;

use craft\helpers\Json;
use Shopify\Rest\Admin2022_10\Metafield as ShopifyMetafield;
use Shopify\Rest\Admin2023_10\Metafield as ShopifyMetafield;

class Metafields
{
Expand Down
6 changes: 3 additions & 3 deletions src/services/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Shopify\Auth\Session;
use Shopify\Clients\Rest;
use Shopify\Context;
use Shopify\Rest\Admin2022_10\Metafield as ShopifyMetafield;
use Shopify\Rest\Admin2022_10\Product as ShopifyProduct;
use Shopify\Rest\Admin2023_10\Metafield as ShopifyMetafield;
use Shopify\Rest\Admin2023_10\Product as ShopifyProduct;
use Shopify\Rest\Base as ShopifyBaseResource;

/**
Expand All @@ -34,7 +34,7 @@ class Api extends Component
/**
* @var string
*/
public const SHOPIFY_API_VERSION = '2022-10';
public const SHOPIFY_API_VERSION = '2023-10';

/**
* @var Session|null
Expand Down
6 changes: 3 additions & 3 deletions src/services/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use craft\shopify\helpers\Metafields as MetafieldsHelper;
use craft\shopify\Plugin;
use craft\shopify\records\ProductData as ProductDataRecord;
use Shopify\Rest\Admin2022_10\Metafield as ShopifyMetafield;
use Shopify\Rest\Admin2022_10\Product as ShopifyProduct;
use Shopify\Rest\Admin2022_10\Variant as ShopifyVariant;
use Shopify\Rest\Admin2023_10\Metafield as ShopifyMetafield;
use Shopify\Rest\Admin2023_10\Product as ShopifyProduct;
use Shopify\Rest\Admin2023_10\Variant as ShopifyVariant;

/**
* Shopify Products service.
Expand Down

0 comments on commit 49ac028

Please sign in to comment.