Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\CheckoutAgreements\Model\AgreementFactory;
16 
17 class Edit extends Agreement implements HttpGetActionInterface
18 {
22  private $agreementFactory;
23 
29  public function __construct(
30  Context $context,
31  Registry $coreRegistry,
32  AgreementFactory $agreementFactory = null
33  ) {
34  $this->agreementFactory = $agreementFactory ?:
35  ObjectManager::getInstance()->get(AgreementFactory::class);
36  parent::__construct($context, $coreRegistry);
37  }
42  public function execute()
43  {
44  $id = $this->getRequest()->getParam('id');
45  $agreementModel = $this->agreementFactory->create();
46 
47  if ($id) {
48  $agreementModel->load($id);
49  if (!$agreementModel->getId()) {
50  $this->messageManager->addError(__('This condition no longer exists.'));
51  $this->_redirect('checkout/*/');
52  return;
53  }
54  }
55 
56  $data = $this->_session->getAgreementData(true);
57  if (!empty($data)) {
58  $agreementModel->setData($data);
59  }
60 
61  $this->_coreRegistry->register('checkout_agreement', $agreementModel);
62 
63  $this->_initAction()->_addBreadcrumb(
64  $id ? __('Edit Condition') : __('New Condition'),
65  $id ? __('Edit Condition') : __('New Condition')
66  )->_addContent(
67  $this->_view->getLayout()->createBlock(
68  BlockEdit::class
69  )->setData(
70  'action',
71  $this->getUrl('checkout/*/save')
72  )
73  );
74  $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Terms and Conditions'));
75  $this->_view->getPage()->getConfig()->getTitle()->prepend(
76  $agreementModel->getId() ? $agreementModel->getName() : __('New Condition')
77  );
78  $this->_view->renderLayout();
79  }
80 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
__construct(Context $context, Registry $coreRegistry, AgreementFactory $agreementFactory=null)
Definition: Edit.php:29