4

How to make an "Update" query in Magento 1.9? I have no Idea how to do it. I added "filtered" column in catalog_product_entity table.

I have the product I.D and here's my Query.

 $productId = '9';
 $data  = array('filtered'=>0);
 $model = Mage::getModel('catalog/product')->load($productId)->addData($data);
 $model->setId($productId)->save();

And this is the query what i want to achieved.

"UPDATE catalog_product_entity SET filtered = 1 WHERE entity_id = 9". 

Note: The column "filtered" is added manually using "ALTER TABLE" in catalog_product_entity.

2
  • Filtered is an text attribute or multiselect or select? Jul 3, 2018 at 9:14
  • "Filtered" is a column, I added manually the filtered column in catalog_product_entity.
    – larp
    Jul 4, 2018 at 3:02

2 Answers 2

3

Try following way


$productId = 9;
$saveData = array('custom_col' => 1);
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$where = $write->quoteInto('product_id = ?', $productId);
$write->update('custom_table', $saveData, $where);
4
  • Its not working :(
    – larp
    Jul 3, 2018 at 8:45
  • Which table you want to save? This code should work.
    – Sohel Rana
    Jul 3, 2018 at 9:12
  • Sorry I missed spelled the table name. :) It's working.
    – larp
    Jul 5, 2018 at 3:05
  • Great. Accept this answer it will help other too.
    – Sohel Rana
    Jul 5, 2018 at 3:51
0

Try this code:

$query =  "UPDATE `catalog_product_entity` SET `filtered` = '1' WHERE `catalog_product_entity`.`entity_id` = 9";

$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$writeConnection->query($query);
$writeConnection->closeConnection();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.