Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: Add L8 & L9 and some style #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Laravel 5 & 6 & 7 Shopping Cart
# Laravel 5, 6, 7, 8 & 9 Shopping Cart
[![Build Status](https://travis-ci.org/darryldecode/laravelshoppingcart.svg?branch=master)](https://travis-ci.org/darryldecode/laravelshoppingcart)
[![Total Downloads](https://poser.pugx.org/darryldecode/cart/d/total.svg)](https://packagist.org/packages/darryldecode/cart)
[![License](https://poser.pugx.org/darryldecode/cart/license.svg)](https://packagist.org/packages/darryldecode/cart)
Expand All @@ -15,13 +15,17 @@ Git repo of the demo: https://github.com/darryldecode/laravelshoppingcart-demo

Install the package through [Composer](http://getcomposer.org/).

For Laravel 5.1~:
`composer require "darryldecode/cart:~2.0"`
### For Laravel 5.5+

For Laravel 5.5, 5.6, or 5.7~:
```zsh
composer require "darryldecode/cart"
```

### For Older versions (5.1)

```composer require "darryldecode/cart:~4.0"``` or
```composer require "darryldecode/cart"```
```zsh
composer require "darryldecode/cart:~2.0"
```

## CONFIGURATION

Expand Down Expand Up @@ -63,24 +67,24 @@ php artisan vendor:publish --provider="Darryldecode\Cart\CartServiceProvider" --
```php
// Quick Usage with the Product Model Association & User session binding

$Product = Product::find($productId); // assuming you have a Product model with id, name, description & price
$product = Product::find($productId); // assuming you have a Product model with id, name, description & price
$rowId = 456; // generate a unique() row ID
$userID = 2; // the user ID to bind the cart contents

// add the product to cart
\Cart::session($userID)->add(array(
'id' => $rowId,
'name' => $Product->name,
'price' => $Product->price,
'name' => $product->name,
'price' => $product->price,
'quantity' => 4,
'attributes' => array(),
'associatedModel' => $Product
'associatedModel' => $product
));

// update the item on cart
\Cart::session($userID)->update($rowId,[
'quantity' => 2,
'price' => 98.67
\Cart::session($userID)->update($rowId, [
'quantity' => 2,
'price' => 98.67
]);

// delete an item on cart
Expand All @@ -90,12 +94,12 @@ $userID = 2; // the user ID to bind the cart contents
$items = \Cart::getContent();
foreach($items as $row) {

echo $row->id; // row ID
echo $row->name;
echo $row->qty;
echo $row->price;
echo $item->associatedModel->id; // whatever properties your model have
echo $row->id; // row ID
echo $row->name;
echo $row->qty;
echo $row->price;
echo $item->associatedModel->id; // whatever properties your model have
echo $item->associatedModel->name; // whatever properties your model have
echo $item->associatedModel->description; // whatever properties your model have
}
Expand Down Expand Up @@ -208,7 +212,7 @@ Cart::session($userId)->add(array(
'price' => 67.99,
'quantity' => 4,
'attributes' => array(),
'associatedModel' => $Product
'associatedModel' => $product
));

// NOTE:
Expand Down Expand Up @@ -440,8 +444,8 @@ $condition = new \Darryldecode\Cart\CartCondition(array(
'target' => 'subtotal', // this condition will be applied to cart's subtotal when getSubTotal() is called.
'value' => '12.5%',
'attributes' => array( // attributes field is optional
'description' => 'Value added tax',
'more_data' => 'more data here'
'description' => 'Value added tax',
'more_data' => 'more data here'
)
));

Expand Down Expand Up @@ -800,7 +804,7 @@ Cart::add(array(

// Now, when iterating over the content of the cart, you can access the model.
foreach(Cart::getContent() as $row) {
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
echo 'You have ' . $row->qty . ' items of ' . $row->model->name . ' with description: "' . $row->model->description . '" in your cart.';
}
```

Expand All @@ -815,19 +819,19 @@ Create a new Service Provider and then on register() method, you can put this li

```php
$this->app['wishlist'] = $this->app->share(function($app)
{
$storage = $app['session']; // laravel session storage
$events = $app['events']; // laravel event handler
$instanceName = 'wishlist'; // your cart instance name
$session_key = 'AsASDMCks0ks1'; // your unique session key to hold cart items

return new Cart(
$storage,
$events,
$instanceName,
$session_key
);
});
{
$storage = $app['session']; // laravel session storage
$events = $app['events']; // laravel event handler
$instanceName = 'wishlist'; // your cart instance name
$session_key = 'AsASDMCks0ks1'; // your unique session key to hold cart items

return new Cart(
$storage,
$events,
$instanceName,
$session_key
);
});

// for 5.4 or newer
use Darryldecode\Cart\Cart;
Expand Down