_helper = $helper; $this->_registry = $registry; $this->_codeHelper = $codeHelper; parent::__construct($context, $data); } /** * Get google experiment code model * * @return \Magento\GoogleOptimizer\Model\Code * @throws \RuntimeException */ protected function _getGoogleExperiment() { return $this->_codeHelper->getCodeObjectByEntity($this->_getEntity()); } /** * Render block HTML * * @return string */ protected function _toHtml() { return parent::_toHtml() . $this->_getScriptCode(); } /** * Return script code * * @return string */ protected function _getScriptCode() { $result = ''; if ($this->_helper->isGoogleExperimentActive() && $this->_getGoogleExperiment()) { $result = $this->_getGoogleExperiment()->getData('experiment_script'); } return $result; } /** * Get entity from registry * * @return mixed * @throws \RuntimeException */ protected function _getEntity() { $entity = $this->_registry->registry($this->_registryName); if (!$entity) { throw new \RuntimeException('Entity is not found in registry.'); } return $entity; } }