When we work in magento with out of box customization then we might need to add feature for search order by phone in admin grid or somewhere else.
In this blog we are going to search order by phone number/telephone/mobile number in magento2.
As technially, we need to search phone in order’s address table and need to get order ids and use that order ids to get order information.
Here is code for search order by phone
<?php
declare(strict_types=1); //We recommend to use always strict_types = 1 for quality code
namespace MageDad\Module\Model;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as OrderCollectionFactory;
use Magento\Sales\Model\ResourceModel\Order\Address\CollectionFactory as AddressCollectionFactory;
class OrderSearch
{
public function __construct(
private OrderCollectionFactory $orderCollectionFactory,
private AddressCollectionFactory $addressCollectionFactory
) { }
/**
* {@inheritdoc}
*/
public function getOrderByPhone($phone)
{
$addressCollection = $this->addressCollectionFactory->create();
$addressCollection->addFieldToFilter('telephone', ['eq' => $phone]);
$orderIds = $addressCollection->getColumnValues('parent_id');
if (count($orderIds) > 0) {
$collection = $this->orderCollectionFactory->create();
$collection->addFieldToFilter('entity_id', ['in' => $orderIds]);
return $collection->getItems();
}
return [];
}
}
If you want to create API for search order by phone then you can refere GitHub module.
I hope this blog is useful to search order by phone in magento2. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.
Keep loving ❤️ Keep inspiring 🤩 Keep liking 👍 No sharing 😂
31 Comments
Hello! Do you know if they make any plugins to help with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success. If you know of any please share. Thank you!
businessiraq.com: Your Ultimate Iraqi Business Gateway. Embark on a journey of discovery and opportunity with our meticulously crafted Iraq business directory, home to comprehensive online business listings that paint a vivid picture of the nation’s diverse economic tapestry. Stay informed and make strategic decisions with our up-to-date Iraq business news, while our Iraq jobs portal connects you with exciting career prospects. And for businesses ready to make their mark, our tender opportunities directory presents a world of procurement possibilities. Connect, explore, and succeed in Iraq with Businessiraq.com.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
A code promo 1xBet est un moyen populaire pour les parieurs d’obtenir des bonus exclusifs sur la plateforme de paris en ligne 1xBet. Ces codes promotionnels offrent divers avantages tels que des bonus de dépôt, des paris gratuits, et des réductions spéciales pour les nouveaux joueurs ainsi que les utilisateurs réguliers.code 1xbet télécharger
I truly enjoy examining on this web site, it has got wonderful articles. “Never fight an inanimate object.” by P. J. O’Rourke.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
We are a group of volunteers and starting a new scheme in our community. Your site offered us with valuable information to work on. You’ve done a formidable job and our whole community will be grateful to you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!
Good – I should certainly pronounce, impressed with your web site. I had no trouble navigating through all the tabs as well as related info ended up being truly simple to do to access. I recently found what I hoped for before you know it in the least. Quite unusual. Is likely to appreciate it for those who add forums or anything, site theme . a tones way for your customer to communicate. Nice task..
Super-Duper site! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
obviously like your website but you have to check the spelling on quite a few of your posts. Several of them are rife with spelling issues and I to find it very bothersome to tell the reality nevertheless I?ll surely come back again.
F*ckin? tremendous issues here. I?m very glad to peer your post. Thank you so much and i am having a look ahead to contact you. Will you please drop me a e-mail?
An fascinating discussion is price comment. I think that it’s best to write extra on this topic, it may not be a taboo topic but generally persons are not enough to talk on such topics. To the next. Cheers
Hello There. I found your blog using msn. This is an extremely well written article. I?ll make sure to bookmark it and come back to read more of your useful info. Thanks for the post. I?ll definitely comeback.
I’m curious to find out what blog system you are working with? I’m having some small security problems with my latest website and I would like to find something more secure. Do you have any suggestions?
Great write-up, I?m normal visitor of one?s web site, maintain up the nice operate, and It’s going to be a regular visitor for a long time.
Thanks for your publication. What I want to say is that when searching for a good on-line electronics retail outlet, look for a website with full information on important factors such as the privacy statement, safety measures details, payment options, along with terms and also policies. Constantly take time to look at help in addition to FAQ segments to get a better idea of how a shop works, what they are capable of doing for you, and ways in which you can make use of the features.
Right now it looks like WordPress is the best blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?
Thank you, I have recently been looking for info approximately this topic for a while and yours is the best I’ve discovered so far. But, what concerning the bottom line? Are you positive concerning the source?
I believe that avoiding ready-made foods could be the first step for you to lose weight. They might taste excellent, but ready-made foods have very little nutritional value, making you consume more in order to have enough power to get with the day. If you’re constantly feeding on these foods, transferring to whole grain products and other complex carbohydrates will make you to have more vitality while taking in less. Thanks alot : ) for your blog post.
Heya i?m for the first time here. I came across this board and I in finding It really helpful & it helped me out a lot. I hope to present one thing again and aid others such as you helped me.
Hello! I’m at work surfing around your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the excellent work!
Thank you, your article surprised me, there is such an excellent point of view. Thank you for sharing, I learned a lot.
Please let me know if you’re looking for a article author for your blog. You have some really great posts and I feel I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine. Please blast me an e-mail if interested. Many thanks!
magnificent post, very informative. I wonder why the other experts of this sector don’t understand this. You must continue your writing. I am sure, you’ve a huge readers’ base already!