mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Revert "Manually merged https://github.com/Crinsane/LaravelShoppingcart/pull/502"
This reverts commit 5d117a0acd.
This commit is contained in:
34
README.md
34
README.md
@@ -49,7 +49,7 @@ Cart::add('293ad', 'Product 1', 1, 9.99);
|
||||
As an optional fifth parameter you can pass it options, so you can add multiple items with the same id, but with (for instance) a different size.
|
||||
|
||||
```php
|
||||
Cart::add('293ad', 'Product 1', 1, 9.99, 'weight' => 550, ['size' => 'large']);
|
||||
Cart::add('293ad', 'Product 1', 1, 9.99, ['size' => 'large']);
|
||||
```
|
||||
|
||||
**The `add()` method will return an CartItem instance of the item you just added to the cart.**
|
||||
@@ -57,7 +57,7 @@ Cart::add('293ad', 'Product 1', 1, 9.99, 'weight' => 550, ['size' => 'large']);
|
||||
Maybe you prefer to add the item using an array? As long as the array contains the required keys, you can pass it to the method. The options key is optional.
|
||||
|
||||
```php
|
||||
Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'weight' => 550, 'options' => ['size' => 'large']]);
|
||||
Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => ['size' => 'large']]);
|
||||
```
|
||||
|
||||
New in version 2 of the package is the possibility to work with the [Buyable](#buyable) interface. The way this works is that you have a model implement the [Buyable](#buyable) interface, which will make you implement a few methods so the package knows how to get the id, name and price from your model.
|
||||
@@ -80,8 +80,8 @@ You can just pass the `add()` method an array of arrays, or an array of Buyables
|
||||
|
||||
```php
|
||||
Cart::add([
|
||||
['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00, 'weight' => 550 ],
|
||||
['id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'weight' => 550, 'options' => ['size' => 'large']]
|
||||
['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 10.00],
|
||||
['id' => '4832k', 'name' => 'Product 2', 'qty' => 1, 'price' => 10.00, 'options' => ['size' => 'large']]
|
||||
]);
|
||||
|
||||
Cart::add([$product1, $product2]);
|
||||
@@ -152,24 +152,6 @@ If you want to completely remove the content of a cart, you can call the destroy
|
||||
Cart::destroy();
|
||||
```
|
||||
|
||||
### Cart::weight()
|
||||
|
||||
The `weight()` method can be used to get the weight total of all items in the cart, given there weight and quantity.
|
||||
|
||||
```php
|
||||
Cart::weight();
|
||||
```
|
||||
|
||||
The method will automatically format the result, which you can tweak using the three optional parameters
|
||||
|
||||
```php
|
||||
Cart::weight($decimals, $decimalSeperator, $thousandSeperator);
|
||||
```
|
||||
|
||||
You can set the default number format in the config file.
|
||||
|
||||
**If you're not using the Facade, but use dependency injection in your (for instance) Controller, you can also simply get the total property `$cart->weight`**
|
||||
|
||||
### Cart::total()
|
||||
|
||||
The `total()` method can be used to get the calculated total of all items in the cart, given there price and quantity.
|
||||
@@ -391,12 +373,12 @@ If you want to switch instances, you just call `Cart::instance('otherInstance')`
|
||||
So a little example:
|
||||
|
||||
```php
|
||||
Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99, 550);
|
||||
Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99);
|
||||
|
||||
// Get the content of the 'shopping' cart
|
||||
Cart::content();
|
||||
|
||||
Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, 550, ['size' => 'medium']);
|
||||
Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
|
||||
|
||||
// Get the content of the 'wishlist' cart
|
||||
Cart::content();
|
||||
@@ -469,7 +451,7 @@ Here is an example:
|
||||
```php
|
||||
|
||||
// First we'll add the item to the cart.
|
||||
$cartItem = Cart::add('293ad', 'Product 1', 1, 9.99, 550, ['size' => 'large']);
|
||||
$cartItem = Cart::add('293ad', 'Product 1', 1, 9.99, ['size' => 'large']);
|
||||
|
||||
// Next we associate a model with the item.
|
||||
Cart::associate($cartItem->rowId, 'Product');
|
||||
@@ -478,7 +460,7 @@ Cart::associate($cartItem->rowId, 'Product');
|
||||
$cartItem->associate('Product');
|
||||
|
||||
// You can even make it a one-liner
|
||||
Cart::add('293ad', 'Product 1', 1, 9.99, 550, ['size' => 'large'])->associate('Product');
|
||||
Cart::add('293ad', 'Product 1', 1, 9.99, ['size' => 'large'])->associate('Product');
|
||||
|
||||
// Now, when iterating over the content of the cart, you can access the model.
|
||||
foreach(Cart::content() as $row) {
|
||||
|
||||
Reference in New Issue
Block a user