0

So, I create + 2 websites with store and store views. I need to set all my products to all this web sites. Possible ways:

  1. Manually per product(but I have more than 200 000 products)
  2. In Manage products -> select all and update attributes (but I it will take a lot of time)
  3. Make a query to DB

Is any one resolve this problem with query? what tables should I take?

  • 1
    keep in mind that 'INSERT INTO catalog_product_website with SELECT from catalog_product_entity' you need consider products without website and not visible singly(these types does not need in catalog_product_website table). – Alfredo A. Jan 15 '15 at 11:37
1

The relation between products an websites is remembered in catalog_product_website.
Insert one line for each combination of product and website in there.

INSERT INTO
    `catalog_product_website`
VALUES
    (1,1),
    (1,2),
....
    (200000, 1),
    (200000, 2),

You might want to split this into more queries because you can reach the limit for the max allowed query size.

When you are done reindex (this will take a lot of time so be patient)

  • Thanks! so may I use loop in which I will set this query? – sergio Feb 27 '14 at 8:55
  • Sure, you can loop through all the products and insert 2 lines in the table catalog_product_website for each product, if the line does not already exist. – Marius Feb 27 '14 at 8:57
  • 1
    Hm also I think about something like: INSERT INTO catalog_product_website ('product_id', 'website_id') SELECT entity_id , 2 from catalog_product_entity.... – sergio Feb 27 '14 at 9:06
  • That could work. I just told you where you need to add something....how you add it?...choose your weapon. – Marius Feb 27 '14 at 9:09
  • Finall. Did. Thanks for advice!!! Really helped me! – sergio Feb 27 '14 at 9:12
1

Use below code to update product website programmatically,

$products = Mage::getModel('catalog/product')->getCollection();

foreach( $products as $product) {
    $product->setStoreId($storeId); // replace $storeId by STORE ID
    $product->setWebsiteIDs($websiteid); // replace $websiteid by WEBSITEID
    try {
        $product->save();
    } catch(Exception $e) {
        echo $e->getMessage();
    }
}
  • 1
    I think it's setWebsiteIds() instead of setStoreId and this won't work for 200k products. – Marius Feb 27 '14 at 8:57
  • yes marius, you are right setWebsiteIds(). – Helphin Feb 27 '14 at 9:02

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.