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?

Ahmad
6181 gold badge6 silver badges16 bronze badges
asked Jul 13, 2023 at 21:30

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') ?? '';
answered Jul 14, 2023 at 4:05
0

Please try this once, Hope it will work.

Repalce from :-

$urlOptions = parse_url($canonicalUrl);

Repalce to :-

$urlOptions = parse_url($canonicalUrl ?? '');
answered Jul 14, 2023 at 4:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.