vanilophp / framework

The truly Laravel E-commerce Framework
https://vanilo.io
MIT License
810 stars 102 forks source link

Extend Products - Adding additional columns #79

Closed daniel-farina closed 4 years ago

daniel-farina commented 4 years ago

Hello,

First of all thank you for putting this together. This has so much potential and I hope to learn it well and eventually contribute.

I'm currently trying to extend products (I'm adding a weight column and a few others) and this is what I did so far:

Now I read the documentation here https://vanilo.io/docs/1.2/models that explains how to extend your model but I find concord to be a bit confusing. I'm have not used it before with Laravel.

I understand you would need to extend it but after looking at all the examples from Concord here https://artkonekt.github.io/concord/#/models?id=detailed-example I ended up even more confused.

I wish there was no Concord to be honest but I know that's currently out of the scope as it was mention on other posts.

Any guidance is greatly appreciated ! Thanks!

<?php

namespace Vanilo\Product\Models;  //or this -->  namespace App; 

use Vanilo\Product\Models\Product as BaseProduct;
use Vanilo\Product\Contracts\Product as ProductContract;

class Products extends BaseProduct implements ProductContract
{

}

I also added this to the boot in appserviceprovider

use App\Products;
use Vanilo\Product\Contracts\Product as ProductContract;
...

        $this->app->concord->registerModel(
            ProductContract::class, Products::class
        );

The error: image

daniel-farina commented 4 years ago

I just found instructions here actually under the tutorials section:

https://vanilo.io/how-to/use-custom-models-in-your-application

However it shows undefined method:

image

Thanks

fulopattila122 commented 4 years ago

Basically, you have 2 options to solve it:

  1. Either extend App\Product from Vanilo\Framework\Models\Product (instead of Vanilo\Product\Models\Product) or
  2. Build your completely own product model: take a look at Vanilo\Framework\Models\Product see what interfaces it implements and what traits it uses and cherry-pick the ones you like or implement them yourself.

The quick option is of course the first one.


Concord background: Normally you shouldn't deal too much with Concord, but it's required for the underlying library to know what overridden model do you end up using in your app. So proxies and all the details of Concord can be ignored by application developers, you only have to implement the base interface and let Concord know that you're using your own model for product contract. Afterward you can use your models normally like any other Eloquent model.

daniel-farina commented 4 years ago

@fulopattila122 That worked. I followed the tutorial and was not aware of Vanilo\Framework\Models\Product instead of Vanilo\Product\Models\Product

Thank you so much, I'll keep playing with it.

fulopattila122 commented 4 years ago

Cool, let me know if you stumble upon other issues. I'll simplify the docs based on your feedback :+1: