I'm struggling with the Magento report for "Products Ordered".
Is the Ordered Quantity affected by the date filter? Why do some of the products show as 0? Where does Magento keep the ordered_qty data? I am using Magento 1.4.0.1.
Magento keeps record of all items sold in sales_order_entity, which you can retrieve like this:
select * from sales_order_entity where
entity_type_id = (select entity_type_id from eav_entity_type where
entity_type_code = 'sales/order_item'
);
By grouping by entity_id and counting the result, you can get an accurate total of the quantity_sold for a date range. You can see how Magento does this in Mage_Reports_Model_Mysql4_Order_Collection. From the code, it appears that Magento does in fact respect the date parameter.
Just to be clear, this means that there is no single place where you can retrieve an "ordered_qty" number without more complex queries. The most obvious reason some products show as 0 is that they haven't sold anything.
In v1.4 and up, you should be able to query the sales_flat_order_item table and then group and sum on qty_ordered. e.g.
select product_id, sku, sum(`qty_ordered`) from sales_flat_order_item group by product_id
Cheers,
JD
Related
I've been searching through the Magento tables, what fields would I use to grab the top 10 buyers name and the total amount each they spent.
i've been looking in the flat_order table ...
If just having the total sales and the customer_id is enough:
SELECT customer_id,SUM(base_grand_total) AS total_sales
FROM sales_flat_order
GROUP BY customer_id
ORDER BY total_sales DESC
LIMIT 10;
If you need the customer information in the same result, you'll have to join in some of the customer_entity tables, but if you're just looking for a quick report, the above should give you the top ten.
P.S. If you do want to tie in customer data, start with the customer_entity table, and things like their name appear to be in the customer_entity_varchar table.
Some of the products in Magento have suddenly disappeared from backend and frontend. When I try to re-create these products I get this error:
The value of attribute "SKU" must be unique
So the products must still exist somewhere in the DB.
I already tried the following without luck:
Truncate all catalog_product_flat tables
ReIndex all indexes
Refresh all Caches
Checked the "status" attribute of the product in Mysql (it was set to 1)
Any ideas how I can get these products back in the frontend/backend?
Try checking the following tables:
catalog_product_entity
catalog_product_entity_datetime
catalog_product_entity_decimal
catalog_product_entity_gallery
catalog_product_entity_group_price
catalog_product_entity_int
catalog_product_entity_media_gallery
catalog_product_entity_media_gallery_value
catalog_product_entity_text
catalog_product_entity_tier_price
catalog_product_entity_varchar
You can find the sku in the catalog_product_entity table.
What are the Tables involved in storing the information of an order.
For example: Customer - product purchased - etc.
I found the product purchases status etc.(invoice and sales tables) but having hard time in linking it to the customer. Could not find who bought what ? Any suggestions
Thanks
The table sales_flat_order has a field customer_id referring to a row in the customer_entity table. But remember that some orders are guest orders, and they are not associated to a customer account. In those cases customer_id is null.
The products (line items) for an order are stored in sales_flat_order_item. There's an order_id linking it to the order and a product_id linking it to the product.
I'm using SSRS 2005. I've got a table with various inventory data. In one columns I've got a subreport that is designed to pull the date of the most recent Purchase Order based upon the product code of whichever row the subreport is in. This would be fine, however I'm now being asked to be able to sort by this date column. My assumption is that you cannot sort a column with a subreport in it, but I thought I'd ask. Is there any way to do this?
You can include the most recent purchase order value in your main report's dataset as a subquery like this:
SELECT *
,(SELECT TOP 1 PurchaseOrder
FROM Purchasing p
WHERE p.ProductCode = i.ProductCode
ORDER BY PurchaseDate DESC
) as LastPurchaseOrder
FROM Inventory
Then you can use that value to sort your table.
I have 3 tables:
listing
photo
calendar
"photo" and "calendar" both have a "listing_id" column in them and every "listing" has a "photo". But I only want to select rows that have no entry in the "calendar" table with the matching "listing_id".
I'm not sure if I'm saying it correctly, but any help would be greatly appreciated. And if someone could show me CodeIgniter syntax, that'd be even better.
This will produce the list of calendar.free_date values that should not be returned because their associated listing_id values do not exist in the listing table.
select free_date from calendar c
where not exists (select * from listing
where listing_id = c.listing_id);
Should work as an SQL query. Not sure about CI syntax. Sorry!
SELECT * FROM listing WHERE listing_id NOT IN (SELECT listing_id FROM calendar)