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 Aug 7 '20 at 3:33
  • use >setPageSize(self::COUNT_PAGE_SIZE) ->setCurPage($p); after join query – Amit Bera Aug 7 '20 at 4:58
  • it's not working for me :( – Denys Maksiura Aug 7 '20 at 10:20
  • can you help me? do you have any other ideas? – Denys Maksiura Aug 10 '20 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.