Question

I have to update attribute "search_sku". I have to update this attribute using sku. I have do this job using mysql. But I am not getting that how can I get this query?

Please help me. Thanks in advanced!

Was it helpful?

Solution

/**
 * Get the resource model
 */
$resource = Mage::getSingleton('core/resource');

/**
 * Retrieve the write connection
 */
$writeConnection = $resource->getConnection('core_write');

/**
 * Retrieve our table name
 */
$table = $resource->getTableName('catalog/product');

/**
 * Set the product ID
 */
$productId = 44;

/**
 * Set the new SKU
 * It is assumed that you are hard coding the new SKU in
 * If the input is not dynamic, consider using the
 * Varien_Db_Select object to insert data
 */
$newSku = 'new-sku';

$query = "UPDATE {$table} SET sku = '{$newSku}' WHERE entity_id = "
         . (int)$productId;

/**
 * Execute the query
 */
$writeConnection->query($query);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top