Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (31 sloc) 978 Bytes
<?php
declare(strict_types=1);
namespace Netgen\Layouts\Sylius\Item\ValueLoader;
use Netgen\Layouts\Item\ValueLoaderInterface;
use Sylius\Component\Product\Model\ProductInterface;
use Sylius\Component\Product\Repository\ProductRepositoryInterface;
use Throwable;
final class ProductValueLoader implements ValueLoaderInterface
{
/**
* @var \Sylius\Component\Product\Repository\ProductRepositoryInterface
*/
private $productRepository;
public function __construct(ProductRepositoryInterface $productRepository)
{
$this->productRepository = $productRepository;
}
public function load($id): ?object
{
try {
$product = $this->productRepository->find($id);
} catch (Throwable $t) {
return null;
}
return $product instanceof ProductInterface ? $product : null;
}
public function loadByRemoteId($remoteId): ?object
{
return $this->load($remoteId);
}
}
You can’t perform that action at this time.