diff --git a/beike/Admin/Http/Controllers/DesignController.php b/beike/Admin/Http/Controllers/DesignController.php index c56edc32..96983e07 100644 --- a/beike/Admin/Http/Controllers/DesignController.php +++ b/beike/Admin/Http/Controllers/DesignController.php @@ -20,7 +20,7 @@ class DesignController extends Controller $data = [ 'editors' => [ 'editor-slide_show', 'editor-image401', 'editor-tab_product', 'editor-product', 'editor-image100', - 'editor-brand', 'editor-icons', 'editor-rich_text', 'editor-image200', 'editor-image300', + 'editor-brand', 'editor-icons', 'editor-rich_text', 'editor-image200', 'editor-image300','editor-slide_show_video', ], 'design_settings' => system_setting('base.design_setting'), ]; diff --git a/beike/Admin/Http/Controllers/ProductController.php b/beike/Admin/Http/Controllers/ProductController.php index 8c75789e..94df0f4a 100644 --- a/beike/Admin/Http/Controllers/ProductController.php +++ b/beike/Admin/Http/Controllers/ProductController.php @@ -118,6 +118,22 @@ class ProductController extends Controller } } + public function copy(ProductRequest $request, Product $product) + { + try { + $product = (new ProductService)->copy($product); + + $data = [ + 'product' => $product, + ]; + hook_action('admin.product.copy.after', $data); + + return json_success(trans('common.copy_success'), []); + } catch (\Exception $e) { + return json_encode($e->getMessage()); + } + } + public function destroy(Request $request, Product $product) { $product->delete(); diff --git a/beike/Admin/Routes/admin.php b/beike/Admin/Routes/admin.php index cbde810a..a3df2130 100644 --- a/beike/Admin/Routes/admin.php +++ b/beike/Admin/Routes/admin.php @@ -214,6 +214,7 @@ Route::prefix($adminName) Route::middleware('can:products_index')->get('products', [Controllers\ProductController::class, 'index'])->name('products.index'); Route::middleware('can:products_create')->get('products/create', [Controllers\ProductController::class, 'create'])->name('products.create'); Route::middleware('can:products_create')->post('products', [Controllers\ProductController::class, 'store'])->name('products.store'); + Route::middleware('can:products_copy')->post('products/{product}/copy', [Controllers\ProductController::class, 'copy'])->name('products.copy'); Route::middleware('can:products_show')->get('products/{product}/edit', [Controllers\ProductController::class, 'edit'])->name('products.edit'); Route::middleware('can:products_update')->put('products/{product}', [Controllers\ProductController::class, 'update'])->name('products.update'); Route::middleware('can:products_delete')->delete('products/{product}', [Controllers\ProductController::class, 'destroy'])->name('products.destroy'); diff --git a/beike/Admin/Services/ProductService.php b/beike/Admin/Services/ProductService.php index 8143e743..21cc8402 100644 --- a/beike/Admin/Services/ProductService.php +++ b/beike/Admin/Services/ProductService.php @@ -19,6 +19,28 @@ class ProductService return $this->createOrUpdate($product, $data); } + public function copy(Product $oldProduct): Product + { + $product = new Product; + $data = $oldProduct->toArray(); + $data['id'] = 0; + $data['created_at'] = now(); + $data['variables'] = json_encode($data['variables'],JSON_UNESCAPED_UNICODE); + $data['descriptions'] = $oldProduct->descriptions()->get()->toArray(); + foreach ($data['descriptions'] as $locale => $description) { + $data['descriptions'][$description['locale']] = $description; + unset($data['descriptions'][$locale]); + } + $data['attributes'] = $oldProduct->attributes()->get()->toArray(); + $data['skus'] = $oldProduct->skus()->get()->toArray(); + $data['numPrices'] = $oldProduct->numPrices()->get()->toArray(); + $data['categories'] = $oldProduct->categories()->get()->toArray(); + $data['relations'] = $oldProduct->relations()->get()->toArray(); + $data['categories'] = array_column($data['categories'],'id'); + $data['relations'] = array_column($data['relations'],'id'); + return $this->createOrUpdate($product, $data); + } + protected function createOrUpdate(Product $product, array $data): Product { $isUpdating = $product->id > 0; diff --git a/beike/Admin/View/DesignBuilders/SlideShowVideo.php b/beike/Admin/View/DesignBuilders/SlideShowVideo.php new file mode 100644 index 00000000..462ce945 --- /dev/null +++ b/beike/Admin/View/DesignBuilders/SlideShowVideo.php @@ -0,0 +1,45 @@ + + * @created 2022-07-08 17:09:15 + * @modified 2022-07-08 17:09:15 + */ + +namespace Beike\Admin\View\DesignBuilders; + +use Illuminate\Contracts\View\View; +use Illuminate\View\Component; + +class SlideShowVideo extends Component +{ + /** + * Create a new component instance. + * + * @return void + */ + public function __construct() + { + } + + /** + * Get the view / contents that represent the component. + * + * @return View + */ + public function render(): View + { + $data['register'] = [ + 'code' => 'slideshow_video', + 'sort' => 0, + 'name' => trans('admin/design_builder.module_slideshow_video'), + 'icon' => '', + 'style' => 'font-size: 40px;', + ]; + + return view('admin::pages.design.module.slideshow_video', $data); + } +} diff --git a/beike/Models/Product.php b/beike/Models/Product.php index 50c98cb2..8b2ad9af 100644 --- a/beike/Models/Product.php +++ b/beike/Models/Product.php @@ -11,7 +11,7 @@ class Product extends Base use HasFactory; use SoftDeletes; - protected $fillable = ['images', 'video', 'position', 'brand_id', 'tax_class_id', 'weight', 'weight_class', 'active', 'variables', 'price_setting']; + protected $fillable = ['images', 'video', 'position', 'brand_id', 'tax_class_id', 'weight', 'weight_class', 'active', 'variables', 'price_setting', 'length', 'width', 'height']; protected $casts = [ 'active' => 'boolean', diff --git a/beike/Services/DesignService.php b/beike/Services/DesignService.php index 35f3d739..b16134d2 100644 --- a/beike/Services/DesignService.php +++ b/beike/Services/DesignService.php @@ -50,6 +50,8 @@ class DesignService $content['module_code'] = $moduleCode; if ($moduleCode == 'slideshow') { return self::handleSlideShow($content); + } elseif ($moduleCode == 'slideshow_video') { + return self::handleSlideShow($content); } elseif (in_array($moduleCode, ['image401', 'image100', 'image200', 'image300'])) { return self::handleImage401($content); } elseif ($moduleCode == 'brand') { diff --git a/beike/Shop/Http/Resources/ProductSimple.php b/beike/Shop/Http/Resources/ProductSimple.php index 1ae2823f..58ff2d50 100644 --- a/beike/Shop/Http/Resources/ProductSimple.php +++ b/beike/Shop/Http/Resources/ProductSimple.php @@ -31,7 +31,7 @@ class ProductSimple extends JsonResource } $name = $this->description->name ?? ''; - $images = $this->images; + $images = $this->images != NULL ? $this->images : []; $data = [ 'id' => $this->id, diff --git a/resources/beike/admin/views/pages/design/module/slideshow_video.blade.php b/resources/beike/admin/views/pages/design/module/slideshow_video.blade.php new file mode 100644 index 00000000..be5913da --- /dev/null +++ b/resources/beike/admin/views/pages/design/module/slideshow_video.blade.php @@ -0,0 +1,129 @@ + + + + +@push('footer-script') + +@endpush diff --git a/resources/beike/admin/views/pages/products/form/form.blade.php b/resources/beike/admin/views/pages/products/form/form.blade.php index 5ba3409a..f04cbb14 100644 --- a/resources/beike/admin/views/pages/products/form/form.blade.php +++ b/resources/beike/admin/views/pages/products/form/form.blade.php @@ -94,6 +94,14 @@ + +
+
CM X
+
CM X
+
CM
+
+
+
diff --git a/resources/beike/admin/views/pages/products/index.blade.php b/resources/beike/admin/views/pages/products/index.blade.php index 9325b39d..eb69168f 100644 --- a/resources/beike/admin/views/pages/products/index.blade.php +++ b/resources/beike/admin/views/pages/products/index.blade.php @@ -144,6 +144,7 @@ @if ($product['deleted_at'] == '') {{ __('common.edit') }} + {{ __('common.copy') }} {{ __('common.delete') }} @hook('admin.product.list.action') @else @@ -255,6 +256,18 @@ location = bk.objectToUrlParams(this.filter, this.url) }, + copyProduct(index) { + const id = this.productIds[index]; + + this.$confirm('{{ __('common.confirm_copy') }}', '{{ __('common.text_hint') }}', { + type: 'warning' + }).then(() => { + $http.post('products/' + id + '/copy').then((res) => { + this.$message.success(res.message); + location.reload(); + }) + }).catch(()=>{}); + }, deleteProduct(index) { const id = this.productIds[index]; @@ -265,7 +278,7 @@ this.$message.success(res.message); location.reload(); }) - }).catch(()=>{});; + }).catch(()=>{}); }, restoreProduct(index) { diff --git a/resources/lang/en/admin/builder.php b/resources/lang/en/admin/builder.php index 342b2d6c..6af671aa 100644 --- a/resources/lang/en/admin/builder.php +++ b/resources/lang/en/admin/builder.php @@ -49,6 +49,7 @@ return [ 'text_suggested_size' => 'Suggested size (width x height):', 'text_word' => 'Text', 'text_add_pictures' => 'Add pictures', + 'text_add_video' => 'Add video', 'text_refresh_cookie' => 'Refresh Cookie', 'text_popup_hint' => 'Note: When the user clicks close, it will no longer be displayed until the browser is closed and reopened. For local testing, click "Refresh Cookie", then refresh the browser, and the pop-up window can be launched again. ', 'text_cookie_refresh_success' => 'Cookie refresh successfully, refresh the browser to see the content of the pop-up window. ', @@ -197,6 +198,7 @@ return [ 'modules_content' => 'Content', 'modules_edit_content' => 'Edit content', 'modules_select_image' => 'Select image', + 'modules_select_video' => 'Select video', 'modules_quantity_line' => 'Display several in one line', 'modules_please_choose' => 'Please choose', 'modules_choose' => 'Choose', diff --git a/resources/lang/en/admin/design_builder.php b/resources/lang/en/admin/design_builder.php index 3be6e263..149bd2fc 100644 --- a/resources/lang/en/admin/design_builder.php +++ b/resources/lang/en/admin/design_builder.php @@ -14,6 +14,7 @@ return [ 'module_banner' => 'Banner', 'module_four_image_pro' => 'For Image PRO', 'module_slideshow' => 'Slideshow', + 'module_slideshow_video'=> 'SlideshowVideo', 'module_tab_products' => 'Tab Products', 'module_product' => 'Products', 'module_icons' => 'Icons', diff --git a/resources/lang/en/admin/product.php b/resources/lang/en/admin/product.php index 7c748db6..a41d82a7 100644 --- a/resources/lang/en/admin/product.php +++ b/resources/lang/en/admin/product.php @@ -45,6 +45,7 @@ return [ 'default_main_product' => 'Default main product', 'modify_order' => 'Double-click to modify, drag to adjust the order', 'weight_text' => 'weight', + 'length_width_height' => 'Length, width and height', 'weight_class' => 'weight unit', 'confirm_batch_product' => 'Are you sure you want to delete the selected products in batches? ', diff --git a/resources/lang/en/common.php b/resources/lang/en/common.php index b4f71fb5..ea550fb0 100644 --- a/resources/lang/en/common.php +++ b/resources/lang/en/common.php @@ -22,6 +22,7 @@ return [ 'deleted_success' => 'Deleted Successfully!', 'restored_success' => 'Restore Successfully!', 'updated_success' => 'Updated Successfully!', + 'copy_success' => 'Copy Successfully!', 'edit_success' => 'Modify Success!', 'get_success' => 'Get Successfully!', 'all' => 'All', @@ -47,12 +48,14 @@ return [ 'reset' => 'Reset', 'export' => 'Export', 'edit' => 'Edit', + 'copy' => 'Copy', 'action' => 'Action', 'add' => 'Add', 'please_choose' => 'Please Choose', 'recommend_size' => 'Recommend Size', 'pick_datetime' => 'Pick Datetime', 'confirm_delete' => 'You sure you want to delete it?', + 'confirm_copy' => 'You sure you want to copy it?', 'text_hint' => 'Hint', 'restore' => 'Restore', 'name' => 'Name', diff --git a/resources/lang/zh_cn/admin/builder.php b/resources/lang/zh_cn/admin/builder.php index 6c0132dd..8fb24d5f 100644 --- a/resources/lang/zh_cn/admin/builder.php +++ b/resources/lang/zh_cn/admin/builder.php @@ -49,6 +49,7 @@ return [ 'text_suggested_size' => '建议尺寸(宽x高): ', 'text_word' => '文字', 'text_add_pictures' => '添加图片', + 'text_add_video' => '添加视频', 'text_refresh_cookie' => '刷新 Cookie', 'text_popup_hint' => '注:用户点击关闭将不再显示,直到浏览器关闭重新打开。本地测试可点击 "刷新 Cookie",后刷新浏览器,弹窗可再次启动。 ', 'text_cookie_refresh_success' => 'Cookie 刷新成功,刷新浏览器即可看到弹窗内容。', @@ -197,6 +198,7 @@ return [ 'modules_content' => '内容', 'modules_edit_content' => '编辑内容', 'modules_select_image' => '选择图片', + 'modules_select_video' => '选择视频', 'modules_quantity_line' => '一行显示几个', 'modules_please_choose' => '请选择', 'modules_choose' => '选择', diff --git a/resources/lang/zh_cn/admin/design_builder.php b/resources/lang/zh_cn/admin/design_builder.php index 9a91fe5c..92acc4fd 100644 --- a/resources/lang/zh_cn/admin/design_builder.php +++ b/resources/lang/zh_cn/admin/design_builder.php @@ -14,6 +14,7 @@ return [ 'module_banner' => '横幅模块', 'module_four_image_pro' => '一行四图 PRO', 'module_slideshow' => '幻灯片模块', + 'module_slideshow_video'=> '视频模块', 'module_tab_products' => '选项卡商品', 'module_product' => '商品模块', 'module_icons' => '图标模块', diff --git a/resources/lang/zh_cn/admin/product.php b/resources/lang/zh_cn/admin/product.php index a658ab74..e223eb44 100644 --- a/resources/lang/zh_cn/admin/product.php +++ b/resources/lang/zh_cn/admin/product.php @@ -45,6 +45,7 @@ return [ 'default_main_product' => '默认主商品', 'modify_order' => '双击修改、拖动调整顺序', 'weight_text' => '重量', + 'length_width_height' => '长宽高', 'weight_class' => '重量单位', 'confirm_batch_product' => '确认要批量删除选中的商品吗?', diff --git a/resources/lang/zh_cn/common.php b/resources/lang/zh_cn/common.php index 4e83b3ed..388a09f2 100644 --- a/resources/lang/zh_cn/common.php +++ b/resources/lang/zh_cn/common.php @@ -21,6 +21,7 @@ return [ 'deleted_success' => '删除成功!', 'restored_success' => '恢复成功!', 'updated_success' => '更新成功!', + 'copy_success' => '复制成功!', 'edit_success' => '修改成功!', 'get_success' => '获取成功!', 'all' => '全部', @@ -46,12 +47,14 @@ return [ 'reset' => '重置', 'export' => '导出', 'edit' => '编辑', + 'copy' => '复制', 'action' => '操作', 'add' => '添加', 'please_choose' => '请选择', 'recommend_size' => '建议尺寸', 'pick_datetime' => '选择时间', 'confirm_delete' => '确定要删除吗?', + 'confirm_copy' => '确定要复制吗?', 'text_hint' => '提示', 'restore' => '恢复', 'name' => '名称', diff --git a/resources/lang/zh_hk/admin/product.php b/resources/lang/zh_hk/admin/product.php index 4f36f53e..95130ab9 100644 --- a/resources/lang/zh_hk/admin/product.php +++ b/resources/lang/zh_hk/admin/product.php @@ -40,6 +40,7 @@ return [ 'default_main_product' => '默認主商品', 'modify_order' => '雙擊修改、拖動調整順序', 'weight_text' => '重量', + 'length_width_height' => '长宽高', 'weight_class' => '重量單位', 'confirm_batch_product' => '確認要批量刪除選中的商品嗎? ', diff --git a/themes/default/design/slideshow.blade.php b/themes/default/design/slideshow.blade.php index 1908c192..40b41e34 100644 --- a/themes/default/design/slideshow.blade.php +++ b/themes/default/design/slideshow.blade.php @@ -53,4 +53,4 @@ slideshowSwiper(); @endif - \ No newline at end of file + diff --git a/themes/default/design/slideshow_video.blade.php b/themes/default/design/slideshow_video.blade.php new file mode 100644 index 00000000..7919b700 --- /dev/null +++ b/themes/default/design/slideshow_video.blade.php @@ -0,0 +1,61 @@ +@push('header') + + +@endpush + +
+ @include('design._partial._module_tool') + +
+
+
+ @foreach($content['images'] as $image) + + @endforeach +
+
+
+
+
+
+ + +
diff --git a/themes/default/product/product.blade.php b/themes/default/product/product.blade.php index 124e19f2..2d8b3295 100644 --- a/themes/default/product/product.blade.php +++ b/themes/default/product/product.blade.php @@ -10,8 +10,8 @@ - - + + @if ($product['video']) diff --git a/themes/default/shared/product.blade.php b/themes/default/shared/product.blade.php index 099ff868..a766c77e 100644 --- a/themes/default/shared/product.blade.php +++ b/themes/default/shared/product.blade.php @@ -40,7 +40,7 @@ data-bs-placement="top" title="{{ __('shop/products.add_to_cart') }}" @if ($product['price_setting'] === 'num') - onclick="bk.addCart({sku_id: '{{ $product['sku_id'] }}',quantity: {{$product['numprices'][0]['num']}} }, this)"> + onclick="bk.addCart({sku_id: '{{ $product['sku_id'] }}',quantity: {{$product['numprices'] != [] ? $product['numprices'][0]['num'] : 1}} }, this)"> @else onclick="bk.addCart({sku_id: '{{ $product['sku_id'] }}'}, this)"> @endif @@ -71,7 +71,7 @@
@if ($product['price_setting'] === 'num') - {{$product['numprices'][0]['num']}} pieces + {{$product['numprices'] != [] ? $product['numprices'][0]['num'] : 1}} pieces @else 1 pieces @endif