Catalog Rule, Channel, Event And Template Done
This commit is contained in:
parent
c2386835a2
commit
137a45b884
|
|
@ -3,29 +3,28 @@
|
|||
namespace Webkul\CatalogRule\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\CatalogRule\Repositories\CatalogRuleRepository;
|
||||
use Webkul\CatalogRule\Helpers\CatalogRuleIndex;
|
||||
use Webkul\CatalogRule\Repositories\CatalogRuleRepository;
|
||||
|
||||
class CatalogRuleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Initialize _config, a default request parameter with route
|
||||
*
|
||||
* Initialize _config, a default request parameter with route.
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* To hold Catalog repository instance
|
||||
*
|
||||
* To hold catalog repository instance.
|
||||
*
|
||||
* @var \Webkul\CatalogRule\Repositories\CatalogRuleRepository
|
||||
*/
|
||||
protected $catalogRuleRepository;
|
||||
|
||||
/**
|
||||
* CatalogRuleIndex
|
||||
*
|
||||
* Catalog rule index.
|
||||
*
|
||||
* @var \Webkul\CatalogRule\Helpers\CatalogRuleIndex
|
||||
*/
|
||||
protected $catalogRuleIndexHelper;
|
||||
|
|
@ -40,8 +39,7 @@ class CatalogRuleController extends Controller
|
|||
public function __construct(
|
||||
CatalogRuleRepository $catalogRuleRepository,
|
||||
CatalogRuleIndex $catalogRuleIndexHelper
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->catalogRuleRepository = $catalogRuleRepository;
|
||||
|
|
@ -88,11 +86,7 @@ class CatalogRuleController extends Controller
|
|||
|
||||
$data = request()->all();
|
||||
|
||||
Event::dispatch('promotions.catalog_rule.create.before');
|
||||
|
||||
$catalogRule = $this->catalogRuleRepository->create($data);
|
||||
|
||||
Event::dispatch('promotions.catalog_rule.create.after', $catalogRule);
|
||||
$this->catalogRuleRepository->create($data);
|
||||
|
||||
$this->catalogRuleIndexHelper->reindexComplete();
|
||||
|
||||
|
|
@ -117,8 +111,8 @@ class CatalogRuleController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
|
|
@ -133,13 +127,9 @@ class CatalogRuleController extends Controller
|
|||
'discount_amount' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$catalogRule = $this->catalogRuleRepository->findOrFail($id);
|
||||
$this->catalogRuleRepository->findOrFail($id);
|
||||
|
||||
Event::dispatch('promotions.catalog_rule.update.before', $catalogRule);
|
||||
|
||||
$catalogRule = $this->catalogRuleRepository->update(request()->all(), $id);
|
||||
|
||||
Event::dispatch('promotions.catalog_rule.update.after', $catalogRule);
|
||||
$this->catalogRuleRepository->update(request()->all(), $id);
|
||||
|
||||
$this->catalogRuleIndexHelper->reindexComplete();
|
||||
|
||||
|
|
@ -156,22 +146,18 @@ class CatalogRuleController extends Controller
|
|||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$catalogRule = $this->catalogRuleRepository->findOrFail($id);
|
||||
$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);
|
||||
|
||||
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Catalog Rule']));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Catalog Rule']));
|
||||
}
|
||||
|
||||
return response()->json(['message' => false], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,37 +3,38 @@
|
|||
namespace Webkul\CatalogRule\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* AttributeFamilyRepository object
|
||||
* Attribute family repository instance.
|
||||
*
|
||||
* @var \Webkul\Attribute\Repositories\AttributeFamilyRepository
|
||||
*/
|
||||
protected $attributeFamilyRepository;
|
||||
|
||||
/**
|
||||
* AttributeRepository object
|
||||
* Attribute repository instance.
|
||||
*
|
||||
* @var \Webkul\Attribute\Repositories\AttributeRepository
|
||||
*/
|
||||
protected $attributeRepository;
|
||||
|
||||
/**
|
||||
* CategoryRepository class
|
||||
* Category repository instance.
|
||||
*
|
||||
* @var \Webkul\Category\Repositories\CategoryRepository
|
||||
*/
|
||||
protected $categoryRepository;
|
||||
|
||||
/**
|
||||
* TaxCategoryRepository class
|
||||
* Tax category repository instance.
|
||||
*
|
||||
* @var \Webkul\CaTaxtegory\Repositories\axCategoryRepository
|
||||
*/
|
||||
|
|
@ -55,8 +56,7 @@ class CatalogRuleRepository extends Repository
|
|||
CategoryRepository $categoryRepository,
|
||||
TaxCategoryRepository $taxCategoryRepository,
|
||||
App $app
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->attributeFamilyRepository = $attributeFamilyRepository;
|
||||
|
||||
$this->attributeRepository = $attributeRepository;
|
||||
|
|
@ -69,21 +69,25 @@ class CatalogRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\CatalogRule\Contracts\CatalogRule';
|
||||
return \Webkul\CatalogRule\Contracts\CatalogRule::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Webkul\CatalogRule\Contracts\CatalogRule
|
||||
*/
|
||||
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;
|
||||
|
|
@ -96,17 +100,23 @@ class CatalogRuleRepository extends Repository
|
|||
|
||||
$catalogRule->customer_groups()->sync($data['customer_groups']);
|
||||
|
||||
Event::dispatch('promotions.catalog_rule.create.after', $catalogRule);
|
||||
|
||||
return $catalogRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $id
|
||||
* @param string $attribute
|
||||
* @return \Webkul\CatalogRule\Contracts\CatalogRule
|
||||
*/
|
||||
public function update(array $data, $id, $attribute = "id")
|
||||
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;
|
||||
|
|
@ -123,11 +133,28 @@ class CatalogRuleRepository extends Repository
|
|||
|
||||
$catalogRule->customer_groups()->sync($data['customer_groups']);
|
||||
|
||||
Event::dispatch('promotions.catalog_rule.update.after', $catalogRule);
|
||||
|
||||
return $catalogRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attributes for catalog rule conditions
|
||||
* 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.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -148,9 +175,9 @@ class CatalogRuleRepository extends Repository
|
|||
'type' => 'select',
|
||||
'label' => trans('admin::app.promotions.catalog-rules.attribute_family'),
|
||||
'options' => $this->getAttributeFamilies(),
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($this->attributeRepository->findWhereNotIn('type', ['textarea', 'image', 'file']) as $attribute) {
|
||||
|
|
@ -166,11 +193,13 @@ class CatalogRuleRepository extends Repository
|
|||
}
|
||||
}
|
||||
|
||||
if ($attribute->validation == 'decimal')
|
||||
if ($attribute->validation == 'decimal') {
|
||||
$attributeType = 'decimal';
|
||||
}
|
||||
|
||||
if ($attribute->validation == 'numeric')
|
||||
if ($attribute->validation == 'numeric') {
|
||||
$attributeType = 'integer';
|
||||
}
|
||||
|
||||
$attributes[0]['children'][] = [
|
||||
'key' => 'product|' . $attribute->code,
|
||||
|
|
@ -184,7 +213,7 @@ class CatalogRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all tax categories
|
||||
* Returns all tax categories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -203,7 +232,7 @@ class CatalogRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all attribute families
|
||||
* Returns all attribute families.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -220,4 +249,4 @@ class CatalogRuleRepository extends Repository
|
|||
|
||||
return $attributeFamilies;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Webkul\Core\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Core\Repositories\ChannelRepository;
|
||||
|
||||
class ChannelController extends Controller
|
||||
|
|
@ -15,7 +14,7 @@ class ChannelController extends Controller
|
|||
protected $_config;
|
||||
|
||||
/**
|
||||
* ChannelRepository object
|
||||
* Channel repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\ChannelRepository
|
||||
*/
|
||||
|
|
@ -63,44 +62,40 @@ class ChannelController extends Controller
|
|||
{
|
||||
$data = $this->validate(request(), [
|
||||
/* general */
|
||||
'code' => ['required', 'unique:channels,code', new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'description' => 'nullable',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'root_category_id' => 'required',
|
||||
'hostname' => 'unique:channels,hostname',
|
||||
'code' => ['required', 'unique:channels,code', new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
'description' => 'nullable',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'root_category_id' => 'required',
|
||||
'hostname' => 'unique:channels,hostname',
|
||||
|
||||
/* currencies and locales */
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
|
||||
/* design */
|
||||
'theme' => 'nullable',
|
||||
'home_page_content' => 'nullable',
|
||||
'footer_content' => 'nullable',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'theme' => 'nullable',
|
||||
'home_page_content' => 'nullable',
|
||||
'footer_content' => 'nullable',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
|
||||
/* seo */
|
||||
'seo_title' => 'required|string',
|
||||
'seo_description' => 'required|string',
|
||||
'seo_keywords' => 'required|string',
|
||||
'seo_title' => 'required|string',
|
||||
'seo_description' => 'required|string',
|
||||
'seo_keywords' => 'required|string',
|
||||
|
||||
/* maintenance mode */
|
||||
'is_maintenance_on' => 'boolean',
|
||||
'maintenance_mode_text' => 'nullable',
|
||||
'allowed_ips' => 'nullable'
|
||||
'allowed_ips' => 'nullable',
|
||||
]);
|
||||
|
||||
$data = $this->setSEOContent($data);
|
||||
|
||||
Event::dispatch('core.channel.create.before');
|
||||
|
||||
$channel = $this->channelRepository->create($data);
|
||||
|
||||
Event::dispatch('core.channel.create.after', $channel);
|
||||
$this->channelRepository->create($data);
|
||||
|
||||
session()->flash('success', trans('admin::app.settings.channels.create-success'));
|
||||
|
||||
|
|
@ -132,49 +127,45 @@ class ChannelController extends Controller
|
|||
|
||||
$data = $this->validate(request(), [
|
||||
/* general */
|
||||
'code' => ['required', 'unique:channels,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
||||
$locale . '.name' => 'required',
|
||||
$locale . '.description' => 'nullable',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'root_category_id' => 'required',
|
||||
'hostname' => 'unique:channels,hostname,' . $id,
|
||||
'code' => ['required', 'unique:channels,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
||||
$locale . '.name' => 'required',
|
||||
$locale . '.description' => 'nullable',
|
||||
'inventory_sources' => 'required|array|min:1',
|
||||
'root_category_id' => 'required',
|
||||
'hostname' => 'unique:channels,hostname,' . $id,
|
||||
|
||||
/* currencies and locales */
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
'locales' => 'required|array|min:1',
|
||||
'default_locale_id' => 'required|in_array:locales.*',
|
||||
'currencies' => 'required|array|min:1',
|
||||
'base_currency_id' => 'required|in_array:currencies.*',
|
||||
|
||||
/* design */
|
||||
'theme' => 'nullable',
|
||||
$locale . '.home_page_content' => 'nullable',
|
||||
$locale . '.footer_content' => 'nullable',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'theme' => 'nullable',
|
||||
$locale . '.home_page_content' => 'nullable',
|
||||
$locale . '.footer_content' => 'nullable',
|
||||
'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp',
|
||||
|
||||
/* seo */
|
||||
$locale . '.seo_title' => 'nullable',
|
||||
$locale . '.seo_description' => 'nullable',
|
||||
$locale . '.seo_keywords' => 'nullable',
|
||||
$locale . '.seo_title' => 'nullable',
|
||||
$locale . '.seo_description' => 'nullable',
|
||||
$locale . '.seo_keywords' => 'nullable',
|
||||
|
||||
/* maintenance mode */
|
||||
'is_maintenance_on' => 'boolean',
|
||||
$locale . '.maintenance_mode_text' => 'nullable',
|
||||
'allowed_ips' => 'nullable'
|
||||
'allowed_ips' => 'nullable',
|
||||
]);
|
||||
|
||||
$data = $this->setSEOContent($data, $locale);
|
||||
|
||||
Event::dispatch('core.channel.update.before', $id);
|
||||
|
||||
$channel = $this->channelRepository->update($data, $id);
|
||||
|
||||
if ($channel->base_currency->code !== session()->get('currency')) {
|
||||
session()->put('currency', $channel->base_currency->code);
|
||||
}
|
||||
|
||||
Event::dispatch('core.channel.update.after', $channel);
|
||||
|
||||
session()->flash('success', trans('admin::app.settings.channels.update-success'));
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
|
|
@ -194,16 +185,12 @@ class ChannelController extends Controller
|
|||
session()->flash('error', trans('admin::app.settings.channels.last-delete-error'));
|
||||
} else {
|
||||
try {
|
||||
Event::dispatch('core.channel.delete.before', $id);
|
||||
|
||||
$this->channelRepository->delete($id);
|
||||
|
||||
Event::dispatch('core.channel.delete.after', $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.settings.channels.delete-success'));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Channel']));
|
||||
}
|
||||
}
|
||||
|
|
@ -255,4 +242,4 @@ class ChannelController extends Controller
|
|||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,30 +2,35 @@
|
|||
|
||||
namespace Webkul\Core\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
class ChannelRepository extends Repository
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\Core\Contracts\Channel';
|
||||
return \Webkul\Core\Contracts\Channel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Webkul\Core\Contracts\Channel
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
Event::dispatch('core.channel.create.before');
|
||||
|
||||
$model = $this->getModel();
|
||||
|
||||
foreach (core()->getAllLocales() as $locale) {
|
||||
|
|
@ -48,17 +53,23 @@ class ChannelRepository extends Repository
|
|||
|
||||
$this->uploadImages($data, $channel, 'favicon');
|
||||
|
||||
Event::dispatch('core.channel.create.after', $channel);
|
||||
|
||||
return $channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $id
|
||||
* @param string $attribute
|
||||
* @return \Webkul\Core\Contracts\Channel
|
||||
*/
|
||||
public function update(array $data, $id, $attribute = "id")
|
||||
public function update(array $data, $id, $attribute = 'id')
|
||||
{
|
||||
Event::dispatch('core.channel.update.before', $id);
|
||||
|
||||
$channel = $this->find($id);
|
||||
|
||||
$channel = parent::update($data, $id, $attribute);
|
||||
|
|
@ -73,16 +84,35 @@ class ChannelRepository extends Repository
|
|||
|
||||
$this->uploadImages($data, $channel, 'favicon');
|
||||
|
||||
Event::dispatch('core.channel.update.after', $channel);
|
||||
|
||||
return $channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete.
|
||||
*
|
||||
* @param $id
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
Event::dispatch('core.channel.delete.before', $id);
|
||||
|
||||
parent::delete($id);
|
||||
|
||||
Event::dispatch('core.channel.delete.after', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload images.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Webkul\Core\Contratcs\Channel $channel
|
||||
* @param \Webkul\Core\Contracts\Channel $channel
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
public function uploadImages($data, $channel, $type = "logo")
|
||||
public function uploadImages($data, $channel, $type = 'logo')
|
||||
{
|
||||
if (isset($data[$type])) {
|
||||
foreach ($data[$type] as $imageId => $image) {
|
||||
|
|
@ -104,7 +134,8 @@ class ChannelRepository extends Repository
|
|||
}
|
||||
|
||||
$channel->{$type} = null;
|
||||
|
||||
$channel->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,20 +2,19 @@
|
|||
|
||||
namespace Webkul\Marketing\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Marketing\Repositories\EventRepository;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* EventRepository object
|
||||
* Event repository instance.
|
||||
*
|
||||
* @var \Webkul\Marketing\Repositories\EventRepository
|
||||
*/
|
||||
|
|
@ -67,11 +66,7 @@ class EventController extends Controller
|
|||
'date' => 'date|required',
|
||||
]);
|
||||
|
||||
Event::dispatch('marketing.events.create.before');
|
||||
|
||||
$locale = $this->eventRepository->create(request()->all());
|
||||
|
||||
Event::dispatch('marketing.events.create.after', $locale);
|
||||
$this->eventRepository->create(request()->all());
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.events.create-success'));
|
||||
|
||||
|
|
@ -111,11 +106,7 @@ class EventController extends Controller
|
|||
'date' => 'date|required',
|
||||
]);
|
||||
|
||||
Event::dispatch('marketing.events.update.before', $id);
|
||||
|
||||
$locale = $this->eventRepository->update(request()->all(), $id);
|
||||
|
||||
Event::dispatch('marketing.events.update.after', $locale);
|
||||
$this->eventRepository->update(request()->all(), $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.events.update-success'));
|
||||
|
||||
|
|
@ -130,19 +121,15 @@ class EventController extends Controller
|
|||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$locale = $this->eventRepository->findOrFail($id);
|
||||
$this->eventRepository->findOrFail($id);
|
||||
|
||||
try {
|
||||
Event::dispatch('marketing.events.delete.before', $id);
|
||||
|
||||
$this->eventRepository->delete($id);
|
||||
|
||||
Event::dispatch('marketing.events.delete.after', $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.events.delete-success'));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Event']));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,29 +2,28 @@
|
|||
|
||||
namespace Webkul\Marketing\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Marketing\Repositories\TemplateRepository;
|
||||
|
||||
class TemplateController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* TemplateRepository object
|
||||
* Template repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\TemplateRepository
|
||||
* @var \Webkul\Marketing\Repositories\TemplateRepository
|
||||
*/
|
||||
protected $templateRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Core\Repositories\TemplateRepository $templateRepository
|
||||
* @param \Webkul\Marketing\Repositories\TemplateRepository $templateRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(TemplateRepository $templateRepository)
|
||||
|
|
@ -67,11 +66,7 @@ class TemplateController extends Controller
|
|||
'content' => 'required',
|
||||
]);
|
||||
|
||||
Event::dispatch('marketing.templates.create.before');
|
||||
|
||||
$locale = $this->templateRepository->create(request()->all());
|
||||
|
||||
Event::dispatch('marketing.templates.create.after', $locale);
|
||||
$this->templateRepository->create(request()->all());
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.templates.create-success'));
|
||||
|
||||
|
|
@ -105,11 +100,7 @@ class TemplateController extends Controller
|
|||
'content' => 'required',
|
||||
]);
|
||||
|
||||
Event::dispatch('marketing.templates.update.before', $id);
|
||||
|
||||
$locale = $this->templateRepository->update(request()->all(), $id);
|
||||
|
||||
Event::dispatch('marketing.templates.update.after', $locale);
|
||||
$this->templateRepository->update(request()->all(), $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.templates.update-success'));
|
||||
|
||||
|
|
@ -124,22 +115,18 @@ class TemplateController extends Controller
|
|||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$locale = $this->templateRepository->findOrFail($id);
|
||||
$this->templateRepository->findOrFail($id);
|
||||
|
||||
try {
|
||||
Event::dispatch('marketing.templates.delete.before', $id);
|
||||
|
||||
$this->templateRepository->delete($id);
|
||||
|
||||
Event::dispatch('marketing.templates.delete.after', $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.templates.delete-success'));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Email Template']));
|
||||
}
|
||||
|
||||
return response()->json(['message' => false], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,68 @@
|
|||
|
||||
namespace Webkul\Marketing\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
class EventRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\Marketing\Contracts\Event';
|
||||
return Webkul\Marketing\Contracts\Event::class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a new entity in repository
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $attributes)
|
||||
{
|
||||
Event::dispatch('marketing.events.create.before');
|
||||
|
||||
$event = parent::create($attributes);
|
||||
|
||||
Event::dispatch('marketing.events.create.after', $event);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $attributes, $id)
|
||||
{
|
||||
Event::dispatch('marketing.events.update.before', $id);
|
||||
|
||||
$event = parent::update($attributes, $id);
|
||||
|
||||
Event::dispatch('marketing.events.update.after', $event);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete.
|
||||
*
|
||||
* @param $id
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
Event::dispatch('marketing.events.delete.before', $id);
|
||||
|
||||
parent::delete($id);
|
||||
|
||||
Event::dispatch('marketing.events.delete.after', $id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,68 @@
|
|||
|
||||
namespace Webkul\Marketing\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
class TemplateRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\Marketing\Contracts\Template';
|
||||
return \Webkul\Marketing\Contracts\Template::class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $attributes)
|
||||
{
|
||||
Event::dispatch('marketing.templates.create.before');
|
||||
|
||||
$template = parent::create($attributes);
|
||||
|
||||
Event::dispatch('marketing.templates.create.after', $template);
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $attributes, $id)
|
||||
{
|
||||
Event::dispatch('marketing.templates.update.before', $id);
|
||||
|
||||
$template = parent::update($attributes, $id);
|
||||
|
||||
Event::dispatch('marketing.templates.update.after', $template);
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete.
|
||||
*
|
||||
* @param int $id
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
Event::dispatch('marketing.templates.delete.before', $id);
|
||||
|
||||
parent::delete($id);
|
||||
|
||||
Event::dispatch('marketing.templates.delete.after', $id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue