Skip to content

Commit f4de08f

Browse files
authored
fix: defend custom attribute resolution against PHP 8.1 exceptions (#481)
* fix: catch PHP 8.1 deprecation exceptions in custom attribute resolution * fix: split try/catch blocks and narrow to Exception in attribute resolution * style: fix PHPCS indentation in Product.php catch blocks
1 parent b77e219 commit f4de08f

3 files changed

Lines changed: 54 additions & 6 deletions

File tree

Doofinder/Feed/Helper/Product.php

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,33 @@ public function getAttributeType(ProductModel $product, string $attributeCode):
414414
return null;
415415
}
416416
$frontend = $attribute->getFrontend();
417-
$value = $frontend->getOption($optionId);
417+
try {
418+
$value = $frontend->getOption($optionId);
419+
} catch (\Exception $e) {
420+
$this->_logger->warning(
421+
sprintf(
422+
'Doofinder: could not resolve type for attribute "%s": %s',
423+
$attributeCode,
424+
$e->getMessage()
425+
),
426+
['product_id' => $product->getId()]
427+
);
428+
return null;
429+
}
418430
if (!$value) {
419-
$value = $frontend->getValue($product);
431+
try {
432+
$value = $frontend->getValue($product);
433+
} catch (\Exception $e) {
434+
$this->_logger->warning(
435+
sprintf(
436+
'Doofinder: could not resolve type for attribute "%s": %s',
437+
$attributeCode,
438+
$e->getMessage()
439+
),
440+
['product_id' => $product->getId()]
441+
);
442+
return null;
443+
}
420444
}
421445

422446
return get_debug_type($value);
@@ -441,9 +465,33 @@ public function getAttribute(ProductModel $product, string $attributeCode)
441465
return null;
442466
}
443467
$frontend = $attribute->getFrontend();
444-
$value = $frontend->getOption($optionId);
468+
try {
469+
$value = $frontend->getOption($optionId);
470+
} catch (\Exception $e) {
471+
$this->_logger->warning(
472+
sprintf(
473+
'Doofinder: could not resolve value for attribute "%s": %s',
474+
$attributeCode,
475+
$e->getMessage()
476+
),
477+
['product_id' => $product->getId()]
478+
);
479+
return null;
480+
}
445481
if (!$value) {
446-
$value = $frontend->getValue($product);
482+
try {
483+
$value = $frontend->getValue($product);
484+
} catch (\Exception $e) {
485+
$this->_logger->warning(
486+
sprintf(
487+
'Doofinder: could not resolve value for attribute "%s": %s',
488+
$attributeCode,
489+
$e->getMessage()
490+
),
491+
['product_id' => $product->getId()]
492+
);
493+
return null;
494+
}
447495
}
448496
if (is_a($value, Phrase::class)) {
449497
$value = $value->render();

Doofinder/Feed/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doofinder/doofinder-magento2",
3-
"version": "1.7.3",
3+
"version": "1.7.4",
44
"description": "Doofinder module for Magento 2",
55
"type": "magento2-module",
66
"require": {

Doofinder/Feed/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Doofinder_Feed" setup_version="1.7.3">
3+
<module name="Doofinder_Feed" setup_version="1.7.4">
44
<sequence>
55
<module name="Magento_Integration" />
66
</sequence>

0 commit comments

Comments
 (0)