get magento order id from customer data - php

I'm having problems getting a collection with join working. I'm trying to get the order ID's connected to customer telephone numbers, saved in sales_flat_order_address. So a join on the collection with sales/order and a filter based on the variable with my phone number in it. I've tried all sorts of combinations, but so far I only get errors and right now I've deleted my code and will try from scratch. Any ideas or links to tutorials about this?

Small code snippet below
$customer = Mage::getModel('customer/customer')->getCollection()
->addAttributeToFilter('attribute_code', value)->load();
//Here your attribute code is phone
$orderCollection = Mage::getModel(’sales/order’)->getCollection();
$orderCollection->getSelect()->where(’e.customer_id =’.$customer->getId());
:)

Related

filtering orders by phone makes duplicated orders (a visualisation problem)

I Created a prestashop module that allow the admin to search order by the phone number. But unforchently, it duplicates in the orders page. There is no duplication inside the database it's just a visualisation problem.
here is my code:
https://drive.google.com/file/d/1vtURm308463iM4tMi2oKVQAB9L0cOZj5/view?usp=sharing
You are joining with address table, using the id_customer.
That way, you get a result for each address related to the customer who did the order.
I mean, each order will appear as many times as addresses has the customer.
To avoid this, you can join using id_delivery_address instead of id_customer.
So you only will get the delivery address, that can be only one.
And I think the interesting phone is from the delivery address.
I edited your file, just line 66, changed:
'abc.`id_customer` = o.`id_customer`'
to:
'abc.`id_address` = o.`id_address_delivery`'
If you need to filter searching a phone in any address related to customer owner of the order, let me know.

display wp_postmeta meta_value in wordpress woocommerce

please help a new member
THE ISSUE:
I have a POS on my WC and it doesn't display sequential orders numbering, so I am using other plugin to achieve this. I need to display the value of a meta_value from my database in the order receipt (printable ticket) after the order is placed. So, the meta_value I need to display on the POS's tickets is the sequential ticket number created by the other plugin.
Gladly this other plugin creates the sequential number in the database from where I hope I can retrieve it somehow.
This meta_value for example "T00001...T00009" has the meta_key = "_order_number" and it's within wp5o_postmeta table of my sql database.
I believe it must be easy for you guys...
Thank you so much
Image of the data
use this filter and implement your post meta
wordpress/wp-content/plugins/woocommerce-openpos/includes/front/Front.php
line 4683
$result['data'] = apply_filters('op_get_next_order_number_info',$order_number_info);

Wordpress list all users and users with subscription level 1 first

So I want to create a list of users, and show the paying users first in the list - How do I do this? I've tried creating an SQL query, however im struggling a bit on how to make JOINS...
Lets say I have 10 users and 4 of them is paying customers. When in my SQL statement I want to get all users, but the ones that are paying should be listed first?
$row = $wpdb->get_results( "SELECT * FROM wptest_users JOIN wptest_usermeta on user.rcp_subscription_level");
So what im trying to do there is getting all users from wptest_users, and then trying to make a join with wptest_usermeta, and getting the meta field I want to order by - So if "rcp_subscription_level" equals 1, then the user is a paying customer...
Hope it makes sense on that im trying to achieve, and hope someone can help?
Ahh, almost got it now:
Got this so far:
SELECT wptest_users.ID, wptest_users.display_name, wptest_usermeta.user_id, wptest_usermeta.meta_value, wptest_usermeta.meta_key FROM wptest_users, wptest_usermeta WHERE wptest_users.ID = user_id AND meta_key = 'rcp_subscription_level' ORDER by user_id
Now I only need to sort it by the value of the subscription level

How do I weed out invalid results from an amazon api query

I'm using this function to request books from amazon that are priced at 0 but I am getting three different responses.
Some books are listed at 0
http://www.amazon.com/dp/B009EFZQV0/?tag=centsme-20
Some have a price
http://www.amazon.com/dp/B00A3H57CG/?tag=centsme-20
And others have a price but are free for prime members
can't find an example now
Now I looked at the source of the page and noticed multiple values for price and that I need the id pricelarge and listprice to both be 0. The faq doesn't help me at all and I'm getting stumped on how to fix this.
This is the query function I'm using now.
$search = new Search();
$conf->setRequest('\ApaiIO\Request\Soap\Request');
$conf->setResponseTransformer('\ApaiIO\ResponseTransformer\ObjectToArray');
$search->setCategory('MobileApps');
$search->setMaximumPrice(0);
$search->setPage($page);
$search->setBrowseNode($bid);
$search->setSort('reviewrank');
$search->setResponseGroup(array('ItemAttributes','ItemIds', 'Images'));
$formattedResponse = $apaiIO->runOperation($search, $conf);
For the response, I would also grab a price variable. That way you can double check the price of the item before you present it to your user.

Magento Order creation sales_flat_quote_item not being made

I have a module that takes a feed from another site and then imports the orders into magento. The problem is that despite the orders being created properly and appering in Magento they don't show up in the Products Ordered report.
The reason seems to be that this report looks at the sales_flat_quote_item table to produce its results but there is no entry for my sale items. They do however appear correctly in sales_flat _order_item.
Below is a shortened version of the code.
Any suggestions as to why im not getting an entry in flat_quote_item?
Why does the Magento model used by the Ordered Products report use the quote table and not the order table?
$quote = Mage::getModel('sales/quote')->setStoreId((string) $dataArray->StoreviewId);
if (is_object($product)) {
$product->setPrice(((string) $orderitem->Price) / $reverseRate);
$item = Mage::getModel('sales/quote_item');
$item->setQuote($quote)->setProduct($product);
$item->setData('qty', (string) $orderitem->Quantity);
$item->setCustomPrice((string) $orderitem->Price);
$item->setOriginalCustomPrice((string) $orderitem->Price);
$quote->addItem($item);
}
This code doesn't show any calls to $item->save or $quote->save, so it could be that you aren't saving the quote object.
Why does the Magento model used by the Ordered Products report use the quote table and not the order table?
Because you could have an order, which wasn't paid or was canceled and thus the product wasn't delivered. You still have an order in the system, it just wasn't executed.
My guess is, that the specific report should only contain successful order, where the products were shipped or at least the quote was sent.
Any suggestions as to why im not getting an entry in flat_quote_item?
You need to generate the quote, which isn't done automatically on saving an order.
See the following forums thread to get hints on how to generate the quote: http://www.magentocommerce.com/boards/viewthread/28426/P30/

Categories