0

i am using following code in view.phtml :

$sellerProductInfo = $this->getSellerProductInfo($productowner['userid']);

if ($sellerProductInfo->getSize() == 0) {
$rowsocial= Mage::getModel('marketplace/userprofile')->getPartnerProfileById($productowner['userid']);
} else {
 $sellersProductInfo = $this->getSellerProductInfo();
 if ($sellersProductInfo->getSize() > 0) {
   $sellerId = $sellersProductInfo->getFirstItem()->getSellerId();
   $rowsocial = Mage::getModel('marketplace/userprofile')->getPartnerProfileById($sellerId);
 }
}

but i am getting error : Fatal error: Call to a member function getSize() on a non-object in line : if ($sellerProductInfo->getSize() == 0)

3
  • what is getSelletProductInfo() method does above ? Apr 19, 2016 at 5:31
  • $this->getSellerProductInfo($productowner['userid']); because it return non object value might be empty value Apr 19, 2016 at 5:47
  • 1
    put it like this if($sellerProductInfo && is_object($sellerProductInfo) && $sellerProductInfo->getSize() == 0) Apr 19, 2016 at 5:49

1 Answer 1

2

This means your $sellerProductInfo is not an object and you are calling the function getSize() in non-object.

I am not sure what $this->getSellerProductInfo($productowner['userid']) function does, but to get rid of your error you can add this condition:

$sellerProductInfo = $this->getSellerProductInfo($productowner['userid']);

if($sellerProductInfo){ //check if this returns true
  if ($sellerProductInfo->getSize() == 0) {
  $rowsocial= Mage::getModel('marketplace/userprofile')->getPartnerProfileById($productowner['userid']);
  } else {
   $sellersProductInfo = $this->getSellerProductInfo();
   if ($sellersProductInfo->getSize() > 0) {
     $sellerId = $sellersProductInfo->getFirstItem()->getSellerId();
     $rowsocial = Mage::getModel('marketplace/userprofile')->getPartnerProfileById($sellerId);
   }
  }
}

Remember

Your above script will never get called if $this->getSellerProductInfo($productowner['userid']) doesn't return anything.

1
  • as a note: he is redeclaring $sellersProductInfo in the else statement, with your code he will never get to that part if it is not an object
    – Robin
    Apr 19, 2016 at 5:50

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.