Some Events Placed Inside The Repository
This commit is contained in:
parent
686fb1c950
commit
8f67109880
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
namespace Webkul\Admin\Http\Controllers;
|
||||
|
||||
use Webkul\Core\Tree;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Admin\Http\Requests\ConfigurationForm;
|
||||
use Webkul\Core\Repositories\CoreConfigRepository;
|
||||
use Webkul\Core\Tree;
|
||||
|
||||
class ConfigurationController extends Controller
|
||||
{
|
||||
|
|
@ -113,12 +112,8 @@ class ConfigurationController extends Controller
|
|||
*/
|
||||
public function store(ConfigurationForm $request)
|
||||
{
|
||||
Event::dispatch('core.configuration.save.before');
|
||||
|
||||
$this->coreConfigRepository->create($request->except(['_token', 'admin_locale']));
|
||||
|
||||
Event::dispatch('core.configuration.save.after');
|
||||
|
||||
session()->flash('success', trans('admin::app.configuration.save-message'));
|
||||
|
||||
return redirect()->back();
|
||||
|
|
|
|||
|
|
@ -2,52 +2,48 @@
|
|||
|
||||
namespace Webkul\Admin\Http\Controllers\Customer;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Admin\Http\Controllers\Controller;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
use Webkul\Customer\Repositories\CustomerAddressRepository;
|
||||
use Webkul\Customer\Repositories\CustomerGroupRepository;
|
||||
use Webkul\Core\Repositories\ChannelRepository;
|
||||
|
||||
use Webkul\Admin\Mail\NewCustomerNotification;
|
||||
use Mail;
|
||||
|
||||
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;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* CustomerRepository object
|
||||
* Customer repository instance.
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\CustomerRepository
|
||||
*/
|
||||
protected $customerRepository;
|
||||
|
||||
/**
|
||||
* CustomerAddress Repository object
|
||||
* Customer address repository instance.
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\CustomerAddressRepository
|
||||
*/
|
||||
protected $customerAddressRepository;
|
||||
|
||||
/**
|
||||
* CustomerGroupRepository object
|
||||
* Customer group repository instance.
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\CustomerGroupRepository
|
||||
*/
|
||||
protected $customerGroupRepository;
|
||||
|
||||
/**
|
||||
* ChannelRepository object
|
||||
* Channel repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\ChannelRepository
|
||||
*/
|
||||
|
|
@ -66,17 +62,19 @@ class CustomerController extends Controller
|
|||
CustomerAddressRepository $customerAddressRepository,
|
||||
CustomerGroupRepository $customerGroupRepository,
|
||||
ChannelRepository $channelRepository
|
||||
)
|
||||
) {
|
||||
$this->_config = request('_config');
|
||||
|
||||
{
|
||||
$this->_config = request('_config');
|
||||
$this->middleware('admin');
|
||||
$this->customerRepository = $customerRepository;
|
||||
$this->middleware('admin');
|
||||
|
||||
$this->customerAddressRepository = $customerAddressRepository;
|
||||
$this->customerGroupRepository = $customerGroupRepository;
|
||||
$this->channelRepository = $channelRepository;
|
||||
}
|
||||
$this->customerRepository = $customerRepository;
|
||||
|
||||
$this->customerAddressRepository = $customerAddressRepository;
|
||||
|
||||
$this->customerGroupRepository = $customerGroupRepository;
|
||||
|
||||
$this->channelRepository = $channelRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
|
|
@ -125,12 +123,8 @@ class CustomerController extends Controller
|
|||
|
||||
$data['is_verified'] = 1;
|
||||
|
||||
Event::dispatch('customer.registration.before');
|
||||
|
||||
$customer = $this->customerRepository->create($data);
|
||||
|
||||
Event::dispatch('customer.registration.after', $customer);
|
||||
|
||||
try {
|
||||
$configKey = 'emails.general.notifications.emails.general.notifications.customer';
|
||||
if (core()->getConfigData($configKey)) {
|
||||
|
|
@ -181,11 +175,7 @@ class CustomerController extends Controller
|
|||
|
||||
$data['status'] = ! isset($data['status']) ? 0 : 1;
|
||||
|
||||
Event::dispatch('customer.update.before');
|
||||
|
||||
$customer = $this->customerRepository->update($data, $id);
|
||||
|
||||
Event::dispatch('customer.update.after', $customer);
|
||||
$this->customerRepository->update($data, $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Customer']));
|
||||
|
||||
|
|
@ -224,7 +214,7 @@ class CustomerController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* To load the note taking screen for the customers
|
||||
* To load the note taking screen for the customers.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\View\View
|
||||
|
|
@ -237,7 +227,7 @@ class CustomerController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* To store the response of the note in storage
|
||||
* To store the response of the note in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
|
@ -261,7 +251,7 @@ class CustomerController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* To mass update the customer
|
||||
* To mass update the customer.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
|
@ -282,7 +272,7 @@ class CustomerController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* To mass delete the customer
|
||||
* To mass delete the customer.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
|
@ -290,7 +280,7 @@ class CustomerController extends Controller
|
|||
{
|
||||
$customerIds = explode(',', request()->input('indexes'));
|
||||
|
||||
if (!$this->customerRepository->checkBulkCustomerIfTheyHaveOrderPendingOrProcessing($customerIds)) {
|
||||
if (! $this->customerRepository->checkBulkCustomerIfTheyHaveOrderPendingOrProcessing($customerIds)) {
|
||||
|
||||
foreach ($customerIds as $customerId) {
|
||||
$this->customerRepository->deleteWhere(['id' => $customerId]);
|
||||
|
|
@ -334,4 +324,4 @@ class CustomerController extends Controller
|
|||
|
||||
return view($this->_config['view'], compact('customer'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
namespace Webkul\Core\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\Core\Contracts\CoreConfig;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Core\Traits\CoreConfigField;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
use Webkul\Core\Contracts\CoreConfig;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\Core\Traits\CoreConfigField;
|
||||
|
||||
class CoreConfigRepository extends Repository
|
||||
{
|
||||
|
|
@ -17,7 +18,7 @@ class CoreConfigRepository extends Repository
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function model(): string
|
||||
public function model(): string
|
||||
{
|
||||
return CoreConfig::class;
|
||||
}
|
||||
|
|
@ -30,6 +31,8 @@ class CoreConfigRepository extends Repository
|
|||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
Event::dispatch('core.configuration.save.before');
|
||||
|
||||
if ($data['locale'] || $data['channel']) {
|
||||
$locale = $data['locale'];
|
||||
$channel = $data['channel'];
|
||||
|
|
@ -49,7 +52,7 @@ class CoreConfigRepository extends Repository
|
|||
$localeBased = isset($field['locale_based']) && $field['locale_based'] ? true : false;
|
||||
|
||||
if (getType($value) == 'array' && ! isset($value['delete'])) {
|
||||
$value = implode(",", $value);
|
||||
$value = implode(',', $value);
|
||||
}
|
||||
|
||||
if (isset($field['channel_based']) && $field['channel_based']) {
|
||||
|
|
@ -109,6 +112,8 @@ class CoreConfigRepository extends Repository
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Event::dispatch('core.configuration.save.after');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Webkul\Customer\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
|
|
@ -17,6 +18,40 @@ class CustomerRepository extends Repository
|
|||
return \Webkul\Customer\Contracts\Customer::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function create($attributes)
|
||||
{
|
||||
Event::dispatch('customer.registration.before');
|
||||
|
||||
$customer = parent::create($attributes);
|
||||
|
||||
Event::dispatch('customer.registration.after', $customer);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $attributes, $id)
|
||||
{
|
||||
Event::dispatch('customer.update.before');
|
||||
|
||||
$customer = parent::update($attributes, $id);
|
||||
|
||||
Event::dispatch('customer.update.after', $customer);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if customer has order pending or processing.
|
||||
*
|
||||
|
|
@ -57,7 +92,7 @@ class CustomerRepository extends Repository
|
|||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
public function uploadImages($data, $customer, $type = "image")
|
||||
public function uploadImages($data, $customer, $type = 'image')
|
||||
{
|
||||
if (isset($data[$type])) {
|
||||
$request = request();
|
||||
|
|
|
|||
Loading…
Reference in New Issue