Skip to content

Commit

Permalink
Merge pull request #73 from eeeeeeeeeve/master
Browse files Browse the repository at this point in the history
Add support for Commerce Products
  • Loading branch information
mmikkel authored May 30, 2024
2 parents 65651e7 + 45fccc3 commit 449f37d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/MatrixMate.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ function (DefineHtmlEvent $event) {
}
);

// Register asset bundle for products
$commercePlugin = Craft::$app->getPlugins()->getPlugin('commerce', false);
if($commercePlugin && $commercePlugin->isInstalled) {
Craft::$app->getView()->hook('cp.commerce.product.edit.content', function (array $context) {
/** @var Element|null $element */
$element = $context['product'] ?? null;
$this->registerAssetBundleForElement($element);
});
}

// Register asset bundle for users
Craft::$app->getView()->hook('cp.users.edit', function (array $context) {
/** @var Element|null $element */
Expand Down Expand Up @@ -182,6 +192,8 @@ protected function getContextForElement(Element $element): string
$context = "globalSet:$element->id";
} elseif ($element instanceof User) {
$context = 'users';
} elseif ($element instanceof \craft\commerce\elements\Product) {
$context = "productType:{$element->getType()->id}";
} else {
$context = '*';
}
Expand Down

0 comments on commit 449f37d

Please sign in to comment.