magento sql query update category from inactive to is active - magento

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.

Related

I cannot find certain fields on the MAGENTO database

I was trying to find this fields because i want to obtain all the products and then, make a query but i was not able to do that(they dont appear in the database diagram for Magento 1.9):
sku, code_brand, code_business_unit, code_line, code_group, code_business, min_sale_qty
This is the diagram:
https://anna.voelkl.at/uploads/magento/ce1922.png
I only found the fields "SKU" and "min_sale_qty". What happened to the others?
Do these fields : code_brand, code_business_unit, code_line, code_group, code_business even exist or they were created by someone?
Anyway, i am using MYSQL connected to the MAGENTO database.
I suppose that code_brand, code_business_unit, code_line, code_group, code_business are custom product attributed that you added right?
When you add a custom attribute, Magento add a row in the table eav_attribute.
There we can find attribute_id and backend_type.
For example if code_brand is a integer the backend_type should be int. So in catalog_product_entity_int we can find rows with the same attribute_id set in the eav_attribute table.
Here you are a sumple query to search that:
SELECT
*
FROM
catalog_product_entity_int
WHERE
attribute_id IN (
SELECT
attribute_id
FROM
eav_attribute
WHERE
attribute_code = 'code_brand'
);

Set Include in Navigation Menu to Yes in database

I want to set Include in Navigation Menu for all categories to Yes.
Can anybody tell me in which table this value is?
Magento use an eav model to save values in the database.
You have to search an attribute called "include_in_menu" in the "eav_attribute" table.
This attribute have an "attribute_id" which will be retrieve in the other tables.
On my installation, this attribute has attribute_id = 67 which is stored as an INTEGER (int)
On magento all the attributes have a type which you can find on the eav_attribute table.
You want to update your categories, we have to update the table where the integer attribute "include_in_menu" of the categories is saved.
As you can see in your database, you have a lot of tables for the categories :
catalog_category_entity, catalog_category_entity_datetime, catalog_category_entity_decimal, catalog_category_entity_int...
You have to select all your categories from the first table : select entity_id from catalog_category_entity
After you have to select the attribute_id in the table related to the good attribute type. Here is "catalog_category_entity_int" for all the INTEGER attribute...
select value from catalog_category_entity_int where attribute_id = 67 and store_id = ...
Be careful if you have multiple stores...All the stores are on the same table.
And now you just have to update value to "1" on the selected rows.
Sorry for my English, i m french...
Best regards
Cédric
This answer worked on Magento EE 2.2.2.
Based on Cedric's answer I used the following query to remove all of the categories from the menu via Sequel Pro.
You can remove all of your categories from your menu by running:
UPDATE catalog_category_entity_int SET value='0' WHERE attribute_id='67'
You can add all of your categories to your menu by running:
UPDATE catalog_category_entity_int SET value='1' WHERE attribute_id='67'
Then flush your cache (php bin/magento cache:flush) and you should see your changes on the frontend.
Again, be careful of what 'store_id' you're affecting.
You can use following query to update all categories:
update catalog_category_entity_int cci
inner join eav_attribute a on a.attribute_id = cci.attribute_id
set cci.value = 1
where a.attribute_code = 'include_in_menu';

How we can write multiple select keyword in a single mysql query using Magento?

here is my query and this give proper ouput.
But How can I set it according to magento rules?
SELECT main_table.*,
(select company from sales_flat_order_address sfoa where sfoa.entity_id=sfo.billing_address_id) as bill_to_company,
(select company from sales_flat_order_address sfoa where sfoa.entity_id=sfo.shipping_address_id) as ship_to_company
FROM sales_flat_order_grid as main_table inner join sales_flat_order as sfo
on main_table.entity_id = sfo.entity_id
please help me....
Thanks & Reagards
Praful
You can use magento default connection Model
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$result=$write->query("your query as like mysql query no different");
$row = $readresult->fetch(); // this will fetch all your data

Reset orders,invoices and shipping to 000001

How can i reset orders,invoices and shipping to 000001 in magento Comunnity 1.7.0.2 ?
What is the simplest and safest method ?
There is a table in the database which stored increment id of order.
It is called “eav_entity_store” table.
You can check which entity type id belongs to which entity by looking at eav_entity_type table.
You can run following query to update last increment id for the order.
update eav_entity_store
inner join eav_entity_type on eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
set eav_entity_store.increment_last_id=000001
where eav_entity_type.entity_type_code='order';

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.

Resources