项目作者: mathewberry

项目描述 :
Shopping Cart For Laravel (DISCONTINUED)
高级语言: PHP
项目地址: git://github.com/mathewberry/cart.git
创建时间: 2017-02-05T13:21:04Z
项目社区:https://github.com/mathewberry/cart

开源协议:MIT License

下载


Shopping cart component

Shopping cart component includes a fully intergratable shopping cart with lots of rich features.

Laravel 5.4 Support for version 0.2.0

Installation

To install through composer simply use the following command:

  1. composer require mathewberry/cart

Next add

  1. Cart` => \Mathewberry\Cart\Facades\Cart::class

to config/app.php

Features

  • Get the subtotal
  • Get the total
  • Get the delivery price
  • Get the voucher price
  • Get the quantity
  • Get the cart total
  • Add a product
  • Add a voucher
  • Check if the cart has a product
  • Update the cart
  • Remove an item from the cart
  • Clear the cart

Usage

Get product

  1. $product = Cart::get($product_id);

Array Structure

  1. // Example
  2. [
  3. "id" => 24,
  4. "price" => 99.99,
  5. "quantity" => 2,
  6. "options" => [...]
  7. ]

Displaying

  1. {{ $product['options']['name'] }} <small>{{ $product['options']['model'] }}</small><br>
  2. <img src="{{ $product['options']['image'] }}">
  3. <a href="{{ route('products', ['id' => $product['id']]) }}"><br>

Usages

Get all products

  1. $products = Cart::content();

Array Structure

  1. // Example
  2. [
  3. [
  4. "id" => 24,
  5. "price" => 99.99,
  6. "quantity" => 2,
  7. "options" => [...]
  8. ],
  9. [
  10. "id" => 34,
  11. "price" => 79.99,
  12. "quantity" => 1,
  13. "options" => [...]
  14. ]
  15. ]

Get the subtotal

  1. // Return the total with shipping or voucher
  2. Cart::subtotal();

Add a new product

  1. /* DATABASE ROW
  2. *
  3. * Id: 24
  4. * Name: 'My Product'
  5. * Model: 'AAA900'
  6. * Price: 99.99
  7. *
  8. */
  9. $product = \App\Models\Product::select(['id', 'model', 'price'])->find(24);
  10. $product_id = $product->id;
  11. $price = $product->price;
  12. $quantity = 1;
  13. // You may add any options you wish.
  14. $options = [
  15. 'name' => $product->name,
  16. 'image' => asset('images/my-product-image.jpg'),
  17. 'model' => $product->model
  18. ];
  19. Cart::add($product_id, $price, $quantity, $options)

Get the total

  1. // Returns the total of the cart
  2. Cart::total();

Get the delivery cost

  1. // Returns the delivery cost
  2. Cart::delivery();

Set the voucher

  1. // Example Data
  2. $id = 24;
  3. $code = "MB25OFF"; // 25% Off
  4. $discount = 25.00; // 25%
  5. $is_fixed = false; // Percentage
  6. $display = '-' . number_format($discount, 2) . '%'; // How it should be displayed to the customer.
  7. Cart::voucher($id, $code, $discount, $is_fixed, $display);

Get the voucher

  1. Cart::voucher();

Structure

  1. [
  2. "id" => $voucher_id, // Voucher id
  3. "code" => $voucher_code, // Voucher code
  4. "display" => $voucher_display, // Customer friendly, e.g: "25%"
  5. "is_fixed" => $voucher_fixed, // Percentage voucher or fixed price
  6. "discount" => $voucher_discount_value // Value of voucher
  7. ]

Displaying

  1. Code: {{ Cart::voucher()['code'] }}<br>
  2. Deducted: {{ Cart::voucher()['display'] }}

Has product

  1. // Returns true or false whether or not the product exists in the cart.
  2. Cart::has($product_id);

Get the total of a product

  1. // Calculates the product price times quantity.
  2. Cart::sum($product_id);

Get the quantity of the cart

  1. // Return a list of all the products in the cart.
  2. Cart::products();

Update cart item

  1. // Add one to the current quantity
  2. Cart::update($product_id);
  1. // Custom quantity to add to existing quantity
  2. Cart::update($product_id, $quantity);

Remove from cart

  1. // Remove a specific product from the cart.
  2. Cart::remove($product_id);

Clear the cart

  1. // Clear the cart of ALL of it's data.
  2. Cart::clear();