[WIP] Finish the order process
This commit is contained in:
@@ -12,13 +12,21 @@ class CustomersDataTable extends DataTable
|
||||
|
||||
public function query(Customer $model)
|
||||
{
|
||||
$model = $model->with('addresses');
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('company')->title('Société'),
|
||||
Column::make('last_name')->title('Nom'),
|
||||
Column::make('first_name')->title('Prénom'),
|
||||
Column::make('address')->title('Adresse'),
|
||||
Column::make('zipcode')->title('Code postal'),
|
||||
Column::make('city')->title('Ville'),
|
||||
Column::make('phone')->title('Téléphone'),
|
||||
Column::make('email')->title('Email'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class CustomerController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data['customer'] = Customers::edit($id);
|
||||
dump($data['customer']);
|
||||
exit;
|
||||
$data['deliveries'] = Deliveries::getOptions();
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Admin.Shop.Customers.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class LoginController extends Controller
|
||||
|
||||
if ($this->guard()->attempt($credentials, $request->get('remember'))) {
|
||||
$request->session()->regenerate();
|
||||
return (back()->getTargetUrl() == route('Shop.login')) ? redirect()->intended(route('home')) : back();
|
||||
return (back()->getTargetUrl() == route('Shop.login')) ? redirect()->intended(route('home')) : back();
|
||||
}
|
||||
return back()->withInput($request->only('email', 'remember'));
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ class CustomerController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
public function profile($id)
|
||||
public function profile($id = false)
|
||||
{
|
||||
//
|
||||
return view('Shop.Profile.profile');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,29 @@ class OrderController extends Controller
|
||||
{
|
||||
public function order()
|
||||
{
|
||||
$data['customer'] = Customers::getWithAddresses();
|
||||
$data['customer'] = Customers::getWithAddresses()->toArray();
|
||||
$data['basket'] = ShopCart::getSummary();
|
||||
$data['deliveries'] = Deliveries::getAllWithSaleChannel()->toArray();
|
||||
$data['sale_channel'] = SaleChannels::getDefault();
|
||||
$data['sale_channel'] = SaleChannels::getDefault()->toArray();
|
||||
return view('Shop.Orders.order', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$data['customer_id'] = Customers::getId();
|
||||
$data['basket'] = ShopCart::getSummary();
|
||||
dump($data);
|
||||
exit;
|
||||
$order = Orders::saveOrder($data);
|
||||
if ($order) {
|
||||
if (intval($data['payment']) === 1) {
|
||||
return redirect('Shop.Payments.online');
|
||||
} else {
|
||||
return redirect('Shop.Orders.confirmed');
|
||||
}
|
||||
} else {
|
||||
return view('Shop.Orders.order');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class Delivery extends Model
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_deliveries';
|
||||
|
||||
public function Customers()
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ class Order extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function Customer()
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function Payments()
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(OrderPayment::class);
|
||||
}
|
||||
|
||||
15
app/Models/Shop/OrderDetail.php
Normal file
15
app/Models/Shop/OrderDetail.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderDetail extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class OrderPayment extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function Order()
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
@@ -283,36 +283,7 @@ class Articles
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags.tag_group')->findOrFail($id);
|
||||
$product_type = $article->product_type;
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => Species::getDescription($article->product->specie_id),
|
||||
'tags' => Species::getTags($article->product->specie_id),
|
||||
];
|
||||
$data[] = [
|
||||
'name' => 'Variétés',
|
||||
'description' => $article->product->description,
|
||||
'tags' => $article->product->tags->toArray()
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => $article->product->description,
|
||||
'tags' => $article->product->tags->toArray()
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data[] = [
|
||||
'name' => 'Marchandise',
|
||||
'description' => $article->product->description,
|
||||
'tags' => $article->product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $data ?? [];
|
||||
return self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
}
|
||||
|
||||
public static function getInheritedByProduct($product_id, $product_type)
|
||||
|
||||
@@ -29,10 +29,11 @@ class Customers
|
||||
$name = $customer->first_name . ' ' . $customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
$ret = $avatar->create($name)
|
||||
->setBackground($bgColor)
|
||||
->setBorder(1, '#29292e')
|
||||
->setBackground('#F2B90F')
|
||||
->setForeground('#335012')
|
||||
->setBorder(1, '#28a745')
|
||||
->setFontFamily('Roboto Condensed')
|
||||
->setDimension(40)
|
||||
->setDimension(36)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
return $ret;
|
||||
@@ -42,7 +43,7 @@ class Customers
|
||||
{
|
||||
$path = storage_path(self::getStorage());
|
||||
if (File::checkDirOrCreate($path)) {
|
||||
$filename = $path . 'user-' . $customer->uuid . '.png';
|
||||
$filename = $path . self::getAvatarFilename($customer);
|
||||
}
|
||||
return $filename ?? false;
|
||||
}
|
||||
@@ -55,58 +56,44 @@ class Customers
|
||||
public static function getAddresses($id = false)
|
||||
{
|
||||
$customer = self::getWithAddresses($id);
|
||||
return $customer ? $customer->addresses : false;
|
||||
}
|
||||
|
||||
public static function getWithAddresses($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return Customer::with('addresses')->find($id);
|
||||
return self::get($id, 'addresses');
|
||||
}
|
||||
|
||||
public static function getName()
|
||||
public static function getName($id = false)
|
||||
{
|
||||
$user = self::getAuth();
|
||||
return $user ? $user->first_name : '';
|
||||
$user = $id ? self::get($id) : self::getAuth();
|
||||
return $user ? $user->first_name . ' ' . $user->last_name : '';
|
||||
}
|
||||
|
||||
public static function getAuth()
|
||||
{
|
||||
return Auth::guard('customer')->user();
|
||||
return self::guard()->user();
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return Auth::guard('customer')->id();
|
||||
return self::guard()->id();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return Auth::guard('customer')->check();
|
||||
return self::guard()->check();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
public static function get($id = false, $relations = false)
|
||||
{
|
||||
return Customer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Customer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Customer::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Customer::find($id);
|
||||
$id = $id ? $id : self::getId();
|
||||
return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$customer = Customer::with(['addresses'])->find($id);
|
||||
$customer = self::get($id, 'addresses');
|
||||
$data = $customer->toArray();
|
||||
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
|
||||
return $data;
|
||||
@@ -126,9 +113,7 @@ class Customers
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function storeDeliveries($customer, $deliveries)
|
||||
@@ -166,7 +151,7 @@ class Customers
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Customer::destroy($id);
|
||||
}
|
||||
@@ -182,4 +167,9 @@ class Customers
|
||||
$path = '/storage/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
}
|
||||
|
||||
public static function guard()
|
||||
{
|
||||
return Auth::guard('customer');
|
||||
}
|
||||
}
|
||||
|
||||
46
app/Repositories/Shop/OrderDetails.php
Normal file
46
app/Repositories/Shop/OrderDetails.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\OrderDetail;
|
||||
|
||||
class OrderDetails
|
||||
{
|
||||
|
||||
public static function saveBasket($order_id, $data)
|
||||
{
|
||||
foreach ($data as $item) {
|
||||
$item['order_id'] = $order_id;
|
||||
$detail = self::store($item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return $relations ? OrderDetail::with($relations)->findOrFail($id) : OrderDetail::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return OrderDetail::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
return OrderDetail::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -6,31 +6,23 @@ use App\Models\Shop\Order;
|
||||
|
||||
class Orders
|
||||
{
|
||||
public static function getOptions()
|
||||
|
||||
public static function saveOrder($data)
|
||||
{
|
||||
return Order::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
$basket = $data['basket'];
|
||||
unset($data['basket']);
|
||||
$order = self::store($data);
|
||||
return $order ? OrderDetails::saveBasket($order->id, $basket) : false;
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return Order::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Order::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Order::findOrFail($id);
|
||||
return $relations ? Order::with($relations)->findOrFail($id) : Order::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -46,7 +38,7 @@ class Orders
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Order::destroy($id);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class TagGroups
|
||||
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
|
||||
if (!$tag['articles_count']) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
@@ -72,8 +72,7 @@ class TagGroups
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user