Coder Social home page Coder Social logo

basket's Introduction

Basket

Build Status PHP from Packagist Latest Version License

This package is based on Basket by philipbrown.

Installation

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

$ composer require faustbrian/basket

Coupons

Important: Coupons are applied AFTER Discounts! This means if you have applied a Discount and a Coupon the Coupon will be applied to the discounted price.

Usage

For usage instructions check the USAGE.md.

Create a coupon

$coupon = new Coupon('COUPON_NAME');
$coupon->add(new PercentageDiscount(20));
$coupon->add(new ValueDiscount(new Money(500, new Currency('GBP'))));

Apply a coupon

$basket->products()->first()->coupon($coupon);

Serialize a coupon - Could be used when the coupon needs to be stored.

$coupon->serialize();

Quantity Discount

Grant 20% discount on each Product if more than 5 are purchased

$quantityDiscount = new PercentageDiscount(20);
$coupon->add(new QuantityDiscount(5, $quantityDiscount));

Grant 5£ discount on each Product if more than 5 are purchased

$quantityDiscount = new ValueDiscount(new Money(500, new Currency('GBP')));
$coupon->add(new QuantityDiscount(5, $quantityDiscount));

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

Credits

License

MIT © Brian Faust

basket's People

Contributors

faustbrian avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

basket's Issues

Refactor the global Basket discount

Currently all calculations that need to be done for specific meta data that are associated to the basket discount are all over the place which is kinda hacky and could cause issues later on.

The plan is to refactor all calculations for the basket discount into one single class that will handle the calculations for multiple meta data to make sure one class is responsible instead of like currently using a trait.

At the moment this trait is used by meta data classes to handle a discount that has been applied to the whole basket https://github.com/faustbrian/Basket/blob/master/src/MetaData/Traits/ApplyDiscount.php

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.