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!
asked Oct 4, 2013 at 13:48
Prashant Parekh
3152 gold badges9 silver badges17 bronze badges
-
1I am not sure what you are asking here. Have you a custom product attribute called "search_sku"? What is it used for? Why do you need it updating and is this a one off update or does it need to up regular?David Manners– David Manners2013年10月04日 14:15:30 +00:00Commented Oct 4, 2013 at 14:15
1 Answer 1
/**
* 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);
answered Oct 4, 2013 at 15:36
Stefan Gregori
1,4292 gold badges18 silver badges26 bronze badges
Explore related questions
See similar questions with these tags.
default