0

I would like to copy categories attributes (e.g title, search engine optimization text like url_key, contents, description etc) from a store view navigation to the default navigation.

In other words, I would like to use the categories in All Store View instead of my store view. However, I have been mistakenly editing the store view categories instead of the global ones and it's time-consuming to re-update that manually.

How to copy these:

enter image description here

To these:

enter image description here

Therefore what is a good approach to do this?

I'm not sure if doing this is correct, but I tried editing directly the table. Not sure if there are other considerations I need to put into mind when editing the table directly.

I thought to copy all records from store id 1 to store id 0 and then delete everything in store id 0 in order to reset it to use (Use Default Value)

INSERT INTO  `catalog_category_entity_text` (
  `attribute_id`,
  `store_id`,
  `entity_id`,
  `value`
) 
SELECT 
  `attribute_id`,
  "0",
  `entity_id`,
  `value` 
FROM
  `catalog_category_entity_text_1` src 
WHERE src.`store_id` = 1 AND src.value IS NOT NULL
  ON DUPLICATE KEY 
  UPDATE 
    `catalog_category_entity_text`.`value` = src.`value` ;
  • I may not have a solution right now, but I can say that your approach would not work for you. The store_id in these tables is the scope of the settings value where 1 would be your store-level, and 0 is global. What you need to look at is the catalog_category_entity table, specifically the path column. You can copy the categories with different paths there, but you would still have to populate all of the tables in my next comment... – mtr.web Mar 9 '18 at 21:13
  • catalog_category_entity_int, catalog_category_entity_text, catalog_category_entity_decimal, catalog_category_entity_datetime, catalog_category_entity_varchar, and catalog_category_product will all need to be populated with the new categories and their new ids – mtr.web Mar 9 '18 at 21:15
  • @mtr.web thank you for your reply. The categories actually exist in both store, I wanted to copy their descriptions etc to global categories. I managed to do that by running a few queries. I added an answer. Again, thank you for your comment. – Mohammed Joraid Mar 10 '18 at 6:37
0

Writing an answer for my future reference.

So I did a three-step insert & update to copy the details of categories in Store view #1 to categories to the global categories store ID #0.

The operation I did was on these tables (I skipped decimal and DateTime as I never selected any of these options)

1) First I backed up these tables _1:

catalog_category_entity_text
catalog_category_entity_varchar
catalog_category_entity_int

2) I ran the following query for all 3 tables. This will insert all edited fields from Store ID#1 in case they were never populated in Store ID#0.

INSERT INTO  `catalog_category_entity_<datatype>` (
  `attribute_id`,
  `store_id`,
  `entity_id`,
  `value`
) 
SELECT 
  `attribute_id`,
  "0",
  `entity_id`,
  `value` 
FROM
  `catalog_category_entity_<datatype>_1` src 
WHERE src.`store_id` = 1 AND src.value IS NOT NULL
  ON DUPLICATE KEY 
  UPDATE 
    `catalog_category_entity_<datatype>`.`value` = src.`value` ;

3) Then update attributes of categories in Store View #0 based on their counterparts from Store View #1, same situation, run for all tables (I also executed this query for all 3 tables).

UPDATE 
  `catalog_category_entity_text` des 
  INNER JOIN `catalog_category_entity_text` src 
    ON src.`attribute_id` = des.`attribute_id` 
    AND des.`entity_id` = src.`entity_id`     
    AND src.value IS NOT NULL  AND src.value !=""
    SET des.`value` = src.value
WHERE src.store_id = 1 AND des.`store_id`=0;

4) And finally, remove everything that belongs to store view #1. This will force categories in store #1 to have (Default Value) selected.

DELETE FROM `catalog_category_entity_text` WHERE store_id = 1;
DELETE FROM `catalog_category_entity_datetime` WHERE store_id = 1;
DELETE FROM `catalog_category_entity_decimal` WHERE store_id = 1;
DELETE FROM `catalog_category_entity_int` WHERE store_id = 1;
DELETE FROM `catalog_category_entity_varchar` WHERE store_id = 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.