dvlpp / merx

Laravel 5.2+ shopping cart package
7 stars 2 forks source link

Custom CartItem class feature #5

Closed RemiCollin closed 8 years ago

RemiCollin commented 8 years ago

Allow the use of a user-configured CartItem class with Merx.

dvlpp commented 8 years ago

Mmm, great idea. I may differ on the implementation... Maybe we can simply use the ioc container, and an abstract Cart Model — to avoid config calls in Eloquent relations.

RemiCollin commented 8 years ago

You mean something like :

return $this->hasMany(app()->make('cart_item_class'), "cart_id");
dvlpp commented 8 years ago

Yes. Now that I see it, your proposal seems closer to me... But it feel to me more clear, especially written like this:

return $this->hasMany(app('CartItem'), "cart_id");

And I would add a Cart interface with the contract, to ensure that the specific implementation is compliant.

RemiCollin commented 8 years ago

An interface is maybe not necessary with a simple check :

app('CartItem') instanceof \Dvlpp\Merx\Models\CartItem;
dvlpp commented 8 years ago

Well, this implies that you are forced to extend Merx's CartItem... But it makes sense. Ok then, I'm merging!