NewConditionHtml.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
  7. use Magento\Framework\App\Action\HttpPostActionInterface;
  8. /**
  9. * Controller class NewConditionHtml. Returns condition html
  10. */
  11. class NewConditionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpPostActionInterface
  12. {
  13. /**
  14. * New condition html action
  15. *
  16. * @return void
  17. */
  18. public function execute()
  19. {
  20. $id = $this->getRequest()->getParam('id');
  21. $formName = $this->getRequest()->getParam('form_namespace');
  22. $typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
  23. $type = $typeArr[0];
  24. $model = $this->_objectManager->create(
  25. $type
  26. )->setId(
  27. $id
  28. )->setType(
  29. $type
  30. )->setRule(
  31. $this->_objectManager->create(\Magento\SalesRule\Model\Rule::class)
  32. )->setPrefix(
  33. 'conditions'
  34. );
  35. if (!empty($typeArr[1])) {
  36. $model->setAttribute($typeArr[1]);
  37. }
  38. if ($model instanceof \Magento\Rule\Model\Condition\AbstractCondition) {
  39. $model->setJsFormObject($this->getRequest()->getParam('form'));
  40. $model->setFormName($formName);
  41. $html = $model->asHtmlRecursive();
  42. } else {
  43. $html = '';
  44. }
  45. $this->getResponse()->setBody($html);
  46. }
  47. }