How to check the product has custom parameters?

I am trying to check if the product has custom parameters or not in the code (my code fires the sales_order_place_after event). I am trying to make the code below but returns nothing. $product->hasCustomOptions() as well as $product->hasOptions()

Please let me know what I am missing.

+7
source share
2 answers

I encountered this error more than I think. Either $_product->hasOptions() , or $_product->hasCustomOptions() always returns false . I still don’t know why this error occurs.

In any case, you can get the same result by doing the following. For custom products:

 <?php if ( $_product->getData('has_options') ): ?> <!-- do something --> <?php endif; ?> 

And get the same result for simple products with customizable options:

 <?php if ( $_product->getData('has_options') && ($_product->getTypeID() == 'simple') ): ?> <!-- do something --> <?php endif; ?> 

I hope this helps the future adventurer!


EDIT


The above solution does not work in cycles when a parameter parameter with a flat category is included in Magento, and we do not want to reload the product inside the foreach cycle!

Instead, we can check the settings using the following single element inside the loop:

 $opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($_product); $optsSize = $opts->getSize(); if ( $optsSize ) { ... // go go go } 
+11
source share

use the method $product->getHasOptions()

+4
source share

All Articles