1

How to get order id from collection with filter customer_is_guest = 1 and customer email

$order_collection = $objectManager->create('Magento\Sales\Model\Order')->getCollection()->addAttributeToFilter('customer_email', $customer_email)->addAttributeToFilter('customer_is_guest',1);

Above code will give me order collection. How to only get order id/ids

  • Try $order_collection = $objectManager->create('Magento\Sales\Model\Order')->getCollection()->addAttributeToFilter('customer_id', array('eq' => NULL)) For guest customer you need to check customer_id is NULL – user55548 Feb 15 at 10:00
1

You can use addFieldToSelect() function in your collection as follows:

$order_collection = $objectManager->create('Magento\Sales\Model\Order')->getCollection()
    ->addFieldToSelect('entity_id')
    ->addAttributeToFilter('customer_email', $customer_email)
    ->addAttributeToFilter('customer_is_guest',1);
0

Try this,

To get guest user orders by specific email

<?php                                                                 
 namespace Vendor\Module\Controller\Orders;                               
 class ReadOrders extends \Magento\Framework\App\Action\Action {
 public function __construct(\Magento\Framework\App\Action\Context $context, 
        \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory) {
    $this->orderCollectionFactory = $orderCollectionFactory;
    parent::__construct($context);
}
public function execute()
{
    $orders = $this->orderCollectionFactory->create()
    ->addAttributeToFilter('customer_email', 'prathap@gmail.com')
    ->addAttributeToFilter('customer_is_guest', '1');
    foreach ($orders as $items) {
        echo $items->getEntityId() . '<pre>';
    }
}}

It will print the increment id of the above order collection filter.

Hope this helps. Peace :)

Your Answer

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

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