ruleType = $ruleType; $this->ruleCondition = $ruleCondition; $this->ruleValue = $ruleValue; $this->jsonEncoder = $jsonEncoder; $this->escaper = $escaper; parent::__construct($context); $this->http = $http; } /** * Execute method. * * @return void */ public function execute() { $attribute = $this->getRequest()->getParam('attribute'); $conditionName = $this->getRequest()->getParam('condition'); $valueName = $this->getRequest()->getParam('value'); if ($attribute && $conditionName && $valueName) { $type = $this->ruleType->getInputType($attribute); $conditionOptions = $this->ruleCondition->getInputTypeOptions($type); $response['condition'] = $this->_getOptionHtml( 'conditions', $conditionName, $conditionOptions ); $elmType = $this->ruleValue->getValueElementType($attribute); if ($elmType == 'select') { $valueOptions = $this->ruleValue->getValueSelectOptions($attribute); $response['cvalue'] = $this->_getOptionHtml( 'cvalue', $valueName, $valueOptions ); } elseif ($elmType == 'text') { $html = ""; $response['cvalue'] = $html; } $this->http->getHeaders()->clearHeaders(); $this->http->setHeader('Content-Type', 'application/json') ->setBody( $this->jsonEncoder->jsonEncode($response) ); } } /** * Get select options. * * @param string $title * @param string $name * @param array $options * * @return string */ private function _getOptionHtml($title, $name, $options) { $block = $this->_view->getLayout()->createBlock( \Magento\Framework\View\Element\Html\Select::class ); $block->setOptions($options) ->setId('') ->setClass('ddg-rules-conditions') ->setTitle($title) ->setName($name); return $block->toHtml(); } }