fix(product): fix error when image not found
This commit is contained in:
@@ -8,6 +8,7 @@ use Cart\Tax;
|
||||
use Exception;
|
||||
use Openguru\OpenCartFramework\Config\Settings;
|
||||
use Openguru\OpenCartFramework\ImageTool\ImageToolInterface;
|
||||
use Openguru\OpenCartFramework\Logger\LoggerInterface;
|
||||
use Openguru\OpenCartFramework\OpenCart\Decorators\OcRegistryDecorator;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
||||
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
|
||||
@@ -23,6 +24,7 @@ class ProductsService
|
||||
private OcModelCatalogProductAdapter $ocModelCatalogProduct;
|
||||
private ImageToolInterface $ocImageTool;
|
||||
private OcRegistryDecorator $oc;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(
|
||||
Builder $queryBuilder,
|
||||
@@ -31,7 +33,8 @@ class ProductsService
|
||||
Settings $settings,
|
||||
OcModelCatalogProductAdapter $ocModelCatalogProduct,
|
||||
ImageToolInterface $ocImageTool,
|
||||
OcRegistryDecorator $registry
|
||||
OcRegistryDecorator $registry,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
$this->currency = $currency;
|
||||
@@ -40,6 +43,7 @@ class ProductsService
|
||||
$this->ocModelCatalogProduct = $ocModelCatalogProduct;
|
||||
$this->ocImageTool = $ocImageTool;
|
||||
$this->oc = $registry;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function getProductsResponse(array $params): array
|
||||
@@ -247,6 +251,7 @@ class ProductsService
|
||||
|
||||
$images = [];
|
||||
foreach ($imagePaths as $imagePath) {
|
||||
try {
|
||||
[$width, $height] = $this->ocImageTool->getRealSize($imagePath);
|
||||
$images[] = [
|
||||
'thumbnailURL' => $this->ocImageTool->resize($imagePath, $imageWidth, $imageHeight, 'placeholder.png'),
|
||||
@@ -260,6 +265,9 @@ class ProductsService
|
||||
'height' => $height,
|
||||
'alt' => $product['product_name'],
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
}
|
||||
|
||||
$price = $this->currency->format(
|
||||
|
||||
Reference in New Issue
Block a user