fixed product sku
This commit is contained in:
parent
336e4ae2d6
commit
464b2e5d77
|
|
@ -39,6 +39,11 @@ class Product extends Model
|
|||
return $this->hasMany(ProductSku::class);
|
||||
}
|
||||
|
||||
public function master_sku()
|
||||
{
|
||||
return $this->hasOne(ProductSku::Class)->where('is_default', 1);
|
||||
}
|
||||
|
||||
public function getPriceFormattedAttribute(): string
|
||||
{
|
||||
return '$' . $this->price;
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@
|
|||
namespace Beike\Shop\Http\Controllers;
|
||||
|
||||
use Beike\Models\Product;
|
||||
use Beike\Shop\Repositories\ProductRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function show(Request $request, Product $product)
|
||||
{
|
||||
$product->load('description', 'skus');
|
||||
$product = ProductRepo::getProductDetail($product);
|
||||
|
||||
$data = [
|
||||
'product' => $product,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,20 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
|
||||
class ProductRepo
|
||||
{
|
||||
/**
|
||||
* 获取产品详情
|
||||
*/
|
||||
public static function getProductDetail($product)
|
||||
{
|
||||
if (is_int($product)) {
|
||||
$product = Product::query()->findOrFail($product);
|
||||
}
|
||||
$product->load('description', 'skus', 'master_sku');
|
||||
dd($product);
|
||||
return $product;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过多个产品分类获取产品列表
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue