0

what is wrong with this foreach, it came with the theme but always comes up with error invalid argument, I don't do code so don't know if its a missing bit of code or missing table or what, its in the theme Helper/Data.php

public function getType(Mage_Catalog_Model_Product $product)
{
    if ('Mage_Catalog_Model_Product' != get_class($product) )
        return;
    foreach ($product->getOptionsType as $o) {
        $optionType = $o['type'];
        if ($optionType == 'file') {
            return true;
        }
    }
    return false;
}
2
  • sorry should be this
    – Mark2109
    Commented Jan 22, 2016 at 14:41
  • public function getType(Mage_Catalog_Model_Product $product) { if ( 'Mage_Catalog_Model_Product' != get_class($product) ) return; foreach ($product->getProductOptionsType() as $o) { $optionType = $o['type']; if ($optionType == 'file') { return true; } } return false;
    – Mark2109
    Commented Jan 22, 2016 at 14:41

2 Answers 2

0

Replace

if ('Mage_Catalog_Model_Product' != get_class($product) )

with

if (!($product instanceof Mage_Catalog_Model_Product))

and replace

foreach ($product->getOptionsType as $o) {

with

if ($product->getOptionsType()) {
    foreach ($product->getOptionsType() as $o) {
    ....
    }
}
3
  • thanks for helping still getting the same error invalid argument on line 106 which is the below line
    – Mark2109
    Commented Jan 22, 2016 at 15:42
  • foreach ($product->getOptionsType as $o) {
    – Mark2109
    Commented Jan 22, 2016 at 15:42
  • see my edit. maybe it works.
    – Marius
    Commented Jan 22, 2016 at 15:50
0

It seems that you pass wrong type of object in getType function.

Example:

Mage::helper('yourmodule')->getType($object); 

The type hint of your function is Mage_Catalog_Model_Product, the object you pass into getType function should be instance of Mage_Catalog_Model_Product

For more detail please read follow this tutorial: http://alanstorm.com/php_primer_type_hints

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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