Skip to content
No description or website provided.
PHP
Branch: master
Clone or download
3 authors Configure Renovate (#22)
* Add renovate.json

* Apply fixes from StyleCI (#23)

[ci skip] [skip ci]

* Update renovate.json


Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Brian Faust <faustbrian@users.noreply.github.com>
Latest commit fe722f4 Oct 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
resources/config Apply fixes from StyleCI (#18) Jun 9, 2019
src Configure Renovate (#22) Oct 6, 2019
tests transfer ownership to artisanry Jun 4, 2019
.editorconfig editorconfig Aug 3, 2017
.gitattributes gitattributes Aug 3, 2017
.gitignore first Nov 4, 2016
.travis.yml update deps Jan 29, 2018
LICENSE
README.md MPL 2.0 Jun 9, 2019
composer.json Update phpunit/phpunit requirement from ^7.5 to ^8.2 (#21) Jun 12, 2019
phpunit.xml.dist first Nov 4, 2016
renovate.json Configure Renovate (#22) Oct 6, 2019

README.md

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).

You can’t perform that action at this time.