Skip to content

Commit

Permalink
Add Craft 4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Dec 18, 2024
1 parent 7a14420 commit 573d98a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Notes for Shopify 5.3 (WIP)

- Shopify now requires Craft CMS 5.3.0 or later.
- Added Craft CMS 4 compatibility.
- Added support for selecting products in Link fields.
- Syncing products now returns presentment prices by default. ([#122](https://github.com/craftcms/shopify/issues/122))
- Added `craft\shopify\linktypes\Product`.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ Build a content-driven storefront by synchronizing [Shopify](https://shopify.com

## Installation

The Shopify plugin requires Craft CMS 5.0.0 or later.
The Shopify plugin (5.3.x) requires either:

- Craft 4.3 or later
- or, Craft 5.0 or later

To install the plugin, visit the [Plugin Store](https://plugins.craftcms.com/shopify) from your Craft project, or follow these instructions.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"prefer-stable": true,
"require": {
"php": "^8.2",
"craftcms/cms": "^5.3.0",
"craftcms/cms": "^5.0.0-beta.10||^4.3.0",
"shopify/shopify-api": "^5.2.0"
},
"require-dev": {
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ public function getStore(): Store
*/
private function _registerUtilityTypes(): void
{
$eventName = defined(Utilities::class . '::EVENT_REGISTER_UTILITIES') ? Utilities::EVENT_REGISTER_UTILITIES : Utilities::EVENT_REGISTER_UTILITY_TYPES;

Check failure on line 187 in src/Plugin.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Access to undefined constant craft\services\Utilities::EVENT_REGISTER_UTILITY_TYPES.

Check failure on line 187 in src/Plugin.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Access to undefined constant craft\services\Utilities::EVENT_REGISTER_UTILITY_TYPES.

Event::on(
Utilities::class,
Utilities::EVENT_REGISTER_UTILITIES,
$eventName,
function(RegisterComponentTypesEvent $event) {
$event->types[] = Sync::class;
}
Expand Down
22 changes: 22 additions & 0 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,28 @@ protected static function defineSortOptions(): array
return $sortOptions;
}

/**
* @param string $attribute
* @return string
* @throws InvalidConfigException
* @TODO remove this method when support for Craft 4 is dropped
*/
protected function tableAttributeHtml(string $attribute): string
{
if (!in_array($attribute, [
'shopifyEdit',
'shopifyStatus',
'shopifyId',
'options',
'tags',
'variants',
])) {
return parent::tableAttributeHtml($attribute);

Check failure on line 697 in src/elements/Product.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Call to an undefined static method craft\base\Element::tableAttributeHtml().

Check failure on line 697 in src/elements/Product.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Call to an undefined static method craft\base\Element::tableAttributeHtml().
}

return $this->attributeHtml($attribute);
}

/**
* @param string $attribute
* @return string
Expand Down
15 changes: 15 additions & 0 deletions src/elements/conditions/products/ProductCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
*/
class ProductCondition extends ElementCondition
{
/**
* @inheritdoc
* @TODO remove this method when support for Craft 4 is dropped
*/
protected function conditionRuleTypes(): array
{
return array_merge(parent::conditionRuleTypes(), [

Check failure on line 21 in src/elements/conditions/products/ProductCondition.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Call to an undefined static method craft\elements\conditions\ElementCondition::conditionRuleTypes().

Check failure on line 21 in src/elements/conditions/products/ProductCondition.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Call to an undefined static method craft\elements\conditions\ElementCondition::conditionRuleTypes().
ProductTypeConditionRule::class,
ShopifyStatusConditionRule::class,
VendorConditionRule::class,
HandleConditionRule::class,
TagsConditionRule::class,
]);
}

/**
* @inheritdoc
*/
Expand Down
9 changes: 9 additions & 0 deletions src/utilities/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public static function id(): string
return 'shopify-sync';
}

/**
* @inheritdoc
* @TODO remove this method when support for Craft 4 is dropped
*/
public static function iconPath(): ?string
{
return self::icon(); // TODO: Change the autogenerated stub
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit 573d98a

Please sign in to comment.