add offers count, & minor fixes code standards
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
use \Cart;
|
||||
|
||||
class ShopCart
|
||||
{
|
||||
@@ -11,8 +12,40 @@ class ShopCart
|
||||
return self::get()->add($data);
|
||||
}
|
||||
|
||||
public static function remove($id)
|
||||
{
|
||||
return self::get()->remove($id);
|
||||
}
|
||||
|
||||
public static function clear()
|
||||
{
|
||||
Cart::session(1)->clear();
|
||||
return Cart::clear();
|
||||
// return self::get()->clear();
|
||||
}
|
||||
|
||||
public static function has($id)
|
||||
{
|
||||
return array_key_exists($id, self::getContent()->toArray());
|
||||
}
|
||||
|
||||
public static function keys()
|
||||
{
|
||||
return array_keys(self::getContent()->toArray());
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return self::getContent()->count();
|
||||
}
|
||||
|
||||
public static function getContent()
|
||||
{
|
||||
return self::get()->getContent();
|
||||
}
|
||||
|
||||
public static function get()
|
||||
{
|
||||
return \Cart::session(Users::getId());
|
||||
return Cart::session(Users::getId());
|
||||
}
|
||||
}
|
||||
|
||||
38
app/Repositories/Core/User/ShopCartStorage.php
Normal file
38
app/Repositories/Core/User/ShopCartStorage.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use Darryldecode\Cart\CartCollection;
|
||||
|
||||
use App\Models\Core\CartStorage;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
|
||||
class ShopCartStorage
|
||||
{
|
||||
public function has($key)
|
||||
{
|
||||
return CartStorage::find($key);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return new CartCollection(CartStorage::find($key)->cart_data);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function put($key, $value)
|
||||
{
|
||||
if ($row = CartStorage::find($key)) {
|
||||
$row->cart_data = $value;
|
||||
$row->save();
|
||||
} else {
|
||||
CartStorage::create([
|
||||
'id' => $key,
|
||||
'cart_data' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user