Skip to content

CartItem always returns Vanilo\Foundation\Models\Product #21

Description

@answeb

Hello,
Using vanilo 4.2 and laravel 11 here.
I created my own Product model and registered it in my AppServiceProvider :

public function boot(): void {
    (...)
    $this->app->concord->registerModel(\Vanilo\Product\Contracts\Product::class, \App\Models\Product::class);
    (...)
}

Model is fairly simple (for now) :

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class Product extends \Vanilo\Foundation\Models\Product {
    use HasFactory;
}

When I add items to the cart, and then get it back, it always return a Vanilo\Foundation\Models\Product type, not App\Model\Product...

The media library does not pick up the images of the product, as they are bound to App\Model\Product :

$ artisan tinker
Psy Shell v0.12.7 (PHP 8.2.27 — cli) by Justin Hileman
> Product::find(1)->media;
[!] Aliasing 'Product' to 'App\Models\Product' for this Tinker session.
= Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection {#6917
    all: [
      Spatie\MediaLibrary\MediaCollections\Models\Media {#6919
        id: 1,
        model_type: "App\Models\Product",
        model_id: 1,
        collection_name: "default",
        (...)

> Cart::addItem(Product::find(1));
= Vanilo\Foundation\Models\CartItem {#7018
    product_type: "product",
   (...)

> Cart::getItems()->first()->product;
= Vanilo\Foundation\Models\Product {#6895
    id: 1,
    name: "Officiis quaerat consequatur nihil.",
   (...)

> Cart::getItems()->first()->product->media;
= Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection {#7065
    all: [],
  }

Can you tell me what I am missing here ?

Thanks !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions