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