how to check product has custom options?

橙三吉。 提交于 2019-12-05 05:14:27

I've encountered this error more times than I care to count. Either $_product->hasOptions() or $_product->hasCustomOptions() always returns false. I still don't know why this error occurs.

Anyway, you can get the same result by doing the following. For configurable products:

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

And to get the same result for simple products with custom options:

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

I hope that helps a future adventurer!


EDIT


The solution above does not work in loops when the flat category data option is enabled in Magento, and we don't want to reload the product inside the foreach loop!!

Instead, we can check for custom options using the following singleton inside the loop:

$opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($_product);
$optsSize = $opts->getSize();

if ( $optsSize ) {
    ... // go go go
}
Alex Moo

use the method $product->getHasOptions()

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!