custom/plugins/VioB2BBudgets/src/Core/System/SalesChannel/Context/SalesChannelContextFactory.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Vio\B2BBudget\Core\System\SalesChannel\Context;
  4. use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory;
  5. use Shopware\Core\System\SalesChannel\Exception\ContextPermissionsLockedException;
  6. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  7. use Vio\B2BBudget\Core\Checkout\Cart\BudgetCartProcessor;
  8. class SalesChannelContextFactory extends AbstractSalesChannelContextFactory
  9. {
  10.     private AbstractSalesChannelContextFactory $coreFactory;
  11.     public function __construct(
  12.         AbstractSalesChannelContextFactory $coreFactory
  13.     )
  14.     {
  15.         $this->coreFactory $coreFactory;
  16.     }
  17.     public function getDecorated(): AbstractSalesChannelContextFactory
  18.     {
  19.         return $this->coreFactory;
  20.     }
  21.     public function create(string $tokenstring $salesChannelId, array $options = []): SalesChannelContext
  22.     {
  23.         $saleChannelContext $this->coreFactory->create($token$salesChannelId$options);
  24.         $permissions $saleChannelContext->getPermissions();
  25.         if (!array_key_exists(BudgetCartProcessor::BUDGET_PERMISSION$permissions)) {
  26.             $permissions[BudgetCartProcessor::BUDGET_PERMISSION] = true;
  27.             try {
  28.                 $saleChannelContext->setPermissions($permissions);
  29.             } catch (ContextPermissionsLockedException $exception) {
  30.             }
  31.         }
  32.         return $saleChannelContext;
  33.     }
  34. }