修改 flat shipping 结构

结账页配送插件循环结构优化

fixed shipping service

wip
This commit is contained in:
Edward Yang 2022-12-01 13:48:16 +08:00
parent 58223f5ea8
commit 088d3103fe
5 changed files with 34 additions and 18 deletions

View File

@ -29,6 +29,7 @@ class ShippingMethodService
$shippingMethods = [];
foreach ($shippingPlugins as $shippingPlugin) {
$plugin = $shippingPlugin->plugin;
$pluginCode = $shippingPlugin->code;
$pluginName = Str::studly($pluginCode);
$className = "Plugin\\{$pluginName}\\Bootstrap";
@ -38,7 +39,11 @@ class ShippingMethodService
}
$quotes = (new $className)->getQuotes($currentCart, $shippingPlugin);
if ($quotes) {
$shippingMethods[$pluginCode] = $quotes;
$shippingMethods[] = [
'code' => $pluginCode,
'name' => $plugin->name,
'quotes' => $quotes
];
}
}
return $shippingMethods;

View File

@ -55,6 +55,7 @@ class CheckoutService
*
* @param $requestData ['shipping_address_id'=>1, 'payment_address_id'=>2, 'shipping_method'=>'code', 'payment_method'=>'code']
* @return array
* @throws \Exception
*/
public function update($requestData): array
{

View File

@ -24,11 +24,12 @@ class ShippingService
return null;
}
$pluginCode = Str::studly($shippingMethod);
$methodArray = explode('.', $shippingMethod);
$pluginCode = Str::studly($methodArray[0]);
$className = "Plugin\\{$pluginCode}\\Bootstrap";
if (!method_exists($className, 'getShippingFee')) {
throw new \Exception("请在插件 {$className} 实现方法 getShippingFee");
throw new \Exception("请在插件 {$className} 实现方法: public function getShippingFee(\$totalService)");
}
$amount = (float)(new $className)->getShippingFee($totalService);
$totalData = [

View File

@ -11,8 +11,6 @@
namespace Plugin\FlatShipping;
use Beike\Shop\Http\Resources\Checkout\ShippingMethodItem;
class Bootstrap
{
/**
@ -21,10 +19,19 @@ class Bootstrap
* @param $currentCart
* @param $shippingPlugin
* @return array
* @throws \Exception
*/
public function getQuotes($currentCart, $shippingPlugin): array
{
$quotes['flat_shipping.0'] = (new ShippingMethodItem($shippingPlugin))->jsonSerialize();
$code = 'flat_shipping';
$pluginSetting = $shippingPlugin->plugin;
$quotes[] = [
'type' => 'shipping',
'code' => "{$code}.0",
'name' => $pluginSetting->name,
'description' => $pluginSetting->description,
'icon' => plugin_resize($code, $pluginSetting->icon),
];
return $quotes;
}

View File

@ -128,18 +128,20 @@
<div class="checkout-black">
<h5 class="checkout-title">{{ __('shop/checkout.delivery_method') }}</h5>
<div class="radio-line-wrap">
<div :class="['radio-line-item', shipping.code == form.shipping_method_code ? 'active' : '']"
v-for="shipping, index in source.shipping_methods" :key="index"
@click="updateCheckout(shipping.code, 'shipping_method_code')">
<div class="left">
<input name="shipping" type="radio" v-model="form.shipping_method_code" :value="shipping.code"
:id="'shipping-method-' + index" class="form-check-input">
<img :src="shipping.icon" class="img-fluid" v-if="shipping.icon">
</div>
<div class="right ms-3">
<div class="title">@{{ shipping.name }}</div>
<div class="sub-title" v-html="shipping.description"></div>
<div class="radio-line-wrap" v-if="source.shipping_methods.length">
<div v-for="methods, index in source.shipping_methods" :key="index">
<div :class="['radio-line-item', shipping.code == form.shipping_method_code ? 'active' : '']"
v-for="shipping, s_index in methods.quotes" :key="index + '-' + s_index"
@click="updateCheckout(shipping.code, 'shipping_method_code')">
<div class="left">
<input name="shipping" type="radio" v-model="form.shipping_method_code" :value="shipping.code"
:id="'shipping-method-' + index" class="form-check-input">
<img :src="shipping.icon" class="img-fluid" v-if="shipping.icon">
</div>
<div class="right ms-3">
<div class="title">@{{ shipping.name }}</div>
<div class="sub-title" v-html="shipping.description"></div>
</div>
</div>
</div>
</div>