1

I am using magento 2.4.6 One of my modules is adding meta tags in catalog. Not my code

case 'catalog_product_view':
                    $currentProduct = $this->_registry->registry('current_product');
                    if ($currentProduct && $currentProduct->getData('enable_index_follow')) {
                        $indexValue = $currentProduct->getData('index_value');
                        $followValue = $currentProduct->getData('follow_value');
                        $indexFollowValue = $this->_indexFollowBuilder->getIndexFollowValue($indexValue, $followValue);
                        $this->_pageConfig->setRobots($indexFollowValue);
                    }
                    if ($currentProduct && $currentProduct->getData('enable_canonical_url')) {
                        $canonicalUrl = $currentProduct->getData('canonical_url');
                        $urlOptions = parse_url($canonicalUrl);
                        if (!isset($urlOptions['scheme'])) {
                            $canonicalUrl = $baseUrl . $canonicalUrl;
                        }
                        $this->_pageConfig->addRemotePageAsset(
                            $canonicalUrl,
                            'canonical',
                            ['attributes' => ['rel' => 'canonical']]
                        );
                    }
                    break;

Line:

$urlOptions = parse_url($canonicalUrl);

throw error:

Deprecated Functionality: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated

I can't fix it.

Any help please?

2 Answers 2

2

Instead of null you can use empty string.

chnage below code from

$canonicalUrl = $currentProduct->getData('canonical_url');

to

$canonicalUrl = $currentProduct->getData('canonical_url') ?? '';
0

Please try this once, Hope it will work.

Repalce from :-

$urlOptions = parse_url($canonicalUrl);

Repalce to :-

$urlOptions = parse_url($canonicalUrl ?? '');

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.