Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Catalog.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
20  protected $queryFactory = null;
21 
27  protected $string;
28 
34  protected $_adminhtmlData = null;
35 
41  public function __construct(
42  \Magento\Backend\Helper\Data $adminhtmlData,
43  \Magento\Framework\Stdlib\StringUtils $string,
45  ) {
46  $this->_adminhtmlData = $adminhtmlData;
47  $this->string = $string;
48  $this->queryFactory = $queryFactory;
49  }
50 
56  public function load()
57  {
58  $result = [];
59  if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
60  $this->setResults($result);
61  return $this;
62  }
63 
64  $collection = $this->queryFactory->get()
65  ->getSearchCollection()
66  ->addAttributeToSelect('name')
67  ->addAttributeToSelect('description')
68  ->addBackendSearchFilter($this->getQuery())
69  ->setCurPage($this->getStart())
70  ->setPageSize($this->getLimit())
71  ->load();
72 
73  foreach ($collection as $product) {
74  $description = strip_tags($product->getDescription());
75  $result[] = [
76  'id' => 'product/1/' . $product->getId(),
77  'type' => __('Product'),
78  'name' => $product->getName(),
79  'description' => $this->string->substr($description, 0, 30),
80  'url' => $this->_adminhtmlData->getUrl('catalog/product/edit', ['id' => $product->getId()]),
81  ];
82  }
83 
84  $this->setResults($result);
85 
86  return $this;
87  }
88 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Helper\Data $adminhtmlData, \Magento\Framework\Stdlib\StringUtils $string, QueryFactory $queryFactory)
Definition: Catalog.php:41