Tracking Unregistered Abandon carts in Magento - magento

Does anyone know where I can start trying to get at cart information from unregistered users. I want to be able to look at abandon carts from people who are not logged in. This doesn't seem to be a default function of magento, but I have a feeling it's in the db somewhere.

all quotes are stored in sales_flat_quote table

I have checked this query and find one or two cases where some results are missing in the results but shows on the magento abandoned cart report. Here is what I tried.
SELECT entity_id, customer_firstname, customer_email, items_count, grand_total, created_at
FROM sales_flat_quote
WHERE entity_id NOT IN (SELECT quote_item_id AS quote_id FROM sales_flat_order_item)
AND items_count >0
AND customer_email IS NOT NULL
ORDER BY `sales_flat_quote`.`created_at` DESC

In case anyone is interested, this is the sql query that I came up with for getting abandon cart items directly out of the database. You'll need to change the date
SELECT quote_id, sku, qty, price, custom_price, row_total, created_at, product_id, store_id
FROM mage_sales_flat_quote_item
WHERE created_at > "2011-04-01"
AND quote_id NOT IN (SELECT quote_item_id AS quote_id FROM mage_sales_flat_order_item)
AND store_id IS NOT NULL

This is more like it.
SELECT `main_table`.*, GROUP_CONCAT(item.sku) AS `skus`, (main_table.base_subtotal_with_discount*main_table.base_to_global_rate) AS `subtotal`, `cust_email`.`email`, `cust_fname`.`value` AS `firstname`, `cust_lname`.`value` AS `lastname`, CONCAT_WS(' ', cust_fname.value, cust_lname.value) AS `customer_name` FROM `sales_flat_quote` AS `main_table`
INNER JOIN `sales_flat_quote_item` AS `item` ON item.quote_id = main_table.entity_id
INNER JOIN `customer_entity` AS `cust_email` ON cust_email.entity_id = main_table.customer_id
INNER JOIN `customer_entity_varchar` AS `cust_fname` ON cust_fname.entity_id = main_table.customer_id AND cust_fname.attribute_id = 5
INNER JOIN `customer_entity_varchar` AS `cust_lname` ON cust_lname.entity_id = main_table.customer_id AND cust_lname.attribute_id = 7 WHERE (items_count != '0') AND (main_table.is_active = '1') AND (main_table.created_at >= '2013-02-04 00:00:00' AND main_table.created_at <= '2013-02-04 24:00:00') AND (main_table.updated_at >= '2013-02-04 00:00:00' AND main_table.updated_at <= '2013-02-04 24:00:00') GROUP BY `item`.`quote_id` ORDER BY updated_at DESC

Related

ORA-00904: invalid column name but I am using the correct column name

Can someone see where I am going wrong in the below query? I am getting the error message that the GROUP BY column doesn't exist, but it clearly does as I see that column name in the output when I don't use the GROUP BY.
SELECT
(SELECT customer_address.post_code FROM customer_address WHERE customer_address.address_type = 0 AND customer_address.customer_no = orders.customer_no) postcode, SUM(orders.order_no) orders
FROM
orders, customer_address
WHERE
orders.delivery_date = '27-MAY-15'
GROUP BY
postcode;
The answer is: You cannot use an alias name in GROUP BY.
So:
GROUP BY (SELECT customer_address.post_code ...);
Or:
select postcode, sum(order_no)
from
(
SELECT
(SELECT customer_address.post_code FROM customer_address WHERE customer_address.address_type = 0 AND customer_address.customer_no = orders.customer_no) postcode,
orders.order_no
FROM orders, customer_address
WHERE orders.delivery_date = '27-MAY-15'
)
GROUP BY postcode;
EDIT:
However, your query seems wrong. Why do you cross-join orders and customer_address? By mistake I guess. Use explicit joins (INNER JOIN customer_address ON ...), when using joins to avoid such errors. But here I guess you'd just have to remove , customer_address.
Then why do you add order numbers? That doesn't seem to make sense.

Oracle CONNECT BY and MAX

I am having difficulty integrating a MAX into a query and would greatly appreciate any help.
Basically what I'm trying to achieve is this: list a supervisor's supervisor's supervised employees along with their latest "day out" punch time.
The part I can't get right is the MAX(day out) part.
Here's the part I got so far that works fine:
SELECT EMPLOYEE.NUMBER,
EMPLOYEE.NAME,
S.NAME AS SUPERVISOR,
EMPLOYEE.HIRE_DATE
FROM EMPLOYEE
LEFT JOIN EMPLOYEE_NUMBER ON EMPLOYEE_NUMBER.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
LEFT JOIN EMPLOYEE S ON S.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
WHERE LEVEL =2
START WITH EMPLOYEE_NUMBER.USERID = (ID OF SUPERVISOR HERE)
CONNECT BY PRIOR EMPLOYEE.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
This part works and gives me the basic input that I need. However, I also need to list, for each employee, his/her lastest "day out" date.
Here's what I tried tried that didn't work:
SELECT EMPLOYEE.NUMBER,
EMPLOYEE.NAME,
S.NAME AS SUPERVISOR,
EMPLOYEE.HIRE_DATE,
MAX(EMPLOYEE_TIME.DATE_OUT)
FROM EMPLOYEE
LEFT JOIN EMPLOYEE_NUMBER ON EMPLOYEE_NUMBER.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
LEFT JOIN EMPLOYEE S ON S.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
LEFT JOIN EMPLOYEE_TIME ON EMPLOYEE_TIME.EMPLOYEE_NUMBER = EMPLOYEE.EMPLOYEE_NUMBER
WHERE LEVEL =2
START WITH EMPLOYEE_NUMBER.USERID = (ID OF SUPERVISOR HERE)
CONNECT BY PRIOR EMPLOYEE.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
GROUP BY
EMPLOYEE.NUMBER,
EMPLOYEE.NAME,
S.NAME,
EMPLOYEE.HIRE_DATE
HAVING MAX(EMPLOYEE_TIME.DATE_OUT) >= SYSDATE-60
It doesn't throw any error, it just keeps on processing forever. I'm guessing something must be looping but I can't figure it out.
Thanks for any help.
A slight change to your query in joining the time table, it need not be joined while CONNECT BY, instead separate it.
SELECT NUMBER,
EMPLOYEE_NAME,
SUPERVISOR,
HIRE_DATE,
MAX(TIME.DATE_OUT)
FROM
(SELECT NUMBER,
EMPLOYEE.NAME AS EMPLOYEE_NAME,
S.NAME AS SUPERVISOR,
EMPLOYEE.HIRE_DATE
FROM EMPLOYEE
LEFT JOIN EMPLOYEE_NUMBER ON EMPLOYEE_NUMBER.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
LEFT JOIN EMPLOYEE S ON S.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER
WHERE LEVEL =2
START WITH EMPLOYEE_NUMBER.USERID = (ID OF SUPERVISOR HERE)
CONNECT BY PRIOR EMPLOYEE.NUMBER = EMPLOYEE.SUPERVISOR_NUMBER) EMP_SUP
INNER JOIN EMPLOYEE_TIME TIME
ON( EMP_SUP.NUMBER = TIME.NUMBER)
GROUP BY
NUMBER,
EMPLOYEE_NAME,
SUPERVISOR,
HIRE_DATE
HAVING MAX(DATE_OUT) >= SYSDATE-60

Magento disable products with no images via Phpmyadmin

i would like to disable products with no images in Magento 1.8. I have tried this code:
UPDATE catalog_product_entity_int SET value = 2
WHERE attribute_id = 4
AND entity_id IN (
SELECT entity_id
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
);
but i have this alert:
Column 'entity_id' in field list is ambiguous
How can i resolve?
Thanks!
In your inner query on line 4 you're listing the column entity_id. This column name entity_id is not unique in your sql field list, because the column entity_id is in the catalog_product_entity table and in the catalog_product_entity_media_gallery as well. MySQL simply doesn't know, which one of these two columns should be shown. So you have to prepend the table in your select area:
UPDATE catalog_product_entity_int SET value = 2
WHERE attribute_id = 4
AND entity_id IN (
SELECT `your_table_name`.`entity_id`
FROM catalog_product_entity_media_gallery
RIGHT OUTER JOIN catalog_product_entity ON catalog_product_entity.entity_id = catalog_product_entity_media_gallery.entity_id
WHERE catalog_product_entity_media_gallery.value is NULL
);

Distinct by order date and products SQL Server 2008

This is my first post here so if I've been mistaken for my post and English I say sorry :)
I already do research in google and unfortunately until now I can't solve this.
This my problem, show the total orders by date on each product and I want to distinct by products
Here's my query sample
SELECT Orders.OrderDate
,SUM(OrderDetails.OrderDetailQuantity) AS totalOrdered
,Products.ProductId
FROM Orders
INNER JOIN OrderDetails ON Orders.OrderId = OrderDetails.OrderId
INNER JOIN Products ON OrderDetails.ProductId = Products.ProductId
GROUP BY Orders.OrderId
,Orders.OrderDate
,Products.ProductId
HAVING (CONVERT(VARCHAR, Orders.OrderDate, 23) BETWEEN #from AND #to)
Now, I want to distinct by product according to the between OrderDate, I know the big problem here is the DATE but I don't have any idea on how to distinct the date by this query.
Please help me. Thank you.
P.S.: if do you want to solve this in linq expression it would be highly accepted :)
Sample data and desired results would help. When you say "distinct by" I assume you mean group by. Note, in the WHERE clause you dont need to cast Order.OrderDate if you ensure that the time component of your #from & #to params are set correctly (to include each entire day). Its never a good idea to apply a cast operation to the left side of a comparison.
SELECT --cast(Orders.OrderDate as date),
Products.ProductId
SUM(OrderDetails.OrderDetailQuantity) AS totalOrdered,
FROM Orders
INNER JOIN OrderDetails ON Orders.OrderId = OrderDetails.OrderId
INNER JOIN Products ON OrderDetails.ProductId = Products.ProductId
where Orders.OrderDate between cast(#from as date) AND cast(#to as date)
GROUP
BY --cast(Orders.OrderDate as date),
Products.ProductId
-- to illustrate:
declare #From datetime = '1/1/2000 10:30:22',
#To datetime = '1/3/2000 9:11:31'
declare #orders table (i int, dt datetime)
insert into #orders
values(1, '1/1/2000 8:00'),(2, '1/2/2000 10:00'), (3, '1/4/2000 3:00')
-- only returns i=2
select *
from #orders
where dt between #From and #To
-- returns i=1 & i=2
select *
from #orders
where dt between cast(#From as date) and cast(#To as date)

Magento Sales Order tables

Hello I am trying to get all customer who has bought this certain product. Although I am new to Magento So need your help. This is what I did so far .
SELECT o.customer_id,i.product_id ,i.NAME
FROM sales_flat_order_item i INNER JOIN sales_flat_order o
ON o.entity_id = i.order_id
WHERE o.customer_id IS NOT NULL
AND product_id = '8' OR product_id = '14' OR product_id = '15' OR product_id = '16' ;
I need to get only the customers who's payment has been approved for these products(Where can I check that) .
How this will work if the payments were made by recurring payments ?
Please provide some way.

Resources