Skip to main content
Rollback to Revision 1
Source Link
Raj
  • 532
  • 7
  • 19

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I waswere thinking of using the iterator walk method, however, I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I was thinking of using the iterator walk method, however, I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I were thinking of using the iterator walk method however I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.

added 1 character in body
Source Link
Prince Patel
  • 22.9k
  • 10
  • 98
  • 121

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I werewas thinking of using the iterator walk method, however, I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I were thinking of using the iterator walk method however I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I was thinking of using the iterator walk method, however, I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.

Tweeted twitter.com/StackMagento/status/754244826565120000
Source Link
Raj
  • 532
  • 7
  • 19

Bulk update products to include new websites

A client has 20000+ products with 7 websites. They used to have 4 websites and most products are associated to 4 websites. What is the best & quickest way to iterate through the products and update the products to include the new websites.

I have the following code however it is far too slow:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addFieldToFilter('sku', array('like' => '02%'));
foreach ($productCollection as $product) {
    echo $product->getSku();
    $product->setWebsiteIds(array(1,2,3,4,5,6,7));
    try {
        $product->save();
        echo " - saved.";
    } catch (Exception $e) {
        echo ' - '.$e->getMessage();
    }
    echo "\n";
}

I were thinking of using the iterator walk method however I understand that the store/website isn't exactly an attribute so it can't be easily updated on its own.