<?php
declare(strict_types=1);
namespace Vio\B2BBudget\Core\System\SalesChannel\Context;
use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory;
use Shopware\Core\System\SalesChannel\Exception\ContextPermissionsLockedException;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Vio\B2BBudget\Core\Checkout\Cart\BudgetCartProcessor;
class SalesChannelContextFactory extends AbstractSalesChannelContextFactory
{
private AbstractSalesChannelContextFactory $coreFactory;
public function __construct(
AbstractSalesChannelContextFactory $coreFactory
)
{
$this->coreFactory = $coreFactory;
}
public function getDecorated(): AbstractSalesChannelContextFactory
{
return $this->coreFactory;
}
public function create(string $token, string $salesChannelId, array $options = []): SalesChannelContext
{
$saleChannelContext = $this->coreFactory->create($token, $salesChannelId, $options);
$permissions = $saleChannelContext->getPermissions();
if (!array_key_exists(BudgetCartProcessor::BUDGET_PERMISSION, $permissions)) {
$permissions[BudgetCartProcessor::BUDGET_PERMISSION] = true;
try {
$saleChannelContext->setPermissions($permissions);
} catch (ContextPermissionsLockedException $exception) {
}
}
return $saleChannelContext;
}
}