Add product view tracking and related functionality
- Implemented product view tracking in ProductController to log user views. - Added a relationship for viewed products in the User model. - Introduced a method in ProductRepository to filter products viewed by a user. - Updated API routes to include endpoint for retrieving viewed products. - Commented out SMS notification logic in SendOrderCreatedNotification. - Removed CreateOrderServiceTest as it is no longer needed.
This commit is contained in:
1 parent
dee6b0df56
commit
968c9ed42a
11 files changed
+319
-86
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Ecommerce\Product\ProductView;
|
||||
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ProductView extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected $table = 'product_views';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'product_id',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Product
|
||||
*/
|
||||
public function product(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
use App\Models\Ecommerce\Product\Cart\CartItem;
|
||||
use App\Models\Ecommerce\Product\Favorite\Favorite;
|
||||
use App\Models\Ecommerce\Product\Order\Order;
|
||||
use App\Models\Ecommerce\Product\ProductView\ProductView;
|
||||
use App\Models\Ecommerce\Product\Review\Review;
|
||||
use App\Models\Post\User\UserDoc;
|
||||
use App\Models\System\Settings\Location\UserAddress;
|
||||
@@ -128,6 +129,14 @@ public function favorites(): HasMany
|
||||
return $this->hasMany(Favorite::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* User's viewed products
|
||||
*/
|
||||
public function productViews(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProductView::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* User's favorite products
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user