I need to write code to get next 10 orders above the given order id.
<?php
namespace Learning\GreetingMessage\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\App\Action\Context;
use Vendor\Module\Model\ModuleFactory;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
class Test extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
protected $_orderCollectionFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
//~ \Magento\Framework\View\Result\PageFactory $pageFactory,
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
)
{
//~ $this->_pageFactory = $pageFactory;
$this->_orderCollectionFactory = $orderCollectionFactory;
return parent::__construct($context);
}
public function execute()
{
//~ $orders = $this->_objectManager->create('Magento\Sales\Api\Data\OrderInterface')->getCollection()->addAttributeToFilter('created_at', array('from'=>date('Y-m-d',strtotime('2018-01-01')), 'to'=>date('Y-m-d',strtotime('2019-01-01')))); // Getting first order
//~ $orders = $this->_objectManager->create('Magento\Sales\Api\Data\OrderInterface')->getCollection()->addAttributeToFilter('entity_id', array('gt'=>0));
$orders = $this->_objectManager->create('Magento\Sales\Api\Data\OrderInterface')->setPageSize(1)->setCurPage(10)->getCollection()->load();
echo "Count is ". count($orders);
foreach($orders as $order)
{
$gross = $order->getGrandTotal();
$tax = $order->getTaxAmount();
$net = $gross - $tax;
$payment = $order->getPayment();
$method = $payment->getMethodInstance();
$methodTitle = $method->getTitle();
echo "<br/>gross :". $gross;
echo "<br/>tax :". $tax;
echo "<br/>net :". $net;
echo "<br/>Created :". $order->getCreatedAt();
echo "<br/>state :". $order->getState();
echo "<br/>payment methodTitle :". $methodTitle;
echo "<br/> Customer : ". $order->getCustomerId();
echo "<br/>Items in order";
$items = $order->getAllItems();
foreach($order->getAllItems() as $orderItem) {
$itemid = $orderItem->getId();
echo "Item id" .$orderItem->getId() . "<br />";
}
}
echo "Hello World";
exit;
}
}