Check https://github.com/draperstudioBasket to see how the underlying Basket works.
First, pull in the package through Composer.
composer require draperstudio/laravel-basket:1.0.*@dev
This function should be used when you want to built your "Product"-Objects on your own.
use DraperStudio\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);
});
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 DraperStudio\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(),
]);
});
$basket->boot(Jurisdiction $jurisdiction);
$basket->load($identifier);
$basket->products();
$basket->count();
$basket->pick($sku);
$basket->add(Product $product);
$basket->update($sku, Closure $action)
$basket->addQuick($sku, $name, $price, $actions = []);
$basket->updateQuick($sku, $actions = []);
$basket->remove($sku);
$basket->discount(Discount $discount);
$basket->getRate();
$basket->getCurrency();
$basket->getDelivery();
$basket->getDiscount();
$basket->getProductsCount();
$basket->getSubtotal();
$basket->getTaxable();
$basket->getTax();
$basket->getTotal();
$basket->getValue();
$basket->getProducts();
$basket->reconcile();
- Fill out ServiceProvider
- Fill out Contracts\Basket
- Add method to edit Basket without fully loading it.
$basket->instance('identifier')->add($product);