Download the PHP package jackiedo/shoppingcart without Composer
On this page you can find all versions of the php package jackiedo/shoppingcart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jackiedo/shoppingcart
More information about jackiedo/shoppingcart
Files in jackiedo/shoppingcart
Package shoppingcart
Short Description A small package use to create shopping cart in Laravel
License MIT
Informations about the package shoppingcart
Laravel Shopping Cart
A small package use to create shopping cart in Laravel application. (Now just only support Laravel 4.x)
Announcement of abandonment
This package is abandoned. Please use the Laravel-Cart package of same distributor for replacement.
Overview
Look at one of the following topics to learn more about LaravelShoppingCart
- Installation
- Usage
- Collections
- Instances
- Models
- Exceptions
- Events
Installation
You can install this package through Composer.
-
First, edit your project's
composer.json
file to requirejackiedo/shoppingcart
: -
Next, update Composer from the Terminal:
- Once update operation completes, the third step is add the service provider. Open
app/config/app.php
, and add a new item to the providers array:
And the final step is add the follow line to the section aliases
:
Usage
Add item to cart
Add a new item.
example:
Update item
Update the specified item.
example:
Get all items
Get all the items.
example:
Get item
Get the specified item.
example:
Remove item
Remove the specified item by raw ID.
example:
Destroy cart
Clean Shopping Cart.
example:
Get total price
Returns the total price of all items.
example:
Count rows
Return the number of rows.
example:
Count quantity
Returns the quantity of all items
$totalItems
: When false
,will return the number of rows.
example:
Search items
Search items by property.
example:
Collections
As you might have seen, there are two methods and one property both return a Collection. These are the Cart::content() (Cart)
, Cart::get() (CartItem)
and Cart::get()->options (CartItemOptions)
.
These Collections extends the 'native' Laravel Collection class, so all methods you know from Collection class can also be used on your shopping cart. With some addition to easily work with your carts content.
Instances
Now the packages also supports multiple instances of the cart. The way this works is like this:
You can set the current instance of the cart with Cart::instance('newInstance')
, at that moment, the active instance of the cart is newInstance
, so when you add, remove or get the content of the cart, you work with the newInstance
instance of the cart.
If you want to switch instances, you just call Cart::instance('otherInstance')
again, and you're working with the otherInstance
again.
So a little example:
Note:
-
Keep in mind that the cart stays in the last set instance for as long as you don't set a different one during script execution.
- The default cart instance is called
main
, so when you're not using instances,Cart::content();
is the same asCart::instance('main')->content()
Models
A special feature is associating a model with the items in the cart. Let's say you have a Product
model in your application. With the new associate()
method, you can tell the cart that an item in the cart, is associated to the Product
model. That way you can access your model right from the CartItem
!
example:
The keyword to access the model is the snake case of model name you associated (Ex: Model name is ShoppingProduct, then the keyword is shopping_product).
The associate()
method has a second optional parameter for specifying the model namespace.
Exceptions
The Cart package will throw exceptions if something goes wrong. This way it's easier to debug your code using the Cart package or to handle the error based on the type of exceptions. The Cart packages can throw the following exceptions:
Exception | Reason |
---|---|
ShoppingcartInvalidItemException | When a new product misses id or title argument (id , title ) |
ShoppingcartInvalidPriceException | When a non-numeric or negative price is passed |
ShoppingcartInvalidQtyException | When a non-numeric or less than 1 quantity is passed |
ShoppingcartInvalidRawIDException | When the $rawId that got passed doesn't exists in the current cart |
ShoppingcartUnknownModelException | When an unknown model is associated to a cart row |
Events
Event Name | Parameters |
---|---|
cart.adding | ($attributes, $cart); |
cart.added | ($attributes, $cart); |
cart.updating | ($row, $cart); |
cart.updated | ($row, $cart); |
cart.removing | ($row, $cart); |
cart.removed | ($row, $cart); |
cart.destroying | ($cart); |
cart.destroyed | ($cart); |
You can easily handle these events, for example:
License
MIT
Thanks for use
Hopefully, this package is useful to you.
All versions of shoppingcart with dependencies
illuminate/support Version 4.2.*
illuminate/session Version 4.2.*
illuminate/events Version 4.2.*