Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target [Vanilo\Checkout\Contracts\CheckoutDataFactory] is not instantiable while building [Vanilo\Checkout\CheckoutManager]. #1

Open
tsybulskyserg opened this issue Jul 4, 2019 · 4 comments

Comments

@tsybulskyserg
Copy link

Hi, guys! I need help(
I am using another modules from vaniloshop (product and card) and it's ok. But with Checkout module I have some problem.
I try to use Checkout module (as a facade, as service and as a container) but I always obtain an error -

Target [Vanilo\Checkout\Contracts\CheckoutDataFactory] is not instantiable while building [Vanilo\Checkout\CheckoutManager].

There is my config/concord.php

return [
    'modules' => [
        Vanilo\Product\Providers\ModuleServiceProvider::class,
        Vanilo\Cart\Providers\ModuleServiceProvider::class,
        Vanilo\Order\Providers\ModuleServiceProvider::class,
        Konekt\Address\Providers\ModuleServiceProvider::class,
        Vanilo\Checkout\Providers\ModuleServiceProvider::class,
    ]
];

Laravel Framework 5.8.26
vanilo/checkout 0.5.1

Can anyone help me please?

@fulopattila122
Copy link
Member

I'll look into it once I'm back to my computer.

In the meantime could you please post here:

  • the output of php artisan concord:models
  • show how do you attempt to use it from your client code?

@fulopattila122
Copy link
Member

fulopattila122 commented Jul 5, 2019

Don't look further, I got it.

The checkout data factory is the logic how you bind all your data (address, customer, products/cart items) in your application.

Since the checkout module is not aware of how you exactly implement addresses, billpayers, etc in your app, there's no default implementation.

What you can do is to take this class as a base example: https://github.com/vanilophp/framework/blob/master/src/Factories/CheckoutDataFactory.php

"copy" it in your application and adopt to your needs (obviously with changing the namespace, etc)

Also, you have to register the binding in your AppServiceProvider::register method:

$this->app->bind(
    Vanilo\Checkout\Contracts\CheckoutDataFactory::class,
    App\CheckoutDataFactory::class //or whatever namespace you'll use
);

Ps.: I see the gap here in the documentation, let's keep this issue open until the documentation has been extended with this Information.

@fulopattila122 fulopattila122 self-assigned this Jul 5, 2019
@fulopattila122 fulopattila122 added this to To Do in Vanilo v1.0 via automation Jul 5, 2019
@tsybulskyserg
Copy link
Author

Hi @fulopattila122 thank you for the response! These are my concord models:

+--------------+---------------------------------------+------------------------------------+
| Entity       | Contract                              | Model                              |
+--------------+---------------------------------------+------------------------------------+
| Address      | Konekt\Address\Contracts\Address      | Konekt\Address\Models\Address      |
| Billpayer    | Vanilo\Order\Contracts\Billpayer      | Vanilo\Order\Models\Billpayer      |
| Cart         | Vanilo\Cart\Contracts\Cart            | Vanilo\Cart\Models\Cart            |
| CartItem     | Vanilo\Cart\Contracts\CartItem        | Vanilo\Cart\Models\CartItem        |
| Country      | Konekt\Address\Contracts\Country      | Konekt\Address\Models\Country      |
| Order        | Vanilo\Order\Contracts\Order          | Vanilo\Order\Models\Order          |
| OrderItem    | Vanilo\Order\Contracts\OrderItem      | Vanilo\Order\Models\OrderItem      |
| Organization | Konekt\Address\Contracts\Organization | Konekt\Address\Models\Organization |
| Person       | Konekt\Address\Contracts\Person       | Konekt\Address\Models\Person       |
| Product      | Vanilo\Product\Contracts\Product      | Vanilo\Product\Models\Product      |
| Province     | Konekt\Address\Contracts\Province     | Konekt\Address\Models\Province     |
+--------------+---------------------------------------+------------------------------------+

I see that Checkout model does not present in a table, but I don't understand why...
I installed Checkout module by instruction (like a Product and Cart modules)...
This is my simple Checkout Controller -

namespace App\Http\Controllers;

use Vanilo\Checkout\Facades\Checkout;
use Vanilo\Cart\Facades\Cart;

class CheckoutController extends Controller {
    public function show() {
        dd(Checkout::getFacadeRoot());
//        dd(Cart::getFacadeRoot());
    }
}

When I ran Checkout::getFacadeRoot() I got -

Target [Vanilo\Checkout\Contracts\CheckoutDataFactory] is not instantiable while building [Vanilo\Checkout\CheckoutManager].

But when I ran Cart::getFacadeRoot() I got correct instance -

CartManager {#543 ▼
  #sessionKey: "vanilo_cart"
  #cart: null
}

And for understanding a problem I installed a full demo store from https://github.com/vanilophp/demo/.
And what I see...

+---------------+-------------------------------------------+----------------------------------------+
| Entity        | Contract                                  | Model                                  |
+---------------+-------------------------------------------+----------------------------------------+
| Address       | Konekt\Address\Contracts\Address          | Vanilo\Framework\Models\Address        |
| Billpayer     | Vanilo\Order\Contracts\Billpayer          | Vanilo\Order\Models\Billpayer          |
| Cart          | Vanilo\Cart\Contracts\Cart                | Vanilo\Cart\Models\Cart                |
| CartItem      | Vanilo\Cart\Contracts\CartItem            | Vanilo\Cart\Models\CartItem            |
| Country       | Konekt\Address\Contracts\Country          | Konekt\Address\Models\Country          |
| Customer      | Konekt\Customer\Contracts\Customer        | Vanilo\Framework\Models\Customer       |
| Order         | Vanilo\Order\Contracts\Order              | Vanilo\Order\Models\Order              |
| OrderItem     | Vanilo\Order\Contracts\OrderItem          | Vanilo\Order\Models\OrderItem          |
| Organization  | Konekt\Address\Contracts\Organization     | Konekt\Address\Models\Organization     |
| Permission    | Konekt\Acl\Contracts\Permission           | Konekt\Acl\Models\Permission           |
| Person        | Konekt\Address\Contracts\Person           | Konekt\Address\Models\Person           |
| Product       | Vanilo\Product\Contracts\Product          | Vanilo\Framework\Models\Product        |
| Profile       | Konekt\User\Contracts\Profile             | Konekt\User\Models\Profile             |
| Property      | Vanilo\Properties\Contracts\Property      | Vanilo\Properties\Models\Property      |
| PropertyValue | Vanilo\Properties\Contracts\PropertyValue | Vanilo\Properties\Models\PropertyValue |
| Province      | Konekt\Address\Contracts\Province         | Konekt\Address\Models\Province         |
| Role          | Konekt\Acl\Contracts\Role                 | Konekt\Acl\Models\Role                 |
| Taxon         | Vanilo\Category\Contracts\Taxon           | Vanilo\Framework\Models\Taxon          |
| Taxonomy      | Vanilo\Category\Contracts\Taxonomy        | Vanilo\Category\Models\Taxonomy        |
| User          | Konekt\User\Contracts\User                | App\User                               |
+---------------+-------------------------------------------+----------------------------------------+

When I ran Checkout::getFacadeRoot() I got correct instance-

CheckoutManager {#580 ▼
  #store: RequestStore {#573 ▼
    #state: null
    #billpayer: Billpayer {#578 ▶}
    #shippingAddress: Address {#577 ▶}
    #dataFactory: CheckoutDataFactory {#575}
    #cart: null
  }
}

I don't know what I am doing incorrectly(

@fulopattila122
Copy link
Member

Checkout has no table, so that's normal.

Did you check my second comment? I think that'll be the solution for your issue.

@fulopattila122 fulopattila122 removed this from To Do in Vanilo v1.0 Nov 12, 2019
@fulopattila122 fulopattila122 added this to To do in Vanilo Backlog Nov 12, 2019
@fulopattila122 fulopattila122 moved this from To do to In progress in Vanilo Backlog Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Vanilo Backlog
  
In progress
Development

No branches or pull requests

2 participants