1

I have this code

$collection = $this->orderCollectionFactory->create()
                ->addFieldToSelect(['increment_id', 'global_currency_code', 'status', 'updated_at', 'total_due', 'shipping_address_id', 'total_refunded', 'total_paid'])
                ->addAttributeToFilter('status', ['in' => [
                    Order::STATE_CLOSED,
                    Order::STATE_COMPLETE,
                    Order::STATE_CANCELED,
                ]])
                ->addAttributeToFilter('main_table.created_at', ['from' => $result['from'], 'to' => $result['to']])
                ->setPageSize(self::COUNT_PAGE_SIZE)
                ->setCurPage($p);
            $collection->getSelect()->joinLeft(
                ['orderItem' => 'sales_order_item'],
                "main_table.entity_id = orderItem.order_id",
                ['tax_amount', 'tax_percent']
            );
            $collection->getSelect()->joinLeft(
                ['billingTable' => 'sales_order_address'],
                "main_table.entity_id = billingTable.parent_id AND billingTable.address_type = '{$this->addressType}'",
                ['vat_id', 'country_id', 'city', 'address_type']
            );

For example This should have 10 orders,

Page 1 -> 5 orders shown
Page 2 -> 5 orders shown
Page 3 -> Same orders from Page 2.

How to make it return empty at page 3 ?

4
  • $collection->load()?
    – Sohel Rana
    Commented Aug 7, 2020 at 3:33
  • use >setPageSize(self::COUNT_PAGE_SIZE) ->setCurPage($p); after join query
    – Amit Bera
    Commented Aug 7, 2020 at 4:58
  • it's not working for me :( Commented Aug 7, 2020 at 10:20
  • can you help me? do you have any other ideas? Commented Aug 10, 2020 at 8:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.