<?php declare(strict_types=1);
namespace Acris\SuppliesUpselling\Storefront\Page\Product;
use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
use Shopware\Core\Content\Product\Exception\ProductNotFoundException;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
use Shopware\Core\Framework\Struct\ArrayEntity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Product\ProductPage;
use Symfony\Component\HttpFoundation\Request;
use Shopware\Storefront\Page\Product\ProductPageLoader as ParentClass;
class ProductPageLoader extends ParentClass
{
private ParentClass $parentProductPageLoader;
private SystemConfigService $systemConfigService;
public function __construct(
ParentClass $parentProductPageLoader,
SystemConfigService $systemConfigService
) {
$this->parentProductPageLoader = $parentProductPageLoader;
$this->systemConfigService = $systemConfigService;
}
/**
* @throws CategoryNotFoundException
* @throws InconsistentCriteriaIdsException
* @throws MissingRequestParameterException
* @throws ProductNotFoundException
*/
public function load(Request $request, SalesChannelContext $salesChannelContext): ProductPage
{
$enableAsynchronousLoading = $this->systemConfigService->get('AcrisSuppliesUpsellingCS.config.enableAsynchronousLoading', $salesChannelContext->getSalesChannel()->getId());
if ($enableAsynchronousLoading) {
$salesChannelContext->addExtension('acrisCrossSellingAsynchronousLoading', new ArrayEntity([
'asynchronousLoading' => $enableAsynchronousLoading
]));
}
return $this->parentProductPageLoader->load($request, $salesChannelContext);
}
}