unodepiera/simplecart

该包最新版本(dev-master)没有提供许可证信息。

Simplecart for Laravel 4

dev-master 2014-02-13 20:10 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:17:04 UTC


README

安装

打开您的 composer.json 文件,并添加以下代码

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

使用 composer update 更新您的包或使用 composer install 安装。

用法

在 app/config/app.php 中找到 providers 键并注册 Simplecart 服务提供者。

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

在 app/config/app.php 中找到 aliases 键。

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

示例用法 Simplecart

插入简单行

```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);

通过行号移除产品

只需传递一个存在的行号即可

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

获取购物车内容

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

获取总金额

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

获取总项目数

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

销毁 simplecart

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

最终示例用法

首次访问插入路由

```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));
});

循环购物车并检查是否有选项

```html <title>Simplecart for Laravel 4</title> @if($cart) @foreach($cart as $items) @endforeach @endif ``` ## 访问我