0

I am getting the below error while calling a function in my PHTML file

Fatal error: Uncaught Error: Call to a member function getTypeId() on null

public function getCurrentProductDealDetail()
{
    $curPro = $this->coreRegistry->registry('current_product');
    $productType = $curPro->getTypeId();
    // echo $productType;
    // die("bdvf");
    $assDealDetails = [];
    if ($productType == "configurable") {
        $dataDeal = $this->getConfigAssociateProDeals(true);
    } elseif ($productType == "grouped") {
        $dataDeal = $this->getGroupAssociateProDeals(true);
    } else {
        $dataDeal = $this->helperData->getProductDealDetail($curPro);
        if ($dataDeal) {
            $dataDeal['entity_id'] = $curPro->getId();
        }
    }
    return $dataDeal;
}

issue while calling the block here

<div class="deal-timer">
<?php
                
blockObj= $block->getLayout()->createBlock('V\M\Block\ViewProduct');
$dealDetail = $blockObj->getCurrentProductDealDetail();
$product = $blockObj->getCurrentProduct();
?>
</div>
2
  • Did you tried to log the data of $curPro, are you getting the current product using registry? Dec 10, 2021 at 4:56
  • yes am getting prod type there
    – Pramod
    Dec 10, 2021 at 5:03

2 Answers 2

0

Try getProductType()

$curPro = $this->coreRegistry->registry('current_product');
$productType = $curPro->getProductType();
3
  • i was also getting value there with my code also
    – Pramod
    Dec 10, 2021 at 5:04
  • and yeah that too thworing the same error for this getProductType()
    – Pramod
    Dec 10, 2021 at 5:11
  • try to print_r($curPro) and check you got product or not ?? Dec 10, 2021 at 5:28
0

Can you check the product before getting the product type id?

$curPro = $this->coreRegistry->registry('current_product');
$productType = $curPro->getId();

If it works, then I think you can get the product type using your code.

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.