¨4.0.1¨
This commit is contained in:
@@ -5,10 +5,14 @@ namespace Modules\Compare;
|
||||
use JsonSerializable;
|
||||
use Modules\Product\Entities\Product;
|
||||
use Darryldecode\Cart\Cart as DarryldecodeCart;
|
||||
use Darryldecode\Cart\Exceptions\InvalidItemException;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
|
||||
class Compare extends DarryldecodeCart implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @throws InvalidItemException
|
||||
*/
|
||||
public function store($productId)
|
||||
{
|
||||
$product = Product::with('files', 'attributes.attribute')
|
||||
@@ -25,15 +29,12 @@ class Compare extends DarryldecodeCart implements JsonSerializable
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function hasAnyProduct()
|
||||
{
|
||||
return $this->products()->isNotEmpty();
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->products()->count();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
@@ -42,11 +43,19 @@ class Compare extends DarryldecodeCart implements JsonSerializable
|
||||
});
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->products()->flatMap->attributes->unique('name');
|
||||
return new EloquentCollection($this->session->get($this->sessionKeyCartItems));
|
||||
}
|
||||
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->products()->count();
|
||||
}
|
||||
|
||||
|
||||
public function relatedProducts()
|
||||
{
|
||||
return $this->products()->load(['relatedProducts' => function ($query) {
|
||||
@@ -54,17 +63,20 @@ class Compare extends DarryldecodeCart implements JsonSerializable
|
||||
}])->pluck('relatedProducts')->flatten();
|
||||
}
|
||||
|
||||
|
||||
public function list()
|
||||
{
|
||||
return $this->products()->pluck('id');
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return new EloquentCollection($this->session->get($this->sessionKeyCartItems));
|
||||
return json_encode($this->jsonSerialize());
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'products' => $this->products(),
|
||||
@@ -72,8 +84,9 @@ class Compare extends DarryldecodeCart implements JsonSerializable
|
||||
];
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return json_encode($this->jsonSerialize());
|
||||
return $this->products()->flatMap->attributes->unique('name');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,37 +3,43 @@
|
||||
namespace Modules\Compare\Http\Controllers;
|
||||
|
||||
use Modules\Compare\Compare;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class CompareController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Modules\Compare\Compare $compare
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Compare $compare
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(Compare $compare)
|
||||
{
|
||||
return view('public.compare.index', compact('compare'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Modules\Compare\Compare $compare
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Compare $compare
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Compare $compare)
|
||||
{
|
||||
$compare->store(request('productId'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $productId
|
||||
* @param \Modules\Compare\Compare $compare
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Compare $compare
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($productId, Compare $compare)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
namespace Modules\Compare\Http\Controllers;
|
||||
|
||||
use Modules\Compare\Compare;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class CompareRelatedProductController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Modules\Compare\Compare $compare
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Compare $compare
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index(Compare $compare)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user