Campaign And Cart Rule Event Moved
This commit is contained in:
parent
d01decf80f
commit
c2386835a2
|
|
@ -3,31 +3,30 @@
|
|||
namespace Webkul\CartRule\Http\Controllers;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Webkul\CartRule\Repositories\CartRuleRepository;
|
||||
use Illuminate\View\View;
|
||||
use Webkul\CartRule\Repositories\CartRuleCouponRepository;
|
||||
use Webkul\CartRule\Repositories\CartRuleRepository;
|
||||
|
||||
class CartRuleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Initialize _config, a default request parameter with route
|
||||
* Initialize _config, a default request parameter with route.
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* To hold Cart repository instance
|
||||
* To hold cart repository instance.
|
||||
*
|
||||
* @var \Webkul\CartRule\Repositories\CartRuleRepository
|
||||
*/
|
||||
protected $cartRuleRepository;
|
||||
|
||||
/**
|
||||
* To hold CartRuleCouponRepository repository instance
|
||||
* To hold cart rule coupon repository repository instance.
|
||||
*
|
||||
* @var \Webkul\CartRule\Repositories\CartRuleCouponRepository
|
||||
*/
|
||||
|
|
@ -44,8 +43,7 @@ class CartRuleController extends Controller
|
|||
public function __construct(
|
||||
CartRuleRepository $cartRuleRepository,
|
||||
CartRuleCouponRepository $cartRuleCouponRepository
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->cartRuleRepository = $cartRuleRepository;
|
||||
|
|
@ -66,7 +64,6 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
|
|
@ -77,6 +74,9 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Copy a given Cart Rule id. Always make the copy is inactive so the
|
||||
* user is able to configure it before setting it live.
|
||||
*
|
||||
* @param int $cartRuleId
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function copy(int $cartRuleId): View
|
||||
{
|
||||
|
|
@ -130,17 +130,12 @@ class CartRuleController extends Controller
|
|||
|
||||
$data = request()->all();
|
||||
|
||||
Event::dispatch('promotions.cart_rule.create.before');
|
||||
|
||||
$cartRule = $this->cartRuleRepository->create($data);
|
||||
|
||||
Event::dispatch('promotions.cart_rule.create.after', $cartRule);
|
||||
$this->cartRuleRepository->create($data);
|
||||
|
||||
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Cart Rule']));
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
} catch (ValidationException $e) {
|
||||
|
||||
if ($firstError = collect($e->errors())->first()) {
|
||||
session()->flash('error', $firstError[0]);
|
||||
}
|
||||
|
|
@ -152,8 +147,7 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
|
|
@ -166,9 +160,8 @@ class CartRuleController 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)
|
||||
|
|
@ -200,17 +193,12 @@ class CartRuleController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
Event::dispatch('promotions.cart_rule.update.before', $cartRule);
|
||||
|
||||
$cartRule = $this->cartRuleRepository->update(request()->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']);
|
||||
} catch (ValidationException $e) {
|
||||
|
||||
if ($firstError = collect($e->errors())->first()) {
|
||||
session()->flash('error', $firstError[0]);
|
||||
}
|
||||
|
|
@ -222,21 +210,16 @@ class CartRuleController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$cartRule = $this->cartRuleRepository->findOrFail($id);
|
||||
$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);
|
||||
|
||||
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Cart Rule']));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
|
|
@ -248,7 +231,7 @@ class CartRuleController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate coupon code for cart rule
|
||||
* Generate coupon code for cart rule.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
|
|
@ -268,4 +251,4 @@ class CartRuleController extends Controller
|
|||
|
||||
return response()->json(['message' => trans('admin::app.response.create-success', ['name' => 'Cart rule coupons'])]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,60 +3,61 @@
|
|||
namespace Webkul\CartRule\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\Tax\Repositories\TaxCategoryRepository;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\Core\Repositories\CountryRepository;
|
||||
use Webkul\Core\Repositories\CountryStateRepository;
|
||||
use Webkul\Tax\Repositories\TaxCategoryRepository;
|
||||
|
||||
class CartRuleRepository 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;
|
||||
|
||||
/**
|
||||
* CartRuleCouponRepository object
|
||||
* Cart rule coupon repository instance.
|
||||
*
|
||||
* @var \Webkul\CartRule\Repositories\CartRuleCouponRepository
|
||||
*/
|
||||
protected $cartRuleCouponRepository;
|
||||
|
||||
/**
|
||||
* TaxCategoryRepository class
|
||||
* Tax category repository instance.
|
||||
*
|
||||
* @var \Webkul\Tax\Repositories\TaxCategoryRepository
|
||||
*/
|
||||
protected $taxCategoryRepository;
|
||||
|
||||
/**
|
||||
* CountryRepository class
|
||||
* Country repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\CountryRepository
|
||||
*/
|
||||
protected $countryRepository;
|
||||
|
||||
/**
|
||||
* CountryStateRepository class
|
||||
* Country state repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\CountryStateRepository
|
||||
*/
|
||||
|
|
@ -84,8 +85,7 @@ class CartRuleRepository extends Repository
|
|||
CountryRepository $countryRepository,
|
||||
CountryStateRepository $countryStateRepository,
|
||||
App $app
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->attributeFamilyRepository = $attributeFamilyRepository;
|
||||
|
||||
$this->attributeRepository = $attributeRepository;
|
||||
|
|
@ -108,7 +108,7 @@ class CartRuleRepository extends Repository
|
|||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\CartRule\Contracts\CartRule';
|
||||
}
|
||||
|
|
@ -119,6 +119,8 @@ 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;
|
||||
|
|
@ -142,6 +144,8 @@ class CartRuleRepository extends Repository
|
|||
]);
|
||||
}
|
||||
|
||||
Event::dispatch('promotions.cart_rule.create.after', $cartRule);
|
||||
|
||||
return $cartRule;
|
||||
}
|
||||
|
||||
|
|
@ -151,8 +155,10 @@ class CartRuleRepository extends Repository
|
|||
* @param string $attribute
|
||||
* @return \Webkul\CartRule\Contracts\CartRule
|
||||
*/
|
||||
public function update(array $data, $id, $attribute = "id")
|
||||
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;
|
||||
|
|
@ -203,11 +209,28 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attributes for cart rule conditions
|
||||
* 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.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -250,8 +273,8 @@ class CartRuleRepository extends Repository
|
|||
'type' => 'select',
|
||||
'options' => $this->getCountries(),
|
||||
'label' => trans('admin::app.promotions.cart-rules.shipping-country'),
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
], [
|
||||
'key' => 'cart_item',
|
||||
'label' => trans('admin::app.promotions.cart-rules.cart-item-attribute'),
|
||||
|
|
@ -276,8 +299,8 @@ class CartRuleRepository extends Repository
|
|||
'key' => 'cart_item|additional',
|
||||
'type' => 'text',
|
||||
'label' => trans('admin::app.promotions.cart-rules.additional'),
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
], [
|
||||
'key' => 'product',
|
||||
'label' => trans('admin::app.promotions.cart-rules.product-attribute'),
|
||||
|
|
@ -302,9 +325,9 @@ class CartRuleRepository extends Repository
|
|||
'type' => 'select',
|
||||
'label' => trans('admin::app.promotions.cart-rules.attribute_family'),
|
||||
'options' => $this->getAttributeFamilies(),
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($this->attributeRepository->findWhereNotIn('type', ['textarea', 'image', 'file']) as $attribute) {
|
||||
|
|
@ -350,7 +373,7 @@ class CartRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all payment methods
|
||||
* Returns all payment methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -371,7 +394,7 @@ class CartRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all shipping methods
|
||||
* Returns all shipping methods.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -392,7 +415,7 @@ class CartRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all countries
|
||||
* Returns all countries.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -411,7 +434,7 @@ class CartRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all attribute families
|
||||
* Returns all attribute families.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -430,7 +453,7 @@ class CartRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all countries
|
||||
* Returns all countries.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -449,7 +472,7 @@ class CartRuleRepository extends Repository
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve all grouped states by country code
|
||||
* Retrieve all grouped states by country code.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -476,4 +499,4 @@ class CartRuleRepository extends Repository
|
|||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,29 +2,28 @@
|
|||
|
||||
namespace Webkul\Marketing\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Marketing\Repositories\CampaignRepository;
|
||||
|
||||
class CampaignController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* CampaignRepository object
|
||||
* Campaign repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\CampaignRepository
|
||||
* @var \Webkul\Marketing\Repositories\CampaignRepository
|
||||
*/
|
||||
protected $campaignRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Core\Repositories\CampaignRepository $campaignRepository
|
||||
* @param \Webkul\Marketing\Repositories\CampaignRepository $campaignRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CampaignRepository $campaignRepository)
|
||||
|
|
@ -69,11 +68,7 @@ class CampaignController extends Controller
|
|||
'marketing_event_id' => 'required_if:schedule_type,event',
|
||||
]);
|
||||
|
||||
Event::dispatch('marketing.campaigns.create.before');
|
||||
|
||||
$locale = $this->campaignRepository->create(request()->all());
|
||||
|
||||
Event::dispatch('marketing.campaigns.create.after', $locale);
|
||||
$this->campaignRepository->create(request()->all());
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.campaigns.create-success'));
|
||||
|
||||
|
|
@ -109,11 +104,7 @@ class CampaignController extends Controller
|
|||
'marketing_event_id' => 'required_if:schedule_type,event',
|
||||
]);
|
||||
|
||||
Event::dispatch('marketing.campaigns.update.before', $id);
|
||||
|
||||
$locale = $this->campaignRepository->update(request()->all(), $id);
|
||||
|
||||
Event::dispatch('marketing.campaigns.update.after', $locale);
|
||||
$this->campaignRepository->update(request()->all(), $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.campaigns.update-success'));
|
||||
|
||||
|
|
@ -128,22 +119,18 @@ class CampaignController extends Controller
|
|||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$locale = $this->campaignRepository->findOrFail($id);
|
||||
$this->campaignRepository->findOrFail($id);
|
||||
|
||||
try {
|
||||
Event::dispatch('marketing.campaigns.delete.before', $id);
|
||||
|
||||
$this->campaignRepository->delete($id);
|
||||
|
||||
Event::dispatch('marketing.campaigns.delete.after', $id);
|
||||
|
||||
session()->flash('success', trans('admin::app.marketing.campaigns.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 Campaign']));
|
||||
}
|
||||
|
||||
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 CampaignRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
* Specify model class name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
public function model()
|
||||
{
|
||||
return 'Webkul\Marketing\Contracts\Campaign';
|
||||
return \Webkul\Marketing\Contracts\Campaign::class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(array $attributes)
|
||||
{
|
||||
Event::dispatch('marketing.campaigns.create.before');
|
||||
|
||||
$campaign = parent::create($attributes);
|
||||
|
||||
Event::dispatch('marketing.campaigns.create.after', $campaign);
|
||||
|
||||
return $campaign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(array $attributes, $id)
|
||||
{
|
||||
Event::dispatch('marketing.campaigns.update.before', $id);
|
||||
|
||||
$campaign = parent::update($attributes, $id);
|
||||
|
||||
Event::dispatch('marketing.campaigns.update.after', $campaign);
|
||||
|
||||
return $campaign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete.
|
||||
*
|
||||
* @param $id
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
Event::dispatch('marketing.campaigns.delete.before', $id);
|
||||
|
||||
parent::delete($id);
|
||||
|
||||
Event::dispatch('marketing.campaigns.delete.after', $id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue