Download the PHP package syscover/shopping-cart without Composer
On this page you can find all versions of the php package syscover/shopping-cart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package shopping-cart
Advanced ShoppingCart to Laravel 5.3
Installation
1 - After install Laravel framework, insert on file composer.json, inside require object this value
and execute on console:
2 - Register service provider, on file config/app.php add to providers array
And register alias, on file config/app.php add to aliases array
3 - Execute publish command
To run laravel testing
publish testing files
and run the test using the following command:
General configuration environment values
We indicate configuration variables available, to change them what you should do from the file environment variables .env
Set product price tax [default value 1]
Defines the types of prices that are introduced in products, this option is consulted when you create or update a product You have this values:
- Value: 1 Excluding tax
- Value: 2 Including tax
Set shipping price tax [default value 1]
Defines the types of prices that are introduced in shipping prices, this option is consulted when you create or update a shipping price
- Value: 1 Excluding tax
- Value: 2 Including tax
Set product display price tax [default value 1]
Defines how you want display product prices You have this values:
- Value: 1 Excluding tax
- Value: 2 Including tax
Set shipping display price tax [default value 1]
Defines how you want display shipping prices
- Value: 1 Excluding tax
- Value: 2 Including tax
The Item Cart gives you the following methods to use:
To add items we have create a Item object with this properties:
- id:string = Id of product
- name:string = Name of product
- quantity:float = Quantity of product than you want add
- inputPrice:float = Price product by unit
- weight:float [default 1.000] = Weight of product
- transportable:boolean [default true] = Set if product can to be delivery
- taxRule:TaxRule[] [default []] = Set tax rules for this product
- options:array [default []] = Set a associative array to set custom options
Add car item to cart, you need create Item objects to add cart, you can use a Item object or Items array if you want add various elements.
We have created TaxRule object to calculate tax from shopping cart, this object has this properties:
- name:string = Name of tax
- taxRate:float = Percentage of tax
- priority:int [default 0] = Order to calculate tax over subtotal. If are different priorities, the highest tax is calculated on the subtotal more taxes lower priority
- sortOrder:int [default 0] = Order to appear tax on screen
Cart is ready to TaxRule object, you can add tax rules to each cartItem object. You can add only one TaxRule or various with a array tax rules
Once defined the rules, you can change them using this method
Of course, you can also reload other rules if necessary
Remember this, if you reset taxRules or add new tax rules to item, you must force calculate amounts from subtotal
To update quantity from a item you have setQuantity method, you'll pass the update method the rowId and the new quantity
If you want to update more attributes of the item, you can pass Item object to the update method with rowId from item to update.
To remove element from the cart, the remove() method on the cart and pass it the rowId
If you want to get the cart items, you have getCartItems method. This method will return a Collection of CartItems which you can iterate over and show the content to your customers.
If you want to get quantity from each items, you can use getQuantity method over each item
If you want to get an item from the cart using its rowId, you can simply call the get() method on the cart and pass it the rowId.
If you want to completely remove the content of a cart, you can call the destroy method on the cart. This will remove all CartItems from the cart for the current cart instance.
Get the subtotal price, without tax
Get tax amount from all items
To get total price
To set shipping amount
To get shipping amount
To know if cart contain any item transportable, you have method
Get the number of items in the cart, total items
To find an item in the cart, you can use the search() method. As you can see the Closure will receive two parameters. The first is the CartItem to perform the check against. The second parameter is the rowId of this CartItem.
The method will return a Collection containing all Items that where found
This way of searching gives you total control over the search process and gives you the ability to create very precise and specific searches.
The package also supports multiple instances of the cart. The way this works is like this: You can set the current instance of the cart with CartProvider::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 CartProvider::instance('otherInstance') again, and you're working with the otherInstance again.
The default cart instance is called default, so when you're not using instances, CartProvider::instance()->getCartItems(); is the same as CartProvider::instance('default')->getCartItems().
So a little example:
We have created PriceRule object to apply discounts over items cart
- name:string = Name of price rule
- description:string = Description of rule
- discountType:int = You have various options, below you have all options
- freeShipping:boolean [default false] = Check this option to set a rule whith free shipping
- discountFixed:float [default null] = Set a discount amount fixed
- discountPercentage:float [default null] = Set a rate percentage to discount
- maximumDiscountAmount:float [default null] = If you choose a discount percentage, you can set a maximum amount to discount
- applyShippingAmount:boolean [default false] = Check this option if you want apply discount to shipping amount too
- combinable:boolean [default true] = Set if this price rule can to have other one in the same cart
With this constants from PriceRule class, you can define discount type
To set price rules you can use addCartPriceRule methop
Scenarios to consider when applying to the pricing rules
- We have created discounts over subtotal and total price, but you can not apply both discounts to the same cart.
- If apply percentage discount and fixed, first will apply fixed discount and last the percentage discount.