crinsane / laravelshoppingcart Goto Github PK
View Code? Open in Web Editor NEWA simple shopping cart implementation for Laravel
License: MIT License
A simple shopping cart implementation for Laravel
License: MIT License
while adding item to cart if i added like
$where = array (
'id' => $product['product_id'],
'options' => array (
'type'=>'physical', // at index 0
'language'=>$product['language'], // at index 1
'image'=>$product['image'], // at index 2
'name'=>$product['product_name'], // at index 3
)
);
then while searching i have to repeat same order cause
in Cart.php at line :234 serialize would create a different string and hence unmatched md5 string ,
i guess we have to modify that logic of generateRowId()
..
may be create options array before feeding to serialize..
also we need to remember that we are searching with some handful of parameters not complete set which was used while adding item to cart.
It would be really awesome if the cart fired off some custom events upon certain actions. Things like:
Event::fire('cart.add', $item)
Event::fire('cart.addBatch', $items)
Event::fire('cart.update', $item)
Event::fire('cart.remove', $item)
Event::fire('cart.destroy')
Hi guys,
i've a problem i these last few days. I dont know why. But when i try to use multiple instance of cart the last new goes to overwritten by first instance and i dont understand why this happened. Maybe i just add the new package with new methods ?
Hi
With the search feature is it possible to search on more than one criteria in options, if so how do it?
I have set types in the options and want to return all items of a specific type.
If I need to do multiple searches how can join the results back together?
There is a bug, it seems, where Cart::addRow throws an exception if the 'id' argument is an integer.
Casting the int to a string solves the issue.
Running PHP 5.4.12 on Win 7, using WAMP.
After the last update the package is incompatible with Laravel 4.0.*
Hello,
After updating to Laravel 4.2 I got this error:
exception 'ErrorException' with message 'Declaration of Gloudemans\Shoppingcart\CartRowCollection::search() should be compatible with Illuminate\Support\Collection::search($value, $strict = false)'
IMHO, this method should return NULL instead of FALSE if the specific item not found. Most L4 Eloquent methods return NULL.
Please Help
How to use it using ajax ,is there any documentation ?
instead of updating only quantity of item in cart we can make
Cart::update()
do change attribute of item whose rowid we specify, it will make it more powerfull to update items attributes.
eg
Cart::update($rowid,'quantity',3)
Needs upgrade for Laravel 4.1
Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - gloudemans/shoppingcart dev-master requires illuminate/support 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9], illuminate/support[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].
Hi guys
// lets delete user cart
\Cart::destroy(); // return null,
But phpdoc says boolean..
/**
* Empty the cart
*
* @return boolean
*/
public function destroy()
{
// Fire the cart.destroy event
$this->event->fire('cart.destroy');
$result = $this->updateCart(NULL);
// Fire the cart.destroyed event
$this->event->fire('cart.destroyed');
return $result;
}
Ideas for adding weight related features
weight attribute is important for physical items in cart for calculating shipping amount etc.
should we make it optional or make it default
as not all items need weight;
as in case of digital items (track downloads) etc.
Remove method returns null. Quick fix should be the following:
return $this->get($rowId) == null;
Same deal with destroy method, but instead you can do the following:
return $this->count() <= 0;
Hi,
From the id of the product in cart collection, is there any way I can do like:
foreach(Cart::content() as $item){
echo $item->product->image;
}
So I would like to link the id of the cart row to product table.
Many thanks for your help..
Regards,
Ferry
Current order is (A,B,C,D and so on) but there is no method to output cart items in order (D,C,B,A) without making a huge mess into code.
For instance - If i want to show only last 3 items into cart there is no option for that.
cart has these items
$cart = array(
array(
'id'=>1,
'name'=>'Prod 1',
'price'=>11,
'qty'=>1,
'options'=array(
'type'=>'physical'
),
array(
'id'=>2,
'name'=>'Prod 2',
'price'=>22,
'qty'=>2,
'options'=array(
'type'=>'digital'
)
);
how can we find for an item using its attributes
Cart::has(array('name'=>'Prod 2','options'=>array('type' => 'digital'))); // determines if cart has item matching the mentioned parameters
i guess i should move 'type' key to level-up in array so i dont have to search it within options array, then it would be
Cart::has(array('name'=>'Prod 2','type'=>'digital')); // determines if cart has item matching the mentioned parameters
Hi ..
I have this code :
Cart::instance($instance)->associate('Product')->add(array('id' => $id, 'name' => $name, 'qty' => $qty, 'price' => $price));
if the instance is 'wishlist' the very first time it does not work.. the wishlist instance is not save. But if the instance is "main" first time and second time its "wishlist" then only the wishlist is instantiated.
How can i fix this?
I'm having an issue with the Cart::associate method. With this code, I'm trying to add items to the DB. I'm not getting any errors and it doesnt store anything to the db
$item = array(
'id' => 1,
'qty' => 1,
'name' => 'htc',
'price' => 50
);
//Add item ID to cart
Cart::associate('cart')->add($item);
Hi,
Is there any payment in the Shoppingcart?
Thanks,
Jeremy
when using it in env where php is
php 5.3.10 as l4 req atleast 5.3.7
it must be ok to run
but it shows this error in ShoppingcartServiceProvider.php at line 17
may be its expecting a more latest php version
Unable to add more than three items to the cart, using Laravel 4.2.6
I just tested Store() changing it to:
public function store() {
echo 'Previous count: ' . Cart::count(false) . '<br />';
$input = Input::all();
$product = Product::find($input['id']);
$quantity = $input['quantity'];
Cart::associate('Product')->add($product->id,$product->description,$quantity,$product->retail_price);
echo 'Post count: ' . Cart::count(false) . '<br />';
return;
}
I destroyed the cart first then added different products 1 at a time
1st product addition produced
Previous count: 0 Post count: 1
and checked the cart, there was now 1 item in the cart
2nd product addition produced
Previous count: 1 Post count: 2
and checked the cart, there was now 2 items in the cart
3rd product addition produced
Previous count: 2 Post count: 3
and checked the cart, there was now 3 items in the cart
4th product addition produced
Previous count: 3 Post count: 4
and checked the cart, there was only 3 items in the cart (the 1st 3 I added)
I checked Cart::content() in Store() and it did indeed have 4 items in it.
checking Cart::content() in index() of /cart and it only had 3 items.
Form displaying add to cart , quantity input and hidden product id. Displayed on the product page
{{ Form::open(['url' => '/orders'], ['enctype' => 'multipart/form-data' ] ) }}
<div class="row">
<div class="form-group">
<p>{{ $product->code }} - {{ $product->description }} <strong>{{ money($product->retail_price) }} each</strong></p>
</div>
</div>
<div class="row">
<div class="form-group col-md-3 col-md-offset-2">
{{ Form::hidden('id', $product->id) }}
{{ Form::label('quantity', 'Quantity') }}
{{ Form::text('quantity', Input::old('quantity'), ['placeholder' => '0', 'required' => 'required', 'class' => 'form-control input-lg'] ) }}
<p class="text-danger">{{ $errors->first('quantity') }}</p>
</div>
</div>
<div class="form-group">
{{ Form::submit('Add To Cart', ['class' => 'btn btn-success btn-block'] ) }}
</div>
{{ Form::close() }}
STORE handling the above form in the orders controller
public function store() {
$input = Input::all();
$product = Product::find($input['id']);
$quantity = $input['quantity'];
Cart::associate('Product')->add($product->id,$product->description,$quantity,$product->retail_price);
return Redirect::to('cart')->with('flash_message','Successfully added to cart');
}
INDEX handling redirect to 'cart' from STORE in the /cart controller
public function index() {
if(!Auth::check()) {
return Redirect::to('join?next=' . $_SERVER['REQUEST_URI']);
}
$content = Cart::content();
return View::make('cart.cart')->with('content',$content);
}
Hi
I've been using this package for a while now but have a problem.
I add items to my cart, I can see the items there if I dump the cart and do a couple of tests. However If I then try to retrieve the cart contents from another function the cart is empty.
Products are added to the cart from an ajax call.
try {
Cart::instance('main')->add(
$product->id,
$product->name,
$people,
$salePerHead,
array(
'cost'=>$costValue,
'type'=>$product->type,
'mealQty'=>$mealQuantity
)
);
} catch (Exception $e) {
return "Error P002: Failed to Add Item";
}
This works
Once added another jquery ajax call from the page gets the cart content to display on the page:
$cart = Cart::content(); $cartCount = Cart::count(); $cartTotal = Cart::total();
These calls don't work - all returning an empty cart. I dont empty the cart between calls.
I'm confused - I've had this working.
I've recently upgraded my project to 4.1 but convinced it was working. I've just done a composer update to make sure I have the latest build
Hi there,
Is it possible to add prices as options?
For example:
Pizza $10.00 (default)
options:
extra cheese $1.00,
and then add this as a single product to the basket, so with a total product price of
12.50
What about fire events when operations was executed?
I propose:
cart.added cart.batched cart.updated cart.removed cart.destroyed
For example I can listen on "cart.added", retrieve the new cart row and save this information in a database record.
Extra options other than quantity, price, id, name aren't being added to the session. Just returns a zero length array.
I'm trying to use the cart class without making use of the facade. What i've done so far is the following :
A class like so :
use Gloudemans\Shoppingcart\Cart;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Session\Session;
class LaravelShoppingCart implements CartInterface {
protected $cart;
public function __construct(Session $session,Event $event){
$this->cart = new Cart($session,$event);
}
And then in the controller
class HomeCtrl extends \BaseController {
protected $cart;
function __construct(CartInterface $cart)
{
$this->cart = $cart;
}
.....
public function testCart()
{
$this->cart->add(array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => array('size' => 'large')));
print_r($this->cart->content());
}
but this gives the following error
Call to undefined method Symfony\Component\EventDispatcher\Event::fire()
Any ideas? using L4.2
Hi guys,
i'm trying to associate a model with the entire namespace but it seems not work
How could I go about adding a shipping row to the cart? My situation is that I dont know shipping costs until the user enters in details and I calculate the weight of the shipment.
Thoughts?
After i add product in the cart and var_dump the content of the cart everything works fine but after refreshing the page when i var_dump the it shows empty cart..
Hi Crinsane.
Thank you for the shopping cart.
i have a question :
Should this work or not ? is it possible to use cart instance with search? I am getting nothing with it. Please let me know if it works or any work around for this.
Thanks again,
Prajwol.
The Cart::add is only adding one item. I tried adding multiple different items but it wont work. It will show only one item when i do a vardump on the cart->content
Hi
I'm trying to get the rowid of the last inserted item but not having much luck. I've tried checking the return value of Cart::add() but this returns a null value.
I need to use the rowid in an associated cart instance - a bit like a one to many relationship but can't see a method or way of obtaining.
I thought Cart::add() would return a row collection?
Is this intended behaviour to return null after an add?
Can we add multiple items into cart
$items = array(
array(
'id' => 1,
'name' => 'Audio CD',
'qty' => 1,
'price' => 49,
'options'=>array()
),
array(
'id' => 2,
'name' => 'Video CD',
'qty' => 1,
'price' => 69,
'options'=>array()
)
);
- Cart::addItems($items); // adding multiple items into cart , return generated rowid if item is one or return it from Cart::add() only
Can I have a example of multiple options? I tried 2 methods, it's not working.
Is there an easy way to see all current carts? For spying on shoppers? :-)
This is a great package, thanks. I would have asked this on the L4 forum but couldn't find any mention of your package there..
It seems I can only maintain a logged-in users cart instance (by using their id) within a single script. What would be the best way to keep their cart instance current whenever they are logged-in? I have tried an event listener, but couldn't get it to work. Any ideas?
Thanks.
Could we have add(), addBatch(), destroy() etc return a boolean which enables us to check for success? It seems to be returning Null every time now, or am I completely missing something?
I needed to add to the product additive with different price. I used the optional array of options (id, name, price for additive). How do I correct this when calculating the total amount?
can we create a new instance of cart for a new wishilist or something like that
eg.
Cart::newCart('name_of_cart');
Using LaravelShoppingcart, what is the recommended method to track abandoned carts? Are cart instances persisted on the database with a timestamp?
Is it better if the add() method could accept array, e.g.,
$data = [
'id' => 58,
'name' => 'Long Sleeve Shirt',
'price' => 98.99,
'qty' => 5,
'options' => [
'size' => 'M'
],
];
Since addbatch() is accepting array, add() should also accept array for consistency. Thought?
Cart::add(array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => array('weight' => 22)));
i dont wanna using foreach to do it
any good method for count the weight in options array
i have to create method myself?
I'm having an issue with storing the cart items to the DB. I data dumped the cart and the object is set but when I check the DB the item is not inserted. Here is a snippet of my code:
$item = array(
'id' => '293ad',
'name' => $this->input['condition'],
'qty' => 1,
'price' => 24
);
//Add item ID to cart
Cart::associate('cart')->add($item);
$content = Cart::content();
dd($content);
and here is my my DB migration
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCartTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cart', function($t) {
$t->string('id');
$t->string('qty');
$t->string('name');
$t->string('price');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('cart');
}
}
What is the recomended method to apply discounts or taxes to the cart? Could be per product (discount/tax) or to the entire cart (coupon maybe) or even adding extra charges (like shipping costs)
ref: https://github.com/moltin/laravel-cart
// Identifier
// With a requestcookie (choose for storage: cache, the session will be expired), the cart could be reloaded from a http request, example: the customer could save his cart link (email, hyperlink) and reopen this later.
// If there is no request, the cookie will be loaded.
'identifier' => 'cookie', //cookie, requestcookie
//Request Cookie
'requestid' => 'CartID', //http input request identifier, example: your customer/backoffice could reload the cart in your shop controller, /public/shop?CartID=871f0bc18ca76e68bf7c3adf8f9426ef
in case, when using Cart::content();
we can also get a session id .
thanks
Is there any way to store a user's cart in the database separately from the session? I'd like to leave my session lifetime relatively short so they don't stay logged in, but would love their cart to persist indefinitely.
I'm getting the above message when trying to remove an item from my cart.
< a href="/cart/remove/{{ $cart_item->rowid }}">Remove
Which is wrapped in a foreach that comes from:
$carts = Cart::content();
And i'm adding content like so:
$cartContents = Cart::add(array('id' => randomNumber(), 'name' => $input['product_name'], 'qty' => 1, 'price' => $price));
But when I do Cart::remove($cart_item->rowid) i get the above error?
Any idea's?
Where is it all saved?
I have a product in my cart with an ID of 10
, for example, and the following returns false
:
Cart::search(array('id' => 10));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.