Improved shop package code style
This commit is contained in:
parent
a4d565e46e
commit
5f6e3be796
|
|
@ -2,40 +2,40 @@
|
|||
|
||||
return [
|
||||
[
|
||||
'key' => 'account',
|
||||
'name' => 'shop::app.layouts.my-account',
|
||||
'key' => 'account',
|
||||
'name' => 'shop::app.layouts.my-account',
|
||||
'route' =>'customer.profile.index',
|
||||
'sort' => 1
|
||||
'sort' => 1
|
||||
], [
|
||||
'key' => 'account.profile',
|
||||
'name' => 'shop::app.layouts.profile',
|
||||
'key' => 'account.profile',
|
||||
'name' => 'shop::app.layouts.profile',
|
||||
'route' =>'customer.profile.index',
|
||||
'sort' => 1
|
||||
'sort' => 1
|
||||
], [
|
||||
'key' => 'account.address',
|
||||
'name' => 'shop::app.layouts.address',
|
||||
'key' => 'account.address',
|
||||
'name' => 'shop::app.layouts.address',
|
||||
'route' =>'customer.address.index',
|
||||
'sort' => 2
|
||||
'sort' => 2
|
||||
], [
|
||||
'key' => 'account.reviews',
|
||||
'name' => 'shop::app.layouts.reviews',
|
||||
'key' => 'account.reviews',
|
||||
'name' => 'shop::app.layouts.reviews',
|
||||
'route' =>'customer.reviews.index',
|
||||
'sort' => 3
|
||||
'sort' => 3
|
||||
], [
|
||||
'key' => 'account.wishlist',
|
||||
'name' => 'shop::app.layouts.wishlist',
|
||||
'key' => 'account.wishlist',
|
||||
'name' => 'shop::app.layouts.wishlist',
|
||||
'route' =>'customer.wishlist.index',
|
||||
'sort' => 4
|
||||
'sort' => 4
|
||||
], [
|
||||
'key' => 'account.orders',
|
||||
'name' => 'shop::app.layouts.orders',
|
||||
'key' => 'account.orders',
|
||||
'name' => 'shop::app.layouts.orders',
|
||||
'route' =>'customer.orders.index',
|
||||
'sort' => 5
|
||||
'sort' => 5
|
||||
], [
|
||||
'key' => 'account.downloadables',
|
||||
'name' => 'shop::app.layouts.downloadable-products',
|
||||
'key' => 'account.downloadables',
|
||||
'name' => 'shop::app.layouts.downloadable-products',
|
||||
'route' =>'customer.downloadable_products.index',
|
||||
'sort' => 6
|
||||
'sort' => 6
|
||||
]
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -34,23 +34,23 @@ class DownloadableProductDataGrid extends DataGrid
|
|||
public function addColumns()
|
||||
{
|
||||
$this->addColumn([
|
||||
'index' => 'increment_id',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.order-id'),
|
||||
'type' => 'string',
|
||||
'index' => 'increment_id',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.order-id'),
|
||||
'type' => 'string',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'product_name',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.name'),
|
||||
'type' => 'string',
|
||||
'index' => 'product_name',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.name'),
|
||||
'type' => 'string',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if ($value->status == 'pending' || $value->status == 'expired') {
|
||||
return $value->product_name;
|
||||
} else {
|
||||
|
|
@ -60,43 +60,45 @@ class DownloadableProductDataGrid extends DataGrid
|
|||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'created_at',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.date'),
|
||||
'type' => 'datetime',
|
||||
'index' => 'created_at',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.date'),
|
||||
'type' => 'datetime',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'status',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.status'),
|
||||
'type' => 'string',
|
||||
'index' => 'status',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.status'),
|
||||
'type' => 'string',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if ($value->status == 'pending')
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if ($value->status == 'pending') {
|
||||
return trans('shop::app.customer.account.downloadable_products.pending');
|
||||
else if ($value->status == 'available')
|
||||
} else if ($value->status == 'available') {
|
||||
return trans('shop::app.customer.account.downloadable_products.available');
|
||||
else if ($value->status == 'expired')
|
||||
} else if ($value->status == 'expired') {
|
||||
return trans('shop::app.customer.account.downloadable_products.expired');
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'remaining_downloads',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.remaining-downloads'),
|
||||
'type' => 'datetime',
|
||||
'index' => 'remaining_downloads',
|
||||
'label' => trans('shop::app.customer.account.downloadable_products.remaining-downloads'),
|
||||
'type' => 'datetime',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => false,
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if (! $value->download_bought)
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if (! $value->download_bought) {
|
||||
return trans('shop::app.customer.account.downloadable_products.unlimited');
|
||||
}
|
||||
|
||||
return $value->remaining_downloads;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ use DB;
|
|||
*/
|
||||
class OrderDataGrid extends DataGrid
|
||||
{
|
||||
protected $index = 'id'; //the column that needs to be treated as index column
|
||||
protected $index = 'id';
|
||||
|
||||
protected $sortOrder = 'desc'; //asc or desc
|
||||
protected $sortOrder = 'desc';
|
||||
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
|
|
@ -29,57 +29,58 @@ class OrderDataGrid extends DataGrid
|
|||
public function addColumns()
|
||||
{
|
||||
$this->addColumn([
|
||||
'index' => 'increment_id',
|
||||
'label' => trans('shop::app.customer.account.order.index.order_id'),
|
||||
'type' => 'string',
|
||||
'index' => 'increment_id',
|
||||
'label' => trans('shop::app.customer.account.order.index.order_id'),
|
||||
'type' => 'string',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'created_at',
|
||||
'label' => trans('shop::app.customer.account.order.index.date'),
|
||||
'type' => 'datetime',
|
||||
'index' => 'created_at',
|
||||
'label' => trans('shop::app.customer.account.order.index.date'),
|
||||
'type' => 'datetime',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'grand_total',
|
||||
'label' => trans('shop::app.customer.account.order.index.total'),
|
||||
'type' => 'number',
|
||||
'index' => 'grand_total',
|
||||
'label' => trans('shop::app.customer.account.order.index.total'),
|
||||
'type' => 'number',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
'wrapper' => function ($value) {
|
||||
'wrapper' => function ($value) {
|
||||
return core()->formatPrice($value->grand_total, $value->order_currency_code);
|
||||
}
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'status',
|
||||
'label' => trans('shop::app.customer.account.order.index.status'),
|
||||
'type' => 'string',
|
||||
'index' => 'status',
|
||||
'label' => trans('shop::app.customer.account.order.index.status'),
|
||||
'type' => 'string',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if ($value->status == 'processing')
|
||||
'sortable' => true,
|
||||
'closure' => true,
|
||||
'wrapper' => function ($value) {
|
||||
if ($value->status == 'processing') {
|
||||
return '<span class="badge badge-md badge-success">Processing</span>';
|
||||
else if ($value->status == 'completed')
|
||||
} else if ($value->status == 'completed') {
|
||||
return '<span class="badge badge-md badge-success">Completed</span>';
|
||||
else if ($value->status == "canceled")
|
||||
} else if ($value->status == "canceled") {
|
||||
return '<span class="badge badge-md badge-danger">Canceled</span>';
|
||||
else if ($value->status == "closed")
|
||||
} else if ($value->status == "closed") {
|
||||
return '<span class="badge badge-md badge-info">Closed</span>';
|
||||
else if ($value->status == "pending")
|
||||
} else if ($value->status == "pending") {
|
||||
return '<span class="badge badge-md badge-warning">Pending</span>';
|
||||
else if ($value->status == "pending_payment")
|
||||
} else if ($value->status == "pending_payment") {
|
||||
return '<span class="badge badge-md badge-warning">Pending Payment</span>';
|
||||
else if ($value->status == "fraud")
|
||||
} else if ($value->status == "fraud") {
|
||||
return '<span class="badge badge-md badge-danger">Fraud</span>';
|
||||
}
|
||||
},
|
||||
'filterable' => true
|
||||
]);
|
||||
|
|
@ -87,10 +88,10 @@ class OrderDataGrid extends DataGrid
|
|||
|
||||
public function prepareActions() {
|
||||
$this->addAction([
|
||||
'type' => 'View',
|
||||
'type' => 'View',
|
||||
'method' => 'GET',
|
||||
'route' => 'customer.orders.view',
|
||||
'icon' => 'icon eye-icon'
|
||||
'route' => 'customer.orders.view',
|
||||
'icon' => 'icon eye-icon'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -83,8 +83,9 @@ class CartController extends Controller
|
|||
if ($result instanceof CartModel) {
|
||||
session()->flash('success', trans('shop::app.checkout.cart.item.success'));
|
||||
|
||||
if ($customer = auth()->guard('customer')->user())
|
||||
if ($customer = auth()->guard('customer')->user()) {
|
||||
$this->wishlistRepository->deleteWhere(['product_id' => $id, 'customer_id' => $customer->id]);
|
||||
}
|
||||
|
||||
if (request()->get('is_buy_now')) {
|
||||
Event::dispatch('shop.item.buy-now', $id);
|
||||
|
|
@ -112,8 +113,9 @@ class CartController extends Controller
|
|||
{
|
||||
$result = Cart::removeItem($itemId);
|
||||
|
||||
if ($result)
|
||||
if ($result) {
|
||||
session()->flash('success', trans('shop::app.checkout.cart.item.success-remove'));
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
|
@ -128,8 +130,9 @@ class CartController extends Controller
|
|||
try {
|
||||
$result = Cart::updateItems(request()->all());
|
||||
|
||||
if ($result)
|
||||
if ($result) {
|
||||
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
session()->flash('error', trans($e->getMessage()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,12 +55,13 @@ class DownloadableProductController extends Controller
|
|||
public function download($id)
|
||||
{
|
||||
$downloadableLinkPurchased = $this->downloadableLinkPurchasedRepository->findOneByField([
|
||||
'id' => $id,
|
||||
'id' => $id,
|
||||
'customer_id' => auth()->guard('customer')->user()->id,
|
||||
]);
|
||||
|
||||
if ($downloadableLinkPurchased->status == 'pending')
|
||||
if ($downloadableLinkPurchased->status == 'pending') {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if ($downloadableLinkPurchased->download_bought
|
||||
&& ($downloadableLinkPurchased->download_bought - $downloadableLinkPurchased->download_used) <= 0) {
|
||||
|
|
@ -74,7 +75,7 @@ class DownloadableProductController extends Controller
|
|||
if ($downloadableLinkPurchased->download_bought) {
|
||||
$this->downloadableLinkPurchasedRepository->update([
|
||||
'download_used' => $downloadableLinkPurchased->download_used + 1,
|
||||
'status' => $remainingDownloads <= 0 ? 'expired' : $downloadableLinkPurchased->status
|
||||
'status' => $remainingDownloads <= 0 ? 'expired' : $downloadableLinkPurchased->status
|
||||
], $downloadableLinkPurchased->id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,10 +114,11 @@ class OnepageController extends Controller
|
|||
Cart::collectTotals();
|
||||
|
||||
if ($cart->haveStockableItems()) {
|
||||
if (! $rates = Shipping::collectRates())
|
||||
if (! $rates = Shipping::collectRates()) {
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
else
|
||||
} else {
|
||||
return response()->json($rates);
|
||||
}
|
||||
} else {
|
||||
return response()->json(Payment::getSupportedPaymentMethods());
|
||||
}
|
||||
|
|
@ -133,8 +134,9 @@ class OnepageController extends Controller
|
|||
{
|
||||
$shippingMethod = request()->get('shipping_method');
|
||||
|
||||
if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
|
||||
if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod)) {
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
|
|
@ -150,8 +152,9 @@ class OnepageController extends Controller
|
|||
{
|
||||
$payment = request()->get('payment');
|
||||
|
||||
if (Cart::hasError() || ! $payment || ! Cart::savePaymentMethod($payment))
|
||||
if (Cart::hasError() || ! $payment || ! Cart::savePaymentMethod($payment)) {
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
|
|
@ -159,7 +162,7 @@ class OnepageController extends Controller
|
|||
|
||||
return response()->json([
|
||||
'jump_to_section' => 'review',
|
||||
'html' => view('shop::checkout.onepage.review', compact('cart'))->render()
|
||||
'html' => view('shop::checkout.onepage.review', compact('cart'))->render()
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -170,8 +173,9 @@ class OnepageController extends Controller
|
|||
*/
|
||||
public function saveOrder()
|
||||
{
|
||||
if (Cart::hasError())
|
||||
if (Cart::hasError()) {
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
|
|
@ -181,7 +185,7 @@ class OnepageController extends Controller
|
|||
|
||||
if ($redirectUrl = Payment::getRedirectUrl($cart)) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'success' => true,
|
||||
'redirect_url' => $redirectUrl
|
||||
]);
|
||||
}
|
||||
|
|
@ -204,8 +208,9 @@ class OnepageController extends Controller
|
|||
*/
|
||||
public function success()
|
||||
{
|
||||
if (! $order = session('order'))
|
||||
if (! $order = session('order')) {
|
||||
return redirect()->route('shop.checkout.cart.index');
|
||||
}
|
||||
|
||||
return view($this->_config['view'], compact('order'));
|
||||
}
|
||||
|
|
@ -219,17 +224,21 @@ class OnepageController extends Controller
|
|||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if ($cart->haveStockableItems() && ! $cart->shipping_address)
|
||||
if ($cart->haveStockableItems() && ! $cart->shipping_address) {
|
||||
throw new \Exception(trans('Please check shipping address.'));
|
||||
}
|
||||
|
||||
if (! $cart->billing_address)
|
||||
if (! $cart->billing_address) {
|
||||
throw new \Exception(trans('Please check billing address.'));
|
||||
}
|
||||
|
||||
if ($cart->haveStockableItems() && ! $cart->selected_shipping_rate)
|
||||
if ($cart->haveStockableItems() && ! $cart->selected_shipping_rate) {
|
||||
throw new \Exception(trans('Please specify shipping method.'));
|
||||
}
|
||||
|
||||
if (! $cart->payment)
|
||||
if (! $cart->payment) {
|
||||
throw new \Exception(trans('Please specify payment method.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,8 +252,9 @@ class OnepageController extends Controller
|
|||
'email' => request()->email
|
||||
]);
|
||||
|
||||
if (! is_null($customer))
|
||||
if (! is_null($customer)) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
return 'false';
|
||||
}
|
||||
|
|
@ -260,8 +270,9 @@ class OnepageController extends Controller
|
|||
'email' => 'required|email'
|
||||
]);
|
||||
|
||||
if (! auth()->guard('customer')->attempt(request(['email', 'password'])))
|
||||
if (! auth()->guard('customer')->attempt(request(['email', 'password']))) {
|
||||
return response()->json(['error' => trans('shop::app.customer.login-form.invalid-creds')]);
|
||||
}
|
||||
|
||||
Cart::mergeCart();
|
||||
|
||||
|
|
@ -289,13 +300,13 @@ class OnepageController extends Controller
|
|||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('shop::app.checkout.total.coupon-applied'),
|
||||
'result' => $result
|
||||
'result' => $result
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('shop::app.checkout.total.cannot-apply-coupon'),
|
||||
'result' => null
|
||||
'result' => null
|
||||
], 422);
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +328,7 @@ class OnepageController extends Controller
|
|||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('admin::app.promotion.status.coupon-removed'),
|
||||
'data' => [
|
||||
'data' => [
|
||||
'grand_total' => core()->currency(Cart::getCart()->grand_total)
|
||||
]
|
||||
], 200);
|
||||
|
|
@ -325,7 +336,7 @@ class OnepageController extends Controller
|
|||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('admin::app.promotion.status.coupon-remove-failed'),
|
||||
'data' => null
|
||||
'data' => null
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,11 +70,12 @@ class OrderController extends Controller
|
|||
{
|
||||
$order = $this->orderRepository->findOneWhere([
|
||||
'customer_id' => auth()->guard('customer')->user()->id,
|
||||
'id' => $id
|
||||
'id' => $id
|
||||
]);
|
||||
|
||||
if (! $order)
|
||||
if (! $order) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return view($this->_config['view'], compact('order'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,9 +98,9 @@ class ProductController extends Controller
|
|||
if (request('type') == 'link') {
|
||||
$productDownloadableLink = $this->productDownloadableLinkRepository->findOrFail(request('id'));
|
||||
|
||||
if ($productDownloadableLink->sample_type == 'file')
|
||||
if ($productDownloadableLink->sample_type == 'file') {
|
||||
return Storage::download($productDownloadableLink->sample_file);
|
||||
else {
|
||||
} else {
|
||||
$fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1);
|
||||
|
||||
$tempImage = tempnam(sys_get_temp_dir(), $fileName);
|
||||
|
|
@ -112,9 +112,9 @@ class ProductController extends Controller
|
|||
} else {
|
||||
$productDownloadableSample = $this->productDownloadableSampleRepository->findOrFail(request('id'));
|
||||
|
||||
if ($productDownloadableSample->type == 'file')
|
||||
if ($productDownloadableSample->type == 'file') {
|
||||
return Storage::download($productDownloadableSample->file);
|
||||
else {
|
||||
} else {
|
||||
$fileName = $name = substr($productDownloadableSample->url, strrpos($productDownloadableSample->url, '/') + 1);
|
||||
|
||||
$tempImage = tempnam(sys_get_temp_dir(), $fileName);
|
||||
|
|
|
|||
|
|
@ -115,12 +115,13 @@ class ReviewController extends Controller
|
|||
public function destroy($id)
|
||||
{
|
||||
$review = $this->productReviewRepository->findOneWhere([
|
||||
'id' => $id,
|
||||
'id' => $id,
|
||||
'customer_id' => auth()->guard('customer')->user()->id
|
||||
]);
|
||||
|
||||
if (! $review)
|
||||
if (! $review) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$this->productReviewRepository->delete($id);
|
||||
|
||||
|
|
|
|||
|
|
@ -78,10 +78,10 @@ class SubscriptionController extends Controller
|
|||
|
||||
if ($mailSent) {
|
||||
$result = $this->subscriptionRepository->create([
|
||||
'email' => $email,
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'email' => $email,
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'is_subscribed' => 1,
|
||||
'token' => $token
|
||||
'token' => $token
|
||||
]);
|
||||
|
||||
if (! $result) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue