Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Order.php
Go to the documentation of this file.
1 <?php
7 
16 {
22  protected $_adminhtmlData = null;
23 
28 
33  public function __construct(
34  \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
35  \Magento\Backend\Helper\Data $adminhtmlData
36  ) {
37  $this->_collectionFactory = $collectionFactory;
38  $this->_adminhtmlData = $adminhtmlData;
39  }
40 
46  public function load()
47  {
48  $result = [];
49  if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
50  $this->setResults($result);
51  return $this;
52  }
53 
54  $query = $this->getQuery();
55  //TODO: add full name logic
56  $collection = $this->_collectionFactory->create()->addAttributeToSelect(
57  '*'
58  )->addAttributeToSearchFilter(
59  [
60  ['attribute' => 'increment_id', 'like' => $query . '%'],
61  ['attribute' => 'billing_firstname', 'like' => $query . '%'],
62  ['attribute' => 'billing_lastname', 'like' => $query . '%'],
63  ['attribute' => 'billing_telephone', 'like' => $query . '%'],
64  ['attribute' => 'billing_postcode', 'like' => $query . '%'],
65  ['attribute' => 'shipping_firstname', 'like' => $query . '%'],
66  ['attribute' => 'shipping_lastname', 'like' => $query . '%'],
67  ['attribute' => 'shipping_telephone', 'like' => $query . '%'],
68  ['attribute' => 'shipping_postcode', 'like' => $query . '%'],
69  ]
70  )->setCurPage(
71  $this->getStart()
72  )->setPageSize(
73  $this->getLimit()
74  )->load();
75 
76  foreach ($collection as $order) {
77  $result[] = [
78  'id' => 'order/1/' . $order->getId(),
79  'type' => __('Order'),
80  'name' => __('Order #%1', $order->getIncrementId()),
81  'description' => $order->getFirstname() . ' ' . $order->getLastname(),
82  'url' => $this->_adminhtmlData->getUrl('sales/order/view', ['order_id' => $order->getId()]),
83  ];
84  }
85 
86  $this->setResults($result);
87 
88  return $this;
89  }
90 }
$order
Definition: order.php:55
__()
Definition: __.php:13
__construct(\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $collectionFactory, \Magento\Backend\Helper\Data $adminhtmlData)
Definition: Order.php:33