Merge pull request #6630 from jitendra-webkul/master

Optimized and refactored code
This commit is contained in:
Jitendra Singh 2022-08-18 14:02:05 +05:30 committed by GitHub
commit b31edf4bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
246 changed files with 1646 additions and 2248 deletions

13
config/.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
db-blade-compiler.php
debugbar.php
dompdf.php
excel.php
flare.php
ignition.php
image.php
imagecache.php
jwt.php
repository.php
scout.php
tinker.php
translatable.php

View File

@ -146,7 +146,7 @@ class AddressDataGrid extends DataGrid
'sortable' => true,
'searchable' => false,
'closure' => function ($row) {
if ($row->default_address == 1) {
if ($row->default_address) {
return '<span class="badge badge-md badge-success"">' . trans('admin::app.customers.addresses.yes') . '</span>';
} else {
return trans('admin::app.customers.addresses.dash');

View File

@ -89,7 +89,7 @@ class AttributeDataGrid extends DataGrid
'sortable' => true,
'searchable' => false,
'closure' => function ($value) {
if ($value->is_required == 1) {
if ($value->is_required) {
return trans('admin::app.datagrid.true');
} else {
return trans('admin::app.datagrid.false');
@ -105,7 +105,7 @@ class AttributeDataGrid extends DataGrid
'searchable' => false,
'filterable' => true,
'closure' => function ($value) {
if ($value->is_unique == 1) {
if ($value->is_unique) {
return trans('admin::app.datagrid.true');
} else {
return trans('admin::app.datagrid.false');
@ -121,7 +121,7 @@ class AttributeDataGrid extends DataGrid
'searchable' => false,
'filterable' => true,
'closure' => function ($value) {
if ($value->value_per_locale == 1) {
if ($value->value_per_locale) {
return trans('admin::app.datagrid.true');
} else {
return trans('admin::app.datagrid.false');
@ -137,7 +137,7 @@ class AttributeDataGrid extends DataGrid
'searchable' => false,
'filterable' => true,
'closure' => function ($value) {
if ($value->value_per_channel == 1) {
if ($value->value_per_channel) {
return trans('admin::app.datagrid.true');
} else {
return trans('admin::app.datagrid.false');

View File

@ -77,7 +77,7 @@ class CampaignDataGrid extends DataGrid
'sortable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 1) {
if ($value->status) {
return trans('admin::app.datagrid.active');
} else {
return trans('admin::app.datagrid.inactive');

View File

@ -86,7 +86,7 @@ class CartRuleCouponsDataGrid extends DataGrid
'sortable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->end_other_rules == 1) {
if ($value->end_other_rules) {
return trans('admin::app.datagrid.true');
} else {
return trans('admin::app.datagrid.false');

View File

@ -88,7 +88,7 @@ class CatalogRuleDataGrid extends DataGrid
'sortable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 1) {
if ($value->status) {
return trans('admin::app.datagrid.active');
} else {
return trans('admin::app.datagrid.inactive');

View File

@ -128,7 +128,7 @@ class CategoryDataGrid extends DataGrid
'searchable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 1) {
if ($value->status) {
return trans('admin::app.datagrid.active');
} else {
return trans('admin::app.datagrid.inactive');

View File

@ -161,7 +161,7 @@ class CategoryProductDataGrid extends DataGrid
'searchable' => false,
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 1) {
if ($value->status) {
return trans('admin::app.datagrid.active');
} else {
return trans('admin::app.datagrid.inactive');

View File

@ -145,13 +145,13 @@ class CustomerDataGrid extends DataGrid
'closure' => function ($row) {
$html = '';
if ($row->status == 1) {
if ($row->status) {
$html .= '<span class="badge badge-md badge-success">' . trans('admin::app.customers.customers.active') . '</span>';
} else {
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.customers.customers.inactive') . '</span>';
}
if ($row->is_suspended == 1) {
if ($row->is_suspended) {
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.customers.customers.suspended') . '</span>';
}

View File

@ -86,7 +86,7 @@ class InventorySourcesDataGrid extends DataGrid
'sortable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 1) {
if ($value->status) {
return trans('admin::app.datagrid.active');
} else {
return trans('admin::app.datagrid.inactive');

View File

@ -59,7 +59,7 @@ class NewsLetterDataGrid extends DataGrid
'sortable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->status === 1) {
if ($value->status) {
return trans('admin::app.datagrid.true');
} else {
return trans('admin::app.datagrid.false');

View File

@ -204,7 +204,7 @@ class ProductDataGrid extends DataGrid
'closure' => function ($value) {
$html = '';
if ($value->status == 1) {
if ($value->status) {
$html .= '<span class="badge badge-md badge-success">' . trans('admin::app.datagrid.active') . '</span>';
} else {
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.datagrid.inactive') . '</span>';

View File

@ -81,7 +81,7 @@ class UserDataGrid extends DataGrid
'sortable' => true,
'filterable' => true,
'closure' => function ($value) {
if ($value->status == 1) {
if ($value->status) {
return trans('admin::app.datagrid.active');
} else {
return trans('admin::app.datagrid.inactive');

View File

@ -79,6 +79,7 @@ class ConfigurationController extends Controller
{
if (! request()->route('slug')) {
$firstItem = current($this->configTree->items);
$secondItem = current($firstItem['children']);
return $this->getSlugs($secondItem);
@ -109,6 +110,7 @@ class ConfigurationController extends Controller
foreach ($data['sales']['carriers'] as $carrier) {
if ($carrier['active']) {
$atLeastOneCarrierEnabled = true;
break;
}
}

View File

@ -2,6 +2,7 @@
namespace Webkul\Admin\Http\Controllers\Customer;
use Illuminate\Support\Facades\Event;
use Webkul\Customer\Rules\VatIdRule;
use Webkul\Admin\DataGrids\AddressDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
@ -73,8 +74,6 @@ class AddressController extends Controller
'address1' => implode(PHP_EOL, array_filter(request()->input('address1'))),
]);
$data = collect(request()->input())->except('_token')->toArray();
$this->validate(request(), [
'company_name' => 'string',
'address1' => 'string|required',
@ -86,15 +85,15 @@ class AddressController extends Controller
'vat_id' => new VatIdRule(),
]);
if ($this->customerAddressRepository->create($data)) {
session()->flash('success', trans('admin::app.customers.addresses.success-create'));
Event::dispatch('customer.addresses.create.before');
return redirect()->route('admin.customer.edit', ['id' => $data['customer_id']]);
} else {
session()->flash('success', trans('admin::app.customers.addresses.error-create'));
$customerAddress = $this->customerAddressRepository->create(request()->all());
return redirect()->back();
}
Event::dispatch('customer.addresses.create.after', $customerAddress);
session()->flash('success', trans('admin::app.customers.addresses.success-create'));
return redirect()->route('admin.customer.edit', ['id' => request('customer_id')]);
}
/**
@ -131,18 +130,15 @@ class AddressController extends Controller
'vat_id' => new VatIdRule(),
]);
$data = collect(request()->input())->except('_token')->toArray();
Event::dispatch('customer.addresses.update.before', $id);
$address = $this->customerAddressRepository->find($id);
$customerAddress = $this->customerAddressRepository->update(request()->all(), $id);
if ($address) {
$this->customerAddressRepository->update($data, $id);
Event::dispatch('customer.addresses.update.after', $customerAddress);
session()->flash('success', trans('admin::app.customers.addresses.success-update'));
session()->flash('success', trans('admin::app.customers.addresses.success-update'));
return redirect()->route('admin.customer.addresses.index', ['id' => $address->customer_id]);
}
return redirect()->route($this->_config['redirect']);
return redirect()->route('admin.customer.addresses.index', ['id' => $customerAddress->customer_id]);
}
/**
@ -153,11 +149,15 @@ class AddressController extends Controller
*/
public function destroy($id)
{
Event::dispatch('customer.addresses.delete.before', $id);
$this->customerAddressRepository->delete($id);
Event::dispatch('customer.addresses.delete.after', $id);
return response()->json([
'redirect' => false,
'message' => trans('admin::app.customers.addresses.success-delete')
'message' => trans('admin::app.customers.addresses.success-delete')
]);
}
@ -172,7 +172,11 @@ class AddressController extends Controller
$addressIds = explode(',', request()->input('indexes'));
foreach ($addressIds as $addressId) {
Event::dispatch('customer.addresses.delete.before', $addressId);
$this->customerAddressRepository->delete($addressId);
Event::dispatch('customer.addresses.delete.after', $addressId);
}
session()->flash('success', trans('admin::app.customers.addresses.success-mass-delete'));

View File

@ -2,14 +2,13 @@
namespace Webkul\Admin\Http\Controllers\Customer;
use Mail;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Webkul\Admin\DataGrids\CustomerDataGrid;
use Webkul\Admin\DataGrids\CustomerOrderDataGrid;
use Webkul\Admin\DataGrids\CustomersInvoicesDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Mail\NewCustomerNotification;
use Webkul\Core\Repositories\ChannelRepository;
use Webkul\Customer\Repositories\CustomerAddressRepository;
use Webkul\Customer\Repositories\CustomerGroupRepository;
use Webkul\Customer\Repositories\CustomerRepository;
@ -26,15 +25,11 @@ class CustomerController extends Controller
* Create a new controller instance.
*
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
* @param \Webkul\Customer\Repositories\CustomerAddressRepository $customerAddressRepository
* @param \Webkul\Customer\Repositories\CustomerGroupRepository $customerGroupRepository
* @param \Webkul\Core\Repositories\ChannelRepository $channelRepository
*/
public function __construct(
protected CustomerRepository $customerRepository,
protected CustomerAddressRepository $customerAddressRepository,
protected CustomerGroupRepository $customerGroupRepository,
protected ChannelRepository $channelRepository
protected CustomerGroupRepository $customerGroupRepository
)
{
$this->_config = request('_config');
@ -61,11 +56,9 @@ class CustomerController extends Controller
*/
public function create()
{
$customerGroup = $this->customerGroupRepository->findWhere([['code', '<>', 'guest']]);
$groups = $this->customerGroupRepository->findWhere([['code', '<>', 'guest']]);
$channelName = $this->channelRepository->all();
return view($this->_config['view'], compact('customerGroup', 'channelName'));
return view($this->_config['view'], compact('groups'));
}
/**
@ -83,18 +76,20 @@ class CustomerController extends Controller
'date_of_birth' => 'date|before:today',
]);
$data = request()->all();
$password = rand(100000, 10000000);
$data['password'] = bcrypt($password);
Event::dispatch('customer.registration.before');
$data['is_verified'] = 1;
$customer = $this->customerRepository->create(array_merge(request()->all() , [
'password' => bcrypt($password),
'is_verified' => 1,
]));
$customer = $this->customerRepository->create($data);
Event::dispatch('customer.registration.after', $customer);
try {
$configKey = 'emails.general.notifications.emails.general.notifications.customer';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewCustomerNotification($customer, $password));
}
@ -116,11 +111,10 @@ class CustomerController extends Controller
public function edit($id)
{
$customer = $this->customerRepository->findOrFail($id);
$address = $this->customerAddressRepository->find($id);
$customerGroup = $this->customerGroupRepository->findWhere([['code', '<>', 'guest']]);
$channelName = $this->channelRepository->all();
return view($this->_config['view'], compact('customer', 'address', 'customerGroup', 'channelName'));
$groups = $this->customerGroupRepository->findWhere([['code', '<>', 'guest']]);
return view($this->_config['view'], compact('customer', 'groups'));
}
/**
@ -139,13 +133,14 @@ class CustomerController extends Controller
'date_of_birth' => 'date|before:today',
]);
$data = request()->all();
Event::dispatch('customer.update.before', $id);
$data['status'] = ! isset($data['status']) ? 0 : 1;
$customer = $this->customerRepository->update(array_merge(request()->all(), [
'status' => request()->has('status'),
'is_suspended' => request()->has('is_suspended'),
]), $id);
$data['is_suspended'] = ! isset($data['is_suspended']) ? 0 : 1;
$this->customerRepository->update($data, $id);
Event::dispatch('customer.update.after', $customer);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Customer']));
@ -199,15 +194,15 @@ class CustomerController extends Controller
'notes' => 'string|nullable',
]);
$customer = $this->customerRepository->find(request()->input('_customer'));
Event::dispatch('customer.update.before', request()->input('_customer'));
$noteTaken = $customer->update(['notes' => request()->input('notes')]);
$customer = $this->customerRepository->update([
'notes' => request()->input('notes'),
], request()->input('_customer'));
if ($noteTaken) {
session()->flash('success', 'Note taken');
} else {
session()->flash('error', 'Note cannot be taken');
}
Event::dispatch('customer.update.after', $customer);
session()->flash('success', 'Note taken');
return redirect()->route($this->_config['redirect']);
}
@ -220,12 +215,17 @@ class CustomerController extends Controller
public function massUpdate()
{
$customerIds = explode(',', request()->input('indexes'));
$updateOption = request()->input('update-options');
foreach ($customerIds as $customerId) {
$customer = $this->customerRepository->find($customerId);
Event::dispatch('customer.update.before', $customerId);
$customer->update(['status' => $updateOption]);
$customer = $this->customerRepository->update([
'status' => $updateOption,
], $customerId);
Event::dispatch('customer.update.after', $customer);
}
session()->flash('success', trans('admin::app.customers.customers.mass-update-success'));
@ -243,9 +243,12 @@ class CustomerController extends Controller
$customerIds = explode(',', request()->input('indexes'));
if (! $this->customerRepository->checkBulkCustomerIfTheyHaveOrderPendingOrProcessing($customerIds)) {
foreach ($customerIds as $customerId) {
$this->customerRepository->deleteWhere(['id' => $customerId]);
Event::dispatch('customer.delete.before', $customerId);
$this->customerRepository->delete($customerId);
Event::dispatch('customer.delete.after', $customerId);
}
session()->flash('success', trans('admin::app.customers.customers.mass-destroy-success'));
@ -254,6 +257,7 @@ class CustomerController extends Controller
}
session()->flash('error', trans('admin::app.response.order-pending', ['name' => 'Customers']));
return redirect()->back();
}

View File

@ -2,6 +2,7 @@
namespace Webkul\Admin\Http\Controllers\Customer;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\CustomerGroupDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Customer\Repositories\CustomerGroupRepository;
@ -62,11 +63,13 @@ class CustomerGroupController extends Controller
'name' => 'required',
]);
$data = request()->all();
Event::dispatch('customer.customer_group.create.before');
$data['is_user_defined'] = 1;
$customerGroup = $this->customerGroupRepository->create(array_merge(request()->all() , [
'is_user_defined' => 1,
]));
$this->customerGroupRepository->create($data);
Event::dispatch('customer.customer_group.create.after', $customerGroup);
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Customer Group']));
@ -99,7 +102,11 @@ class CustomerGroupController extends Controller
'name' => 'required',
]);
$this->customerGroupRepository->update(request()->all(), $id);
Event::dispatch('customer.customer_group.update.before', $id);
$customerGroup = $this->customerGroupRepository->update(request()->all(), $id);
Event::dispatch('customer.customer_group.update.after', $customerGroup);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Customer Group']));
@ -116,21 +123,25 @@ class CustomerGroupController extends Controller
{
$customerGroup = $this->customerGroupRepository->findOrFail($id);
if ($customerGroup->is_user_defined == 0) {
if (! $customerGroup->is_user_defined) {
return response()->json([
'message' => trans('admin::app.customers.customers.group-default'),
], 400);
}
if (count($customerGroup->customers) > 0) {
if ($customerGroup->customers->count()) {
return response()->json([
'message' => trans('admin::app.response.customer-associate', ['name' => 'Customer Group']),
], 400);
}
try {
Event::dispatch('customer.customer_group.delete.before', $id);
$this->customerGroupRepository->delete($id);
Event::dispatch('customer.customer_group.delete.after', $id);
return response()->json(['message' => trans('admin::app.response.delete-success', ['name' => 'Customer Group'])]);
} catch (\Exception $e) {}

View File

@ -20,9 +20,7 @@ class ExportController extends Controller
$gridName = explode('\\', $criteria['gridName']);
$path = '\Webkul\Admin\DataGrids' . '\\' . last($gridName);
$gridInstance = app($path);
$gridInstance = app('\Webkul\Admin\DataGrids' . '\\' . last($gridName));
$records = $gridInstance->export();
@ -34,9 +32,7 @@ class ExportController extends Controller
if ($format == 'csv') {
return Excel::download(new DataGridExport($records), last($gridName) . '.csv');
}
if ($format == 'xls') {
} elseif ($format == 'xls') {
return Excel::download(new DataGridExport($records), last($gridName) . '.xlsx');
}

View File

@ -99,21 +99,21 @@ class InvoiceController extends Controller
'invoice.items.*' => 'required|numeric|min:0',
]);
$data = request()->all();
if (! $this->invoiceRepository->haveProductToInvoice($data)) {
if (! $this->invoiceRepository->haveProductToInvoice(request()->all())) {
session()->flash('error', trans('admin::app.sales.invoices.product-error'));
return redirect()->back();
}
if (! $this->invoiceRepository->isValidQuantity($data)) {
if (! $this->invoiceRepository->isValidQuantity(request()->all())) {
session()->flash('error', trans('admin::app.sales.invoices.invalid-qty'));
return redirect()->back();
}
$this->invoiceRepository->create(array_merge($data, ['order_id' => $orderId]));
$this->invoiceRepository->create(array_merge(request()->all(), [
'order_id' => $orderId,
]));
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Invoice']));
@ -148,15 +148,9 @@ class InvoiceController extends Controller
$invoice = $this->invoiceRepository->findOrFail($id);
if ($invoice) {
$this->sendDuplicateInvoiceMail($invoice, $request->email);
$this->sendDuplicateInvoiceMail($invoice, $request->email);
session()->flash('success', __('admin::app.sales.invoices.invoice-sent'));
return redirect()->back();
}
session()->flash('error', __('admin::app.response.something-went-wrong'));
session()->flash('success', trans('admin::app.sales.invoices.invoice-sent'));
return redirect()->back();
}

View File

@ -86,15 +86,12 @@ class OrderController extends Controller
*/
public function comment($id)
{
$data = array_merge(request()->all(), [
'order_id' => $id,
]);
Event::dispatch('sales.order.comment.create.before');
$data['customer_notified'] = isset($data['customer_notified']) ? 1 : 0;
Event::dispatch('sales.order.comment.create.before', $data);
$comment = $this->orderCommentRepository->create($data);
$comment = $this->orderCommentRepository->create(array_merge(request()->all(), [
'order_id' => $id,
'customer_notified' => request()->has('customer_notified'),
]));
Event::dispatch('sales.order.comment.create.after', $comment);

View File

@ -96,7 +96,9 @@ class ShipmentController extends Controller
return redirect()->back();
}
$this->shipmentRepository->create(array_merge($data, ['order_id' => $orderId]));
$this->shipmentRepository->create(array_merge($data, [
'order_id' => $orderId,
]));
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Shipment']));
@ -141,7 +143,10 @@ class ShipmentController extends Controller
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
if ($child->qty_to_ship < $finalQty || $availableQty < $finalQty) {
if (
$child->qty_to_ship < $finalQty
|| $availableQty < $finalQty
) {
return false;
}
}
@ -150,7 +155,10 @@ class ShipmentController extends Controller
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
if ($orderItem->qty_to_ship < $qty || $availableQty < $qty) {
if (
$orderItem->qty_to_ship < $qty
|| $availableQty < $qty
) {
return false;
}
}

View File

@ -5,6 +5,8 @@ namespace Webkul\Admin\Listeners;
use Illuminate\Support\Facades\Mail;
use Webkul\User\Notifications\AdminUpdatePassword;
use Webkul\Customer\Notifications\CustomerUpdatePassword;
use Webkul\Customer\Models\Customer;
use Webkul\User\Models\Admin;
class PasswordChange
{
@ -17,11 +19,9 @@ class PasswordChange
public function sendUpdatePasswordMail($adminOrCustomer)
{
try {
if ($adminOrCustomer instanceof \Webkul\Customer\Models\Customer) {
if ($adminOrCustomer instanceof Customer) {
Mail::queue(new CustomerUpdatePassword($adminOrCustomer));
}
if ($adminOrCustomer instanceof \Webkul\User\Models\Admin) {
} elseif ($adminOrCustomer instanceof Admin) {
Mail::queue(new AdminUpdatePassword($adminOrCustomer));
}
} catch (\Exception $e) {

View File

@ -21,8 +21,8 @@ class CancelOrderAdminNotification extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to(core()->getAdminEmailDetails()['email'])
->subject(trans('shop::app.mail.order.cancel.subject'))
->view('shop::emails.sales.order-cancel-admin');
->to(core()->getAdminEmailDetails()['email'])
->subject(trans('shop::app.mail.order.cancel.subject'))
->view('shop::emails.sales.order-cancel-admin');
}
}

View File

@ -22,8 +22,8 @@ class CancelOrderNotification extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($this->order->customer_email, $this->order->customer_full_name)
->subject(trans('shop::app.mail.order.cancel.subject'))
->view('shop::emails.sales.order-cancel');
->to($this->order->customer_email, $this->order->customer_full_name)
->subject(trans('shop::app.mail.order.cancel.subject'))
->view('shop::emails.sales.order-cancel');
}
}

View File

@ -21,7 +21,8 @@ class DuplicateInvoiceNotification extends Mailable
public $invoice,
public $customerEmail
)
{}
{
}
/**
* Build the message.

View File

@ -16,12 +16,15 @@ class InvoiceOverdueReminder extends Mailable
*
* @param \Webkul\Customer\Contracts\Customer $customer
* @param \Webkul\Sales\Contracts\Invoice $invoice
* @return void
*/
public function __construct(
public $customer,
public $invoice
)
{}
{
}
/**
* Build the message.
@ -31,8 +34,11 @@ class InvoiceOverdueReminder extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($this->customer->email)
->subject(trans('shop::app.mail.invoice.reminder.subject'))
->view('shop::emails.customer.invoice-reminder')->with(['customer' => $this->customer, 'invoice' => $this->invoice]);
->to($this->customer->email)
->subject(trans('shop::app.mail.invoice.reminder.subject'))
->view('shop::emails.customer.invoice-reminder')->with([
'customer' => $this->customer,
'invoice' => $this->invoice,
]);
}
}

View File

@ -29,8 +29,8 @@ class NewAdminNotification extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to(core()->getAdminEmailDetails()['email'])
->subject(trans('shop::app.mail.order.subject'))
->view('shop::emails.sales.new-admin-order');
->to(core()->getAdminEmailDetails()['email'])
->subject(trans('shop::app.mail.order.subject'))
->view('shop::emails.sales.new-admin-order');
}
}

View File

@ -33,8 +33,11 @@ class NewCustomerNotification extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($this->customer->email)
->subject(trans('shop::app.mail.customer.new.subject'))
->view('shop::emails.customer.new-customer')->with(['customer' => $this->customer, 'password' => $this->password]);
->to($this->customer->email)
->subject(trans('shop::app.mail.customer.new.subject'))
->view('shop::emails.customer.new-customer')->with([
'customer' => $this->customer,
'password' => $this->password,
]);
}
}

View File

@ -33,8 +33,8 @@ class NewInventorySourceNotification extends Mailable
$inventory = $this->shipment->inventory_source;
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($inventory->contact_email, $inventory->name)
->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-inventorysource-shipment');
->to($inventory->contact_email, $inventory->name)
->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-inventorysource-shipment');
}
}

View File

@ -31,8 +31,8 @@ class NewInvoiceNotification extends Mailable
$order = $this->invoice->order;
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($order->customer_email, $order->customer_full_name)
->subject(trans('shop::app.mail.invoice.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-invoice');
->to($order->customer_email, $order->customer_full_name)
->subject(trans('shop::app.mail.invoice.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-invoice');
}
}

View File

@ -29,8 +29,8 @@ class NewOrderNotification extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($this->order->customer_email, $this->order->customer_full_name)
->subject(trans('shop::app.mail.order.subject'))
->view('shop::emails.sales.new-order');
->to($this->order->customer_email, $this->order->customer_full_name)
->subject(trans('shop::app.mail.order.subject'))
->view('shop::emails.sales.new-order');
}
}

View File

@ -31,8 +31,8 @@ class NewRefundNotification extends Mailable
$order = $this->refund->order;
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($order->customer_email, $order->customer_full_name)
->subject(trans('shop::app.mail.refund.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-refund');
->to($order->customer_email, $order->customer_full_name)
->subject(trans('shop::app.mail.refund.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-refund');
}
}

View File

@ -31,8 +31,8 @@ class NewShipmentNotification extends Mailable
$order = $this->shipment->order;
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($order->customer_email, $order->customer_full_name)
->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-shipment');
->to($order->customer_email, $order->customer_full_name)
->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id]))
->view('shop::emails.sales.new-shipment');
}
}

View File

@ -29,8 +29,8 @@ class OrderCommentNotification extends Mailable
public function build()
{
return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name'])
->to($this->comment->order->customer_email, $this->comment->order->customer_full_name)
->subject(trans('shop::app.mail.order.comment.subject', ['order_id' => $this->comment->order->increment_id]))
->view('shop::emails.sales.new-order-comment');
->to($this->comment->order->customer_email, $this->comment->order->customer_full_name)
->subject(trans('shop::app.mail.order.comment.subject', ['order_id' => $this->comment->order->increment_id]))
->view('shop::emails.sales.new-order-comment');
}
}

View File

@ -105,13 +105,15 @@ class AdminServiceProvider extends ServiceProvider
&& substr_count($item['key'], '.') == 1
) {
foreach ($allowedPermissions as $key => $value) {
if ($item['key'] == $value) {
$neededItem = $allowedPermissions[$key + 1];
if ($item['key'] != $value) {
continue;
}
foreach (config('menu.admin') as $key1 => $findMatced) {
if ($findMatced['key'] == $neededItem) {
$item['route'] = $findMatced['route'];
}
$neededItem = $allowedPermissions[$key + 1];
foreach (config('menu.admin') as $key1 => $findMatced) {
if ($findMatced['key'] == $neededItem) {
$item['route'] = $findMatced['route'];
}
}
}

View File

@ -240,7 +240,7 @@
<script>
var groups = @json($attributeFamily ? $attributeFamily->attribute_groups : []);
var custom_attributes = @json($custom_attributes);
var custom_attributes = @json($customAttributes);
Vue.component('group-list', {

View File

@ -237,7 +237,7 @@
<script>
var groups = @json($attributeFamily->attribute_groups);
var custom_attributes = @json($custom_attributes);
var custom_attributes = @json($customAttributes);
Vue.component('group-list', {

View File

@ -89,7 +89,7 @@
<div class="control-group">
<label for="customerGroup" >{{ __('admin::app.customers.customers.customer_group') }}</label>
<select class="control" id="customerGroup" name="customer_group_id">
@foreach ($customerGroup as $group)
@foreach ($groups as $group)
<option value="{{ $group->id }}"> {{ $group->name}} </>
@endforeach
</select>

View File

@ -168,7 +168,7 @@
@endif
<select class="control" id="customerGroup" name="customer_group_id">
@foreach ($customerGroup as $group)
@foreach ($groups as $group)
<option value="{{ $group->id }}" {{ $selectedCustomerOption == $group->id ? 'selected' : '' }}>
{{ $group->name}}
</option>

View File

@ -2,6 +2,7 @@
namespace Webkul\Attribute\Http\Controllers;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\AttributeDataGrid;
use Webkul\Attribute\Repositories\AttributeRepository;
@ -62,11 +63,13 @@ class AttributeController extends Controller
'type' => 'required',
]);
$data = request()->all();
Event::dispatch('catalog.attribute.create.before');
$data['is_user_defined'] = 1;
$attribute = $this->attributeRepository->create(array_merge(request()->all(), [
'is_user_defined' => 1,
]));
$this->attributeRepository->create($data);
Event::dispatch('catalog.attribute.create.after', $attribute);
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Attribute']));
@ -113,7 +116,11 @@ class AttributeController extends Controller
'type' => 'required',
]);
$this->attributeRepository->update(request()->all(), $id);
Event::dispatch('catalog.attribute.update.before', $id);
$attribute = $this->attributeRepository->update(request()->all(), $id);
Event::dispatch('catalog.attribute.update.after', $attribute);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Attribute']));
@ -137,8 +144,12 @@ class AttributeController extends Controller
}
try {
Event::dispatch('catalog.attribute.delete.before', $id);
$this->attributeRepository->delete($id);
Event::dispatch('catalog.attribute.delete.after', $id);
return response()->json(['message' => trans('admin::app.response.delete-success', ['name' => 'Attribute'])]);
} catch (\Exception $e) {}
@ -166,16 +177,18 @@ class AttributeController extends Controller
}
foreach ($indexes as $index) {
Event::dispatch('catalog.attribute.delete.before', $index);
$this->attributeRepository->delete($index);
Event::dispatch('catalog.attribute.delete.after', $index);
}
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success', ['resource' => 'attributes']));
return redirect()->back();
} else {
session()->flash('error', trans('admin::app.datagrid.mass-ops.method-error'));
return redirect()->back();
}
return redirect()->back();
}
}

View File

@ -2,6 +2,7 @@
namespace Webkul\Attribute\Http\Controllers;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\AttributeFamilyDataGrid;
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
use Webkul\Attribute\Repositories\AttributeRepository;
@ -53,9 +54,9 @@ class AttributeFamilyController extends Controller
{
$attributeFamily = $this->attributeFamilyRepository->with(['attribute_groups.custom_attributes'])->findOneByField('code', 'default');
$custom_attributes = $this->attributeRepository->all(['id', 'code', 'admin_name', 'type']);
$customAttributes = $this->attributeRepository->all(['id', 'code', 'admin_name', 'type']);
return view($this->_config['view'], compact('custom_attributes', 'attributeFamily'));
return view($this->_config['view'], compact('attributeFamily', 'customAttributes'));
}
/**
@ -70,8 +71,12 @@ class AttributeFamilyController extends Controller
'name' => 'required',
]);
Event::dispatch('catalog.attribute_family.create.before');
$attributeFamily = $this->attributeFamilyRepository->create(request()->all());
Event::dispatch('catalog.attribute_family.create.after', $attributeFamily);
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Family']));
return redirect()->route($this->_config['redirect']);
@ -87,9 +92,9 @@ class AttributeFamilyController extends Controller
{
$attributeFamily = $this->attributeFamilyRepository->with(['attribute_groups.custom_attributes'])->findOrFail($id, ['*']);
$custom_attributes = $this->attributeRepository->all(['id', 'code', 'admin_name', 'type']);
$customAttributes = $this->attributeRepository->all(['id', 'code', 'admin_name', 'type']);
return view($this->_config['view'], compact('attributeFamily', 'custom_attributes'));
return view($this->_config['view'], compact('attributeFamily', 'customAttributes'));
}
/**
@ -105,8 +110,12 @@ class AttributeFamilyController extends Controller
'name' => 'required',
]);
Event::dispatch('catalog.attribute_family.update.before', $id);
$attributeFamily = $this->attributeFamilyRepository->update(request()->all(), $id);
Event::dispatch('catalog.attribute_family.update.after', $attributeFamily);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Family']));
return redirect()->route($this->_config['redirect']);
@ -135,8 +144,12 @@ class AttributeFamilyController extends Controller
}
try {
Event::dispatch('catalog.attribute_family.delete.before', $id);
$this->attributeFamilyRepository->delete($id);
Event::dispatch('catalog.attribute_family.delete.after', $id);
return response()->json([
'message' => trans('admin::app.response.delete-success', ['name' => 'Family']),
]);
@ -161,9 +174,13 @@ class AttributeFamilyController extends Controller
if (request()->isMethod('delete')) {
$indexes = explode(',', request()->input('indexes'));
foreach ($indexes as $key => $value) {
foreach ($indexes as $index) {
try {
$this->attributeFamilyRepository->delete($value);
Event::dispatch('catalog.attribute_family.delete.before', $index);
$this->attributeFamilyRepository->delete($index);
Event::dispatch('catalog.attribute_family.delete.after', $index);
} catch (\Exception $e) {
report($e);
$suppressFlash = true;

View File

@ -56,8 +56,8 @@ class Attribute extends TranslatableModel implements AttributeContract
public function scopeFilterableAttributes(Builder $query): Builder
{
return $query->where('is_filterable', 1)
->where('swatch_type', '<>', 'image')
->orderBy('position');
->where('swatch_type', '<>', 'image')
->orderBy('position');
}
/**

View File

@ -27,10 +27,10 @@ class AttributeFamily extends Model implements AttributeFamilyContract
public function custom_attributes()
{
return (AttributeProxy::modelClass())::join('attribute_group_mappings', 'attributes.id', '=', 'attribute_group_mappings.attribute_id')
->join('attribute_groups', 'attribute_group_mappings.attribute_group_id', '=', 'attribute_groups.id')
->join('attribute_families', 'attribute_groups.attribute_family_id', '=', 'attribute_families.id')
->where('attribute_families.id', $this->id)
->select('attributes.*');
->join('attribute_groups', 'attribute_group_mappings.attribute_group_id', '=', 'attribute_groups.id')
->join('attribute_families', 'attribute_groups.attribute_family_id', '=', 'attribute_families.id')
->where('attribute_families.id', $this->id)
->select('attributes.*');
}

View File

@ -17,7 +17,7 @@ class AttributeGroup extends Model implements AttributeGroupContract
public function custom_attributes()
{
return $this->belongsToMany(AttributeProxy::modelClass(), 'attribute_group_mappings')
->withPivot('position')
->orderBy('pivot_position', 'asc');
->withPivot('position')
->orderBy('pivot_position', 'asc');
}
}

View File

@ -2,37 +2,37 @@
namespace Webkul\Attribute\Repositories;
use Illuminate\Container\Container;
use Illuminate\Support\Str;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Support\Facades\Event;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Attribute\Repositories\AttributeGroupRepository;
use Illuminate\Container\Container as App;
use Illuminate\Support\Str;
class AttributeFamilyRepository extends Repository
{
/**
* Create a new controller instance.
* Create a new repository instance.
*
* @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
* @param \Webkul\Attribute\Repositories\AttributeGroupRepository $attributeGroupRepository
* @param \Illuminate\Container\Container $container
* @return void
*/
public function __construct(
protected AttributeRepository $attributeRepository,
protected AttributeGroupRepository $attributeGroupRepository,
App $app
Container $container
)
{
parent::__construct($app);
parent::__construct($container);
}
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Attribute\Contracts\AttributeFamily';
}
@ -43,8 +43,6 @@ class AttributeFamilyRepository extends Repository
*/
public function create(array $data)
{
Event::dispatch('catalog.attribute_family.create.before');
$attributeGroups = isset($data['attribute_groups']) ? $data['attribute_groups'] : [];
unset($data['attribute_groups']);
@ -69,8 +67,6 @@ class AttributeFamilyRepository extends Repository
}
}
Event::dispatch('catalog.attribute_family.create.after', $family);
return $family;
}
@ -84,8 +80,6 @@ class AttributeFamilyRepository extends Repository
{
$family = $this->find($id);
Event::dispatch('catalog.attribute_family.update.before', $id);
$family->update($data);
$previousAttributeGroupIds = $family->attribute_groups()->pluck('id');
@ -136,8 +130,6 @@ class AttributeFamilyRepository extends Repository
$this->attributeGroupRepository->delete($attributeGroupId);
}
Event::dispatch('catalog.attribute_family.update.after', $family);
return $family;
}
@ -166,17 +158,4 @@ class AttributeFamilyRepository extends Repository
return $trimmed;
}
/**
* @param int $id
* @return void
*/
public function delete($id)
{
Event::dispatch('catalog.attribute_family.delete.before', $id);
parent::delete($id);
Event::dispatch('catalog.attribute_family.delete.after', $id);
}
}

View File

@ -10,9 +10,9 @@ class AttributeGroupRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Attribute\Contracts\AttributeGroup';
}

View File

@ -10,9 +10,9 @@ class AttributeOptionRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Attribute\Contracts\AttributeOption';
}

View File

@ -6,13 +6,12 @@ use Webkul\Core\Eloquent\Repository;
class AttributeOptionTranslationRepository extends Repository
{
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Attribute\Contracts\AttributeOptionTranslation';
}

View File

@ -2,8 +2,7 @@
namespace Webkul\Attribute\Repositories;
use Illuminate\Container\Container as App;
use Illuminate\Support\Facades\Event;
use Illuminate\Container\Container;
use Webkul\Attribute\Repositories\AttributeOptionRepository;
use Webkul\Core\Eloquent\Repository;
@ -13,22 +12,23 @@ class AttributeRepository extends Repository
* Create a new repository instance.
*
* @param \Webkul\Attribute\Repositories\AttributeOptionRepository $attributeOptionRepository
* @param \Illuminate\Container\Container $container
* @return void
*/
public function __construct(
protected AttributeOptionRepository $attributeOptionRepository,
App $app
Container $container
)
{
parent::__construct($app);
parent::__construct($container);
}
/**
* Specify model class name.
*
* @return mixed
* @return string
*/
public function model()
public function model(): string
{
return 'Webkul\Attribute\Contracts\Attribute';
}
@ -41,8 +41,6 @@ class AttributeRepository extends Repository
*/
public function create(array $data)
{
Event::dispatch('catalog.attribute.create.before');
$data = $this->validateUserInput($data);
$options = isset($data['options']) ? $data['options'] : [];
@ -62,8 +60,6 @@ class AttributeRepository extends Repository
}
}
Event::dispatch('catalog.attribute.create.after', $attribute);
return $attribute;
}
@ -81,23 +77,21 @@ class AttributeRepository extends Repository
$attribute = $this->find($id);
Event::dispatch('catalog.attribute.update.before', $id);
$data['enable_wysiwyg'] = ! isset($data['enable_wysiwyg']) ? 0 : 1;
$data['enable_wysiwyg'] = isset($data['enable_wysiwyg']);
$attribute->update($data);
if (in_array($attribute->type, ['select', 'multiselect', 'checkbox'])) {
if (isset($data['options'])) {
foreach ($data['options'] as $optionId => $optionInputs) {
$isNew = $optionInputs['isNew'] == 'true' ? true : false;
$isNew = $optionInputs['isNew'] == 'true';
if ($isNew) {
$this->attributeOptionRepository->create(array_merge([
'attribute_id' => $attribute->id,
], $optionInputs));
} else {
$isDelete = $optionInputs['isDelete'] == 'true' ? true : false;
$isDelete = $optionInputs['isDelete'] == 'true';
if ($isDelete) {
$this->attributeOptionRepository->delete($optionId);
@ -109,26 +103,9 @@ class AttributeRepository extends Repository
}
}
Event::dispatch('catalog.attribute.update.after', $attribute);
return $attribute;
}
/**
* Delete attribute.
*
* @param int $id
* @return void
*/
public function delete($id)
{
Event::dispatch('catalog.attribute.delete.before', $id);
parent::delete($id);
Event::dispatch('catalog.attribute.delete.after', $id);
}
/**
* Validate user input.
*
@ -260,29 +237,18 @@ class AttributeRepository extends Repository
foreach ($attributes as $key => $attribute) {
if (
$attribute->code != 'tax_category_id'
&& ($attribute->type == 'select'
|| $attribute->type == 'multiselect'
|| $attribute->code == 'sku')
&& (
in_array($attribute->type ,['select', 'multiselect'])
|| $attribute->code == 'sku'
)
) {
if ($attribute->options()->exists()) {
array_push($trimmed, [
'id' => $attribute->id,
'name' => $attribute->admin_name,
'type' => $attribute->type,
'code' => $attribute->code,
'has_options' => true,
'options' => $attribute->options,
]);
} else {
array_push($trimmed, [
'id' => $attribute->id,
'name' => $attribute->admin_name,
'type' => $attribute->type,
'code' => $attribute->code,
'has_options' => false,
'options' => null,
]);
}
array_push($trimmed, [
'id' => $attribute->id,
'name' => $attribute->admin_name,
'type' => $attribute->type,
'code' => $attribute->code,
'options' => $attribute->options,
]);
}
}

View File

@ -37,7 +37,15 @@ class Booking
/**
* @return array
*/
protected $daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
protected $daysOfWeek = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
];
/**
* Create a new helper instance.
@ -95,7 +103,7 @@ class Booking
$bookingProductSlot = $this->typeRepositories[$bookingProduct->type]->findOneByField('booking_product_id', $bookingProduct->id);
$availabileDays = $this->getAvailableWeekDays($bookingProduct);
$availableDays = $this->getAvailableWeekDays($bookingProduct);
foreach ($this->daysOfWeek as $index => $isOpen) {
$slots = [];
@ -106,7 +114,7 @@ class Booking
$slotsByDays[] = [
'name' => trans($this->daysOfWeek[$index]),
'slots' => isset($availabileDays[$index]) ? $this->conver24To12Hours($slots) : [],
'slots' => isset($availableDays[$index]) ? $this->conver24To12Hours($slots) : [],
];
}
@ -128,8 +136,8 @@ class Booking
}
return count($slots)
? implode(' | ', $slots)
: '<span class="text-danger">' . trans('bookingproduct::app.shop.products.closed') . '</span>';
? implode(' | ', $slots)
: '<span class="text-danger">' . trans('bookingproduct::app.shop.products.closed') . '</span>';
}
/**
@ -162,15 +170,16 @@ class Booking
$currentTime = Carbon::now();
$availableFrom = ! $bookingProduct->available_from && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
$availableTo = ! $bookingProduct->available_from && $bookingProduct->available_to
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
for ($i = 0; $i < 7; $i++) {
$date = clone $currentTime;
$date->addDays($i);
if (
@ -221,6 +230,7 @@ class Booking
foreach ($slots as $index => $slot) {
$slots[$index]['from'] = Carbon::createFromTimeString($slot['from'])->format("h:i a");
$slots[$index]['to'] = Carbon::createFromTimeString($slot['to'])->format("h:i a");
}
@ -250,16 +260,16 @@ class Booking
$requestedDate = Carbon::createFromTimeString($date . " 00:00:00");
$availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
$availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
$timeDurations = $bookingProductSlot->same_slot_all_days
? $bookingProductSlot->slots
: ($bookingProductSlot->slots[$requestedDate->format('w')] ?? []);
? $bookingProductSlot->slots
: ($bookingProductSlot->slots[$requestedDate->format('w')] ?? []);
if (
$requestedDate < $availableFrom
@ -387,7 +397,7 @@ class Booking
return $slot['timestamp'] == $cartItem['additional']['booking']['slot'];
});
return count($filtered) ? false : true;
return ! count($filtered);
}
/**
@ -399,12 +409,12 @@ class Booking
$timestamps = explode('-', $data['additional']['booking']['slot']);
$result = $this->bookingRepository->getModel()
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
->where('bookings.product_id', $data['product_id'])
->where('bookings.from', $timestamps[0])
->where('bookings.to', $timestamps[1])
->first();
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
->where('bookings.product_id', $data['product_id'])
->where('bookings.from', $timestamps[0])
->where('bookings.to', $timestamps[1])
->first();
return ! is_null($result->total_qty_booked) ? $result->total_qty_booked : 0;
}
@ -576,10 +586,6 @@ class Booking
*/
public function isCartItemInactive(\Webkul\Checkout\Contracts\CartItem $item): bool
{
if ($item->product->status === 0) {
return true;
}
return false;
return ! $item->product->status;
}
}

View File

@ -12,7 +12,7 @@ class DefaultSlot extends Booking
protected $daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
/**
* Returns slots for a perticular day
* Returns slots for a particular day
*
* @param \Webkul\BookingProduct\Contracts\BookingProduct $bookingProduct
* @param string $date
@ -34,12 +34,12 @@ class DefaultSlot extends Booking
$currentTime = Carbon::now();
$availableFrom = $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
$availableTo = $bookingProduct->available_to
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
if (
$requestedDate < $availableFrom
@ -51,8 +51,8 @@ class DefaultSlot extends Booking
$slots = [];
return $bookingProductSlot->booking_type == 'one'
? $this->getOneBookingForManyDaysSlots($bookingProductSlot, $requestedDate)
: $this->getManyBookingsforOneDaySlots($bookingProductSlot, $requestedDate);
? $this->getOneBookingForManyDaysSlots($bookingProductSlot, $requestedDate)
: $this->getManyBookingsForOneDaySlots($bookingProductSlot, $requestedDate);
}
/**
@ -98,19 +98,19 @@ class DefaultSlot extends Booking
* @param string $requestedDate
* @return array
*/
public function getManyBookingsforOneDaySlots($bookingProductSlot, $requestedDate)
public function getManyBookingsForOneDaySlots($bookingProductSlot, $requestedDate)
{
$bookingProduct = $bookingProductSlot->booking_product;
$currentTime = Carbon::now();
$availableFrom = $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
$availableTo = $bookingProduct->available_to
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
$timeDuration = $bookingProductSlot->slots[$requestedDate->format('w')] ?? [];

View File

@ -91,11 +91,11 @@ class EventTicket extends Booking
public function getBookedQuantity($data)
{
$result = $this->bookingRepository->getModel()
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
->where('bookings.product_id', $data['product_id'])
->where('bookings.booking_product_event_ticket_id', $data['additional']['booking']['ticket_id'])
->first();
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
->where('bookings.product_id', $data['product_id'])
->where('bookings.booking_product_event_ticket_id', $data['additional']['booking']['ticket_id'])
->first();
return ! is_null($result->total_qty_booked) ? $result->total_qty_booked : 0;
}
@ -114,6 +114,7 @@ class EventTicket extends Booking
$ticket = $bookingProduct->event_tickets()->find($product['additional']['booking']['ticket_id']);
$price = $ticket->price;
if ($this->isInSale($ticket)) {
$price = $ticket->special_price;
}
@ -186,7 +187,15 @@ class EventTicket extends Booking
{
return $ticket->special_price !== null
&& $ticket->special_price > 0.0
&& ($ticket->special_price_from === null || $ticket->special_price_from === '0000-00-00 00:00:00' || $ticket->special_price_from <= Carbon::now())
&& ($ticket->special_price_to === null || $ticket->special_price_to === '0000-00-00 00:00:00' || $ticket->special_price_to > Carbon::now());
&& (
$ticket->special_price_from === null
|| $ticket->special_price_from === '0000-00-00 00:00:00'
|| $ticket->special_price_from <= Carbon::now()
)
&& (
$ticket->special_price_to === null
|| $ticket->special_price_to === '0000-00-00 00:00:00'
|| $ticket->special_price_to > Carbon::now()
);
}
}

View File

@ -33,16 +33,16 @@ class RentalSlot extends Booking
$currentTime = Carbon::now();
$availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
? Carbon::createFromTimeString($bookingProduct->available_from)
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
$availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
? Carbon::createFromTimeString($bookingProduct->available_to)
: Carbon::createFromTimeString('2080-01-01 00:00:00');
$timeDurations = $bookingProductSlot->same_slot_all_days
? $bookingProductSlot->slots
: $bookingProductSlot->slots[$requestedDate->format('w')] ?? [];
? $bookingProductSlot->slots
: $bookingProductSlot->slots[$requestedDate->format('w')] ?? [];
if (
$requestedDate < $availableFrom
@ -139,18 +139,18 @@ class RentalSlot extends Booking
}
$result = $this->bookingRepository->getModel()
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
->where('bookings.product_id', $data['product_id'])
->where(function ($query) use($from, $to) {
$query->where(function ($query) use($from) {
$query->where('bookings.from', '<=', $from)->where('bookings.to', '>=', $from);
})
->orWhere(function($query) use($to) {
$query->where('bookings.from', '<=', $to)->where('bookings.to', '>=', $to);
});
})
->first();
->leftJoin('order_items', 'bookings.order_item_id', '=', 'order_items.id')
->addSelect(DB::raw('SUM(qty_ordered - qty_canceled - qty_refunded) as total_qty_booked'))
->where('bookings.product_id', $data['product_id'])
->where(function ($query) use($from, $to) {
$query->where(function ($query) use($from) {
$query->where('bookings.from', '<=', $from)->where('bookings.to', '>=', $from);
})
->orWhere(function($query) use($to) {
$query->where('bookings.from', '<=', $to)->where('bookings.to', '>=', $to);
});
})
->first();
return ! is_null($result->total_qty_booked) ? $result->total_qty_booked : 0;
}
@ -187,12 +187,12 @@ class RentalSlot extends Booking
$requestedToDate = Carbon::createFromTimeString($cartItem['additional']['booking']['date_to'] . " 23:59:59");
$availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . ' 00:00:00')
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
? Carbon::createFromTimeString($bookingProduct->available_from->format('Y-m-d') . ' 00:00:00')
: Carbon::createFromTimeString($currentTime->format('Y-m-d 00:00:00'));
$availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from
? Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . ' 23:59:59')
: Carbon::createFromTimeString('2080-01-01 00:00:00');
? Carbon::createFromTimeString($bookingProduct->available_to->format('Y-m-d') . ' 23:59:59')
: Carbon::createFromTimeString('2080-01-01 00:00:00');
if (
$requestedFromDate < $availableFrom

View File

@ -45,12 +45,12 @@ class BookingController extends Controller
{
if (request('view_type')) {
$startDate = request()->get('startDate')
? Carbon::createFromTimeString(request()->get('startDate') . " 00:00:01")
: Carbon::now()->startOfWeek()->format('Y-m-d H:i:s');
? Carbon::createFromTimeString(request()->get('startDate') . " 00:00:01")
: Carbon::now()->startOfWeek()->format('Y-m-d H:i:s');
$endDate = request()->get('endDate')
? Carbon::createFromTimeString(request()->get('endDate') . " 23:59:59")
: Carbon::now()->endOfWeek()->format('Y-m-d H:i:s');
? Carbon::createFromTimeString(request()->get('endDate') . " 23:59:59")
: Carbon::now()->endOfWeek()->format('Y-m-d H:i:s');
$bookings = $this->bookingRepository->getBookings([strtotime($startDate), strtotime($endDate)])
->map(function ($booking) {

View File

@ -21,11 +21,11 @@ class BookingProductController extends Controller
* Create a new controller instance.
*
* @param \Webkul\BookingProduct\Repositories\BookingProductRepository $bookingProductRepository
* @param \Webkul\BookingProduct\Helpers\DefaultSlot $defaultSlotHelper
* @param \Webkul\BookingProduct\Helpers\AppointmentSlot $appointmentSlotHelper
* @param \Webkul\BookingProduct\Helpers\RentalSlot $rentalSlotHelper
* @param \Webkul\BookingProduct\Helpers\EventTicket $EventTicketHelper
* @param \Webkul\BookingProduct\Helpers\TableSlot $tableSlotHelper
* @param \Webkul\BookingProduct\Helpers\DefaultSlot $defaultSlotHelper
* @param \Webkul\BookingProduct\Helpers\AppointmentSlot $appointmentSlotHelper
* @param \Webkul\BookingProduct\Helpers\RentalSlot $rentalSlotHelper
* @param \Webkul\BookingProduct\Helpers\EventTicket $EventTicketHelper
* @param \Webkul\BookingProduct\Helpers\TableSlot $tableSlotHelper
* @return void
*/
public function __construct(

View File

@ -9,9 +9,9 @@ class BookingProductAppointmentSlotRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\BookingProductAppointmentSlot';
}

View File

@ -9,9 +9,9 @@ class BookingProductDefaultSlotRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\BookingProductDefaultSlot';
}

View File

@ -11,17 +11,16 @@ class BookingProductEventTicketRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\BookingProductEventTicket';
}
/**
* @param array $data
* @param \Webkul\BookingProduct\Contracts\BookingProduct $bookingProduct
*
* @param array $data
* @param \Webkul\BookingProduct\Contracts\BookingProduct $bookingProduct
* @return void
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/

View File

@ -9,9 +9,9 @@ class BookingProductRentalSlotRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\BookingProductRentalSlot';
}

View File

@ -2,7 +2,7 @@
namespace Webkul\BookingProduct\Repositories;
use Illuminate\Container\Container as App;
use Illuminate\Container\Container;
use Carbon\Carbon;
use Webkul\Core\Eloquent\Repository;
@ -21,6 +21,7 @@ class BookingProductRepository extends Repository
* @param \Webkul\BookingProduct\Repositories\BookingProductEventTicketRepository $bookingProductEventTicketRepository
* @param \Webkul\BookingProduct\Repositories\BookingProductRentalSlotRepository $bookingProductRentalSlotRepository
* @param \Webkul\BookingProduct\Repositories\BookingProductTableSlotRepository $bookingProductTableSlotRepository
* @param \Illuminate\Container\Container $container
* @return void
*/
public function __construct(
@ -29,10 +30,10 @@ class BookingProductRepository extends Repository
BookingProductEventTicketRepository $bookingProductEventTicketRepository,
BookingProductRentalSlotRepository $bookingProductRentalSlotRepository,
BookingProductTableSlotRepository $bookingProductTableSlotRepository,
App $app
Container $container
)
{
parent::__construct($app);
parent::__construct($container);
$this->typeRepositories['default'] = $bookingProductDefaultSlotRepository;
@ -48,9 +49,9 @@ class BookingProductRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\BookingProduct';
}

View File

@ -9,9 +9,9 @@ class BookingProductTableSlotRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\BookingProductTableSlot';
}

View File

@ -2,7 +2,6 @@
namespace Webkul\BookingProduct\Repositories;
use Illuminate\Container\Container as App;
use Illuminate\Support\Facades\Event;
use Carbon\Carbon;
use Webkul\Core\Eloquent\Repository;
@ -12,9 +11,9 @@ class BookingRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\BookingProduct\Contracts\Booking';
}

View File

@ -40,14 +40,14 @@ class Booking extends Virtual
/**
* Create a new product type instance.
*
* @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
* @param \Webkul\Product\Repositories\ProductAttributeValueRepository $attributeValueRepository
* @param \Webkul\Product\Repositories\ProductInventoryRepository $productInventoryRepository
* @param \Webkul\Product\Repositories\ProductImageRepository $productImageRepository
* @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
* @param \Webkul\Product\Repositories\ProductAttributeValueRepository $attributeValueRepository
* @param \Webkul\Product\Repositories\ProductInventoryRepository $productInventoryRepository
* @param \Webkul\Product\Repositories\ProductImageRepository $productImageRepository
* @param \Webkul\BookingProduct\Repositories\BookingProductRepository $bookingProductRepository
* @param \Webkul\BookingProduct\Helpers\BookingHelper $bookingHelper
* @param \Webkul\Product\Repositories\ProductVideoRepository $productVideoRepository
* @param \Webkul\BookingProduct\Helpers\BookingHelper $bookingHelper
* @param \Webkul\Product\Repositories\ProductVideoRepository $productVideoRepository
* @return void
*/
public function __construct(

View File

@ -2,6 +2,7 @@
namespace Webkul\CMS\Http\Controllers\Admin;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\CMSPageDataGrid;
use Webkul\CMS\Http\Controllers\Controller;
use Webkul\CMS\Repositories\CmsRepository;
@ -57,8 +58,6 @@ class PageController extends Controller
*/
public function store()
{
$data = request()->all();
$this->validate(request(), [
'url_key' => ['required', 'unique:cms_page_translations,url_key', new \Webkul\Core\Contracts\Validations\Slug],
'page_title' => 'required',
@ -66,8 +65,12 @@ class PageController extends Controller
'html_content' => 'required',
]);
Event::dispatch('cms.pages.create.before');
$page = $this->cmsRepository->create(request()->all());
Event::dispatch('cms.pages.create.after', $page);
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'page']));
return redirect()->route($this->_config['redirect']);
@ -107,7 +110,11 @@ class PageController extends Controller
'channels' => 'required',
]);
$this->cmsRepository->update(request()->all(), $id);
Event::dispatch('cms.pages.update.before', $id);
$page = $this->cmsRepository->update(request()->all(), $id);
Event::dispatch('cms.pages.update.after', $page);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Page']));
@ -122,11 +129,15 @@ class PageController extends Controller
*/
public function delete($id)
{
$page = $this->cmsRepository->findOrFail($id);
try {
Event::dispatch('cms.pages.delete.before', $id);
$this->cmsRepository->delete($id);
Event::dispatch('cms.pages.delete.after', $id);
if ($page->delete()) {
return response()->json(['message' => trans('admin::app.cms.pages.delete-success')]);
}
} catch (\Exception $e) {}
return response()->json(['message' => trans('admin::app.cms.pages.delete-failure')], 500);
}
@ -138,32 +149,20 @@ class PageController extends Controller
*/
public function massDelete()
{
$data = request()->all();
if (request()->isMethod('post')) {
$indexes = explode(',', request()->input('indexes'));
if ($data['indexes']) {
$pageIDs = explode(',', $data['indexes']);
foreach ($indexes as $index) {
Event::dispatch('cms.pages.delete.before', $index);
$count = 0;
$this->cmsRepository->delete($index);
foreach ($pageIDs as $pageId) {
$page = $this->cmsRepository->find($pageId);
if ($page) {
$page->delete();
$count++;
}
Event::dispatch('cms.pages.delete.after', $index);
}
if (count($pageIDs) == $count) {
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success', [
'resource' => 'CMS Pages',
]));
} else {
session()->flash('success', trans('admin::app.datagrid.mass-ops.partial-action', [
'resource' => 'CMS Pages',
]));
}
session()->flash('success', trans('admin::app.datagrid.mass-ops.delete-success', [
'resource' => 'CMS Pages',
]));
} else {
session()->flash('warning', trans('admin::app.datagrid.mass-ops.no-resource'));
}

View File

@ -2,7 +2,6 @@
namespace Webkul\CMS\Repositories;
use Illuminate\Support\Facades\Event;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Webkul\Core\Eloquent\Repository;
use Webkul\CMS\Models\CmsPageTranslationProxy;
@ -12,9 +11,9 @@ class CmsRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\CMS\Contracts\CmsPage';
}
@ -25,8 +24,6 @@ class CmsRepository extends Repository
*/
public function create(array $data)
{
Event::dispatch('cms.pages.create.before');
$model = $this->getModel();
foreach (core()->getAllLocales() as $locale) {
@ -43,8 +40,6 @@ class CmsRepository extends Repository
$page->channels()->sync($data['channels']);
Event::dispatch('cms.pages.create.after', $page);
return $page;
}
@ -58,8 +53,6 @@ class CmsRepository extends Repository
{
$page = $this->find($id);
Event::dispatch('cms.pages.update.before', $id);
$locale = isset($data['locale']) ? $data['locale'] : app()->getLocale();
$data[$locale]['html_content'] = str_replace('=&gt;', '=>', $data[$locale]['html_content']);
@ -68,8 +61,6 @@ class CmsRepository extends Repository
$page->channels()->sync($data['channels']);
Event::dispatch('cms.pages.update.after', $id);
return $page;
}
@ -88,7 +79,7 @@ class CmsRepository extends Repository
->select(\DB::raw(1))
->exists();
return $exists ? false : true;
return ! $exists;
}
/**

View File

@ -53,10 +53,10 @@ class CartRule
{
$appliedCartRuleIds = [];
$this->calculateCartItemTotals($cart, $cart->items);
$this->calculateCartItemTotals($cart);
foreach ($cart->items as $item) {
$itemCartRuleIds = $this->process($cart, $item);
$itemCartRuleIds = $this->process($item);
$appliedCartRuleIds = array_merge($appliedCartRuleIds, $itemCartRuleIds);
@ -132,41 +132,41 @@ class CartRule
public function canProcessRule($cart, $rule): bool
{
if ($rule->coupon_type) {
if (strlen($cart->coupon_code)) {
/** @var \Webkul\CartRule\Models\CartRule $rule */
// Laravel relation is used instead of repository for performance
// reasons (cart_rule_coupon-relation is pre-loaded by self::getCartRuleQuery())
$coupon = $rule->cart_rule_coupon()->where('code', $cart->coupon_code)->first();
if (! strlen($cart->coupon_code)) {
return false;
}
/** @var \Webkul\CartRule\Models\CartRule $rule */
// Laravel relation is used instead of repository for performance
// reasons (cart_rule_coupon-relation is pre-loaded by self::getCartRuleQuery())
$coupon = $rule->cart_rule_coupon()->where('code', $cart->coupon_code)->first();
if (
$coupon
&& $coupon->code === $cart->coupon_code
) {
if (
$coupon->usage_limit
&& $coupon->times_used >= $coupon->usage_limit
) {
return false;
}
if (
$coupon
&& $coupon->code === $cart->coupon_code
$cart->customer_id
&& $coupon->usage_per_customer
) {
$couponUsage = $this->cartRuleCouponUsageRepository->findOneWhere([
'cart_rule_coupon_id' => $coupon->id,
'customer_id' => $cart->customer_id,
]);
if (
$coupon->usage_limit
&& $coupon->times_used >= $coupon->usage_limit
$couponUsage
&& $couponUsage->times_used >= $coupon->usage_per_customer
) {
return false;
}
if (
$cart->customer_id
&& $coupon->usage_per_customer
) {
$couponUsage = $this->cartRuleCouponUsageRepository->findOneWhere([
'cart_rule_coupon_id' => $coupon->id,
'customer_id' => $cart->customer_id,
]);
if (
$couponUsage
&& $couponUsage->times_used >= $coupon->usage_per_customer
) {
return false;
}
}
} else {
return false;
}
} else {
return false;
@ -193,11 +193,10 @@ class CartRule
/**
* Cart item discount calculation process
*
* @param \Webkul\Checkout\Contracts\Cart $cart
* @param \Webkul\Checkout\Models\CartItem $item
* @return array
*/
public function process($cart, CartItem $item): array
public function process(CartItem $item): array
{
$item->discount_percent = 0;
$item->discount_amount = 0;
@ -205,8 +204,8 @@ class CartRule
$appliedRuleIds = [];
foreach ($rules = $this->getCartRules($cart) as $rule) {
if (! $this->canProcessRule($cart, $rule)) {
foreach ($rules = $this->getCartRules($item->cart) as $rule) {
if (! $this->canProcessRule($item->cart, $rule)) {
continue;
}
@ -319,7 +318,7 @@ class CartRule
* Cart shipping discount calculation process
*
* @param \Webkul\Checkout\Contracts\Cart $cart
* @return void
* @return self|void
*/
public function processShippingDiscount($cart)
{
@ -418,9 +417,7 @@ class CartRule
$appliedRuleIds = [];
foreach ($cart->items->all() as $item) {
foreach ($this->getCartRules($cart) as $rule) {
if (! $this->canProcessRule($cart, $rule)) {
continue;
}
@ -466,36 +463,37 @@ class CartRule
* Calculate cart item totals for each rule
*
* @param \Webkul\Checkout\Contracts\Cart $cart
* @param \Illuminate\Support\Collecton $items
* @return \Webkul\Rule\Helpers\Validator
* @return array|void
*/
public function calculateCartItemTotals($cart, $items)
public function calculateCartItemTotals($cart)
{
foreach ($this->getCartRules($cart) as $rule) {
if ($rule->action_type == 'cart_fixed') {
$totalPrice = $totalBasePrice = $validCount = 0;
if ($rule->action_type != 'cart_fixed') {
continue;
}
foreach ($items as $item) {
if (! $this->canProcessRule($cart, $rule)) {
continue;
}
$totalPrice = $totalBasePrice = $validCount = 0;
if (! $this->validator->validate($rule, $item)) {
continue;
}
$quantity = $rule->discount_quantity ? min($item->quantity, $rule->discount_quantity) : $item->quantity;
$totalBasePrice += $item->base_price * $quantity;
$validCount++;
foreach ($cart->items as $item) {
if (! $this->canProcessRule($cart, $rule)) {
continue;
}
$this->itemTotals[$rule->id] = [
'base_total_price' => $totalBasePrice,
'total_items' => $validCount,
];
if (! $this->validator->validate($rule, $item)) {
continue;
}
$quantity = $rule->discount_quantity ? min($item->quantity, $rule->discount_quantity) : $item->quantity;
$totalBasePrice += $item->base_price * $quantity;
$validCount++;
}
$this->itemTotals[$rule->id] = [
'base_total_price' => $totalBasePrice,
'total_items' => $validCount,
];
}
}
@ -546,9 +544,8 @@ class CartRule
}
/**
* @param $customerGroupId
* @param $channelId
*
* @param integer $customerGroupId
* @param integer $channelId
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getCartRuleQuery($customerGroupId, $channelId): \Illuminate\Database\Eloquent\Collection

View File

@ -3,8 +3,9 @@
namespace Webkul\CartRule\Http\Controllers;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Event;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\CartRuleDataGrid;
use Webkul\CartRule\Http\Requests\CartRuleRequest;
@ -99,9 +100,11 @@ class CartRuleController extends Controller
public function store(CartRuleRequest $cartRuleRequest)
{
try {
$data = $cartRuleRequest->all();
Event::dispatch('promotions.cart_rule.create.before');
$this->cartRuleRepository->create($data);
$cartRule = $this->cartRuleRepository->create($cartRuleRequest->all());
Event::dispatch('promotions.cart_rule.create.after', $cartRule);
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Cart Rule']));
@ -152,8 +155,12 @@ class CartRuleController extends Controller
}
}
Event::dispatch('promotions.cart_rule.update.before', $id);
$cartRule = $this->cartRuleRepository->update($cartRuleRequest->all(), $id);
Event::dispatch('promotions.cart_rule.update.after', $cartRule);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Cart Rule']));
return redirect()->route($this->_config['redirect']);
@ -177,8 +184,12 @@ class CartRuleController extends Controller
$this->cartRuleRepository->findOrFail($id);
try {
Event::dispatch('promotions.cart_rule.delete.before', $id);
$this->cartRuleRepository->delete($id);
Event::dispatch('promotions.cart_rule.delete.after', $id);
return response()->json(['message' => trans('admin::app.response.delete-success', ['name' => 'Cart Rule'])]);
} catch (Exception $e) {}

View File

@ -41,7 +41,10 @@ class CartRuleRequest extends FormRequest
]);
}
if (request()->has('action_type') && request()->action_type == 'by_percent') {
if (
request()->has('action_type')
&& request()->action_type == 'by_percent'
) {
$rules = array_merge($rules, [
'discount_amount' => 'required|numeric|min:0|max:100',
]);

View File

@ -111,7 +111,7 @@ class CartRule extends Model implements CartRuleContract
public function coupon_code(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->cart_rule_coupon()
->where('is_primary', 1);
->where('is_primary', 1);
}
/**
@ -121,8 +121,7 @@ class CartRule extends Model implements CartRuleContract
*/
public function getCouponCodeAttribute()
{
$coupon = $this->coupon_code()
->first();
$coupon = $this->coupon_code()->first();
if (! $coupon) {
return;

View File

@ -18,9 +18,9 @@ class CartRuleCouponRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\CartRule\Contracts\CartRuleCoupon';
}

View File

@ -9,9 +9,9 @@ class CartRuleCouponUsageRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\CartRule\Contracts\CartRuleCouponUsage';
}

View File

@ -9,9 +9,9 @@ class CartRuleCustomerRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\CartRule\Contracts\CartRuleCustomer';
}

View File

@ -2,8 +2,7 @@
namespace Webkul\CartRule\Repositories;
use Illuminate\Container\Container as App;
use Illuminate\Support\Facades\Event;
use Illuminate\Container\Container;
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Category\Repositories\CategoryRepository;
@ -24,7 +23,7 @@ class CartRuleRepository extends Repository
* @param \Webkul\Tax\Repositories\TaxCategoryRepository $taxCategoryRepository
* @param \Webkul\Core\Repositories\CountryRepository $countryRepository
* @param \Webkul\Core\Repositories\CountryStateRepository $countryStateRepository
* @param \Illuminate\Container\Container $app
* @param \Illuminate\Container\Container $container
* @return void
*/
public function __construct(
@ -35,18 +34,18 @@ class CartRuleRepository extends Repository
protected TaxCategoryRepository $taxCategoryRepository,
protected CountryRepository $countryRepository,
protected CountryStateRepository $countryStateRepository,
App $app
Container $container
)
{
parent::__construct($app);
parent::__construct($container);
}
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
public function model()
public function model(): string
{
return 'Webkul\CartRule\Contracts\CartRule';
}
@ -57,13 +56,11 @@ class CartRuleRepository extends Repository
*/
public function create(array $data)
{
Event::dispatch('promotions.cart_rule.create.before');
$data['starts_from'] = isset($data['starts_from']) && $data['starts_from'] ? $data['starts_from'] : null;
$data['ends_till'] = isset($data['ends_till']) && $data['ends_till'] ? $data['ends_till'] : null;
$data['status'] = ! isset($data['status']) ? 0 : 1;
$data['status'] = isset($data['status']);
$cartRule = parent::create($data);
@ -85,8 +82,6 @@ class CartRuleRepository extends Repository
]);
}
Event::dispatch('promotions.cart_rule.create.after', $cartRule);
return $cartRule;
}
@ -98,15 +93,13 @@ class CartRuleRepository extends Repository
*/
public function update(array $data, $id, $attribute = 'id')
{
Event::dispatch('promotions.cart_rule.update.before', $id);
$data['starts_from'] = $data['starts_from'] ?: null;
$data['ends_till'] = $data['ends_till'] ?: null;
$data['status'] = ! isset($data['status']) ? 0 : 1;
$data['conditions'] = $data['conditions'] ?? [];
$data = array_merge($data, [
'starts_from' => $data['starts_from'] ?: null,
'ends_till' => $data['ends_till'] ?: null,
'status' => isset($data['status']),
'conditions' => $data['conditions'] ?? [],
]);
$cartRule = $this->find($id);
@ -118,7 +111,10 @@ class CartRuleRepository extends Repository
if ($data['coupon_type']) {
if (! $data['use_auto_generation']) {
$cartRuleCoupon = $this->cartRuleCouponRepository->findOneWhere(['is_primary' => 1, 'cart_rule_id' => $cartRule->id]);
$cartRuleCoupon = $this->cartRuleCouponRepository->findOneWhere([
'is_primary' => 1,
'cart_rule_id' => $cartRule->id,
]);
if ($cartRuleCoupon) {
$this->cartRuleCouponRepository->update([
@ -138,7 +134,10 @@ class CartRuleRepository extends Repository
]);
}
} else {
$this->cartRuleCouponRepository->deleteWhere(['is_primary' => 1, 'cart_rule_id' => $cartRule->id]);
$this->cartRuleCouponRepository->deleteWhere([
'is_primary' => 1,
'cart_rule_id' => $cartRule->id,
]);
$this->cartRuleCouponRepository->getModel()->where('cart_rule_id', $cartRule->id)->update([
'usage_limit' => $data['uses_per_coupon'] ?? 0,
@ -150,26 +149,9 @@ class CartRuleRepository extends Repository
$cartRuleCoupon = $this->cartRuleCouponRepository->deleteWhere(['is_primary' => 1, 'cart_rule_id' => $cartRule->id]);
}
Event::dispatch('promotions.cart_rule.update.after', $cartRule);
return $cartRule;
}
/**
* Delete.
*
* @param $id
* @return int
*/
public function delete($id)
{
Event::dispatch('promotions.cart_rule.delete.before', $id);
parent::delete($id);
Event::dispatch('promotions.cart_rule.delete.after', $id);
}
/**
* Returns attributes for cart rule conditions.
*
@ -282,9 +264,7 @@ class CartRuleRepository extends Repository
if ($attribute->validation == 'decimal') {
$attributeType = 'decimal';
}
if ($attribute->validation == 'numeric') {
} elseif ($attribute->validation == 'numeric') {
$attributeType = 'integer';
}

View File

@ -57,8 +57,8 @@ class CatalogRuleIndex
}
$productIds = $product->getTypeInstance()->isComposite()
? $product->getTypeInstance()->getChildrenIds()
: [$product->id];
? $product->getTypeInstance()->getChildrenIds()
: [$product->id];
$this->cleanIndexes($productIds);
@ -100,14 +100,14 @@ class CatalogRuleIndex
$catalogRules = $this->catalogRuleRepository->scopeQuery(function($query) {
return $query->where(function ($query1) {
$query1->where('catalog_rules.starts_from', '<=', Carbon::now()->format('Y-m-d'))
->orWhereNull('catalog_rules.starts_from');
})
->where(function ($query2) {
$query2->where('catalog_rules.ends_till', '>=', Carbon::now()->format('Y-m-d'))
->orWhereNull('catalog_rules.ends_till');
})
->orderBy('sort_order', 'asc');
$query1->where('catalog_rules.starts_from', '<=', Carbon::now()->format('Y-m-d'))
->orWhereNull('catalog_rules.starts_from');
})
->where(function ($query2) {
$query2->where('catalog_rules.ends_till', '>=', Carbon::now()->format('Y-m-d'))
->orWhereNull('catalog_rules.ends_till');
})
->orderBy('sort_order', 'asc');
})->findWhere(['status' => 1]);
return $catalogRules;

View File

@ -38,8 +38,9 @@ class CatalogRuleProduct
*/
public function insertRuleProduct($rule, $batchCount = 1000, $product = null)
{
if (! (float) $rule->discount_amount)
if (! (float) $rule->discount_amount) {
return;
}
$productIds = $this->getMatchingProductIds($rule, $product);
@ -90,10 +91,10 @@ class CatalogRuleProduct
{
$qb = $this->productRepository->scopeQuery(function($query) use($rule, $product) {
$qb = $query->distinct()
->addSelect('products.*')
->leftJoin('product_flat', 'products.id', '=', 'product_flat.product_id')
->leftJoin('channels', 'product_flat.channel', '=', 'channels.code')
->whereIn('channels.id', $rule->channels()->pluck('id')->toArray());
->addSelect('products.*')
->leftJoin('product_flat', 'products.id', '=', 'product_flat.product_id')
->leftJoin('channels', 'product_flat.channel', '=', 'channels.code')
->whereIn('channels.id', $rule->channels()->pluck('id')->toArray());
if ($product) {
$qb->where('products.id', $product->id);
@ -162,7 +163,7 @@ class CatalogRuleProduct
$query = $query->leftJoin('product_attribute_values as ' . 'pav_' . $attribute->code, function($qb) use($attribute) {
$qb = $qb->where('pav_' . $attribute->code . '.channel', $attribute->value_per_channel ? core()->getDefaultChannelCode() : null)
->where('pav_' . $attribute->code . '.locale', $attribute->value_per_locale ? app()->getLocale() : null);
->where('pav_' . $attribute->code . '.locale', $attribute->value_per_locale ? app()->getLocale() : null);
$qb->on('products.id', 'pav_' . $attribute->code . '.product_id')
->where('pav_' . $attribute->code . '.attribute_id', $attribute->id);
@ -183,13 +184,13 @@ class CatalogRuleProduct
{
$results = $this->catalogRuleProductRepository->scopeQuery(function($query) use($product) {
$qb = $query->distinct()
->select('catalog_rule_products.*')
->leftJoin('products', 'catalog_rule_products.product_id', '=', 'products.id')
->orderBy('channel_id', 'asc')
->orderBy('customer_group_id', 'asc')
->orderBy('product_id', 'asc')
->orderBy('sort_order', 'asc')
->orderBy('catalog_rule_id', 'asc');
->select('catalog_rule_products.*')
->leftJoin('products', 'catalog_rule_products.product_id', '=', 'products.id')
->orderBy('channel_id', 'asc')
->orderBy('customer_group_id', 'asc')
->orderBy('product_id', 'asc')
->orderBy('sort_order', 'asc')
->orderBy('catalog_rule_id', 'asc');
$qb = $this->addAttributeToSelect('price', $qb);

View File

@ -3,6 +3,7 @@
namespace Webkul\CatalogRule\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\CatalogRuleDataGrid;
use Webkul\CatalogRule\Helpers\CatalogRuleIndex;
use Webkul\CatalogRule\Http\Requests\CatalogRuleRequest;
@ -64,9 +65,11 @@ class CatalogRuleController extends Controller
*/
public function store(CatalogRuleRequest $catalogRuleRequest)
{
$data = $catalogRuleRequest->all();
Event::dispatch('promotions.catalog_rule.create.before');
$this->catalogRuleRepository->create($data);
$catalogRule = $this->catalogRuleRepository->create($catalogRuleRequest->all());
Event::dispatch('promotions.catalog_rule.create.after', $catalogRule);
$this->catalogRuleIndexHelper->reindexComplete();
@ -99,7 +102,11 @@ class CatalogRuleController extends Controller
{
$this->catalogRuleRepository->findOrFail($id);
$this->catalogRuleRepository->update($catalogRuleRequest->all(), $id);
Event::dispatch('promotions.catalog_rule.update.before', $id);
$catalogRule = $this->catalogRuleRepository->update($catalogRuleRequest->all(), $id);
Event::dispatch('promotions.catalog_rule.update.after', $catalogRule);
$this->catalogRuleIndexHelper->reindexComplete();
@ -119,8 +126,12 @@ class CatalogRuleController extends Controller
$this->catalogRuleRepository->findOrFail($id);
try {
Event::dispatch('promotions.catalog_rule.delete.before', $id);
$this->catalogRuleRepository->delete($id);
Event::dispatch('promotions.catalog_rule.delete.after', $id);
return response()->json(['message' => trans('admin::app.response.delete-success', ['name' => 'Catalog Rule'])]);
} catch (\Exception $e) {}

View File

@ -10,9 +10,9 @@ class CatalogRuleProductPriceRepository extends Repository
/**
* Specify Model class name.
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\CatalogRule\Contracts\CatalogRuleProductPrice';
}

View File

@ -9,9 +9,9 @@ class CatalogRuleProductRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\CatalogRule\Contracts\CatalogRuleProduct';
}

View File

@ -2,12 +2,11 @@
namespace Webkul\CatalogRule\Repositories;
use Illuminate\Container\Container as App;
use Illuminate\Support\Facades\Event;
use Illuminate\Container\Container;
use Webkul\Core\Eloquent\Repository;
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Category\Repositories\CategoryRepository;
use Webkul\Core\Eloquent\Repository;
use Webkul\Tax\Repositories\TaxCategoryRepository;
class CatalogRuleRepository extends Repository
@ -19,7 +18,7 @@ class CatalogRuleRepository extends Repository
* @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
* @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository
* @param \Webkul\Tax\Repositories\TaxCategoryRepository $taxCategoryRepository
* @param \Illuminate\Container\Container $app
* @param \Illuminate\Container\Container $container
* @return void
*/
public function __construct(
@ -27,20 +26,20 @@ class CatalogRuleRepository extends Repository
protected AttributeRepository $attributeRepository,
protected CategoryRepository $categoryRepository,
protected TaxCategoryRepository $taxCategoryRepository,
App $app
Container $container
)
{
parent::__construct($app);
parent::__construct($container);
}
/**
* Specify model class name.
*
* @return mixed
* @return string
*/
public function model()
public function model(): string
{
return \Webkul\CatalogRule\Contracts\CatalogRule::class;
return 'Webkul\CatalogRule\Contracts\CatalogRule';
}
/**
@ -51,13 +50,11 @@ class CatalogRuleRepository extends Repository
*/
public function create(array $data)
{
Event::dispatch('promotions.catalog_rule.create.before');
$data['starts_from'] = $data['starts_from'] ?: null;
$data['ends_till'] = $data['ends_till'] ?: null;
$data['status'] = ! isset($data['status']) ? 0 : 1;
$data = array_merge($data, [
'starts_from' => $data['starts_from'] ?: null,
'ends_till' => $data['ends_till'] ?: null,
'status' => isset($data['status']),
]);
$catalogRule = parent::create($data);
@ -65,8 +62,6 @@ class CatalogRuleRepository extends Repository
$catalogRule->customer_groups()->sync($data['customer_groups']);
Event::dispatch('promotions.catalog_rule.create.after', $catalogRule);
return $catalogRule;
}
@ -80,15 +75,12 @@ class CatalogRuleRepository extends Repository
*/
public function update(array $data, $id, $attribute = 'id')
{
Event::dispatch('promotions.catalog_rule.update.before', $id);
$data['starts_from'] = $data['starts_from'] ?: null;
$data['ends_till'] = $data['ends_till'] ?: null;
$data['status'] = ! isset($data['status']) ? 0 : 1;
$data['conditions'] = $data['conditions'] ?? [];
$data = array_merge($data, [
'starts_from' => $data['starts_from'] ?: null,
'ends_till' => $data['ends_till'] ?: null,
'status' => isset($data['status']),
'conditions' => $data['conditions'] ?? [],
]);
$catalogRule = $this->find($id);
@ -98,26 +90,9 @@ class CatalogRuleRepository extends Repository
$catalogRule->customer_groups()->sync($data['customer_groups']);
Event::dispatch('promotions.catalog_rule.update.after', $catalogRule);
return $catalogRule;
}
/**
* Delete.
*
* @param $id
* @return int
*/
public function delete($id)
{
Event::dispatch('promotions.catalog_rule.delete.before', $id);
parent::delete($id);
Event::dispatch('promotions.catalog_rule.delete.after', $id);
}
/**
* Returns attributes for catalog rule conditions.
*

View File

@ -2,12 +2,13 @@
namespace Webkul\Category\Http\Controllers;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\CategoryDataGrid;
use Webkul\Admin\DataGrids\CategoryProductDataGrid;
use Webkul\Core\Repositories\ChannelRepository;
use Webkul\Category\Repositories\CategoryRepository;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Category\Http\Requests\CategoryRequest;
use Webkul\Category\Repositories\CategoryRepository;
use Webkul\Core\Models\Channel;
class CategoryController extends Controller
{
@ -21,11 +22,13 @@ class CategoryController extends Controller
/**
* Create a new controller instance.
*
* @param \Webkul\Core\Repositories\ChannelRepository $channelRepository
* @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository
* @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository
* @return void
*/
public function __construct(
protected ChannelRepository $channelRepository,
protected CategoryRepository $categoryRepository,
protected AttributeRepository $attributeRepository
)
@ -69,7 +72,11 @@ class CategoryController extends Controller
*/
public function store(CategoryRequest $categoryRequest)
{
$this->categoryRepository->create($categoryRequest->all());
Event::dispatch('catalog.category.create.before');
$category = $this->categoryRepository->create($categoryRequest->all());
Event::dispatch('catalog.category.create.after', $category);
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Category']));
@ -115,7 +122,11 @@ class CategoryController extends Controller
*/
public function update(CategoryRequest $categoryRequest, $id)
{
$this->categoryRepository->update($categoryRequest->all(), $id);
Event::dispatch('catalog.category.update.before', $id);
$category = $this->categoryRepository->update($categoryRequest->all(), $id);
Event::dispatch('catalog.category.update.after', $category);
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Category']));
@ -137,8 +148,12 @@ class CategoryController extends Controller
}
try {
Event::dispatch('catalog.category.delete.before', $id);
$this->categoryRepository->delete($id);
Event::dispatch('catalog.category.delete.after', $id);
return response()->json(['message' => trans('admin::app.response.delete-success', ['name' => 'Category'])]);
} catch (\Exception $e) {}
@ -153,6 +168,7 @@ class CategoryController extends Controller
public function massDestroy()
{
$suppressFlash = true;
$categoryIds = explode(',', request()->input('indexes'));
foreach ($categoryIds as $categoryId) {
@ -167,7 +183,11 @@ class CategoryController extends Controller
try {
$suppressFlash = true;
Event::dispatch('catalog.category.delete.before', $categoryId);
$this->categoryRepository->delete($categoryId);
Event::dispatch('catalog.category.delete.after', $categoryId);
} catch (\Exception $e) {
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Category']));
}
@ -192,15 +212,17 @@ class CategoryController extends Controller
*/
public function categoryProductCount()
{
$product_count = 0;
$productCount = 0;
$indexes = explode(',', request()->input('indexes'));
foreach ($indexes as $index) {
$category = $this->categoryRepository->find($index);
$product_count += $category->products->count();
$productCount += $category->products->count();
}
return response()->json(['product_count' => $product_count]);
return response()->json(['product_count' => $productCount]);
}
/**
@ -209,17 +231,17 @@ class CategoryController extends Controller
* This method will fetch all root category ids from the channel. If `id` is present,
* then it is not deletable.
*
* @param \Webkul\Category\Models\Category $category
* @param \Webkul\Category\Contracts\Category $category
* @return bool
*/
private function isCategoryDeletable($category)
{
static $rootIdInChannels;
static $channelRootCategoryIds;
if (! $rootIdInChannels) {
$rootIdInChannels = Channel::pluck('root_category_id');
if (! $channelRootCategoryIds) {
$channelRootCategoryIds = $this->channelRepository->pluck('root_category_id');
}
return $category->id === 1 || $rootIdInChannels->contains($category->id);
return $category->id === 1 || $channelRootCategoryIds->contains($category->id);
}
}

View File

@ -135,13 +135,11 @@ class Category extends TranslatableModel implements CategoryContract
'parent_id',
'=',
null,
],
[
], [
'_lft',
'<=',
$this->_lft,
],
[
], [
'_rgt',
'>=',
$this->_rgt,
@ -163,6 +161,7 @@ class Category extends TranslatableModel implements CategoryContract
while (isset($category->parent)) {
$category = $category->parent;
$categories[] = $category;
}

View File

@ -4,7 +4,6 @@ namespace Webkul\Category\Repositories;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
use Webkul\Category\Models\CategoryTranslationProxy;
use Webkul\Core\Eloquent\Repository;
@ -14,11 +13,11 @@ class CategoryRepository extends Repository
/**
* Specify model class name.
*
* @return mixed
* @return string
*/
public function model()
public function model(): string
{
return \Webkul\Category\Contracts\Category::class;
return 'Webkul\Category\Contracts\Category';
}
/**
@ -29,8 +28,6 @@ class CategoryRepository extends Repository
*/
public function create(array $data)
{
Event::dispatch('catalog.category.create.before');
if (
isset($data['locale'])
&& $data['locale'] == 'all'
@ -41,6 +38,7 @@ class CategoryRepository extends Repository
foreach ($model->translatedAttributes as $attribute) {
if (isset($data[$attribute])) {
$data[$locale->code][$attribute] = $data[$attribute];
$data[$locale->code]['locale_id'] = $locale->id;
}
}
@ -55,8 +53,6 @@ class CategoryRepository extends Repository
$category->filterableAttributes()->sync($data['attributes']);
}
Event::dispatch('catalog.category.create.after', $category);
return $category;
}
@ -72,8 +68,6 @@ class CategoryRepository extends Repository
{
$category = $this->find($id);
Event::dispatch('catalog.category.update.before', $id);
$data = $this->setSameAttributeValueToAllLocale($data, 'slug');
$category->update($data);
@ -84,26 +78,9 @@ class CategoryRepository extends Repository
$category->filterableAttributes()->sync($data['attributes']);
}
Event::dispatch('catalog.category.update.after', $id);
return $category;
}
/**
* Delete category.
*
* @param int $id
* @return void
*/
public function delete($id)
{
Event::dispatch('catalog.category.delete.before', $id);
parent::delete($id);
Event::dispatch('catalog.category.delete.after', $id);
}
/**
* Specify category tree.
*
@ -174,7 +151,7 @@ class CategoryRepository extends Repository
->select(DB::raw(1))
->exists();
return $exists ? false : true;
return ! $exists;
}
/**
@ -193,7 +170,7 @@ class CategoryRepository extends Repository
}
/**
* Retrive category from slug.
* Retrieve category from slug.
*
* @param string $slug
* @return \Webkul\Category\Contracts\Category
@ -237,6 +214,7 @@ class CategoryRepository extends Repository
foreach ($data[$type] as $imageId => $image) {
$file = $type . '.' . $imageId;
$dir = 'category/' . $category->id;
if ($request->hasFile($file)) {
@ -245,6 +223,7 @@ class CategoryRepository extends Repository
}
$category->{$type} = $request->file($file)->store($dir);
$category->save();
}
}
@ -254,6 +233,7 @@ class CategoryRepository extends Repository
}
$category->{$type} = null;
$category->save();
}
}

View File

@ -25,7 +25,6 @@ class Cart
{
use CartCoupons, CartTools, CartValidators;
/**
* @var \Webkul\Checkout\Contracts\Cart
*/
@ -34,12 +33,12 @@ class Cart
/**
* Create a new class instance.
*
* @param \Webkul\Checkout\Repositories\CartRepository $cartRepository
* @param \Webkul\Checkout\Repositories\CartItemRepository $cartItemRepository
* @param \Webkul\Checkout\Repositories\CartAddressRepository $cartAddressRepository
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
* @param \Webkul\Tax\Repositories\TaxCategoryRepository $taxCategoryRepository
* @param \Webkul\Customer\Repositories\WishlistRepository $wishlistRepository
* @param \Webkul\Checkout\Repositories\CartRepository $cartRepository
* @param \Webkul\Checkout\Repositories\CartItemRepository $cartItemRepository
* @param \Webkul\Checkout\Repositories\CartAddressRepository $cartAddressRepository
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
* @param \Webkul\Tax\Repositories\TaxCategoryRepository $taxCategoryRepository
* @param \Webkul\Customer\Repositories\WishlistRepository $wishlistRepository
* @param \Webkul\Customer\Repositories\CustomerAddressRepository $customerAddressRepository
* @return void
*/
@ -127,11 +126,11 @@ class Cart
foreach ($items as $item) {
if ($item->product->getTypeInstance()->compareOptions($item->additional, $data['additional'])) {
if (isset($data['additional']['parent_id'])) {
if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional, $parentData ?: request()->all())) {
return $item;
}
} else {
if (! isset($data['additional']['parent_id'])) {
return $item;
}
if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional, $parentData ?: request()->all())) {
return $item;
}
}
@ -279,7 +278,7 @@ class Cart
if (
$item->product
&& $item->product->status === 0
&& ! $item->product->status
) {
throw new Exception(__('shop::app.checkout.cart.item.inactive'));
}
@ -331,7 +330,7 @@ class Cart
if ($cartItem = $cart->items()->find($itemId)) {
$cartItem->delete();
if ($cart->items()->get()->count() == 0) {
if (! $cart->items()->get()->count()) {
$this->removeCart($cart);
} else {
Shipping::collectRates();
@ -384,7 +383,7 @@ class Cart
if ($this->isCartItemInactive($item)) {
$this->cartItemRepository->delete($item->id);
if ($cart->items->count() == 0) {
if (! $cart->items->count()) {
$this->removeCart($cart);
}
@ -420,8 +419,7 @@ class Cart
&& (
$user->email
&& $user->first_name
&&
$user->last_name
&& $user->last_name
)
) {
$cart->customer_email = $user->email;
@ -623,7 +621,7 @@ class Cart
$cartItems = $cart->items()->get();
if (count($cartItems) === 0) {
if (! count($cartItems)) {
$this->removeCart($cart);
return false;

View File

@ -22,9 +22,9 @@ class CartAddressFactory extends Factory
public function definition(): array
{
return [
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName,
'email' => $this->faker->email,
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName,
'email' => $this->faker->email,
'address_type' => CartAddress::ADDRESS_TYPE_BILLING,
];
}

View File

@ -20,18 +20,13 @@ class Cart extends Model implements CartContract
'updated_at',
];
// protected $with = [
// 'items',
// 'items.children',
// ];
/**
* To get relevant associated items with the cart instance
*/
public function items(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(CartItemProxy::modelClass())
->whereNull('parent_id');
->whereNull('parent_id');
}
/**
@ -56,7 +51,7 @@ class Cart extends Model implements CartContract
public function billing_address(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->addresses()
->where('address_type', CartAddress::ADDRESS_TYPE_BILLING);
->where('address_type', CartAddress::ADDRESS_TYPE_BILLING);
}
/**
@ -64,8 +59,7 @@ class Cart extends Model implements CartContract
*/
public function getBillingAddressAttribute()
{
return $this->billing_address()
->first();
return $this->billing_address()->first();
}
/**
@ -74,7 +68,7 @@ class Cart extends Model implements CartContract
public function shipping_address(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->addresses()
->where('address_type', CartAddress::ADDRESS_TYPE_SHIPPING);
->where('address_type', CartAddress::ADDRESS_TYPE_SHIPPING);
}
/**
@ -82,8 +76,7 @@ class Cart extends Model implements CartContract
*/
public function getShippingAddressAttribute()
{
return $this->shipping_address()
->first();
return $this->shipping_address()->first();
}
/**
@ -100,7 +93,7 @@ class Cart extends Model implements CartContract
public function selected_shipping_rate(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->shipping_rates()
->where('method', $this->shipping_method);
->where('method', $this->shipping_method);
}
/**
@ -109,8 +102,8 @@ class Cart extends Model implements CartContract
public function getSelectedShippingRateAttribute()
{
return $this->selected_shipping_rate()
->where('method', $this->shipping_method)
->first();
->where('method', $this->shipping_method)
->first();
}
/**
@ -162,7 +155,7 @@ class Cart extends Model implements CartContract
public function hasProductsWithQuantityBox(): bool
{
foreach ($this->items as $item) {
if ($item->product->getTypeInstance()->showQuantityBox() === true) {
if ($item->product->getTypeInstance()->showQuantityBox()) {
return true;
}
}
@ -178,7 +171,7 @@ class Cart extends Model implements CartContract
public function hasGuestCheckoutItems(): bool
{
foreach ($this->items as $item) {
if ($item->product->getAttribute('guest_checkout') === 0) {
if (! $item->product->getAttribute('guest_checkout')) {
return false;
}
}

View File

@ -41,9 +41,9 @@ class CartItem extends Model implements CartItemContract
public function product_flat()
{
return (ProductFlatProxy::modelClass())::where('product_flat.product_id', $this->product_id)
->where('product_flat.locale', app()->getLocale())
->where('product_flat.channel', core()->getCurrentChannelCode())
->select('product_flat.*');
->where('product_flat.locale', app()->getLocale())
->where('product_flat.channel', core()->getCurrentChannelCode())
->select('product_flat.*');
}
/**
@ -51,8 +51,7 @@ class CartItem extends Model implements CartItemContract
*/
public function getProductFlatAttribute()
{
return $this->product_flat()
->first();
return $this->product_flat()->first();
}
public function cart(): HasOne

View File

@ -17,7 +17,7 @@ class CartAddressRepository extends Repository
*
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Checkout\Contracts\CartAddress';
}

View File

@ -10,32 +10,13 @@ class CartItemRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Checkout\Contracts\CartItem';
}
/**
* @param array $data
* @param $id
* @param string $attribute
*
* @return \Webkul\Checkout\Contracts\CartItem|null
*/
public function update(array $data, $id, $attribute = "id"): ?CartItem
{
$item = $this->find($id);
if ($item) {
$item->update($data);
}
return $item;
}
/**
* @param int $cartItemId
* @return int

View File

@ -9,49 +9,21 @@ class CartRepository extends Repository
/**
* Specify Model class name
*
* @return Mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Checkout\Contracts\Cart';
}
/**
* @param array $data
* @return \Webkul\Checkout\Contracts\Cart
*/
public function create(array $data)
{
$cart = $this->model->create($data);
return $cart;
}
/**
* @param array $data
* @param int $id
* @param string $attribute
* @return \Webkul\Checkout\Contracts\Cart
*/
public function update(array $data, $id, $attribute = "id")
{
$cart = $this->find($id);
$cart->update($data);
return $cart;
}
/**
* Method to detach associations. Use this only with guest cart only.
*
* @param int $cartId
* @return bool
*/
public function deleteParent($cartId) {
$cart = $this->model->find($cartId);
public function deleteParent($cartId)
{
return $this->model->destroy($cartId);
}
}

View File

@ -196,7 +196,10 @@ trait CartTools
}
if (! $wishlistItem->additional) {
$wishlistItem->additional = ['product_id' => $wishlistItem->product_id, 'quantity' => 1];
$wishlistItem->additional = [
'product_id' => $wishlistItem->product_id,
'quantity' => 1,
];
}
request()->merge($wishlistItem->additional);

View File

@ -27,7 +27,7 @@ trait CartValidators
$count = $cart->all_items()->where('product_id', $product->id)->count();
return $count > 0 ? true : false;
return $count > 0;
}
/**
@ -37,11 +37,10 @@ trait CartValidators
*/
public function hasError(): bool
{
if (! $this->getCart()) {
return true;
}
if (! $this->isItemsHaveSufficientQuantity()) {
if (
! $this->getCart()
|| ! $this->isItemsHaveSufficientQuantity()
) {
return true;
}

View File

@ -64,11 +64,15 @@ class BookingCron extends Command
ProductFlat::query()->where('product_id', $expEvent->product_id)
->update(['status' => 0]);
Log::info('BookingCron: deactivated expired event', ['booking_product_id' => $expEvent->id, 'product_id' => $expEvent->product_id]);
Log::info('BookingCron: deactivated expired event', [
'booking_product_id' => $expEvent->id,
'product_id' => $expEvent->product_id,
]);
}
$this->info('All expired events have been deactivated');
} else {
Log::info('BookingCron: Did not find any expired events to be deactivated');
$this->info('Did not find any expired events to be deactivated');
}
}

View File

@ -917,7 +917,7 @@ class Core
*/
public function isCountryRequired()
{
return $this->getConfigData('customer.address.requirements.country') == 1;
return (bool) $this->getConfigData('customer.address.requirements.country');
}
/**
@ -927,7 +927,7 @@ class Core
*/
public function isStateRequired()
{
return $this->getConfigData('customer.address.requirements.state') == 1;
return (bool) $this->getConfigData('customer.address.requirements.state');
}
/**
@ -937,7 +937,7 @@ class Core
*/
public function isPostCodeRequired()
{
return $this->getConfigData('customer.address.requirements.postcode') == 1;
return (bool) $this->getConfigData('customer.address.requirements.postcode');
}
/**

View File

@ -5,7 +5,6 @@ namespace Webkul\Core\Eloquent;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Eloquent\BaseRepository;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Container\Container as App;
use Prettus\Repository\Traits\CacheableRepository;

View File

@ -62,7 +62,7 @@ class Handler extends AppExceptionHandler
*/
private function isAdminUri()
{
return strpos(\Illuminate\Support\Facades\Request::path(), 'admin') !== false ? true : false;
return strpos(\Illuminate\Support\Facades\Request::path(), 'admin') !== false;
}
/**

View File

@ -2,6 +2,7 @@
namespace Webkul\Core\Http\Controllers;
use Illuminate\Support\Facades\Event;
use Webkul\Admin\DataGrids\ExchangeRatesDataGrid;
use Webkul\Core\Repositories\CurrencyRepository;
use Webkul\Core\Repositories\ExchangeRateRepository;
@ -68,7 +69,12 @@ class ExchangeRateController extends Controller
'rate' => 'required|numeric',
]);
$this->exchangeRateRepository->create(request()->all());
Event::dispatch('core.exchange_rate.create.before');
$exchangeRate = $this->exchangeRateRepository->create(request()->all());
Event::dispatch('core.exchange_rate.create.after', $exchangeRate);
session()->flash('success', trans('admin::app.settings.exchange_rates.create-success'));
@ -103,7 +109,11 @@ class ExchangeRateController extends Controller
'rate' => 'required|numeric',
]);
$this->exchangeRateRepository->update(request()->all(), $id);
Event::dispatch('core.exchange_rate.update.before', $id);
$exchangeRate = $this->exchangeRateRepository->update(request()->all(), $id);
Event::dispatch('core.exchange_rate.update.after', $exchangeRate);
session()->flash('success', trans('admin::app.settings.exchange_rates.update-success'));
@ -139,8 +149,12 @@ class ExchangeRateController extends Controller
$this->exchangeRateRepository->findOrFail($id);
try {
Event::dispatch('core.exchange_rate.delete.before', $id);
$this->exchangeRateRepository->delete($id);
Event::dispatch('core.exchange_rate.delete.after', $id);
return response()->json(['message' => trans('admin::app.settings.exchange_rates.delete-success')]);
} catch (\Exception $e) {
report($e);

View File

@ -60,18 +60,17 @@ class SubscriptionController extends Controller
*/
public function update($id)
{
$data = request()->all();
$subscriber = $this->subscribersListRepository->findOrFail($id);
$customer = $subscriber->customer;
if (! is_null($customer)) {
$customer->subscribed_to_news_letter = $data['is_subscribed'];
$customer->subscribed_to_news_letter = request('is_subscribed');
$customer->save();
}
$result = $subscriber->update($data);
$result = $subscriber->update(request()->all());
if ($result) {
session()->flash('success', trans('admin::app.customers.subscribers.update-success'));

View File

@ -14,11 +14,11 @@ class ChannelRepository extends Repository
/**
* Specify model class name.
*
* @return mixed
* @return string
*/
public function model()
public function model(): string
{
return \Webkul\Core\Contracts\Channel::class;
return 'Webkul\Core\Contracts\Channel';
}
/**

View File

@ -20,7 +20,7 @@ class CoreConfigRepository extends Repository
*/
public function model(): string
{
return CoreConfig::class;
return 'Webkul\Core\Contracts\CoreConfig';
}
/**
@ -50,9 +50,9 @@ class CoreConfigRepository extends Repository
foreach ($recurssiveData as $fieldName => $value) {
$field = core()->getConfigField($fieldName);
$channelBased = isset($field['channel_based']) && $field['channel_based'] ? true : false;
$channelBased = isset($field['channel_based']) && $field['channel_based'];
$localeBased = isset($field['locale_based']) && $field['locale_based'] ? true : false;
$localeBased = isset($field['locale_based']) && $field['locale_based'];
if (
getType($value) == 'array'

View File

@ -12,9 +12,9 @@ class CountryRepository extends Repository
/**
* Specify Model class name
*
* @return mixed
* @return string
*/
function model()
function model(): string
{
return 'Webkul\Core\Contracts\Country';
}

Some files were not shown because too many files have changed in this diff Show More