Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The general issue is in code syntax - the <code>unset($product-&gt;getOptions());</code> says to PHP to unlink the name (variable, array index or object property) from the value it stores. However, entity that is returned by the method/function call, has no name. I.e. it is not a variable, object property or array index, it is just a pure value. So calling <code>unset()</code> on it doesn't make sense. </p> <p>It is not a Magento error, it is violation of general PHP syntax.</p> <p>If you want to unset options in a Product model, then you need to go other way. First of all, you need to change syntax. Second, you need to note that Product model is not designed to change custom options dynamically. </p> <p>You have two options, how to implement desired functionality:</p> <p>1) If you need just to delete option and save product, then you need to change <code>unset($product-&gt;getOptions());</code> to </p> <pre><code>$optionsData = $option-&gt;getData(); $optionsData['is_delete'] = 1; $product-&gt;setProductOptions(array($option-&gt;getId() =&gt; $optionsData)); $product-&gt;setCanSaveCustomOptions(true); $product-&gt;save(); </code></pre> <p>Loading product again will return you the product without the option:</p> <pre><code>$product = Mage::getModel('catalog/product')-&gt;load($product_id); </code></pre> <p>2) If you need to delete option and continue working with the same Product model, then you need to rewrite Product model class (<a href="http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/" rel="noreferrer">this article</a> explains how to do that) and add your custom method to unset the property you want. That is how a rewrited class would look like:</p> <pre><code>class MageDev_NewCatalog_Model_Product extends Mage_Catalog_Model_Product { public function unsetOption($optionId) { unset($this-&gt;_options[$optionId]; } } </code></pre> <p>Then you need to change <code>unset($product-&gt;getOptions());</code> to <code>$product-&gt;unsetOption($option-&gt;getId())</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload