Skip to content

Commit

Permalink
Craft 5/Commerce 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Mar 3, 2024
1 parent 3212e4b commit 8b6f957
Show file tree
Hide file tree
Showing 26 changed files with 293 additions and 259 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "verbb/gift-voucher",
"description": "Sell and redeem digital gift vouchers for Craft Commerce.",
"type": "craft-plugin",
"version": "3.0.7",
"version": "4.0.0-beta.1",
"keywords": [
"craft",
"cms",
Expand All @@ -25,20 +25,20 @@
}
],
"require": {
"php": "^8.0.2",
"craftcms/cms": "^4.0.0",
"craftcms/commerce": "^4.0.0",
"verbb/base": "^2.0.0"
"php": "^8.2",
"craftcms/cms": "^5.0.0-beta.1",
"craftcms/commerce": "^5.0.0-beta.1",
"verbb/base": "^3.0.0-beta.1"
},
"autoload": {
"psr-4": {
"verbb\\giftvoucher\\": "src/"
"verbb\\giftvoucher\\": "src/"
}
},
"extra": {
"name": "Gift Voucher",
"handle": "gift-voucher",
"changelogUrl": "https://raw.githubusercontent.com/verbb/gift-voucher/craft-4/CHANGELOG.md",
"changelogUrl": "https://raw.githubusercontent.com/verbb/gift-voucher/craft-5/CHANGELOG.md",
"class": "verbb\\giftvoucher\\GiftVoucher"
}
}
46 changes: 30 additions & 16 deletions config.codekit3
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"uuidString" : "ECE3F09A-2816-43C6-9715-3F4A30BD28C5"
}
],
"creatorBuild" : "34365",
"creatorBuild" : "34518",
"files" : {
"\/.github" : {
"ft" : 65536,
Expand Down Expand Up @@ -252,7 +252,7 @@
"oF" : 0,
"oS" : 3,
"pg" : 0,
"sct" : 1
"sct" : 0
},
"\/src\/resources\/src\/scss\/gift-voucher.scss" : {
"aP" : 1,
Expand All @@ -267,7 +267,7 @@
"oF" : 0,
"oS" : 3,
"pg" : 0,
"sct" : 1
"sct" : 0
},
"\/src\/services" : {
"ft" : 65536,
Expand Down Expand Up @@ -829,6 +829,10 @@
"active" : 0,
"optionString" : "'always', {exceptAfterSingleLine: false}"
},
"logical-assignment-operators" : {
"active" : 0,
"optionString" : "'always', {'enforceForIfStatements': false}"
},
"max-classes-per-file" : {
"active" : 0,
"optionString" : "1"
Expand Down Expand Up @@ -989,6 +993,9 @@
"no-empty-pattern" : {
"active" : 1
},
"no-empty-static-block" : {
"active" : 0
},
"no-eq-null" : {
"active" : 0
},
Expand Down Expand Up @@ -1020,7 +1027,8 @@
"active" : 1
},
"no-fallthrough" : {
"active" : 1
"active" : 1,
"optionString" : "{'allowEmptyCase': false}"
},
"no-floating-decimal" : {
"active" : 0
Expand Down Expand Up @@ -1128,6 +1136,9 @@
"no-new-func" : {
"active" : 0
},
"no-new-native-nonconstructor" : {
"active" : 0
},
"no-new-object" : {
"active" : 0
},
Expand Down Expand Up @@ -1182,7 +1193,8 @@
"optionString" : "'event', 'fdescribe'"
},
"no-restricted-imports" : {
"active" : 0
"active" : 0,
"optionString" : ""
},
"no-restricted-properties" : {
"active" : 0,
Expand All @@ -1196,9 +1208,6 @@
"active" : 0,
"optionString" : "'except-parens'"
},
"no-return-await" : {
"active" : 0
},
"no-script-url" : {
"active" : 0
},
Expand Down Expand Up @@ -1749,7 +1758,7 @@
"autoOutputPathReplace1" : "sass",
"autoOutputPathReplace2" : "css",
"autoOutputPathStyle" : 2,
"compilerType" : 1,
"compilerType" : 0,
"cssoStyle" : 0,
"decimalPrecision" : 10,
"emitCharset" : 1,
Expand Down Expand Up @@ -1810,11 +1819,12 @@
"createDeclarationFile" : 0,
"jsxMode" : 0,
"minifierStyle" : 0,
"moduleDetectionType" : 0,
"moduleResolutionType" : 0,
"moduleType" : 2,
"removeComments" : 0,
"sourceMapStyle" : 0,
"targetECMAVersion" : 0
"targetECMAVersion" : 2018
},
"languageDefaultsUserDefined" : [

Expand Down Expand Up @@ -1866,10 +1876,14 @@
"ENVIRONMENT:::$NODE_ENV"
],
"rollupTreeshakingEnabled" : 1,
"rollupTreeshakingModuleSideEffects" : 1,
"skippedFoldersString" : "node_modules,\/src\/data,\/src\/variables,log,\/src\/tasks,\/src\/controllers,\/src\/helpers,\/src\/records,\/.github,\/src\/errors,\/src\/adjusters,\/src\/services,\/src\/templates,\/storage\/framework\/sessions,\/src\/storage,\/src\/migrations,logs,\/src\/elements,_cache,\/src\/fields,_logs,\/src\/assetbundles,\/src\/models,\/src\/events,\/src\/base,\/docs,cache,\/src\/integrations,\/src\/resources\/dist",
"sourceFolderName" : "source",
"susyVersion" : 3,
"tsAllowArbitraryExtensions" : 0,
"tsAllowImportingTSExtensions" : 0,
"tsAllowSyntheticDefaultImports" : 0,
"tsAllowUMDGlobalAccess" : 0,
"tsAllowUnreachableCode" : 0,
"tsAllowUnusedLabels" : 0,
"tsAlwaysStrict" : 0,
Expand All @@ -1878,36 +1892,36 @@
"tsEmitDecoratorMetadata" : 0,
"tsESModuleInterop" : 0,
"tsExactOptionalPropertyTypes" : 0,
"tsExperimentalDecorators" : 0,
"tsForceConsistentCasingInFileNames" : 0,
"tsImportHelpers" : 0,
"tsIsolatedModules" : 0,
"tsJSXFactory" : "React.createElement",
"tsKeyofStringsOnly" : 0,
"tsNoEmitHelpers" : 0,
"tsNoFallthroughCasesInSwitch" : 0,
"tsNoImplicitAny" : 0,
"tsNoImplicitOverride" : 0,
"tsNoImplicitReturns" : 0,
"tsNoImplicitThis" : 0,
"tsNoImplicitUseStrict" : 0,
"tsNoLib" : 0,
"tsNoPropertyAccessFromIndexSignature" : 0,
"tsNoResolve" : 0,
"tsNoStrictGenericChecks" : 0,
"tsNoUncheckedIndexAccess" : 0,
"tsNoUnusedLocals" : 0,
"tsNoUnusedParameters" : 0,
"tsPreserveConstEnums" : 0,
"tsPreserveSymlinks" : 0,
"tsResolveJsonModule" : 0,
"tsSkipDefaultLibCheck" : 0,
"tsSkipLibCheck" : 0,
"tsStrictBindCallApply" : 0,
"tsStrictFunctionTypes" : 0,
"tsStrictNullChecks" : 0,
"tsStrictPropertyInitialization" : 0,
"tsStripInternal" : 0,
"tsSuppressExcessPropertyErrors" : 0,
"tsSuppressImplicitAnyIndexErrors" : 0,
"tsUseDefineForClassFields" : 0,
"tsUseUnknownInCatchVariables" : 0,
"tsVerbatimModuleSyntax" : 0,
"uglifyDefinesString" : "",
"uglifyFlags2" : {
"arguments" : {
Expand Down Expand Up @@ -1940,7 +1954,7 @@
},
"comments" : {
"active" : 0,
"flagValue" : -1
"flagValue" : 1
},
"comparisons" : {
"active" : 1,
Expand Down
6 changes: 3 additions & 3 deletions docs/get-started/requirements.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Requirements

## Craft CMS
Gift Voucher requires Craft CMS 4.0 or greater.
Gift Voucher requires Craft CMS 5.0 or greater.

## Craft Commerce
Gift Voucher requires Craft Commerce 4.0 or greater (Pro edition).
Gift Voucher requires Craft Commerce 5.0 or greater (Pro edition).

## PHP
Gift Voucher requires PHP 8.0.2 or greater.
Gift Voucher requires PHP 8.2 or greater.
2 changes: 1 addition & 1 deletion docs/get-started/upgrading-from-v2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Upgrading from v2
While the [changelog](https://github.com/verbb/gift-voucher/blob/craft-4/CHANGELOG.md) is the most comprehensive list of changes, this guide provides high-level overview and organizes changes by category.
While the [changelog](https://github.com/verbb/gift-voucher/blob/craft-5/CHANGELOG.md) is the most comprehensive list of changes, this guide provides high-level overview and organizes changes by category.

## Renamed Classes
The following classes have been renamed.
Expand Down
48 changes: 23 additions & 25 deletions src/GiftVoucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ public function init(): void

self::$plugin = $this;

$this->_registerComponents();
$this->_registerLogTarget();
$this->_registerElementTypes();
$this->_registerFieldTypes();
$this->_registerPurchasableTypes();
$this->_registerVariable();
$this->_registerEventHandlers();
$this->_registerAdjusters();
$this->_registerCraftEventListeners();
$this->_registerProjectConfigEventListeners();
$this->_registerProjectConfigEventHandlers();

if (Craft::$app->getRequest()->getIsCpRequest()) {
$this->_registerCpRoutes();
Expand All @@ -101,6 +98,11 @@ public function init(): void
if (Craft::$app->getEdition() === Craft::Pro) {
$this->_registerPermissions();
}

// Setup dynamics component for code storage, because it can't be done in `static::config()`
$components = $this->getComponents();
$components['codeStorage'] = $this->getSettings()->codeStorage;
$this->setComponents($components);
}

public function afterInstall(): void
Expand All @@ -124,44 +126,44 @@ public function getSettingsResponse(): mixed

public function getCpNavItem(): ?array
{
$navItems = parent::getCpNavItem();
$nav = parent::getCpNavItem();

if (Craft::$app->getUser()->checkPermission('giftVoucher-manageVouchers')) {
$navItems['subnav']['vouchers'] = [
$nav['subnav']['vouchers'] = [
'label' => Craft::t('gift-voucher', 'Vouchers'),
'url' => 'gift-voucher/vouchers',
];
}

if (Craft::$app->getUser()->checkPermission('giftVoucher-manageVoucherTypes')) {
$navItems['subnav']['voucherTypes'] = [
$nav['subnav']['voucherTypes'] = [
'label' => Craft::t('gift-voucher', 'Voucher Types'),
'url' => 'gift-voucher/voucher-types',
];
}

if (Craft::$app->getUser()->checkPermission('giftVoucher-manageCodes')) {
$navItems['subnav']['codes'] = [
$nav['subnav']['codes'] = [
'label' => Craft::t('gift-voucher', 'Voucher Codes'),
'url' => 'gift-voucher/codes',
];
}

if (Craft::$app->getUser()->checkPermission('giftVoucher-bulkGenerateCodes')) {
$navItems['subnav']['bulk-generate'] = [
$nav['subnav']['bulk-generate'] = [
'label' => Craft::t('gift-voucher', 'Bulk Generate Codes'),
'url' => 'gift-voucher/codes/bulk-generate',
];
}

if (Craft::$app->getUser()->getIsAdmin() && Craft::$app->getConfig()->getGeneral()->allowAdminChanges) {
$navItems['subnav']['settings'] = [
$nav['subnav']['settings'] = [
'label' => Craft::t('gift-voucher', 'Settings'),
'url' => 'gift-voucher/settings',
];
}

return $navItems;
return $nav;
}


Expand Down Expand Up @@ -218,6 +220,14 @@ private function _registerEventHandlers(): void
if (Craft::$app->plugins->getPlugin('klaviyoconnect') && class_exists(Track::class)) {
Event::on(Track::class, Track::ADD_LINE_ITEM_CUSTOM_PROPERTIES, [$this->getKlaviyoConnect(), 'addLineItemCustomProperties']);
}

if (Craft::$app->getRequest()->getIsCpRequest()) {
Event::on(Plugins::class, Plugins::EVENT_AFTER_SAVE_PLUGIN_SETTINGS, function(PluginEvent $event): void {
if ($event->plugin === $this) {
$this->getCodes()->saveFieldLayout();
}
});
}
}

private function _registerElementTypes(): void
Expand Down Expand Up @@ -295,23 +305,11 @@ private function _registerAdjusters(): void
private function _registerVariable(): void
{
Event::on(CraftVariable::class, CraftVariable::EVENT_INIT, function(Event $event): void {
$variable = $event->sender;
$variable->set('giftVoucher', GiftVoucherVariable::class);
$event->sender->set('giftVoucher', GiftVoucherVariable::class);
});
}

private function _registerCraftEventListeners(): void
{
if (Craft::$app->getRequest()->getIsCpRequest()) {
Event::on(Plugins::class, Plugins::EVENT_AFTER_SAVE_PLUGIN_SETTINGS, function(PluginEvent $event): void {
if ($event->plugin === $this) {
$this->getCodes()->saveFieldLayout();
}
});
}
}

private function _registerProjectConfigEventListeners(): void
private function _registerProjectConfigEventHandlers(): void
{
$projectConfigService = Craft::$app->getProjectConfig();
$voucherTypeService = $this->getVoucherTypes();
Expand Down
Loading

0 comments on commit 8b6f957

Please sign in to comment.