<?php
/**
* LandofCoder
*
* NOTICE OF LICENSE
*
* This source file is subject to the landofcoder.com license that is
* available through the world-wide-web at this URL:
* https://landofcoder.com/license
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category LandofCoder
* @package Lofmp_CouponCode
* @copyright Copyright (c) 2016 Landofcoder (https://landofcoder.com/)
* @license https://landofcoder.com/LICENSE-1.0.html
*/
namespace Lofmp\CouponCode\Controller\Adminhtml\Coupon;
class Edit extends \Lofmp\CouponCode\Controller\Adminhtml\Coupon
{
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context, $coreRegistry);
}
/**
* Index action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
// 1. Get ID and create model
$id = $this->getRequest()->getParam('couponcode_id');
$model = $this->_objectManager->create('Lofmp\CouponCode\Model\Coupon');
// 2. Initial checking
if ($id) {
$model->load($id);
if (!$model->getId()) {
$this->messageManager->addError(__('This Coupon no longer exists.'));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/');
}
}
$this->_coreRegistry->register('lofmpcouponcode_coupon', $model);
$resultPage = $this->resultPageFactory->create();
// 5. Build edit form
$this->initPage($resultPage)->addBreadcrumb(
$id ? __('Edit Coupon') : __('New Coupon'),
$id ? __('Edit Coupon') : __('New Coupon')
);
$resultPage->getConfig()->getTitle()->prepend(__('Coupons'));
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getName() : __('New Coupon'));
return $resultPage;
}
/**
* {@inheritdoc}
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Lofmp_CouponCode::coupon_edit');
}
}
|