fixed checkout
This commit is contained in:
parent
3dd229f919
commit
31697c0093
|
|
@ -92,31 +92,31 @@ class PluginRepo
|
||||||
/**
|
/**
|
||||||
* 获取所有配送方式
|
* 获取所有配送方式
|
||||||
*/
|
*/
|
||||||
public static function getShippingMethods(): array
|
public static function getShippingMethods()
|
||||||
{
|
{
|
||||||
$allPlugins = self::allPlugins();
|
$allPlugins = self::allPlugins();
|
||||||
return $allPlugins->where('type', 'shipping')->filter(function ($item) {
|
return $allPlugins->where('type', 'shipping')->filter(function ($item) {
|
||||||
$plugin = (new Manager)->getPlugin($item->code);
|
$plugin = (new Manager)->getPlugin($item->code);
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
$item->plugin = $plugin->toArray();
|
$item->plugin = $plugin;
|
||||||
}
|
}
|
||||||
return $plugin && $plugin->getEnabled();
|
return $plugin && $plugin->getEnabled();
|
||||||
})->toArray();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有支付方式
|
* 获取所有支付方式
|
||||||
*/
|
*/
|
||||||
public static function getPaymentMethods(): array
|
public static function getPaymentMethods()
|
||||||
{
|
{
|
||||||
$allPlugins = self::allPlugins();
|
$allPlugins = self::allPlugins();
|
||||||
return $allPlugins->where('type', 'payment')->filter(function ($item) {
|
return $allPlugins->where('type', 'payment')->filter(function ($item) {
|
||||||
$plugin = (new Manager)->getPlugin($item->code);
|
$plugin = (new Manager)->getPlugin($item->code);
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
$item->plugin = $plugin->toArray();
|
$item->plugin = $plugin;
|
||||||
}
|
}
|
||||||
return $plugin && $plugin->getEnabled();
|
return $plugin && $plugin->getEnabled();
|
||||||
})->toArray();
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Beike\Shop\Http\Resources\Checkout;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class PaymentMethodItem extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request): array
|
||||||
|
{
|
||||||
|
$pluginSetting = $this->plugin;
|
||||||
|
return [
|
||||||
|
'type' => $this->type,
|
||||||
|
'code' => $this->code,
|
||||||
|
'name' => $pluginSetting->name,
|
||||||
|
'description' => $pluginSetting->description,
|
||||||
|
'icon' => $pluginSetting->icon,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Beike\Shop\Http\Resources\Checkout;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ShippingMethodItem extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request): array
|
||||||
|
{
|
||||||
|
$pluginSetting = $this->plugin;
|
||||||
|
return [
|
||||||
|
'type' => $this->type,
|
||||||
|
'code' => $this->code,
|
||||||
|
'name' => $pluginSetting->name,
|
||||||
|
'description' => $pluginSetting->description,
|
||||||
|
'icon' => $pluginSetting->icon,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,8 @@ use Beike\Repositories\AddressRepo;
|
||||||
use Beike\Repositories\PluginRepo;
|
use Beike\Repositories\PluginRepo;
|
||||||
use Beike\Repositories\SettingRepo;
|
use Beike\Repositories\SettingRepo;
|
||||||
use Beike\Repositories\CountryRepo;
|
use Beike\Repositories\CountryRepo;
|
||||||
|
use Beike\Shop\Http\Resources\Checkout\PaymentMethodItem;
|
||||||
|
use Beike\Shop\Http\Resources\Checkout\ShippingMethodItem;
|
||||||
|
|
||||||
class CheckoutService
|
class CheckoutService
|
||||||
{
|
{
|
||||||
|
|
@ -23,8 +25,8 @@ class CheckoutService
|
||||||
$customer = current_customer();
|
$customer = current_customer();
|
||||||
|
|
||||||
$addresses = AddressRepo::listByCustomer(current_customer());
|
$addresses = AddressRepo::listByCustomer(current_customer());
|
||||||
$shipments = PluginRepo::getShippingMethods();
|
$shipments = ShippingMethodItem::collection(PluginRepo::getShippingMethods())->jsonSerialize();
|
||||||
$payments = PluginRepo::getPaymentMethods();
|
$payments = PaymentMethodItem::collection(PluginRepo::getPaymentMethods())->jsonSerialize();
|
||||||
|
|
||||||
$cartList = CartService::list($customer, true);
|
$cartList = CartService::list($customer, true);
|
||||||
$carts = CartService::reloadData($cartList);
|
$carts = CartService::reloadData($cartList);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue