Skip to content

Commit

Permalink
feat: Added to find Craft Commerce / Products
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Jan 11, 2023
1 parent c23a6f5 commit 6725d2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Related Changelog

## 2.0.1 - 2023-01-11

### Updated
- Updated to support Craft Commerce / Products, thanks @matt-adigital

## 2.0.0 - 2022-08-10

### Updated
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/related",
"description": "A simple plugin that adds a widget within the Craft CP page sidebar, allowing you to quickly and easily access related entries.",
"type": "craft-plugin",
"version": "2.0.0",
"version": "2.0.1",
"keywords": [
"craft",
"cms",
Expand Down
15 changes: 13 additions & 2 deletions src/services/RelatedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public function getRelated($elementId)
/** @var Element[] $entries */
$entries = $query->all();

// dd($entries);

/** @var Query $query */
$query = Category::find();
$query->relatedTo = $element;
Expand All @@ -96,10 +94,23 @@ public function getRelated($elementId)
/** @var Element[] $users */
$users = $query->all();

$products = [];
try {
if (class_exists('craft\commerce\elements\Product')) {
$query = craft\commerce\elements\Product::find();
$query->relatedTo = $element;
$query->anyStatus();
$products = $query->all();
}
} catch (\Exception $exception) {
// Add logging in the future
}

$elements = array_merge(
$entries,
$categories,
$users,
$products,
);

return collect(
Expand Down

0 comments on commit 6725d2d

Please sign in to comment.