getEnabled example

private readonly Connection $connection,
        private readonly IncrementGatewayRegistry $gatewayRegistry,
        private readonly AdminElasticsearchHelper $adminEsHelper
    ) {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);

        if ($this->adminEsHelper->getEnabled() !== true) {
            $io->error('Admin elasticsearch is not enabled');

            return self::FAILURE;
        }

        $answer = $io->ask('Are you sure you want to reset the Admin Elasticsearch indexing?', 'yes');

        if ($answer !== 'yes') {
            $io->error('Canceled clearing indexing process');

            return self::SUCCESS;
        }

        $currency = $context->getCurrency();
        $currencyTaxFreeAmount = $currency->getTaxFreeFrom();
        $isReachedCurrencyTaxFreeAmount = $currencyTaxFreeAmount > 0 && $cartNetAmount >= $currencyTaxFreeAmount;

        if ($isReachedCurrencyTaxFreeAmount) {
            return CartPrice::TAX_STATE_FREE;
        }

        $country = $context->getShippingLocation()->getCountry();

        $isReachedCustomerTaxFreeAmount = $country->getCustomerTax()->getEnabled() && $this->isReachedCountryTaxFreeAmount($context$country$cartNetAmount);
        $isReachedCompanyTaxFreeAmount = $this->taxDetector->isCompanyTaxFree($context$country) && $this->isReachedCountryTaxFreeAmount($context$country$cartNetAmount, CountryDefinition::TYPE_COMPANY_TAX_FREE);
        if ($isReachedCustomerTaxFreeAmount || $isReachedCompanyTaxFreeAmount) {
            return CartPrice::TAX_STATE_FREE;
        }

        if ($this->taxDetector->useGross($context)) {
            return CartPrice::TAX_STATE_GROSS;
        }

        return CartPrice::TAX_STATE_NET;
    }

    
public static function getSubscribedEvents(): array
    {
        return [
            EntityWrittenContainerEvent::class => [
                ['refresh', -1000],
            ],
        ];
    }

    public function iterate(AdminIndexingBehavior $indexingBehavior): void
    {
        if (!$this->adminEsHelper->getEnabled()) {
            return;
        }

        /** @var array<string> $entities */
        $entities = array_keys($this->indexer);

        if ($indexingBehavior->getOnlyEntities()) {
            $entities = array_intersect($entities$indexingBehavior->getOnlyEntities());
        } elseif ($indexingBehavior->getSkipEntities()) {
            $entities = array_diff($entities$indexingBehavior->getSkipEntities());
        }

        

class AdminElasticsearchHelperTest extends TestCase
{
    /** * @dataProvider searchHelperProvider */
    public function testSearchHelper(bool $adminEsEnabled, bool $refreshIndices, string $adminIndexPrefix): void
    {
        $searchHelper = new AdminElasticsearchHelper($adminEsEnabled$refreshIndices$adminIndexPrefix);

        static::assertEquals($adminEsEnabled$searchHelper->getEnabled());
        static::assertEquals($refreshIndices$searchHelper->getRefreshIndices());
        static::assertEquals($adminIndexPrefix$searchHelper->getPrefix());
        static::assertEquals($adminIndexPrefix . '-promotion-listing', $searchHelper->getIndex('promotion-listing'));
    }

    public function testSetEnable(): void
    {
        $searchHelper = new AdminElasticsearchHelper(false, false, 'sw-admin');

        static::assertFalse($searchHelper->getEnabled());
        static::assertFalse($searchHelper->getRefreshIndices());
        
public function __construct(
        private readonly AdminSearcher $searcher,
        private readonly DefinitionInstanceRegistry $definitionRegistry,
        private readonly JsonEntityEncoder $entityEncoder,
        private readonly AdminElasticsearchHelper $adminEsHelper
    ) {
    }

    #[Route(path: '/api/_admin/es-search', name: 'api.admin.es-search', methods: ['POST'], defaults: ['_routeScope' => ['administration']])]     public function elastic(Request $request, Context $context): Response
    {
        if ($this->adminEsHelper->getEnabled() === false) {
            throw ElasticsearchAdminException::esNotEnabled();
        }

        $term = trim((string) $request->get('term', ''));
        $entities = $request->request->all('entities');

        if (empty($term)) {
            throw ElasticsearchAdminException::missingTermParameter();
        }

        $limit = $request->get('limit', 10);

        
#[Package('checkout')] class TaxDetector
{
    public function useGross(SalesChannelContext $context): bool
    {
        return $context->getCurrentCustomerGroup()->getDisplayGross();
    }

    public function isNetDelivery(SalesChannelContext $context): bool
    {
        $shippingLocationCountry = $context->getShippingLocation()->getCountry();
        $countryTaxFree = $shippingLocationCountry->getCustomerTax()->getEnabled();

        if ($countryTaxFree) {
            return true;
        }

        return $this->isCompanyTaxFree($context$shippingLocationCountry);
    }

    public function getTaxState(SalesChannelContext $context): string
    {
        if ($this->isNetDelivery($context)) {
            
Home | Imprint | This part of the site doesn't use cookies.