0

I have to update website for some items and price. I do it in the loop and fetch data from csv file.

I did it this way:

    $productCollection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToFilter('name', $name)
            ->addAttributeToSelect('*')
            ->setPageSize(1)
            ->getFirstItem();
        $product->setWebsiteIds($websiteID);
        $product->setPrice($price);
        $product->setSku($sku);
        $product->getResource()->saveAttribute($product, "price");
        $product->getResource()->saveAttribute($product, "sku");
        $product->getResource()->saveAttribute($product, "website_id");

The price is updated but I have problem with website_id and sku. I got exception.

in SKU case:

Column not found: 1054 Unknown column 'catalog_product_entity.value_id' in 'field list' in /var/www/html/cisco/lib/Zend/Db/Statement/Pdo.php on line 228

in Website case:

Call to a member function getBackend() on boolean in /var/www/html/cisco/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1548

If I use save() instead of saveAttribute() it works fine but because of the performance I must do it another way.

Could you tell me guys how could I fix it?

2

You should be able to use the catalog/product_website model to assign products to websites in bulk.

Mage::getSingleton('catalog/product_website')->addProducts($websiteIds, $productIds);

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.