darryldecode / laravelshoppingcart Goto Github PK
View Code? Open in Web Editor NEWShopping Cart Implementation for Laravel Framework
Shopping Cart Implementation for Laravel Framework
Hi,
I needed to create a new cart instance and retain the same one throughout the session. So I created a new service provider and added the code in the register() method. Now how do I use this cart name/ instance while adding or updating my cart contents?
Thank You!
Hi,
Its leave the whole conditions of the cart in session? Because I set a condition and on checkout I lose the getConditions() values.
Another thing, I tried something like $condition->getValue ()-> first () without the need to use a foreach. Is there any way?
Thank you.
I've tried to type hint the Cart so that I'm not doing static calls. From what I understand better for unit testing.
But the problem is that the _construct requires session, events and so on. Is there any way to do this?
I want to be able to do something like $this->cart-clear() or $this->cart->add()
Hello. How can I set time to live for goods in my cart.
In several hours cart becomes empty.
Have you considered to use something other then Item ID for Cart::update() and Cart::remove() functions? In cases where cart holds multiple instances of the same Item ID how do you work with items in the cart?
How do I get subtotal per item after apply cartcondition using Cart::getContent()?
Possible to have instance like this?
Cart::instance('shopping')->add(455, 'Sample Item', 100.99, 2, array());
What are you guys thinking of adding the possibility to have attributes on conditions. I have a condition with the name 'discount'. This because I only want to have the option to have one 'discount' rule so I can update the value if they enter another promo code. But I would like to add some more information on this condition due attributes.
Hi all,
I have a question about adding per-item conditions to already existing products in cart. I have a 'cart' page, which contains a form for coupons, which can be assigned to certain products/categories in the shop, so when the user is filling in his coupon, he might already have the product(s) on sale in the cart. Is there a way to assign a per-item condition to a certain existing product in cart.
Thank you.
Hello.
It is possible to clean the all conditions?
Because the Cart::clear() only clean the cart. Even this option is not documented in the readme.
Thank you for your great work.
Hi there!
Would you mind doing a quick and brief tutorial on how to add items to cart and have it show up in the view?
Cart::update(456, array(
'quantity' => -1, // if the current product has a quantity of 1, it will subtract 1 how to remove from cart ?
));
Good day. I have a problem with the library and I would like to fix it because I am comfortable with its features, the problem is when I want to add more than 3 items to cart this not stored. Here I leave a link that leads to a picture of the implementation of the method add () http://prntscr.com/b6gqg2
This is probably a function you want to add. Most carts these days display the total number of items in the cart. I see no function for this. Not hard for me to write, but thought I'd mention it.
It seems Cart::removeItemCondition($itemId, $conditionName) has no effect.
Can you please add laravel 5.2 support? Now getting these errors:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for laravel/framework 5.2.* -> satisfiable by laravel/framework[v5.2.0].
- darryldecode/cart dev-master requires illuminate/validation 5.0.x|5.1.x -> satisfiable by illuminate/validation[v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.6, v5.1.8].
- don't install illuminate/validation v5.0.0|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.0.22|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.0.25|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.0.26|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.0.28|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.0.33|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.0.4|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.1|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.13|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.16|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.2|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.20|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.22|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.25|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.6|don't install laravel/framework v5.2.0
- don't install illuminate/validation v5.1.8|don't install laravel/framework v5.2.0
- Installation request for darryldecode/cart dev-master -> satisfiable by darryldecode/cart[dev-master].
In a condition I have the calculated value from that condition.
object(Darryldecode\Cart\CartCondition)[293]
private 'args' =>
array (size=5)
'name' => string 'Coupon' (length=22)
'type' => string 'discount' (length=8)
'target' => string 'subtotal' (length=8)
'value' => string '-10%' (length=4)
'attributes' =>
array (size=3)
'title' => string 'Lorem ipsum dolor' (length=15)
'description' => string '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Ubi ut eam caperet aut quando? Hoc est non dividere, sed frangere. Duo Reges: constructio interrete. Eiuro, inquit adridens, iniquum, hac quidem de re;</p>
' (length=348)
'valid until' => string '2016-06-15' (length=10)
private 'parsedRawValue' => float 1.045
How can I use it?
Hi , what namespace "use" at the top of controller for this cart module?
Thank you
What is the right to put in composer.json
"darryldecode/cart": "^2.4"
or "darryldecode/cart": "dev-master"
Hello,
I would like add the same item, but with different attributes.
e.g.:
item in cart has attribute = ['color' => 'red'],
and I would like to add the same item with attribute = ['color' => 'blue'].
I except two items with different arguments in cart, but old item`s attributes are overwritten with new attributes and quantity is updated to 2.
I didn't find this in documentation, maybe I missed it.
Is there any way how to achieve this, please ?
...Thank You.
Problem with getTotal method, if there are no conditions the total returns 0, I think convenient to put the condition: if $conditions->count() is false $newTotal = $subTotal
You seem to be missing displaying this in the documentation.
Cart::clear();
Do you mind adding database support beside session only?
we've encountered several session problems because of ajax calls adding and removing from the cart.
we'd like to have a backup to the database without having to do it manually on each call.
(preferable to do both sides, sessions and db, or make it optional)
Great work on the project though, we've been using it for quiet a while now!
kind regards,
Jurien Hamaker.
How I can do rounding in subtotal
Hi, how to put weight & calculate total weight?
Thanks
Hi,
After I add a product and refresh the page, the quantity is increasing and is affecting the total price. It affects the quantity of only the last added product and not the ones before that.
Is this something that can be rectified?
I'm trying to adapt this very nice cart you've created on a project where the quantities are services based in time broken down by half hour. So a quantity could be 1.5 (1 and 1/2 hours). When I add 1.5 as a quantity it rounds down. I thought perhaps if I changed the validation but doing so didn't seem to have any effect.
Any tips on how I might make this adjustment?
Hey,
First all, sorry about my english.
Make any sense if we can allow to put another argument on Cart::add for weight?
/**
* add item to the cart, it can be an array or multi dimensional array
*
* @param string|array $id
* @param string $name
* @param float $price
* @param int $quantity
* @param array $attributes
* @param CartCondition|array $conditions
* @return $this
* @throws InvalidItemException
*/
public function add($id, $name = null, $price = null, $quantity = null, $attributes = array(), $conditions = array(), $weight = 0)
{
// if the first argument is an array,
// we will need to call add again
if( is_array($id) )
{
// the first argument is an array, now we will need to check if it is a multi dimensional
// array, if so, we will iterate through each item and call add again
if( Helpers::isMultiArray($id) )
{
foreach($id as $item)
{
$this->add(
$item['id'],
$item['name'],
$item['price'],
$item['quantity'],
Helpers::issetAndHasValueOrAssignDefault($item['attributes'], array()),
Helpers::issetAndHasValueOrAssignDefault($item['conditions'], array()),
Helpers::issetAndHasValueOrAssignDefault($item['weight'], 0)
);
}
}
else
{
$this->add(
$id['id'],
$id['name'],
$id['price'],
$id['quantity'],
Helpers::issetAndHasValueOrAssignDefault($id['attributes'], array()),
Helpers::issetAndHasValueOrAssignDefault($id['conditions'], array()),
Helpers::issetAndHasValueOrAssignDefault($item['weight'], 0)
);
}
return $this;
}
// validate data
$item = $this->validate(array(
'id' => $id,
'name' => $name,
'price' => Helpers::normalizePrice($price),
'quantity' => $quantity,
'attributes' => new ItemAttributeCollection($attributes),
'conditions' => $conditions,
'weight' => $weight
));
// get the cart
$cart = $this->getContent();
// if the item is already in the cart we will just update it
if( $cart->has($id) )
{
$this->events->fire($this->getInstanceName().'.updating', array($item, $this));
$this->update($id, $item);
$this->events->fire($this->getInstanceName().'.updated', array($item, $this));
}
else
{
$this->events->fire($this->getInstanceName().'.adding', array($item, $this));
$this->addRow($id, $item);
$this->events->fire($this->getInstanceName().'.added', array($item, $this));
}
return $this;
}
Next we can add"tax" by weight? Or get total weight? Or even calculating shipping cost?
What you think about this?
Is this project still maintained?
Hello,
Code in config/app.php
`'providers' => [
Darryldecode\Cart\CartServiceProvider::class,
],
'aliases' => [
'Cart' => Darryldecode\Cart\Facades\CartFacade::class,
],`
In Controller
tried Cart::add() got error Class 'Cart' not found
tried \Cart:add() got the same error
In header I used both
use Cart;
and use Darryldecode\Cart\Facades\CartFacade;
with this I got another error:
Class 'App\Http\Controllers\Cart' not found
tried 'use Darryldecode\Cart\Cart;' as well. Same error
Cart keep only one item?
Hi
I have configure cart and applied few condition for testing purpose but cart total or discount total is not display correctly can you please help me below is my code?
$condition1 = new \Darryldecode\Cart\CartCondition(array(
'name' => 'VAT',
'type' => 'tax',
'target' => 'subtotal',
'value' => '10%',
));
$itemCondition3 = new \Darryldecode\Cart\CartCondition(array(
'name' => 'Discount',
'type' => 'misc',
'target' => 'subtotal',
'value' => '-5%',
));
Cart::condition([$condition1,$itemCondition3]);
<table class="table">
<tbody>
<tr>
<td>Order subtotal</td>
<th align="right">${{number_format(Cart::getSubTotal(),2)}}</th>
</tr>
@foreach(Cart::getConditions() as $condition)
<tr>
<td>{{$condition->getName()}} ({{$condition->getValue()}})</td>
<th align="right">${{number_format($condition->getCalculatedValue(Cart::getSubTotal()),2)}}</th>
</tr>
@endforeach
<tr class="total">
<td>Total</td>
<th align="right">${{number_format(Cart::getTotal(),2)}}</th>
</tr>
</tbody>
</table>
Hi,
I've noticed that if you add an item with a condition which ends up substracting more than the item's price, the item price ends up negative (e.g. price 15, value -20 results with -5 product price). Is that something that should be allowed? In my case, I would never want a negative product price. Please let me know and I can make a PR.
Test code:
$product = [
'id' => 123,
'name' => 'Sample Item 1',
'price' => 15,
'quantity' => 1,
'conditions' => new \Darryldecode\Cart\CartCondition([
'name' => 'Substract 20',
'type' => 'shipping',
'target' => 'item',
'value' => '-20',
]),
];
\Cart::add($product);
dd(\Cart::getTotal()); // -5
When I want to echo out the total value in the view, I get the following error:
ErrorException
Trying to get property of non-object.. {view file name}
/vendor/darryldecode/cart/src/Darryldecode/Cart/Cart.php510
Line: $originalPrice = $item->price;
Of course I have some items in the cart, and all items have price set.
CartCollection {#401 ▼
#items: array:2 [▼
21 => array:6 [▼
"quantity" => 6
"id" => "21"
"name" => "******************"
"price" => 7800.0
"attributes" => ItemAttributeCollection {#341 ▶}
"conditions" => []
]
31 => array:6 [▼
"quantity" => 6
"id" => "31"
"name" => "**************"
"price" => 1.0
"attributes" => ItemAttributeCollection {#342 ▶}
"conditions" => []
]
]
}
EDIT: its not always, when I clear the cart, no error happens. It's something with adding to the cart...
EDIT 2: some way one of my item differs from others:
CartCollection {#386 ▼
#items: array:2 [▼
21 => ItemCollection {#341 ▶}
31 => array:6 [▶]
]
}
this is why error happens.. any idea?
EDIT 3:
When I constantly add, remove items to the cart, sometimes one of the items randomly will be saved as array, and not as ItemCollection. Of course I use the same code all the way..
CartCollection {#435 ▼
#items: array:4 [▼
21 => ItemCollection {#341 ▶}
27 => ItemCollection {#343 ▶}
22 => ItemCollection {#345 ▶}
20 => array:6 [▶]
]
}
One idea:
Would put a field with the sum total of each item (quantity * price).
Example:
Cart::get($itemId);
[id] => 23
[name] => Item Name
[price] => 5.00
[quantity] => 3
[sum] => 15.00
Thank you!
I have an item in my cart with two conditions. One of them is shipping, the other one is Vat.
$shippingCondition = new \Darryldecode\Cart\CartCondition(array(
'name' => 'shipping costs',
'type' => 'shipping',
'target' => 'item',
'value' => '3.95',
]
));
$vatCondition = new \Darryldecode\Cart\CartCondition(array(
'name' => 'vat 6%',
'type' => 'tax',
'target' => 'item',
'value' => '6%',
));
Items can be 6% or 21% vat in the Netherlands.
What I like to have is the possiblity to use specific conditions when showing the item in my cart:
$item->getPriceSumWithConditions($vatCondition);
This way I can show the price with VAT per Item on a line in my cart and use the shipping at the end with the Cart totals summary.
And while mentioning this, it would be nice to have the possibility to sum up the totals per item condition too with a specific function. This way I can show the sum of the 6% en 21% Vat items separately, as well as the total shipping costs, which can vary per item.
Hi,
I'm using darryldecode/cart in my code, I'm using currently laravel 5.2, and i want to upgrade to 5.3.
when i run composer update, i get the following error:
Problem 1
- darryldecode/cart dev-master requires illuminate/validation 5.0.x|5.1.x|5.2.x -> satisfiable by laravel/framework[v5.2.39], illuminate/validation[v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.6, v5.2.7].
Is the cart compatible with laravel 5.3 ?
Thanks!
When I am updating the cart by adding or subtracting quantities (and loading the page with the cart again) the order of the items is changing. Is there a way to set the order? By example alphabetically on the items names? Or simply by the order the items are originally added to the cart?
Will you be updating the cart for Laravel 5.1? I can't update to 5.1 until the cart will accept it.
Problem 1
- Installation request for darryldecode/cart dev-master -> satisfiable by darryldecode/cart[dev-master].
- Conclusion: remove laravel/framework v5.1.1
- Conclusion: don't install laravel/framework v5.1.1
- darryldecode/cart dev-master requires illuminate/validation 5.0.@dev -> satisfiable by illuminate/validation[v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.4].
- don't install illuminate/validation v5.0.0|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.22|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.25|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.26|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.28|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.4|don't install laravel/framework v5.1.0
- Installation request for laravel/framework 5.1. -> satisfiable by laravel/framework[v5.1.0, v5.1.1].
Because the class is already called "Cart", it's superfluous to have "cart" in method names.
// Instead of:
Cart::clearCartConditions();
// It should be:
Cart::clearConditions();
This is a consistency issue which bugs me personally. I keep forgetting to add Cart
whenever I want to call that specific method. If you want to keep "cart" in the method name, at least make it consistent by changing Cart::clear()
to Cart::clearCart()
.
But again, I recommend just renaming Cart::clearCartConditions()
to Cart::clearConditions()
. Cart::clearCartConditions()
should be deprecated in the next version or just removed.
Hi there,
Is it possible to update the article quantity if a product is added twice (and making sure the selected quantity is added)?
Of course not so difficult to calculate myself but it would be nice to have a function to get the total quantity of all items in the cart. Now I have a quantity of 14 and stil just 1 when I use count().
I have installed package successfully ,
Cart::add(455, 'Sample Item', 100.99, 2, array());
Works , but get empty response when trying to retrieve the cart :
return Cart::getContent() ;
Hi,
I'm having a problem.
In one route i add an item tot the cart with "Cart::add(455, 'Sample Item', 100.99, 2, array());" and in another route i get the items with "Cart::getContent()".
The problem is that Cart::getContent() always return empty.
I checked the session with Session::get() (and the session id) and the items appear but Cart::getContent always return an empty array.
Can you help me please?
Thanks.
I think it would be nice to be able to find and remove conditions by the type they are e.g.
$condition = new CartCondition([
'name' => 'Discount 10%',
'type' => 'promo',
'target' => 'subtotal',
'value' => '-10%',
]);
Cart::findCartConditionType('promo');
Cart::removeCartConditionType('promo');
Could you add the ability to fetch the actual value from the condition rather than what you supply it:
for example:
Name | Value |
---|---|
cart sub total | £10 |
vat @ 20% | £2 |
total | £12 |
Currently when you do $condition->getValue() it only returns the value you supplied in the condition.
// add condition single condition
$condition = new CartCondition([
'name' => 'VAT 20%',
'type' => 'tax',
'target' => 'total',
'value' => '20%',
]);
What we really need is another method like $condition->getCalculateValue() will return the value that targets the sub total, or whatever value you have applied the condition to.
Hi ,
Cart::update(456, array(
'quantity' => array(
'relative' => false,
'value' => 5
),
));
give me this :
ErrorException in Cart.php line 204:
preg_match() expects parameter 2 to be string, array given
When a new condition is added using the Cartcondition like below, the discount is calculated over the price, which is good.
$discountCondition = new \Darryldecode\Cart\CartCondition([
'name' => 'discount-code',
'type' => 'discount-code',
'target' => 'subtotal',
'value' => $discountValue, // (-30%)
'attributes' => [
'code' => $code
]
]);
\Cart::condition($discountCondition);
But when a customer removes the discount code, and I remove the condition (\Cart::removeCartCondition('discount-code');
), the condition is removed after the code is executed, but when I reload the page, the condition is still applied. The condition is also shown in the \Cart::getConditions();
array.
Could you please take a look at it :)
Hello,
first of all, thank you for the nice implementation.
I was quite surprised that the cart quantity update method actually adds quantity.
Is there a way to easy update the quantity with a certain value, e.g. if the quantity is 5 to make it 7 right away, and not 5+7=12?
Thanks
Can i apply cartcondition only for one quantity for item?
Let say, id 1, buy 2 quantities, i want to set cartcondition only for 1 quantity
is it possbile?
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.