54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Stemcell\Sales\Block\Order;
|
|
|
|
use Magento\Framework\App\ObjectManager;
|
|
use Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
|
|
|
|
class History extends \Magento\Sales\Block\Order\History
|
|
{
|
|
protected CollectionFactoryInterface $orderCollectionFactory;
|
|
|
|
public function __construct(
|
|
\Magento\Framework\View\Element\Template\Context $context,
|
|
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
|
|
\Magento\Customer\Model\Session $customerSession,
|
|
\Magento\Sales\Model\Order\Config $orderConfig,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $orderCollectionFactory, $customerSession, $orderConfig, $data);
|
|
$this->orderCollectionFactory = $orderCollectionFactory;
|
|
}
|
|
|
|
public function getOrders()
|
|
{
|
|
if (!($customerId = $this->_customerSession->getCustomerId())) {
|
|
return false;
|
|
}
|
|
if (!$this->orders) {
|
|
$this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
|
|
'*'
|
|
)->addFieldToFilter(
|
|
'status',
|
|
['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
|
|
)->setOrder(
|
|
'created_at',
|
|
'desc'
|
|
);
|
|
}
|
|
$q = trim((string)$this->_request->getParam('q', ''));
|
|
if (!empty($q)) {
|
|
$this->orders->addFieldToFilter('increment_id', ['like' => '%' . $q . '%']);
|
|
}
|
|
return $this->orders;
|
|
}
|
|
|
|
protected function getOrderCollectionFactory()
|
|
{
|
|
if ($this->orderCollectionFactory === null) {
|
|
$this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class);
|
|
}
|
|
return $this->orderCollectionFactory;
|
|
}
|
|
}
|