GithubHelp home page GithubHelp logo

simplecart's Introduction

Simple Cart for Laravel 4

Installation

Open your composer.json and add the next code

```json { "require": { "laravel/framework": "4.0.*", "unodepiera/simplecart": "dev-master" }, "minimum-stability": "dev" } ```

Update your packages with composer update or install with composer install.

Usage

Find the providers key in app/config/app.php and register the Simplecart Service Provider.

```json 'providers' => array( //... 'Unodepiera\Simplecart\SimplecartServiceProvider' ) ```

Find the aliases key in app/config/app.php.

```json 'aliases' => array( //... 'Simplecart' => 'Unodepiera\Simplecart\Facades\Simplecart', ) ```

Example Usage Simplecart

Insert simple row

```php $id = 19; $qty = 20; $price = 550; $item = array( 'id' => 5, 'qty' => $qty, 'price' => $price, 'name' => "hair", 'medida' => "xl" );
//add options to row
$item["options"] = array("color" => "blue", "avaliable" => "si");

//add row to cart
Simplecart::insert($item);
<h2>Update a product</h2>
```php
	$update = array(
    	'id' => 5,
        'rowid'	=> "e4da3b7fbbce2345d7772b0674a318d5",
        'qty' => 25,
        'price' => $price,
        'name' => "shirt",
        'medida' => "xl"
    );

    Simplecart::update($update);

Remove a product by rowid

You just need to pass a rowid that there

```php Simplecart::remove_item("8e296a067a37563370ded05f5a3bf3ec"); ```

Get cart content

```php Simplecart::get_content(); ```

Get total cost

```php Simplecart::total_cart(); ```

Get total items

```php Simplecart::total_articles(); ```

Destroy simplecart

```php Simplecart::destroy(); ```

Final example usage

First visit route insert

```php Route::get("insert", function(){ $id = 9; $qty = 5; $price = 1500; $item = array( 'id' => $id, 'qty' => $qty, 'price' => $price, 'name' => "shirt", 'medida' => "xxl" );
//add options to row
$item["options"] = array("color" => "orange", "avaliable" => "yes");

//add row to cart
Simplecart::insert($item);

});

<h3>Then create the next view and visit the route show</h3>
```php
Route::get("show", function()
{
	$cart = Simplecart::get_content();
	$totalcart = Simplecart::total_cart();
	$totalitems = Simplecart::total_articles();
	return View::make("cart", array("cart" => $cart, "total_cart" => $totalcart, "total_items" => $totalitems));
});

Loop the cart and check if has options

```html <title>Simplecart for Laravel 4</title> @if($cart) @foreach($cart as $items) @endforeach
Id Name Options Price Qty Total price
{{ $items['id'] }} {{ $items['name'] }} @if(isset($items['options'])) @foreach($items['options'] as $key => $val) {{ $key }}: {{ $val }} @endforeach @else ---- @endif {{ $items['price'] }} {{ $items['qty'] }} {{ $items['total'] }}
Total: {{ $total_cart }} Items: {{ $total_items }}
@endif ``` ## Visit me

simplecart's People

Contributors

israel981 avatar

Watchers

Daniel avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.