Add hook for total service.
This commit is contained in:
parent
d1fed8b618
commit
2a2067204a
|
|
@ -17,7 +17,7 @@ use Illuminate\Support\Str;
|
||||||
|
|
||||||
class TotalService
|
class TotalService
|
||||||
{
|
{
|
||||||
public const TOTAL_CODES = [
|
private const TOTAL_CODES = [
|
||||||
'subtotal',
|
'subtotal',
|
||||||
'tax',
|
'tax',
|
||||||
'shipping',
|
'shipping',
|
||||||
|
|
@ -92,16 +92,31 @@ class TotalService
|
||||||
*/
|
*/
|
||||||
public function getTotals(CheckoutService $checkout): array
|
public function getTotals(CheckoutService $checkout): array
|
||||||
{
|
{
|
||||||
foreach (self::TOTAL_CODES as $code) {
|
$maps = $this->getTotalClassMaps();
|
||||||
$serviceName = Str::studly($code) . 'Service';
|
foreach ($maps as $service) {
|
||||||
$service = "\Beike\\Shop\\Services\\TotalServices\\{$serviceName}";
|
|
||||||
if (! class_exists($service) || ! method_exists($service, 'getTotal')) {
|
if (! class_exists($service) || ! method_exists($service, 'getTotal')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$service::getTotal($checkout);
|
$service::getTotal($checkout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->totals;
|
return hook_filter('service.total.totals', $this->totals);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* total 与类名 映射
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function getTotalClassMaps()
|
||||||
|
{
|
||||||
|
$maps = [];
|
||||||
|
foreach (self::TOTAL_CODES as $code) {
|
||||||
|
$serviceName = Str::studly($code) . 'Service';
|
||||||
|
$maps[$code] = "\Beike\\Shop\\Services\\TotalServices\\{$serviceName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return hook_filter('service.total.maps', $maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue