moltin / cart Goto Github PK
View Code? Open in Web Editor NEWShopping cart composer package
License: Other
Shopping cart composer package
License: Other
Hey there, this package is great ... do you feel it's ready for primetime? And when will the official production release be available?
I can´t get an item by its ID,
I'm trying to remove it from the cart but I obtain:
Call to a member function toArray() on a non-object
I can reproduce the issue like this:
foreach (Cart::contents() as $item) {
\Log::info ('ID: '. $item->id); // Outputs "42" (integer)
\Log::info ('Item', Cart::item ($item->id)->toArray ()); // error
}
Also I can't remove the item using
Cart::item((string) $id)->remove()
Maybe some nice way of changing the session/storage identifier key, so you can modify it, to avoid name collision.
without changing the source of the storage driver.
public function getRemoveItem($getremover) {
Cart::remove('22');
}
Am I doing something wrong here?
One thing that I'm in desperate need for is a Coupon functionality ... To be able to use a coupon to give a overall cart (or even product specific) discount.
What are your thoughts?
This isn't really an "issue" per-say, but I do think it should be outlined in your documentation...
What is the best way to reference the cart throughout an application? For example, in Laravel, if I want to pull up the Cart within a Route, what's the recommended way of getting the Cart object?
Have you thought about adding a static method? Check out Cartify: https://github.com/brunogaspar/cartify
Cartify::cart()->total_items() is an example of how the static methods can be called from anywhere in the app.
Ikeeci
I'm assuming that the "id" attribute for a cart item represents the Cart id? At first I thought it was supposed to be the product id as a database reference, but I cannot add multiple items with the same "id".
Again, I'll reference the Cartify project here on GitHub ... the "id" for each Cart item was automatically generated, which allowed you to add multiple of the same product, which had a direct impact on the "quantity" field... the quantity was automatically handled, and if all of the attributes of an add product was the same as another that exists in the cart, the quantity was automatically added to... otherwise, it was a new item in the Cart.
Does that make sense?
Hello i have implement this class with no success.
Here my code, no errors, no warnings, only blank screen.
require_once('vendor/autoload.php');
use Moltin\Cart\Cart;
use Moltin\Cart\Storage\Session;
use Moltin\Cart\Identifier\Cookie;
function shopping_items()
{
$cart = shopping_getCart();
$cartItems = $cart->contents();
$d = '';
if (count($cartItems) > 0) {
foreach ($cartItems as $item) {
$d .= "<li>{$item->name} {$item->quantity}x{$item->price}</li>";
}
}
return "<ul>$d</ul>";
}
function shopping_getCart()
{
return new Cart(new Session, new Cookie);
}
function shopping_add_item()
{
$cart = shopping_getCart();
$cart->insert(array(
'id' => 'foo',
'name' => 'bar',
'price' => 100,
'quantity' => 1
));
}
shopping_add_item();
echo shopping_items();
how can i implement this library to laravel 4 framework
How can I use this package so that when an item is added to the cart it checks the stock level and if is set to 1 or below, if the customer goes back and tries to order another of the same item it knows that it already exists and that there is only one of them?
Any idea's?
Hi,
Just wondering if you could provide some more information on access the $identifier.
Cart::has($itemIdentifier);
Cart::item($itemIdentifier);
Cart::remove($itemIdentifier);
What I'm not getting is how am I suppose the know the $identifier when all I know is the item id.
Could you please provide some sample uses.
Many thanks.
Hi,
Using this package i want to grab the options from the Cart:insert method.
How would this be done?
I tried $item->options()->first_option but fails.
Hi
Am having the product with different size and different price values. How to show it in the basket. I tried but it shows single ID with all value appended it to it. But I need to show each individual product with different size and price amount. Kindly suggest me how to do that.
For example,
Am having a product called Shirt, Each shirt have sizes like L, M, XL and each varies based on the size. Suppose if the user ordered L and M size shirt mean it will show only one shirt with all values not as separate shirt with different size and price.
Please help to solve this issue.
I have the following which adds to the cart:
{{ Form::open(['route' => 'cart']) }}
<input type="hidden" name="path" value="{{ Request::path() }}">
<input type="hidden" name="image" value="{{ $item->image }}">
<input type="hidden" name="product" value="{{ $item->name }}">
<input type="hidden" name="description" value="{{ $item->seo_description }}">
<input type="hidden" name="qty" value="1">
<input type="hidden" name="size" value="{{ Session::get('size') }}">
<input type="hidden" name="colour" value="{{ Session::get('colour') }}">
<input type="hidden" name="price" value="{{ $item->price }}">
@if ($item->stock > 0) <button class="btn btn-success">Add to Bag</button> @else <a href="" class="btn btn-primary">Email us</a> @endif
{{ Form::close() }}
Then I have this which shows the items of the carts.
@foreach($items as $item)
<tr>
<td class="col-sm-8 col-md-6">
<div class="media">
<span class="thumbnail pull-left"> <img class="media-object" src="/uploads/product-images/{{$item->image}}" style="width: 72px; height: 72px;"> </span>
<div class="media-body">
<h4 class="media-heading"><a href="{{ $item->path }}">{{ $item->name }}</a></h4>
<span>Status: </span><span class="text-success"><strong>In Stock</strong></span>
</div>
</div></td>
<td class="col-sm-1 col-md-1" style="text-align: center">
<input type="email" class="form-control" id="exampleInputEmail1" value="1">
</td>
<td class="col-sm-1 col-md-1 text-center"><strong>£{{ $item->price }}</strong></td>
<td class="col-sm-1 col-md-1">
</td>
</tr>
@endforeach
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h5>Subtotal</h5></td>
<td class="text-right"><h5><strong>£{{ $item->price }}</strong></h5></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h3>Total</h3></td>
<td class="text-right"><h3><strong>£{{ Cart::total(false) }}</strong></h3></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><a href="/remove/{{ $item->identifier }}" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove</a>
But like I said it only shows one item, but yet the amount in £ is correct.
Show what should I be doing? Or what am I doing wrong?
Also a suggestion would be to update the docs a little more with more info like this to show people like me more examples.
If i have 3 products in the cart and use remove(); on a Laravel route to remove an item to then redirect back it shows that the session has been destroyed.
Why is this? Or am I doing something wrong?
Hi,
I'm struggling to install your cart package via composer - every time I try, I get the error:
Problem 1
- Installation request for moltin/cart dev-master -> satisfiable by moltin/cart[dev-master].
- moltin/cart dev-master requires moltin/tax dev-master -> no matching package found.
and here is my composer.json
:
{
"require" : {
"moltin/cart": "dev-master"
}
}
Any help would be much appreciated.
Thanks
I'm having an issue (or me not understanding) how to to save more than one item to my database.
If i die and dump Cart::contents()
i get the following: which shows two items.
protected 'addModifier' => int 1
protected 'data' =>
array (size=11)
'id' => string '100' (length=3)
'name' => string 'Beautiful Evening Dress' (length=23)
'price' => string '35.00' (length=5)
'quantity' => string '1' (length=1)
'image' => string 'dtTCkLMT3C7lrYE6b1afd6H1hH5IyJ6hYnPWhQbHwkGgCIfhmaTsP9kUhxUr.jpg' (length=64)
'path' => string 'category/new-in' (length=15)
'description' => string 'Beautiful Evening Dress ' (length=24)
'stock' => string '0' (length=1)
'delivery' => string '3.99' (length=4)
'colour' => string 'Black' (length=5)
'size' => string '22' (length=2)
'6de83ad2f06a80ee5b06ead51cb74fb5' =>
object(Moltin\Cart\Item)[137]
protected 'identifier' => string '6de83ad2f06a80ee5b06ead51cb74fb5' (length=32)
protected 'store' =>
object(Moltin\Cart\Storage\LaravelSession)[138]
protected 'identifier' => null
public 'id' => string '66f7ef23c389dcafb9394506a5b5d934' (length=32)
protected 'tax' =>
object(Moltin\Tax\Tax)[139]
protected 'percentage' => int 0
protected 'deductModifier' => int 1
protected 'addModifier' => int 1
protected 'data' =>
array (size=11)
'id' => string '53' (length=2)
'name' => string 'Black and Silver Pattern dress with Sequins ' (length=44)
'price' => string '25.00' (length=5)
'quantity' => string '1' (length=1)
'image' => string 'USoWtjCsby50.jpg' (length=16)
'path' => string 'category/new-in' (length=15)
'description' => string 'Black and Silver Pattern dress with Sequins ' (length=44)
'stock' => string '1' (length=1)
'delivery' => string '3.99' (length=4)
'colour' => string 'Patterned' (length=9)
'size' => string '14' (length=2)
So the question is, how do i save these items to the DB?
Using session, let's say we have:
$A = ["id" => "example", "quantity" => 5, ...];
// and
$B = ["id" => "example", "quantity" => 11, ...];
If we Cart::insert($A)
we see from Cart::contents(true)
that we have a quantity of 5.
However, using this same cart - if we Cart::insert($B)
then examine the contents we see that we have a quantity of 11 until the script ends. At this point the quantity is once again 5 and the new information is not stored.
If this information were stored (not sure if intentional) then item updates would be much simpler in many cases.
Methods that take an id (has
, item
etc) should take the identifier, not the user-defined id. The reason for this is because there can be multiple items with the same id, but with different product options.
I have not been able to figure this out. Once an item is in the cart I cannot change its tax percentage for calculation. I may be missing something, but I have struggled for a couple hours to figure it out. When attempting to change tax for the item the tax property changes successfully, but the tax is calculated based on when I originally added the item. Any thoughts?
Thanks!
Awesome cart BTW, start of something good for sure!
Hi,
i ask you if it's possibile make something like cookie::forever of Laravel.
The point is, and i ask you some days ago, i need to stay saved somewehere the cart content for a not logged user. So now moltin cart package works only with Session, so when i close browser and reload page the cart is empty.
I need to use another cookie to maintain alive the content ?
Hi Guys,
When setting the Cart::identifier('test123'); I was under the impression that I would rename the identifier that was generated or move the cart contents over into it?
Seems it just creates a empty array under a cart session variable...
What am I missing here?
Thanks
The variable names for $id and $identifier can be confusing. In the cart we should use $itemIdentifier for item identifiers to prevent confusion between the cart identifier.
Seems after a new request not any of the Cart::method() seems to be working.
However when i dump sessions then i see cart value in there.
@foreach( Cart::contents(true) as $item )
{{ print_r($item) }}
@Endforeach
Does nothing, should output all the contents
@if(Cart::totalItems())
Does nothing either.
Keep in mind this is blade syntax, however the package seems not to work.
This is however the output from sessions
Array ( [_sf2_attributes] => Array ( [_token] => 27TqPweZAfKCtYCEhMZlP6YSYCKi1R1iLlLByeFM [cart] => Array ( [10a60423601f1e90ec6721796e3a1932] => Array ( ) [15a28e729264ee3f3050c238bea1311a] => Array ( [8a48aa7c8e5202841ddaf767bb4d10da] => Moltin\Cart\Item Object ( [identifier:protected] => 8a48aa7c8e5202841ddaf767bb4d10da [store:protected] => Moltin\Cart\Storage\LaravelSession Object ( [identifier:protected] => [id] => 15a28e729264ee3f3050c238bea1311a ) [tax:protected] => Moltin\Tax\Tax Object ( [percentage:protected] => 0 [deductModifier:protected] => 1 [addModifier:protected] => 1 ) [data:protected] => Array ( [id] => 6 [name] => Battery - Lithium CR2025 [price] => 1 [quantity] => 3 ) ) ) ) [flash] => Array ( [old] => Array ( ) [new] => Array ( ) ) ) [_sf2_flashes] => Array ( ) [_sf2_meta] => Array ( [u] => 1375124033 [c] => 1375121483 [l] => 7200 ) ) 1
So the content is definately there.
Currently it is possible to add any custom data to an item, but I think we need to allow the ability to add custom data to the entire cart object. This would be useful for setting the coupon code that is applied to the cart, or some other useful data.
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.