I am trying to add custom options in my product programmatically with a observer when I save an custom product in admin:


and this is my observer:

public function catalogProductSaveBefore($observer) {
    $product = $observer->getProduct();

    if ($product->getTypeID() == "cartaovirtual") { //this is my custom product type
        //here I am failing to delete old custom option
        $oldOptions = $product->getOptionInstance()->getOptions();
        foreach ($oldOptions as $key => $option) {
            if ($oldOptions[$key]['title'] == "Número do Cartão") {
                $oldOptions[$key]['is_delete'] = 1;

        //here I create my custom option (this works fine!)
        $option = array(
            "title" => "Número do Cartão",
            "type" => "field",
            "is_require" => 1,
            "sort_order" => 1,
            "price" => 0,
            "price_type" => "fixed",
            "sku" => ""


I can only delete the "Custom Options" when I'm editing the product and I click on the tab "Custom Options".


  • If I open this product type, change the product name and save, the product creates new attributes and does not delete the old attributes.

  • If I open this product type, change the product name, open "Custom Options" tab (without making any changes) and save. This works correctly deleting the old attributes and create the new attribute.


  • His problem is different, and that reply code has the same problem as mine.
    – Eduardo
    Jul 30 '14 at 19:04
  • 1
    Shouldn't $product->getTypeID() be $product->getTypeId()?
    – benmarks
    Jul 30 '14 at 19:14
  • Either one or the other work.
    – Eduardo
    Jul 30 '14 at 19:22

have you tried doing:


instead of:

  • Thanks for your reply. I tried but this doesn't worked.
    – Eduardo
    Jul 30 '14 at 19:08

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