ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
/**
|
||||
* @method array|null getFulltextAttributes()
|
||||
* @method Attribute setFulltextAttributes(array $attributes)
|
||||
*/
|
||||
class Attribute extends \Magento\Framework\View\Element\Text
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
$this->setText('');
|
||||
foreach (array_keys($this->getFulltextAttributes()) as $attributeCode) {
|
||||
$this->addText('<%= option_extra_attrs.option_' . self::calcOptionHash($attributeCode) . ' %>');
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $optionValue
|
||||
* @return string
|
||||
*/
|
||||
public function calcOptionHash($optionValue)
|
||||
{
|
||||
return sprintf('%u', crc32($this->getData('name') . $this->getData('id') . $optionValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setData('name', $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
class Combining extends \Magento\Framework\View\Element\Html\Select
|
||||
{
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\Source\CombiningType
|
||||
*/
|
||||
private $source;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Context $context,
|
||||
\Amasty\ElasticSearch\Model\Source\CombiningType $source,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return $this
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
if (!$this->getOptions()) {
|
||||
$this->setOptions($this->source->toOptionArray());
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
|
||||
use Amasty\ElasticSearch\Model\Config\QuerySettings as BackendModel;
|
||||
|
||||
class QuerySettings extends AbstractFieldArray
|
||||
{
|
||||
public const STYLE = 'style="width:90px"';
|
||||
|
||||
/**
|
||||
* @var null|Attribute
|
||||
*/
|
||||
private $attributeRenderer;
|
||||
|
||||
/**
|
||||
* @var null|YesNo
|
||||
*/
|
||||
private $wildcardRenderer;
|
||||
|
||||
/**
|
||||
* @var null|YesNo
|
||||
*/
|
||||
private $spellCorrectionRenderer;
|
||||
|
||||
/**
|
||||
* @var null|Combining
|
||||
*/
|
||||
private $combiningRenderer;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\Source\FulltextAttributes
|
||||
*/
|
||||
private $fulltextAttributesSource;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
parent::_construct();
|
||||
$this->fulltextAttributesSource = $this->getData('fulltext_attributes');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getAttributeRenderer()
|
||||
{
|
||||
if (!$this->attributeRenderer) {
|
||||
$this->attributeRenderer = $this->getLayout()->createBlock(
|
||||
Attribute::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->attributeRenderer
|
||||
->setFulltextAttributes($this->fulltextAttributesSource->toArray())
|
||||
->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->attributeRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return YesNo|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getWildcardRenderer()
|
||||
{
|
||||
if (!$this->wildcardRenderer) {
|
||||
$this->wildcardRenderer = $this->getLayout()->createBlock(
|
||||
YesNo::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->wildcardRenderer->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->wildcardRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return YesNo|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getSpellCorrectionRenderer()
|
||||
{
|
||||
if (!$this->spellCorrectionRenderer) {
|
||||
$this->spellCorrectionRenderer = $this->getLayout()->createBlock(
|
||||
YesNo::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->spellCorrectionRenderer->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->spellCorrectionRenderer;
|
||||
}
|
||||
/**
|
||||
* @return YesNo|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getCombiningRenderer()
|
||||
{
|
||||
if (!$this->combiningRenderer) {
|
||||
$this->combiningRenderer = $this->getLayout()->createBlock(
|
||||
Combining::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->combiningRenderer->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->combiningRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _prepareToRender()
|
||||
{
|
||||
$this->setTemplate('system/config/array.phtml');
|
||||
$this->addColumn(
|
||||
BackendModel::ATTRIBUTE,
|
||||
['label' => __('Attribute'), 'renderer' => $this->getAttributeRenderer()]
|
||||
);
|
||||
$this->addColumn(
|
||||
BackendModel::WILDCARD,
|
||||
['label' => __('Wildcard'), 'renderer' => $this->getWildcardRenderer()]
|
||||
);
|
||||
$this->addColumn(
|
||||
BackendModel::SPELLING,
|
||||
['label' => __('Spell Correction'), 'renderer' => $this->getSpellCorrectionRenderer()]
|
||||
);
|
||||
$this->addColumn(
|
||||
BackendModel::COMBINING,
|
||||
['label' => __('Match Mode'), 'renderer' => $this->getCombiningRenderer()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
|
||||
{
|
||||
$optionId = $this->getAttributeRenderer()->calcOptionHash($row->getData(BackendModel::ATTRIBUTE));
|
||||
$value = $this->fulltextAttributesSource->toArray()[$row->getData(BackendModel::ATTRIBUTE)];
|
||||
$optionExtraAttr['option_'. $optionId] = $value;
|
||||
|
||||
$optionId = $this->getWildcardRenderer()->calcOptionHash($row->getData(BackendModel::WILDCARD));
|
||||
$optionExtraAttr['option_'. $optionId] = ' checked ';
|
||||
|
||||
$optionId = $this->getSpellCorrectionRenderer()->calcOptionHash($row->getData(BackendModel::SPELLING));
|
||||
$optionExtraAttr['option_'. $optionId] = ' checked ';
|
||||
|
||||
$optionId = $this->getCombiningRenderer()->calcOptionHash($row->getData(BackendModel::COMBINING));
|
||||
$optionExtraAttr['option_'. $optionId] = 'selected="selected"';
|
||||
|
||||
$row->setData('option_extra_attrs', $optionExtraAttr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
use Magento\Framework\View\Element\Context;
|
||||
use Magento\Framework\View\Element\Html\Select;
|
||||
|
||||
class YesNo extends Select
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Source\Yesno
|
||||
*/
|
||||
private $source;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Magento\Config\Model\Config\Source\Yesno $source,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return $this
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
if (!$this->getOptions()) {
|
||||
$this->setOptions($this->source->toOptionArray());
|
||||
}
|
||||
|
||||
if (!$this->_beforeToHtml()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = '<div name="' . $this->getName() . '" class="admin__actions-switch ' . $this->getClass() . '">';
|
||||
$selectedHtml = ' <%= option_extra_attrs.option_' . self::calcOptionHash('1') . ' %>';
|
||||
$html .= ' <input id="' . $this->getName() . '" type="checkbox" class="admin__actions-switch-checkbox input-'
|
||||
. $this->getColumnName() . '" ' . $selectedHtml . '" name="' . $this->getName() . '"/>' .
|
||||
'<label class="admin__actions-switch-label ' . $this->getColumnName() . '" for="' . $this->getName()
|
||||
. '" style="width: 70px;">' .
|
||||
'<span class="admin__actions-switch-text" data-text-on="'. __('Yes'). '" data-text-off="' . __('No')
|
||||
. '"></span></label>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\RelevanceRule;
|
||||
|
||||
use Amasty\ElasticSearch\Controller\Adminhtml\RelevanceRule\AbstractRelevance;
|
||||
use Magento\Backend\Block\Widget\Form;
|
||||
use Magento\Backend\Block\Widget\Form\Generic;
|
||||
use Magento\Ui\Component\Layout\Tabs\TabInterface;
|
||||
|
||||
class Conditions extends Generic implements TabInterface
|
||||
{
|
||||
/**
|
||||
* @var Form\Renderer\Fieldset
|
||||
*/
|
||||
private $rendererFieldset;
|
||||
|
||||
/**
|
||||
* @var \Magento\Rule\Block\Conditions
|
||||
*/
|
||||
private $conditions;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\Block\Template\Context $context,
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Framework\Data\FormFactory $formFactory,
|
||||
\Magento\Rule\Block\Conditions $conditions,
|
||||
\Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $registry, $formFactory, $data);
|
||||
$this->conditions = $conditions;
|
||||
$this->rendererFieldset = $rendererFieldset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTabClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTabUrl()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isAjaxLoaded()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTabLabel()
|
||||
{
|
||||
return __('Conditions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getTabTitle()
|
||||
{
|
||||
return __('Conditions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function canShowTab()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function isHidden()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _prepareForm()
|
||||
{
|
||||
$model = $this->_coreRegistry->registry(AbstractRelevance::CURRENT_RULE)->getCatalogRule();
|
||||
$form = $this->addTabToForm($model);
|
||||
$this->setForm($form);
|
||||
return parent::_prepareForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\CatalogRule\Model\Rule $model
|
||||
* @param string $fieldsetId
|
||||
* @param string $formName
|
||||
* @return \Magento\Framework\Data\Form
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function addTabToForm(
|
||||
\Magento\CatalogRule\Model\Rule $model,
|
||||
$fieldsetId = 'conditions_fieldset',
|
||||
$formName = 'amasty_elastic_relevancerule_form'
|
||||
) {
|
||||
/** @var \Magento\Framework\Data\Form $form */
|
||||
$form = $this->_formFactory->create();
|
||||
$form->setHtmlIdPrefix('rule_');
|
||||
$conditionsFieldSetId = $model->getConditionsFieldSetId($formName);
|
||||
$newChildUrl = $this->getUrl(
|
||||
'amasty_elastic/relevancerule/newConditionHtml/form/' . $conditionsFieldSetId,
|
||||
['form_namespace' => $formName]
|
||||
);
|
||||
|
||||
$renderer = $this->rendererFieldset
|
||||
->setNameInLayout($this->getNameInLayout() . 'fieldset_renderer')
|
||||
->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')
|
||||
->setNewChildUrl($newChildUrl)
|
||||
->setFieldSetId($conditionsFieldSetId);
|
||||
|
||||
$fieldset = $form->addFieldset(
|
||||
$fieldsetId,
|
||||
['legend' => __('Rule won\'t work if no conditions are applied')]
|
||||
)
|
||||
->setRenderer($renderer);
|
||||
|
||||
$fieldset->addField(
|
||||
'conditions',
|
||||
'text',
|
||||
[
|
||||
'name' => 'conditions',
|
||||
'label' => __('Conditions'),
|
||||
'title' => __('Conditions'),
|
||||
'required' => true
|
||||
]
|
||||
)->setRule($model)->setRenderer($this->conditions);
|
||||
|
||||
$form->setValues($model->getData());
|
||||
$this->setConditionFormName($model->getConditions(), $formName, $conditionsFieldSetId);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Rule\Model\Condition\AbstractCondition $conditions
|
||||
* @param string $formName
|
||||
* @param string $jsFormName
|
||||
* @return void
|
||||
*/
|
||||
private function setConditionFormName(
|
||||
\Magento\Rule\Model\Condition\AbstractCondition $conditions,
|
||||
$formName,
|
||||
$jsFormName
|
||||
) {
|
||||
$conditions->setFormName($formName);
|
||||
$conditions->setJsFormObject($jsFormName);
|
||||
|
||||
if ($conditions->getConditions() && is_array($conditions->getConditions())) {
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
$this->setConditionFormName($condition, $formName, $jsFormName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\System\Config;
|
||||
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
use Magento\Framework\Json\EncoderInterface;
|
||||
|
||||
class ConnectionChecker extends \Magento\Config\Block\System\Config\Form\Field
|
||||
{
|
||||
/**
|
||||
* @var EncoderInterface
|
||||
*/
|
||||
private $jsonEncoder;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\Block\Template\Context $context,
|
||||
EncoderInterface $jsonEncoder,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->jsonEncoder = $jsonEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
protected function _prepareLayout()
|
||||
{
|
||||
parent::_prepareLayout();
|
||||
$this->setTemplate('Amasty_ElasticSearch::system/config/connection.phtml');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
public function render(AbstractElement $element)
|
||||
{
|
||||
$element = clone $element;
|
||||
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
|
||||
|
||||
return parent::render($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _getElementHtml(AbstractElement $element)
|
||||
{
|
||||
$originalData = $element->getOriginalData();
|
||||
$this->addData(
|
||||
[
|
||||
'button_label' => __($originalData['button_label']),
|
||||
'json_config' => $this->generateButtonConfig($element),
|
||||
'html_id' => $element->getHtmlId()
|
||||
]
|
||||
);
|
||||
|
||||
return $this->_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getFieldMapping()
|
||||
{
|
||||
return [
|
||||
'hostname' => 'server_hostname',
|
||||
'port' => 'server_port',
|
||||
'index' => 'index_prefix',
|
||||
'enableAuth' => 'enable_auth',
|
||||
'username' => 'username',
|
||||
'password' => 'password',
|
||||
'timeout' => 'server_timeout',
|
||||
'engine' => 'engine',
|
||||
'customAnalyzer' => 'custom_analyzer'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $element
|
||||
* @return mixed
|
||||
*/
|
||||
private function generateButtonConfig(AbstractElement $element)
|
||||
{
|
||||
$result = [
|
||||
'url' => $this->_urlBuilder->getUrl('amasty_elastic/config_checker/connection'),
|
||||
'elementId' => $element->getHtmlId(),
|
||||
'successText' => __('Successful! Test again?'),
|
||||
'failedText' => __('Connection failed! Test again?'),
|
||||
'fieldMapping' => $this->getFieldMapping(),
|
||||
'validation' => [],
|
||||
];
|
||||
|
||||
return $this->jsonEncoder->encode($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user