Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

faustbrian-archives/laravel-basket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Basket

Build Status PHP from Packagist Latest Version License

Check https://github.com/Artisanry/Basket to see how the underlying Basket works.

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/basket

Usage

Default Way of adding a Product

This function should be used when you want to built your "Product"-Objects on your own.

use Artisanry\LaravelBasket\Basket;

get('/', function (Basket $basket) {
    // Setup the Basket for UK
    $basket = $basket->setup('uuid_for_example', new UnitedKingdom());

    // Build a new Product
    $product = new Product(1, 'Four Steps to the Epiphany', new Money(1000, new Currency('GBP')), new UnitedKingdomValueAddedTax());
    $product->action(function ($product) {
            $product->quantity(1);
            $product->freebie(false);
            $product->taxable(false);
            $product->delivery(new Money(500, new Currency('GBP')));
            $product->coupon($coupon);
            $product->tags(new Collection(['four steps', 'movie', 'cinema']));
            $product->discount(new PercentageDiscount(20));
            $product->category(new PhysicalBook());
    });

    // Add a new Product
    $basket->add($product);
});

Lazy/Convenient Way of adding a Product

This method should be used if you want to have your "Product"-Objects build by LaravelBasket. It will create the "Product"-Object and build all objects that are required like "Money"-Objects for delivery costs.

use Artisanry\LaravelBasket\Basket;

get('/', function (Basket $basket) {
    // Setup the Basket for UK
    $basket = $basket->setup('uuid_for_example', new UnitedKingdom());

    // Add a new Product
    $basket->addQuick(1, 'Four Steps to the Epiphany', 1000, [
        'quantity' => 1,
        'freebie' => false,
        'taxable' => false,
        'delivery' => 500,
        'coupon' => $coupon,
        'tags' => ['four steps', 'movie', 'cinema'];
        'discount' => new PercentageDiscount(20),
        'category' => new PhysicalBook(),
    ]);
});

Methods

Setup a new Basket with the given Jurisdictions

$basket->boot(Jurisdiction $jurisdiction);

Set the basket instance to the "identifier"-instance

$basket->load($identifier);

Get the products in the Basket

$basket->products();

Get the number of products in the Basket

$basket->count();

Pick a product from the Basket

$basket->pick($sku);

Add a new product to the Basket

$basket->add(Product $product);

Update a product in the Basket

$basket->update($sku, Closure $action)

Add a new product to the Basket (Lazy/Convenience Version)

$basket->addQuick($sku, $name, $price, $actions = []);

Update a product in the Basket (Lazy/Convenience Version)

$basket->updateQuick($sku, $actions = []);

Remove a product from the Basket

$basket->remove($sku);

Apply a discount to the Basket

$basket->discount(Discount $discount);

Get the Jurisdiction tax rate of the Basket

$basket->getRate();

Get the Jurisdiction currency of the Basket

$basket->getCurrency();

Get the delivery cost of the Order

$basket->getDelivery();

Get the discount of the Order

$basket->getDiscount();

Get the number of products of the Order

$basket->getProductsCount();

Get the subtotal of the Order

$basket->getSubtotal();

Get the taxable status of the Order

$basket->getTaxable();

Get the tax of the Order

$basket->getTax();

Get the total value of the Order

$basket->getTotal();

Get the value of the Order

$basket->getValue();

Get the products of the Order

$basket->getProducts();

Perform Reconciliation and return the Order

$basket->reconcile();

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@basecode.sh. All security vulnerabilities will be promptly addressed.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).