Tables involved in storing order information for a certain product in magento - magento

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.

Related

Where do I find the customer ID in a Magento 2 database?

I'm using the CreativeMinds Multi User Accounts plugin. In the cminds_multiuseraccounts_subaccount table it references customer_id and parent_customer_id. Where is the customer_id defined?
You can find customer id in 'customer_entity' Table

Laravel - Please advise on table name

I am in trouble with the name of the pivot table.
products ... Product master table
shop ... Shop master table.
shop_sales ... A table that links products and dates. It leads to another table. The column is date and shop_id.
I want to add a table to shop_sales to manage products and the number sold.
shop_sale_products vs product_shop_sale
Does laravel recommend product_shop_sale?
thanks.

Magento grabbing the top 10 buyers

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.

Database table design Issue

I have a table design doubt.
First table called products_mast contains
CONTRACTS_ID (PK),
AGREEMENT_NO,
SUPPLIER_CODE,
START_DATE,
END_DATE
PROD_EXTENSION_NO
Second table called products_det contains
HIRING_ID (PK),
CONTRACTS_ID(FK),
PRODUCT_CODE,
RATE
The above tables are linked with CONTRACTS_ID. Start Dates and End Dates are in one table and product rates in second table.
In my third table TRANSACTIONS contains,
TRANS_ID,
TRANS_REF_NO,
HIRING_ID FK (products_det),
REMARKS
One issue is normally the agreement_no can get extended for a period with new product rates for the extended agreement. So I add those details in
products_mast and products_det with same agreement no with extension 002 (for new extension). In TRANSACTIONS how can I refer to correct
rates if I am linking HIRING_ID with products_det because HIRING_ID gets incremented with new extension. How can I resolve this issue?
I'm not quite sure I follow exactly what you are suggesting regards agreement no value of extension 002 (new extension) however if it's a case of uniquely identifying the transaction per agreement no, what about adding a FK to the table Transactions linking it back to the AGREEMENT_NO field in the products_mast table?

Magento Products Ordered Report

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

Resources