1

I need to transfer data stored in an attribute (cjm_imageswitcher as serialised data array) for all configurable products into the database table mg_catalog_product_entity_media_gallery_value.

The code below loops through the configurable products and the serailised data of the attribute.

Is there a way to update the single field selectorbase of mg_catalog_product_entity_media_gallery_value for each configurable product without using a direct sql query?

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

$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'configurable'));

foreach ($collectionConfigurable as $_configurableproduct):

    $product    = Mage::getModel('catalog/product')->load($_configurableproduct->getId());

    $imageSwitch    = $product->getData('cjm_imageswitcher');

    //UPDATE IMAGE SWITCH

    if ($imageSwitch != 'N;'):
            $imageSwitch = unserialize ($imageSwitch);

        foreach ($imageSwitch as $value=>$selectorbase):

            if ($selectorbase == ''):
                $selectorbase = 0;
            endif;

            **// UPDATE SELECTOR BASE VIA DIRECT SQL????
            $sql = 'UPDATE "mg_catalog_product_entity_media_gallery_value" SET selectorbase = '.(int)$selectorbase.' WHERE value_id = '.(int)$value;**

        endforeach;


    endif;
endforeach;
?>
2

The table does not contain a selectorbase column unless an extension added it, and this is not a table designed for extending. So there is no core method to update it.

Still, theres the Zend_Db abstraction layer, so you don't need to use plain SQL.

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.