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
16 changes: 15 additions & 1 deletion src/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Rapidez\Core\Http\Controllers;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App;
use Rapidez\Core\Events\ProductViewEvent;
use Rapidez\Core\Models\EavAttribute;
use Rapidez\Core\Models\Product;
use TorMorten\Eventy\Facades\Eventy;

Expand All @@ -12,14 +16,24 @@ class ProductController
public function show(int $productId)
{
$productModel = config('rapidez.models.product');
$productModel::shouldBeStrict(! App::isProduction()); // Throw errors if relations are used but not eager loaded if not in production.
Copy link
Member

Choose a reason for hiding this comment

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

Is this working? I'd to change the throwMissingAttributeExceptionIfApplicable() as we're overwriting it to make this work:

protected function throwMissingAttributeExceptionIfApplicable($key)
{
    if ($this->hasCustomAttribute($key)) {
        return $this->getCustomAttribute($key);
    }

    return parent::throwMissingAttributeExceptionIfApplicable($key);
}


$frontAttributes = EavAttribute::getCachedCatalog()->where('is_visible_on_front', 1)->pluck('attribute_id');
Copy link
Member

Choose a reason for hiding this comment

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

is_visible_on_front / "Visible on Catalog Pages on Storefront" is used to show/hide attributes from the specs table right? Is that the right thing to use here?

/** @var \Rapidez\Core\Models\Product $product */
$product = $productModel::query()
->withEventyGlobalScopes('productpage.scopes')
->whereInAttribute('visibility', [
Product::VISIBILITY_IN_CATALOG,
Product::VISIBILITY_BOTH,
])
// It's important these are AFTER `whereInAttribute`
// as it seems to reset the global scopes
->withoutGlobalscope('customAttributes')
->withGlobalScope('customAttributes', fn (Builder $builder) => $builder->withCustomAttributes(
fn (Relation $q) => $q
->whereIn($q->qualifyColumn('attribute_id'), $frontAttributes)
)
)
->withEventyGlobalScopes('productpage.scopes')
->findOrFail($productId);

$attributes = [
Expand Down
Loading