Question

Try to bulk update label name in catalog_product_entity_media_gallery_value,

CSV formate :

enter image description here

Workout:

<?php
require_once 'app/Mage.php';
umask("0");
Mage::app();

ini_set('display_errors',"1");
ini_set('display_startup_errors', "1");
error_reporting(E_ALL);

    if (($handle = fopen("inputs.csv", "r")) !== FALSE)
    {
        while (($data = fgetcsv($handle, '1000', ",")) !== FALSE)
        {
            $sql='UPDATE catalog_product_entity_media_gallery_value SET label='.$data['2'].' WHERE value_id = '.$data['0'].'';
            echo $sql.'<br/>';
            mysqli_query($sql); 


        }
        fclose($handle);
    }
?>

How to alter my script for Magento 1.9?

Was it helpful?

Solution

Try this code

<?php
require_once 'app/Mage.php';
umask("0");
Mage::app();

ini_set('display_errors',"1");
ini_set('display_startup_errors', "1");
error_reporting(E_ALL);
$connection=Mage::getSingleton('core/resource')->getConnection('core_write');
    if (($handle = fopen("inputs.csv", "r")) !== FALSE)
    {
        while (($data = fgetcsv($handle, '1000', ",")) !== FALSE)
        {


            $sql = "UPDATE " . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity_media_gallery_value') . " cped
                SET  cped.label = ?
            WHERE  cped.value_id = ?";
            $connection->query($sql, array($data['2'], $data['0']));


        }
        fclose($handle);
    }
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top