unisharp/pricing is a Laravel package for a modularized pricing package for buyable..
It currently has 4 GitHub stars and 1.660 downloads on Packagist.
Install it with composer require unisharp/pricing.
Discover more Laravel packages by unisharp
or browse all Laravel packages to compare alternatives.
Last updated
A modularized pricing package for buyalbe.
composer require unisharp/pricing dev-master
php artisan vendor:publish --tag pricing
Set available pricing modules in config/pricing.php
return [
'modules' => [
UniSharp\Pricing\Tests\Fixtures\TestModule::class,
]
];
UniSharp\Pricing\ModuleContract which needs handle and finish functions.config/pricing.php, the first module will handle the pricing logic and pass pricing instance to the next module (Pipeline Pattern).
addFee,addDeduction,writeModuleLogwill only change pricing instance's properties.getModuleInfocan get extra info of that module.
namespace UniSharp\Pricing\Tests\Fixtures;
use Closure;
use UniSharp\Pricing\Pricing;
use UniSharp\Pricing\ModuleContract;
use Illuminate\Contracts\Pipeline\Pipeline;
class TestModule implements ModuleContract
{
const FEE = 99;
const DEDUCTION = 88;
const LOG = 'log';
public function handle(Pricing $pricing, Closure $next)
{
$pricing->addFee(static::FEE);
$pricing->addDeduction(static::DEDUCTION);
$pricing->writeModuleLog(static::LOG);
$info = $pricing->getModuleInfo();
return $next($pricing);
}
public function finish(Pricing $pricing)
{
//
}
}
use UniSharp\Pricing\Facades\Pricing;
class Foo {
// set items and get original price
Pricing::setItems(UniSharp\Cart\CartItemCollection $items)
->getOriginalTotal();
// apply some modules
Pricing::apply(ModuleA::class)
->apply(ModuleB::class);
// apply some modules with some extra info
Pricing::apply(ModuleA::class)
->apply(ModuleB::class)
->with([
ModuleA::class => 'extra info A',
ModuleB::class => 'extra info B',
]);
// apply modules and get final total
Pricing::apply(ModuleA::class)
->apply(ModuleB::class)
->getTotal();
// apply modules and execute them
Pricing::apply(ModuleA::class)
->apply(ModuleB::class)
->execute();
// get all applied modules
Pricing::getAppliedModules();
// get all fees
Pricing::getFees();
// get fee of a specific module
Pricing::getFee(ModuleA::class);
// get all deductions
Pricing::getDeductions();
// get deduction of a specific module
Pricing::getDeduction(ModuleA::class);
// get items
Pricing::getItems();
}