darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.33k stars 435 forks source link

multiple instance query #67

Open virsoni opened 7 years ago

virsoni commented 7 years ago

Hi

I have placed below code in Appserviceprovider > register method.

    $this->app['wishlist'] = $this->app->share(function($app)
    {
        $storage = $app['session']; // laravel session storage
        $events = $app['events']; // laravel event handler
        $instanceName = 'wishlist'; // your cart instance name
        $session_key = 'AsASDMCks0ks1'; // your unique session key to hold cart items

        return new Cart(
            $storage,
            $events,
            $instanceName,
            $session_key
        );
    });

How can i Add product in wishlist cart like this \Cart::add('1','test', '0', 1); ?

virsoni commented 7 years ago

can anybody reply on this plz?

virsoni commented 7 years ago
virsoni commented 7 years ago

# ### can anybody reply on my issue please ? @Turaylon @it-can @pvdptje @Beaudinn @darryldecode

pvdptje commented 7 years ago

You could do it like this: app('wishlist')->add(..).

You could also make a new facade for the wishlist, like this:

http://pastebin.com/Y6WVMHxx

And place this facade in your app.php config file. Now you could do something like Wishlist::add(..);

Turaylon commented 7 years ago

You can create your own custom facade. Example you can create a Wishlist Facade putting in a file like app/Facades/Wishlist.php and put this code:

<?php

namespace App\Facades;
use Illuminate\Support\Facades\Facade;

class Wishlist extends Facade{
    protected static function getFacadeAccessor() { return 'wishlist'; }
}

Add in tour config/app.php the following line: 'Wishlist' => App\Facades\Wishlist::class

and then you can use all the function of the cart on your custom Wishlist Facade like this:

\Wishlist::add('1','test', '0', 1);

virsoni commented 7 years ago

Thanks for your replies I will try it out.. soon :)

virsoni commented 7 years ago

Hi

I have placed the code as under but when I call \Wishlist::add('1','test', '0', 1); its not working.

<?php

namespace App\Facades; use Illuminate\Support\Facades\Facade;

class Wishlist extends Facade{ protected static function getFacadeAccessor() { return 'wishlist'; } } Add in tour config/app.php the following line: 'Wishlist' => App\Facades\Wishlist::class

getting below issue when call \Wishlist::add('1','test', '0', 1); FatalThrowableError in Facade.php line 223: Call to undefined method App\Facades\Wishlist::add() @Turaylon @pvdptje

pvdptje commented 7 years ago

That's odd. What happens when you try this:

app('wishlist')->add(...)' ?

virsoni commented 7 years ago

Call to undefined method App\Facades\Wishlist::add()

same issue display.

Where exactly I have to place below code and how? app('wishlist')->add(...)' ? @pvdptje

virsoni commented 7 years ago

Call to undefined method App\Facades\Wishlist::add()

same issue display.

Where exactly I have to place below code and how? app('wishlist')->add(...)' ? @Turaylon @pvdptje

pvdptje commented 7 years ago

On the place where you want to add something to your wishlist. Instead of using the facade, you use app('wishlist') to access the wishlist directly.

virsoni commented 7 years ago

appserviceprovider app_wishlist_code

I have tried as you said but its not working yet can you please check attached screenshots of code I used and provide your steps again if possible?

getting below error now when execute order app_wishlist_code.png screenshot's line of code. Call to undefined method Darryldecode\Cart\Facades\CartFacade::add() @pvdptje @Turaylon

virsoni commented 7 years ago

https://cloud.githubusercontent.com/assets/16146696/18581319/af89d574-7c1d-11e6-9a46-6ab3107777c2.png https://cloud.githubusercontent.com/assets/16146696/18581298/97c8eb00-7c1d-11e6-9c4c-91a8df624ffd.png

I have tried as you said but its not working yet can you please check attached screenshots of code I used and provide your steps again if possible?

getting below error now when execute order app_wishlist_code.png screenshot's line of code. Call to undefined method Darryldecode\Cart\Facades\CartFacade::add()

@pvdptje @Turaylon

pvdptje commented 7 years ago

In your service provider, you instantiate a new Cart class. Is this the actual Cart class or the facade class?

virsoni commented 7 years ago

Yes its actual Cart class of Darryldecode.

pvdptje commented 7 years ago

The error references to the CartFacade from the package. You did make your own facade if i'm correct. So there's something going wrong there.

If you can grant me access to your repository, i can check when i'm home.

Also, calling app('wishlist') will never produce this error: Call to undefined method Darryldecode\Cart\Facades\CartFacade::add() , because you are not calling a facade.