相关商品功能
This commit is contained in:
parent
c5da315a30
commit
6e8d7f295f
|
|
@ -117,6 +117,7 @@ class ProductController extends Controller
|
|||
'descriptions' => $descriptions ?? [],
|
||||
'category_ids' => $categoryIds ?? [],
|
||||
'product_attributes' => ProductAttributeResource::collection($product->attributes),
|
||||
'relations' => ProductResource::collection($product->relations)->resource,
|
||||
'languages' => LanguageRepo::all(),
|
||||
'tax_classes' => TaxClassRepo::getList(),
|
||||
'source' => [
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ class ProductService
|
|||
$product->skus()->createMany($skus);
|
||||
|
||||
$product->categories()->sync($data['categories'] ?? []);
|
||||
$product->relations()->sync($data['relations'] ?? []);
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ class Product extends Base
|
|||
return $this->belongsTo(Brand::Class, 'brand_id', 'id');
|
||||
}
|
||||
|
||||
public function relations()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, ProductRelation::class, 'product_id', 'relation_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function inCurrentWishlist()
|
||||
{
|
||||
$customer = current_customer();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* ProductRelation.php
|
||||
*
|
||||
* @copyright 2022 beikeshop.com - All Rights Reserved
|
||||
* @link https://beikeshop.com
|
||||
* @author TL <mengwb@guangda.work>
|
||||
* @created 2022-12-30 11:04:40
|
||||
* @modified 2022-12-30 11:04:40
|
||||
*/
|
||||
|
||||
namespace Beike\Models;
|
||||
|
||||
class ProductRelation extends Base
|
||||
{
|
||||
protected $table = 'product_relations';
|
||||
protected $fillable = ['product_id', 'relation_id'];
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasMany(Product::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ class ProductRepo
|
|||
if (is_int($product)) {
|
||||
$product = Product::query()->findOrFail($product);
|
||||
}
|
||||
$product->load('description', 'skus', 'master_sku', 'brand');
|
||||
$product->load('description', 'skus', 'master_sku', 'brand', 'relations');
|
||||
return $product;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,11 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function show(Request $request, Product $product)
|
||||
{
|
||||
$relationIds = $product->relations->pluck('id')->toArray();
|
||||
$product = ProductRepo::getProductDetail($product);
|
||||
$data = [
|
||||
'product' => (new ProductDetail($product))->jsonSerialize(),
|
||||
'relations' => ProductRepo::getProductsByIds($relationIds)->jsonSerialize(),
|
||||
];
|
||||
$data = hook_filter('product.show', $data);
|
||||
return view('product', $data);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('product_relations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('product_id')->comment('商品 ID')->index('product_id');
|
||||
$table->unsignedInteger('relation_id')->comment('关联商品 ID')->index('relation_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('product_relations');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* dd.php
|
||||
*
|
||||
* @copyright 2022 beikeshop.com - All Rights Reserved
|
||||
* @link https://beikeshop.com
|
||||
* @author TL <mengwb@guangda.work>
|
||||
* @created 2022-12-27 16:19:06
|
||||
* @modified 2022-12-27 16:19:06
|
||||
*/
|
||||
|
||||
return [
|
||||
'merchant_id' => 'Merchant ID',
|
||||
'lianlianpay_public_key' => 'Lianlian Public-Key',
|
||||
'merchant_secret_key' => 'Merchant Secret Key',
|
||||
'test' => 'Test Mode',
|
||||
|
||||
'system_error' => 'system error',
|
||||
'customer_has_restrictions' => 'you has restrictions to perform exchange operation',
|
||||
'annual_limit_exceeded' => 'you has exceeded the annual limit. for you to continue shopping, send proof of income to request limit increase ',
|
||||
'boleto_limit_exceeded' => 'boleto_limit_exceeded ',
|
||||
'fx_transaction_limit_exceeded' => 'fx_transaction_limit_exceeded',
|
||||
'payment_completed' => 'payment_completed',
|
||||
'payment_closed' => 'payment_closed ',
|
||||
'refund_amount_exceeded' => 'the refund amount can not be greater than the amount of the order previously paid ',
|
||||
'non_refundable_order' => 'the current order status does not allow a refund',
|
||||
'refund_already_requested' => 'the refund of this order has already been requested.',
|
||||
'insufficient_balance' => 'merchant does not have enough balance for this operation ',
|
||||
];
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* dd.php
|
||||
*
|
||||
* @copyright 2022 beikeshop.com - All Rights Reserved
|
||||
* @link https://beikeshop.com
|
||||
* @author TL <mengwb@guangda.work>
|
||||
* @created 2022-12-27 16:19:06
|
||||
* @modified 2022-12-27 16:19:06
|
||||
*/
|
||||
|
||||
return [
|
||||
'merchant_id' => '商户ID',
|
||||
'lianlianpay_public_key' => '连连公钥',
|
||||
'merchant_secret_key' => '商户私钥',
|
||||
'test' => '测试模式',
|
||||
|
||||
'system_error' => 'system error',
|
||||
'customer_has_restrictions' => 'you has restrictions to perform exchange operation',
|
||||
'annual_limit_exceeded' => 'you has exceeded the annual limit. for you to continue shopping, send proof of income to request limit increase ',
|
||||
'boleto_limit_exceeded' => 'boleto_limit_exceeded ',
|
||||
'fx_transaction_limit_exceeded' => 'fx_transaction_limit_exceeded',
|
||||
'payment_completed' => 'payment_completed',
|
||||
'payment_closed' => 'payment_closed ',
|
||||
'refund_amount_exceeded' => 'the refund amount can not be greater than the amount of the order previously paid ',
|
||||
'non_refundable_order' => 'the current order status does not allow a refund',
|
||||
'refund_already_requested' => 'the refund of this order has already been requested.',
|
||||
'insufficient_balance' => 'merchant does not have enough balance for this operation ',
|
||||
];
|
||||
Loading…
Reference in New Issue