12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\CatalogSearch\Model\ResourceModel;
- /**
- * Advanced Catalog Search resource model
- *
- * @api
- * @since 100.0.2
- */
- class Advanced extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
- {
- /**
- * Core event manager proxy
- *
- * @var \Magento\Framework\Event\ManagerInterface
- */
- protected $_eventManager = null;
- /**
- * Store manager
- *
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $_storeManager;
- /**
- * Construct
- *
- * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Framework\Event\ManagerInterface $eventManager
- * @param string $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- \Magento\Framework\Event\ManagerInterface $eventManager,
- $connectionName = null
- ) {
- $this->_storeManager = $storeManager;
- $this->_eventManager = $eventManager;
- parent::__construct($context, $connectionName);
- }
- /**
- * Initialize connection and define catalog product table as main table
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init('catalog_product_entity', 'entity_id');
- }
- /**
- * Prepare search condition for attribute
- *
- * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
- * @param string|array $value
- * @return string|array
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public function prepareCondition($attribute, $value)
- {
- $condition = false;
- if (is_array($value)) {
- if ($attribute->getBackendType() == 'varchar') { // multiselect
- // multiselect
- $condition = ['in_set' => $value];
- } elseif (!isset($value['from']) && !isset($value['to'])) { // select
- // select
- $condition = ['in' => $value];
- } elseif (isset($value['from']) && '' !== $value['from'] || isset($value['to']) && '' !== $value['to']) {
- // range
- $condition = $value;
- }
- } else {
- if (strlen($value) > 0) {
- if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
- $condition = ['like' => $value]; // text search
- } else {
- $condition = $value;
- }
- }
- }
- return $condition;
- }
- }
|