Magento disable products with no images via Phpmyadmin - magento

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
);

Related

magento sql query update category from inactive to is active

I currently have an magento site with a couple of hundred categories, the problem I have is the person who added them set is active to NO. I would like to update all the main and sub categories to is_active to be YES (TRUE).
I have tried the following update Query which updated the is_active to 1 but does not update in Magento even after I re indexed all in Index Management.
UPDATE catalog_category_flat_store_1 SET is_active = 1 WHERE is_active = 0
Thanks for your help.
The catalog_category_flat_store_1 table is a generated table from the EAV tables done for performance reasons. It's not the true source of the category config data.
You'll need to update the data in the EAV. Run this query to find where is_active is stored:
SELECT t1.attribute_id, t1.attribute_code, t1.backend_type
FROM eav_entity_type AS t0
INNER JOIN eav_attribute AS t1 ON (t0.entity_type_id = t1.entity_type_id)
WHERE (t0.entity_model = 'catalog/category')
On my server it has an attribute_id of 42.
You'll then need to query catalog_category_entity and join on catalog_category_entity_int to get the rows to update.

How to get product manufacturer name from manufacturer value id by mysql?

I know how to get the product manufacturer id, but I need the product manufacturer id & name using MySQL.
75 is the attribute id for getting product manufacturer id.
Anyone can help?
I want it in SQL format.
First of all I want to get this out of the way.
If you have the product as an object you can get the manufacturer id like this:
$product->getManufacturer();
and for the name:
$product->getAttributeText('manufacturer');
Now for the sql part...I don't know why you would need it but here goes.
Let's say the product id is 10.
Try this query.
SELECT
i.value as manufacturer_id,
v.value as manufacturer_name
FROM
catalog_product_entity_int i
LEFT JOIN
eav_attribute_option o
ON i.value = o.option_id
LEFT JOIN
eav_attribute_option_value v
ON o.option_id = v.option_id AND
v.store_id = 0
WHERE
i.entity_id = 10 AND
i.attribute_id = 75 AND
i.store_id = 0;
if you want the values for an other store view just replace the 0 in v.store_id = 0 and i.store_id = 0 with the value of your store id. 0 means default values.
Great code, thanks!
On my Magento 2.3.1 i have just changed attribute_id to '83' and added SKU. It works correctly.
SELECT
e.sku as SKU,
i.value as manufacturer_id,
v.value as manufacturer_name
FROM
catalog_product_entity_int i
LEFT JOIN
eav_attribute_option o
ON i.value = o.option_id
LEFT JOIN
eav_attribute_option_value v
ON o.option_id = v.option_id AND
v.store_id = 0
LEFT JOIN
catalog_product_entity e
ON i.entity_id = e.entity_id
WHERE
i.attribute_id = 83 AND
i.store_id = 0
ORDER BY `SKU` DESC

Retrieving a list of rows with only a single item from other table in Oracle

I have two tables in Oracle database (10g express)
product
product_image
One product can have multiple images. Hence, there a one-to-many relationship from product to product_image and the product_image table has a foreign key that refers to the primary key of the product table.
I need to fetch a list of products with only a single image name in each row of the result set being retrieved regardless of the images being in the product_image table (even though there are no images for some of products).
The image name to be retrieved from the product_image table is generally the first image name in the product_image table after sorting each set of images for each product in ascending order. Something like the following.
prod_id prod_name prod_image
1 aaa aaa.jpg //The first image name in the product_image table after sorting images for prod_id in ascending order.
2 bbb bbb.jpg //Similar to the first case.
3 ccc - //No image(s) found in the product_image table
4 ddd - //Similar to the previous case.
The general join statement for these two tables would be something similar to the following.
SELECT p.prod_id, p.prod_name, pi.prod_image
FROM product p
INNER JOIN product_image pi
ON p.prod_id=pi.prod_id;
Is this possible using a single SQL statement?
If I understood your question correctly I think the following query will work. I have not tested it.
SELECT p.prod_id, p.prod_name, MIN(DBMS_LOB.substr(pi.prod_image, 1))
FROM product p LEFT JOIN product_image pi
ON p.prod_id=pi.prod_id
GROUP BY p.prod_id, p.prod_name
ORDER BY p.prod_name;
Try this, you can generate row number for each image per prod_id and use that. To return null or blank from missing product image you should use left outer join
WITH CTE AS
(
SELECT prod_id, DBMS_LOB.substr(prod_image,1,4000) prod_image,
row_number() over (partition by prod_id order by prod_image) rn
FROM product_image
)
SELECT p.prod_id, p.prod_name, nvl(pi.prod_image,'-') prod_image
FROM product p
LEFT OUTER JOIN CTE pi
ON p.prod_id=pi.prod_id and pi.rn = 1;
The following SQL worked as mentioned in the question.
SELECT
p.prod_id,
p.prod_name,
t.prod_image
FROM
product p
LEFT OUTER JOIN(
SELECT
pi.prod_image_id,
pi.prod_id,
pi.prod_image
FROM
product_image pi
INNER JOIN (
SELECT
MIN(pi.prod_image_id) AS prod_image_id
FROM
product_image pi
GROUP BY
pi.prod_id
) prod_image
ON pi.prod_image_id=prod_image.prod_image_id
)t ON p.prod_id=t.prod_id ORDER BY p.prod_id DESC;
Reference:
SQL Select only rows with Max Value on a Column

Where are magento attribute values and product images stored?

I need to create a SQL query to export my Magento site products in XML format.
I can't figure where are attribute values and product images stored.
By now my query is this:
SELECT cpe.entity_id, cpe.sku, csi.qty, eav_color.value, eav_talla.value
FROM catalog_product_entity AS cpe
JOIN cataloginventory_stock_item AS csi ON csi.product_id = cpe.entity_id
JOIN catalog_product_entity_int AS eav_color ON eav_color.entity_id = cpe.entity_id
AND eav_color.attribute_id =85
JOIN catalog_product_entity_int AS eav_talla ON eav_talla.entity_id = cpe.entity_id
AND eav_talla.attribute_id =127
WHERE csi.qty >0
AND csi.is_in_stock
AND cpe.type_id = 'simple'
LIMIT 0 , 30
But I am getting attributes ids (I think). My query returns this:
entity_id sku qty value value
6000 0121011000-RED-L 2.0000 66 5
I am getting 66 as value for column attribute and value 5 for "talla" attribute.. But those values must be "RED" and "L". I don't understand in wich table are those values stored.
And on the other hand I need to get the product images but I can't figure in where table are stored.
Although there is EAV attribute for image it is actually stored in two tables.
The first one is catalog_product_entity_media_gallery with columns:
value_id - id for the current table
attribute_id - id of an attribute in eav_attribute table
entity_id - id of a product from catalog_product_entity table
value - path to the file
The second is catalog_product_entity_media_gallery_value with columns:
value_id - id of the catalog_product_entity_media_gallery row
store_id - id of a store
label - label of an image
position - position in list of images
disabled - disable the image for the store
So catalog_product_entity_media_gallery defines images for products and catalog_product_entity_media_gallery_value handles settings for different store views.

Tracking Unregistered Abandon carts in 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

Resources