![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-catalog-search/Model/Search/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\CatalogSearch\Model\Search; use Magento\Search\Model\QueryFactory; /** * Search model for backend search */ class Catalog extends \Magento\Framework\DataObject { /** * Catalog search data * * @var \Magento\Search\Model\QueryFactory */ protected $queryFactory = null; /** * Magento string lib * * @var \Magento\Framework\Stdlib\StringUtils */ protected $string; /** * @var \Magento\Backend\Helper\Data */ protected $_adminhtmlData = null; /** * @param \Magento\Backend\Helper\Data $adminhtmlData * @param \Magento\Framework\Stdlib\StringUtils $string * @param QueryFactory $queryFactory */ public function __construct( \Magento\Backend\Helper\Data $adminhtmlData, \Magento\Framework\Stdlib\StringUtils $string, QueryFactory $queryFactory ) { $this->_adminhtmlData = $adminhtmlData; $this->string = $string; $this->queryFactory = $queryFactory; } /** * Load search results * * @return $this */ public function load() { $result = []; if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) { $this->setResults($result); return $this; } $collection = $this->queryFactory->get() ->getSearchCollection() ->addAttributeToSelect('name') ->addAttributeToSelect('description') ->addBackendSearchFilter($this->getQuery()) ->setCurPage($this->getStart()) ->setPageSize($this->getLimit()) ->load(); foreach ($collection as $product) { $description = $product->getDescription() !== null ? strip_tags($product->getDescription()) : ''; $result[] = [ 'id' => 'product/1/' . $product->getId(), 'type' => __('Product'), 'name' => $product->getName(), 'description' => $this->string->substr($description, 0, 30), 'url' => $this->_adminhtmlData->getUrl('catalog/product/edit', ['id' => $product->getId()]), ]; } $this->setResults($result); return $this; } }