Skip to content

Commit

Permalink
create seperate package for marketing.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Nov 4, 2024
1 parent 5568406 commit bf5653a
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 96 deletions.
3 changes: 1 addition & 2 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Illuminate\Support\Facades\Facade;
use Illuminate\Support\ServiceProvider;
use Webkul\WebForm\Contracts\WebForm;

return [

Expand Down Expand Up @@ -209,7 +208,7 @@
Webkul\DataGrid\Providers\DataGridServiceProvider::class,
Webkul\EmailTemplate\Providers\EmailTemplateServiceProvider::class,
Webkul\Email\Providers\EmailServiceProvider::class,
Webkul\Marketing\Providers\MarketingEventServiceProvider::class,
Webkul\Marketing\Providers\MarketingServiceProvider::class,
Webkul\Installer\Providers\InstallerServiceProvider::class,
Webkul\Lead\Providers\LeadServiceProvider::class,
Webkul\Product\Providers\ProductServiceProvider::class,
Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/Admin/src/Config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
'route' => 'admin.settings.email_templates.index',
'sort' => 2,
'icon-class' => 'icon-settings-mail',
],
],
[
'key' => 'settings.automation.events',
'name' => 'admin::app.layouts.events',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?php

namespace Webkul\Admin\DataGrids\Settings;
namespace Webkul\Admin\DataGrids\Settings\Marketing;

use Illuminate\Support\Facades\DB;
use Webkul\DataGrid\DataGrid;

class MarketingEventDataGrid extends DataGrid
class EventDataGrid extends DataGrid
{
/**
* Prepare query builder.
*/
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('marketing_events')
$queryBuilder = DB::table('events')
->addSelect(
'marketing_events.id',
'marketing_events.name',
'marketing_events.description',
'marketing_events.date',
'events.id',
'events.name',
'events.description',
'events.date',
);

$this->addFilter('id', 'marketing_events.id');
$this->addFilter('id', 'events.id');

return $queryBuilder;
}
Expand All @@ -34,7 +34,7 @@ public function prepareColumns()
{
$this->addColumn([
'index' => 'id',
'label' => trans('admin::app.settings.marketing-events.index.datagrid.id'),
'label' => trans('admin::app.settings.marketing.events.index.datagrid.id'),
'type' => 'string',
'sortable' => true,
'searchable' => true,
Expand All @@ -43,7 +43,7 @@ public function prepareColumns()

$this->addColumn([
'index' => 'name',
'label' => trans('admin::app.settings.marketing-events.index.datagrid.name'),
'label' => trans('admin::app.settings.marketing.events.index.datagrid.name'),
'type' => 'string',
'sortable' => true,
'searchable' => true,
Expand All @@ -52,14 +52,14 @@ public function prepareColumns()

$this->addColumn([
'index' => 'description',
'label' => trans('admin::app.settings.marketing-events.index.datagrid.description'),
'label' => trans('admin::app.settings.marketing.events.index.datagrid.description'),
'type' => 'string',
'sortable' => true,
]);

$this->addColumn([
'index' => 'date',
'label' => trans('admin::app.settings.marketing-events.index.datagrid.date'),
'label' => trans('admin::app.settings.marketing.events.index.datagrid.date'),
'type' => 'string',
'sortable' => true,
]);
Expand All @@ -76,15 +76,15 @@ public function prepareActions()
$this->addAction([
'index' => 'edit',
'icon' => 'icon-edit',
'title' => trans('admin::app.settings.marketing-events.index.datagrid.edit'),
'title' => trans('admin::app.settings.marketing.events.index.datagrid.edit'),
'method' => 'GET',
'url' => fn ($row) => route('admin.settings.marketing_events.edit', $row->id),
]);

$this->addAction([
'index' => 'delete',
'icon' => 'icon-delete',
'title' => trans('admin::app.settings.marketing-events.index.datagrid.delete'),
'title' => trans('admin::app.settings.marketing.events.index.datagrid.delete'),
'method' => 'DELETE',
'url' => fn ($row) => route('admin.settings.marketing_events.delete', $row->id),
]);
Expand All @@ -97,7 +97,7 @@ public function prepareMassActions(): void
{
$this->addMassAction([
'icon' => 'icon-delete',
'title' => trans('admin::app.settings.marketing-events.index.datagrid.delete'),
'title' => trans('admin::app.settings.marketing.events.index.datagrid.delete'),
'method' => 'POST',
'url' => route('admin.settings.marketing_events.mass_delete'),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
<?php

namespace Webkul\Admin\Http\Controllers\Settings;
namespace Webkul\Admin\Http\Controllers\Settings\Marketing;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\MarketingEventDataGrid;
use Webkul\Admin\DataGrids\Settings\Marketing\EventDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Marketing\Repositories\MarketingEventRepository;
use Webkul\Marketing\Repositories\EventRepository;

class MarketingEventController extends Controller
class EventController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct(protected MarketingEventRepository $marketingEventRepository)
{
}
public function __construct(protected EventRepository $eventRepository) {}

/**
* Display a listing of the marketing events.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(MarketingEventDataGrid::class)->process();
return datagrid(EventDataGrid::class)->process();
}

return view('admin::settings.marketing-events.index');
return view('admin::settings.marketing.events.index');
}

/**
Expand All @@ -44,7 +42,7 @@ public function store(): JsonResponse

Event::dispatch('settings.marketing-event.create.before');

$marketingEvent = $this->marketingEventRepository->create($validatedData);
$marketingEvent = $this->eventRepository->create($validatedData);

Event::dispatch('settings.marketing-event.create.after', $marketingEvent);

Expand All @@ -67,7 +65,7 @@ public function update(int $id): JsonResponse

Event::dispatch('settings.marketing-event.update.before', $id);

$marketingEvent = $this->marketingEventRepository->update($validatedData, $id);
$marketingEvent = $this->eventRepository->update($validatedData, $id);

Event::dispatch('settings.marketing-event.update.after', $marketingEvent);

Expand All @@ -84,7 +82,7 @@ public function destroy(int $id): JsonResponse
{
Event::dispatch('settings.marketing-event.delete.before', $id);

$this->marketingEventRepository->delete($id);
$this->eventRepository->delete($id);

Event::dispatch('settings.marketing-event.delete.after', $id);

Expand All @@ -95,20 +93,17 @@ public function destroy(int $id): JsonResponse

/**
* Remove the specified marketing events from storage.
*
* @param MassDestroyRequest $massDestroyRequest
* @return JsonResponse
*/
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$marketingEvents = $this->marketingEventRepository->findWhereIn('id', $massDestroyRequest->input('indices'));
$marketingEvents = $this->eventRepository->findWhereIn('id', $massDestroyRequest->input('indices'));

dd($marketingEvents);

foreach ($marketingEvents as $marketingEvent) {
Event::dispatch('settings.marketing-event.delete.before', $marketingEvent);

$this->marketingEventRepository->delete($marketingEvent->id);
$this->eventRepository->delete($marketingEvent->id);

Event::dispatch('settings.marketing-event.delete.after', $marketingEvent);
}
Expand Down
54 changes: 28 additions & 26 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,35 +1082,37 @@
],
],

'marketing-events' => [
'index' => [
'create-btn' => 'Create Marketing Event',
'title' => 'Marketing Events',
'create-success' => 'Marketing Event created successfully.',
'update-success' => 'Marketing Event updated successfully.',
'delete-success' => 'Marketing Event deleted successfully.',
'delete-failed' => 'Marketing Event can not be deleted.',

'datagrid' => [
'delete' => 'Delete',
'edit' => 'Edit',
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'date' => 'Date',
],
'marketing' => [
'events' => [
'index' => [
'create-btn' => 'Create Marketing Event',
'title' => 'Marketing Events',
'create-success' => 'Marketing Event created successfully.',
'update-success' => 'Marketing Event updated successfully.',
'delete-success' => 'Marketing Event deleted successfully.',
'delete-failed' => 'Marketing Event can not be deleted.',

'datagrid' => [
'delete' => 'Delete',
'edit' => 'Edit',
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'date' => 'Date',
],

'create' => [
'title' => 'Create Marketing Event',
'name' => 'Name',
'date' => 'Date',
'description' => 'Description',
],
'create' => [
'title' => 'Create Marketing Event',
'name' => 'Name',
'date' => 'Date',
'description' => 'Description',
],

'edit' => [
'title' => 'Edit Marketing Event',
'edit' => [
'title' => 'Edit Marketing Event',
],
],
],
]
],

'tags' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<x-admin::layouts>
<!-- Page Title -->
<x-slot:title>
@lang('admin::app.settings.marketing-events.index.title')
@lang('admin::app.settings.marketing.events.index.title')
</x-slot>

<div class="flex flex-col gap-4">
Expand All @@ -18,7 +18,7 @@
</div>

<div class="text-xl font-bold dark:text-gray-300">
@lang('admin::app.settings.marketing-events.index.title')
@lang('admin::app.settings.marketing.events.index.title')
</div>
</div>

Expand All @@ -32,7 +32,7 @@
class="primary-button"
@click="$refs.marketingEvent.actionType = 'create';$refs.marketingEvent.toggleModal()"
>
@lang('admin::app.settings.marketing-events.index.create-btn')
@lang('admin::app.settings.marketing.events.index.create-btn')
</button>

{!! view_render_event('admin.settings.marketing-events.index.create_button.after') !!}
Expand Down Expand Up @@ -144,8 +144,8 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
<p class="text-lg font-bold text-gray-800 dark:text-white">
@{{
actionType == 'create'
? "@lang('admin::app.settings.marketing-events.index.create.title')"
: "@lang('admin::app.settings.marketing-events.index.edit.title')"
? "@lang('admin::app.settings.marketing.events.index.create.title')"
: "@lang('admin::app.settings.marketing.events.index.edit.title')"
}}
</p>
Expand All @@ -158,7 +158,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
<!-- Name -->
<x-admin::form.control-group>
<x-admin::form.control-group.label class="required">
@lang('admin::app.settings.marketing-events.index.create.name')
@lang('admin::app.settings.marketing.events.index.create.name')
</x-admin::form.control-group.label>
<x-admin::form.control-group.control
Expand All @@ -176,11 +176,10 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
<x-admin::form.control-group.error control-name="name" />
</x-admin::form.control-group>
<!-- Description -->
<x-admin::form.control-group>
<x-admin::form.control-group.label class="required">
@lang('admin::app.settings.marketing-events.index.create.description')
@lang('admin::app.settings.marketing.events.index.create.description')
</x-admin::form.control-group.label>
<x-admin::form.control-group.control
Expand All @@ -197,7 +196,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
<!-- Date -->
<x-admin::form.control-group>
<x-admin::form.control-group.label class="required">
@lang('admin::app.settings.marketing-events.index.create.date')
@lang('admin::app.settings.marketing.events.index.create.date')
</x-admin::form.control-group.label>
<x-admin::form.control-group.control
Expand Down
4 changes: 2 additions & 2 deletions packages/Webkul/Admin/src/Routes/Admin/settings-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use Illuminate\Support\Facades\Route;
use Webkul\Admin\Http\Controllers\Settings\AttributeController;
use Webkul\Admin\Http\Controllers\Settings\EmailTemplateController;
use Webkul\Admin\Http\Controllers\Settings\MarketingEventController;
use Webkul\Admin\Http\Controllers\Settings\GroupController;
use Webkul\Admin\Http\Controllers\Settings\LocationController;
use Webkul\Admin\Http\Controllers\Settings\Marketing\EventController;
use Webkul\Admin\Http\Controllers\Settings\PipelineController;
use Webkul\Admin\Http\Controllers\Settings\RoleController;
use Webkul\Admin\Http\Controllers\Settings\SettingController;
Expand Down Expand Up @@ -294,7 +294,7 @@
/**
* Events Routes.
*/
Route::controller(MarketingEventController::class)->prefix('events')->group(function () {
Route::controller(EventController::class)->prefix('events')->group(function () {
Route::get('', 'index')->name('admin.settings.marketing_events.index');

Route::post('create', 'store')->name('admin.settings.marketing_events.store');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Webkul\Marketing\Contracts;

interface MarketingEvent {}
interface Event {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public function up(): void
{
Schema::create('marketing_events', function (Blueprint $table) {
Schema::create('events', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
Expand All @@ -25,6 +25,6 @@ public function up(): void
*/
public function down(): void
{
Schema::dropIfExists('marketing_events');
Schema::dropIfExists('events');
}
};
Loading

0 comments on commit bf5653a

Please sign in to comment.