0

I have below code.

$collection = $this->orderCollectionFactory->create()
                //['increment_id', 'global_currency_code', 'status', 'updated_at']
                ->addFieldToSelect('*')
                ->addAttributeToFilter('status', ['in' => [
                    Order::STATE_CLOSED,
                    Order::STATE_COMPLETE,
                    Order::STATE_CANCELED
                ]])
                ->addAttributeToFilter('created_at', ['from' => $result['from'], 'to' => $result['to']]);

            $data = $collection->getData();

How can I get billing address in my collection?

1 Answer 1

1

Have you tried this?

foreach ($collection as $order) {
   $billingAddress = $order->getBillingAddress();
}

Please, always check magento core firstly, mostly your answers to your questions lies there.

2
  • I want to get all the data in one request, I have about 50,000 products and I don't really want to run a loop Aug 3, 2020 at 15:27
  • By reading your code, you are already asking for a loop because you are forming a collection. If you want to get a single order - use a order repository or create a search criteria with conditions to fit a single order. By you example you are fetching multiple entities, but somehow you want to get billing address of all of those entities at the same time without loop in a single call - that is not possible without a loop.
    – Macas
    Aug 3, 2020 at 18:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.