Order.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Model\Search;
  7. /**
  8. * Search Order Model
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Order extends \Magento\Framework\DataObject
  15. {
  16. /**
  17. * Adminhtml data
  18. *
  19. * @var \Magento\Backend\Helper\Data
  20. */
  21. protected $_adminhtmlData = null;
  22. /**
  23. * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
  24. */
  25. protected $_collectionFactory;
  26. /**
  27. * @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $collectionFactory
  28. * @param \Magento\Backend\Helper\Data $adminhtmlData
  29. */
  30. public function __construct(
  31. \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
  32. \Magento\Backend\Helper\Data $adminhtmlData
  33. ) {
  34. $this->_collectionFactory = $collectionFactory;
  35. $this->_adminhtmlData = $adminhtmlData;
  36. }
  37. /**
  38. * Load search results
  39. *
  40. * @return $this
  41. */
  42. public function load()
  43. {
  44. $result = [];
  45. if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
  46. $this->setResults($result);
  47. return $this;
  48. }
  49. $query = $this->getQuery();
  50. //TODO: add full name logic
  51. $collection = $this->_collectionFactory->create()->addAttributeToSelect(
  52. '*'
  53. )->addAttributeToSearchFilter(
  54. [
  55. ['attribute' => 'increment_id', 'like' => $query . '%'],
  56. ['attribute' => 'billing_firstname', 'like' => $query . '%'],
  57. ['attribute' => 'billing_lastname', 'like' => $query . '%'],
  58. ['attribute' => 'billing_telephone', 'like' => $query . '%'],
  59. ['attribute' => 'billing_postcode', 'like' => $query . '%'],
  60. ['attribute' => 'shipping_firstname', 'like' => $query . '%'],
  61. ['attribute' => 'shipping_lastname', 'like' => $query . '%'],
  62. ['attribute' => 'shipping_telephone', 'like' => $query . '%'],
  63. ['attribute' => 'shipping_postcode', 'like' => $query . '%'],
  64. ]
  65. )->setCurPage(
  66. $this->getStart()
  67. )->setPageSize(
  68. $this->getLimit()
  69. )->load();
  70. foreach ($collection as $order) {
  71. $result[] = [
  72. 'id' => 'order/1/' . $order->getId(),
  73. 'type' => __('Order'),
  74. 'name' => __('Order #%1', $order->getIncrementId()),
  75. 'description' => $order->getFirstname() . ' ' . $order->getLastname(),
  76. 'url' => $this->_adminhtmlData->getUrl('sales/order/view', ['order_id' => $order->getId()]),
  77. ];
  78. }
  79. $this->setResults($result);
  80. return $this;
  81. }
  82. }