getCurrency example

/** * @param array<array<string, mixed>> $products * * @return array<array<string, mixed>> */
    private function assignAdditionalText(array $products): array
    {
        $shop = $this->entityManager->getRepository(Shop::class)->getActiveDefault();

        $context = $this->contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        $tempProducts = $this->buildListProducts($products);
        $tempProducts = $this->additionalTextService->buildAdditionalTextLists($tempProducts$context);

        foreach ($tempProducts as $tempProduct) {
            $number = $tempProduct->getNumber();
            if (!isset($products[$number])) {
                continue;
            }
            

        $this->config = $config;
    }

    /** * {@inheritdoc} */
    public function getSelection(ShopContextInterface $context)
    {
        $fallback = $context->getFallbackCustomerGroup();
        $current = $context->getCurrentCustomerGroup();
        $currency = $context->getCurrency();

        $priceField = 'defaultPrice.price';
        if ($fallback->getId() != $current->getId()) {
            $priceField = 'IFNULL(customerPrice.price, defaultPrice.price)';
        }

        $discount = $current->useDiscount() ? $current->getPercentageDiscount() : 0;

        $considerMinPurchase = $this->config->get('calculateCheapestPriceWithMinPurchase');

        $taxCase = $this->buildTaxCase($context);

        
$context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        foreach ($cases as $i => $case) {
            // prepare currency factor calculation             $factor = 1;
            if ($case->usedCurrency !== Defaults::CURRENCY) {
                $factor = 1.5;
            }

            $context->getContext()->assign(['currencyFactor' => $factor]);
            $context->getCurrency()->setId($case->usedCurrency);

            // test different tax states             $context->setTaxState($case->taxState);

            // create a new product for this case             $id = $ids->create('product-' . $i);

            $price = [
                [
                    'currencyId' => $case->currencyId,
                    'gross' => $case->gross,
                    
yield 'render with default language' => [
            [7],
            function DDocumentGenerateOperation $operation, ContainerInterface $container) use ($documentDate): void {
                $operation->assign([
                    'config' => [
                        'displayHeader' => true,
                        'documentDate' => $documentDate,
                    ],
                ]);
            },
            function DRenderedDocument $rendered, OrderEntity $order, ContainerInterface $container): void {
                static::assertNotNull($order->getCurrency());

                static::assertStringContainsString(
                    $container->get(CurrencyFormatter::class)->formatCurrencyByLanguage(
                        $order->getAmountTotal(),
                        $order->getCurrency()->getIsoCode(),
                        Context::createDefaultContext()->getLanguageId(),
                        Context::createDefaultContext(),
                    ),
                    $rendered->getHtml()
                );

                

        $activeShopId = $context->getShop()->getId();
        $premiums = $this->connection->fetchAllAssociative($sql[$activeShopId]);

        $activeFactor = $context->getCurrency()->getFactor();
        foreach ($premiums as &$premium) {
            if ($premium['subshopID'] === '0') {
                $sql = ' SELECT factor FROM s_core_currencies INNER JOIN s_core_shops ON s_core_shops.currency_id = s_core_currencies.id WHERE s_core_shops.`default` = 1 LIMIT 1 ';
                $premiumFactor = $this->connection->fetchOne($sql[]);
            } else {
                $sql = ' SELECT factor FROM s_core_currencies INNER JOIN s_core_shops ON s_core_shops.currency_id = s_core_currencies.id WHERE s_core_shops.id = ? LIMIT 1 ';
$cart->setErrors($errors);
        $cart->setData($data);

        return \serialize([
            'compressed' => $this->compress,
            'content' => $content,
            // used for migration             'token' => $cart->getToken(),
            'customer_id' => $context->getCustomerId(),
            'rule_ids' => $context->getRuleIds(),
            'currency_id' => $context->getCurrency()->getId(),
            'shipping_method_id' => $context->getShippingMethod()->getId(),
            'payment_method_id' => $context->getPaymentMethod()->getId(),
            'country_id' => $context->getShippingLocation()->getCountry()->getId(),
            'sales_channel_id' => $context->getSalesChannel()->getId(),
            'price' => $cart->getPrice()->getTotalPrice(),
            'line_item_count' => $cart->getLineItems()->count(),
            'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);
    }
}
$contextLanguage = $languages->get($context->getContext()->getLanguageId());
        if (!$contextLanguage) {
            throw new \RuntimeException(sprintf('Context language with id %s not found', $context->getContext()->getLanguageId()));
        }

        $page = new HeaderPagelet(
            $navigation,
            $languages,
            $currencies,
            $contextLanguage,
            $context->getCurrency(),
            $this->getServiceMenu($context)
        );

        $this->eventDispatcher->dispatch(new HeaderPageletLoadedEvent($page$context$request));

        return $page;
    }

    private function getServiceMenu(SalesChannelContext $context): CategoryCollection
    {
        $serviceId = $context->getSalesChannel()->getServiceCategoryId();

        
private function getQuery(ShopContextInterface $context): RangeQuery
    {
        return new RangeQuery(
            $this->getPseudoPriceField($context),
            ['gt' => 0]
        );
    }

    private function getPseudoPriceField(ShopContextInterface $context): string
    {
        $key = $context->getCurrentCustomerGroup()->getKey();
        $currency = $context->getCurrency()->getId();

        return 'calculatedPrices.' . $key . '_' . $currency . '.calculatedPseudoPrice';
    }
}

        return $this->currency;
    }
}

class MoneyDataMapper implements DataMapperInterface
{
    public function mapDataToForms(mixed $viewData, \Traversable $forms): void
    {
        $forms = iterator_to_array($forms);
        $forms['amount']->setData($viewData ? $viewData->getAmount() : 0);
        $forms['currency']->setData($viewData ? $viewData->getCurrency() : 'EUR');
    }

    public function mapFormsToData(\Traversable $forms, mixed &$viewData): void
    {
        $forms = iterator_to_array($forms);

        $amount = $forms['amount']->getData();
        if (!is_numeric($amount)) {
            $failure = new TransformationFailedException('Expected numeric value');
            $failure->setInvalidMessage('Money amount should be numeric. {{ amount }} is invalid.', ['{{ amount }}' => json_encode($amount)]);

            
// detect active payment method, first check if checkout defined other payment method, otherwise validate if customer logged in, at least use shop default         $payment = $this->getPaymentMethod($options$base$customer);

        [$itemRounding$totalRounding] = $this->getCashRounding($base$shippingLocation);

        $context = new Context(
            $base->getContext()->getSource(),
            [],
            $base->getCurrencyId(),
            $base->getContext()->getLanguageIdChain(),
            $base->getContext()->getVersionId(),
            $base->getCurrency()->getFactor(),
            true,
            CartPrice::TAX_STATE_GROSS,
            $itemRounding
        );

        $salesChannelContext = new SalesChannelContext(
            $context,
            $token,
            $options[SalesChannelContextService::DOMAIN_ID] ?? null,
            $base->getSalesChannel(),
            $base->getCurrency(),
            
return $definition;
    }

    private function getPriceValue(PriceCollection $price, SalesChannelContext $context): float
    {
        /** @var Price $currency */
        $currency = $price->getCurrencyPrice($context->getCurrencyId());

        $value = $this->getPriceForTaxState($currency$context);

        if ($currency->getCurrencyId() !== $context->getCurrency()->getId()) {
            $value *= $context->getContext()->getCurrencyFactor();
        }

        return $value;
    }

    private function getPriceForTaxState(Price $price, SalesChannelContext $context): float
    {
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            return $price->getGross();
        }

        
public function getLanguages(): LanguageCollection
    {
        return new LanguageCollection(
            $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getLanguage())
        );
    }

    public function getCurrencies(): CurrencyCollection
    {
        return new CurrencyCollection(
            $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getCurrency())
        );
    }

    public function getTypes(): SalesChannelTypeCollection
    {
        return new SalesChannelTypeCollection(
            $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getType())
        );
    }

    public function getApiAlias(): string
    {
&& !$twigContext['context'] instanceof SalesChannelContext
            )
        ) {
            if (isset($twigContext['testMode']) && $twigContext['testMode'] === true) {
                return $price;
            }

            throw new \InvalidArgumentException('Error while processing Twig currency filter. No context or locale given.');
        }

        if (!$currencyIsoCode && $twigContext['context'] instanceof SalesChannelContext) {
            $currencyIsoCode = $twigContext['context']->getCurrency()->getIsoCode();
        }

        if (!$currencyIsoCode) {
            if (isset($twigContext['testMode']) && $twigContext['testMode'] === true) {
                return $price;
            }

            throw new \InvalidArgumentException('Error while processing Twig currency filter. Could not resolve currencyIsoCode.');
        }

        if ($twigContext['context'] instanceof Context) {
            
$price = $this->getCurrencyPrice($priceCollection$context);
        }

        $definition = new QuantityPriceDefinition($price$rules, 1);

        return $this->priceCalculator->calculate($definition$context);
    }

    private function getCurrencyPrice(PriceCollection $priceCollection, SalesChannelContext $context): float
    {
        /** @var Price $price */
        $price = $priceCollection->getCurrencyPrice($context->getCurrency()->getId());

        $value = $this->getPriceForTaxState($price$context);

        if ($price->getCurrencyId() === Defaults::CURRENCY) {
            $value *= $context->getContext()->getCurrencyFactor();
        }

        return $value;
    }

    private function getPriceForTaxState(Price $price, SalesChannelContext $context): float
    {

    private function getAdditionalTexts(array $products): array
    {
        $shopRepo = $this->get(ModelManager::class)->getRepository(Shop::class);

        $shop = $shopRepo->getActiveDefault();

        $contextService = $this->get(ContextServiceInterface::class);

        $context = $contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        $service = $this->get(AdditionalTextServiceInterface::class);

        return $service->buildAdditionalTextLists($products$context);
    }

    /** * @return ListProduct[] */
    
Home | Imprint | This part of the site doesn't use cookies.