Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Http/Controllers/CP/ProductAttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rapidez\StatamicQueryBuilder\Http\Controllers\CP;

use Rapidez\StatamicQueryBuilder\Models\ProductAttribute as QueryBuilderProductAttribute;
use Statamic\Http\Controllers\CP\CpController;

class ProductAttributeController extends CpController
Expand All @@ -13,8 +14,19 @@ public function index()
return [];
}

return $model::with('attributeOptions')
->filterable()
->get();
$query = $model::with('attributeOptions');

// Pick the correct filter strategy for the configured model.
if (is_a($model, QueryBuilderProductAttribute::class, true)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_a can return true even when $model is an empty object, i think instanceof would be better here because that also checks if it really is a "object"

$query->filterable();
} else {
$query->whereIn('eav_attribute.attribute_id', function ($subQuery) {
$subQuery->select('attribute_id')
->from('catalog_eav_attribute')
->where('is_filterable', '>', 0);
});
}

return $query->get();
}
}
Loading