1

I have a product P in attribute set S where a value is set to attribute A.

If I now remove attribute A from the attribute set S, the value for A of P remains in the database as long as I don't completely remove the attribute X itself.

How can I remove these values so that the function hasData() of Mage_Catalog_Model_Product returns false?

1

This is not tested and may not work:

$productAttributes = $product->getTypeInstance(true)->getEditableAttributes($product);
foreach ($product->getData() as $code=>$value) {
    if (!array_key_exists($code, $productAttributes) {
        $product->setData($code, null);
    }
}
$product->save();
| improve this answer | |

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.