I am trying to print sql query. But it is not printing. Please help
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Customer\Model\SessionFactory $customerSession,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
\Magento\Sales\Model\Order\Config $orderConfig,
array $data = []
){
$this->_orderCollectionFactory = $orderCollectionFactory;
$this->_customerSession = $customerSession;
$this->_orderConfig = $orderConfig;
parent::__construct($context, $data);
}
public function getOrders()
{
$customer = $this->_customerSession->create();
$customerId = $customer->getCustomer()->getId();
if (!($customerId)) {
return false;
}
if (!$this->orders) {
$this->orders = $this->_orderCollectionFactory->create($customerId)->addFieldToSelect(
'*'
)->addFieldToFilter(
'status',
['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
)->setOrder(
'created_at',
'desc'
)->setPageSize(1)
->setCurPage(1)
->load();
}
$this->_orderCollectionFactory->printLogQuery(true);
Best Answer
$this->_orderCollectionFactory is an factory class so you need to create this first.
[Update]
Replace following code:
Make sure you are login user and clear cache.