setCurrency example

return $signature;
    }

    /** * Updates all currency dependencies (e.g. in the shop model or in the shop context). */
    private function updateCurrencyDependencies(int $currencyId): void
    {
        $currencyModel = $this->get(ModelManager::class)->find(Currency::class$currencyId);

        $shopModel = $this->get('shop');
        $shopModel->setCurrency($currencyModel);

        $currency = $this->get('currency');
        $currency->setFormat($currencyModel->toArray());

        $this->get(ContextServiceInterface::class)->initializeShopContext();
    }

    /** * @param CheckoutBasketArray $basket * * @return list<string> */


            $repository = Shopware()->Models()->getRepository(Shop::class);

            $shopId = is_numeric($order['language']) ? $order['language'] : $order['subshopID'];
            $shop = $repository->getActiveById($shopId);
            if ($shop === null) {
                continue;
            }

            $repository = Shopware()->Models()->getRepository(Currency::class);
            $shop->setCurrency($repository->find($order['currencyID']));
            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

            foreach ($orderPositions[$orderId] as &$position) {
                $position['link'] = $this->get(RouterInterface::class)->assemble([
                    'module' => 'frontend', 'sViewport' => 'detail',
                    'sArticle' => $position['articleID'],
                ]);

                $position['link_rating_tab'] = $this->get(RouterInterface::class)->assemble([
                    'module' => 'frontend', 'sViewport' => 'detail',
                    'sArticle' => $position['articleID'],
                    
$discount = new PromotionDiscountEntity();
        $discount->setId('D5');
        $discount->setType(PromotionDiscountEntity::TYPE_ABSOLUTE);
        $discount->setValue($standardDiscountValue);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $currency = new CurrencyEntity();
        $currency->setId('C1');

        $advancedPrice = new PromotionDiscountPriceEntity();
        $advancedPrice->setUniqueIdentifier(Uuid::randomHex());
        $advancedPrice->setCurrency($currency);
        $advancedPrice->setCurrencyId($currency->getId());
        $advancedPrice->setPrice($currencyDiscountValue);

        $advancedPricesCollection = new PromotionDiscountPriceCollection([]);
        $advancedPricesCollection->add($advancedPrice);

        $discount->setPromotionDiscountPrices($advancedPricesCollection);

        $this->salesChannelContext->method('getCurrency')->willReturn($currency);

        $item = $builder->buildDiscountLineItem('code', $this->promotion, $discount, 'C1', $currencyFactor);

        
$discount->setType(PromotionDiscountEntity::TYPE_PERCENTAGE);
        $discount->setValue(40);
        $discount->setMaxValue(30.0);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $currency = new CurrencyEntity();
        $currency->setId('currency');
        $this->salesChannelContext->method('getCurrency')->willReturn($currency);

        $advancedPrice = new PromotionDiscountPriceEntity();
        $advancedPrice->setUniqueIdentifier(Uuid::randomHex());
        $advancedPrice->setCurrency($currency);
        $advancedPrice->setCurrencyId($currency->getId());
        $advancedPrice->setPrice(20);
        $discount->setPromotionDiscountPrices(new PromotionDiscountPriceCollection([$advancedPrice]));

        $builder = new PromotionItemBuilder();

        $item = $builder->buildDiscountLineItem('', $this->promotion, $discount$currency->getId()$currencyFactor);

        static::assertEquals(20, $item->getPayload()['maxValue']);
    }

    
        $shop = $repository->getById($this->_order->order->language);
        if ($shop === null) {
            throw new ModelNotFoundException(Shop::class$this->_order->order->language);
        }

        if (!empty($this->_order->order->currencyID)) {
            $repository = Shopware()->Models()->getRepository(Currency::class);
            $currency = $repository->find($this->_order->order->currencyID);
            if ($currency === null) {
                throw new ModelNotFoundException(Currency::class$this->_order->order->currencyID);
            }
            $shop->setCurrency($currency);
        }

        Shopware()->Container()->get(ShopRegistrationServiceInterface::class)->registerResources($shop);
    }

    /** * Set object configuration from array */
    protected function setConfig(array $config)
    {
        $this->_config = $config;
        
use Shopware\Bundle\StoreFrontBundle\Struct\Currency;

class CurrencyHydrator extends Hydrator
{
    public function hydrate($data)
    {
        $currency = new Currency();
        $currency->setId((int) $data['__currency_id']);
        $currency->setName($data['__currency_name']);
        $currency->setFactor((float) $data['__currency_factor']);
        $currency->setCurrency($data['__currency_currency']);
        $currency->setSymbol($data['__currency_templatechar']);
        $currency->setSymbolPosition($data['__currency_symbol_position']);

        return $currency;
    }
}
protected $symbolPosition;

    /** * @return Currency */
    public static function createFromCurrencyEntity(CurrencyEntity $currency)
    {
        $struct = new self();

        $struct->setId($currency->getId());
        $struct->setName($currency->getName());
        $struct->setCurrency($currency->getCurrency());
        $struct->setFactor($currency->getFactor());
        $struct->setSymbol($currency->getSymbol());

        return $struct;
    }

    /** * @param int $id */
    public function setId($id)
    {
        
$this->sCurrency = $this->sGetCurrency($this->sSettings['currencyID']);
        $this->sCustomergroup = $this->sGetCustomergroup($this->sSettings['customergroupID']);

        $this->articleMediaAlbum = $this->getMediaRepository()
            ->getAlbumWithSettingsQuery(-1)
            ->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);

        if ($this->sCurrency === false) {
            throw new RuntimeException('Currency could not be fetched correctly.');
        }
        $currency = Shopware()->Models()->getRepository(Currency::class)->find($this->sCurrency['id']);
        $shop->setCurrency($currency);
        Shopware()->Container()->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        if ($this->sCustomergroup !== false) {
            Shopware()->Container()->get('session')->offsetSet('sUserGroup', $this->sCustomergroup['groupkey']);
        }

        $this->contextService->initializeContext();

        $this->shop = $shop;

        $this->sSYSTEM->sCONFIG = $this->config;
    }
$response->setRedirect($url);

            return;
        }

        // Upgrade currency         if ($request->getCookie('currency') !== null) {
            $currencyValue = $request->getCookie('currency');
            foreach ($shop->getCurrencies() as $currency) {
                if ($currencyValue == $currency->getId()
                    || $currencyValue == $currency->getCurrency()) {
                    $shop->setCurrency($currency);
                    break;
                }
            }
        }

        // Start session in frontend controllers         $session = $this->get('session');

        if ($cookieKey !== null) {
            $session->set($cookieKey$cookieValue);
        }

        

    public function hydrate($data)
    {
        $shop = new Shop();
        $shop->setId((int) $data['__shop_id']);
        $shop->setIsDefault((bool) $data['__shop_default']);
        $shop->setName($data['__shop_name']);
        $shop->setTitle($data['__shop_title']);
        $shop->setFallbackId((int) $data['__shop_fallback_id']);
        $shop->setCurrency($this->currencyHydrator->hydrate($data));
        $shop->setCustomerGroup($this->customerGroupHydrator->hydrate($data));
        $shop->setCategory($this->categoryHydrator->hydrate($data));
        $shop->setLocale($this->localeHydrator->hydrate($data));

        $parent = $data;
        if ($data['parent']) {
            $parent = $data['parent'];
        }

        $shop->setTemplate($this->templateHydrator->hydrate($parent));
        $shop->setParentId((int) $parent['__shop_id']);
        
Home | Imprint | This part of the site doesn't use cookies.