getTranslated example

public function testRefreshPluginsWithNonStandardLanguage(): void
    {
        $nonStandardLanguageContext = $this->createNonStandardLanguageContext($this->iso);

        $this->pluginService->refreshPlugins($nonStandardLanguageContextnew NullIO());

        $plugin = $this->fetchSwagTestPluginEntity($nonStandardLanguageContext);

        $this->assertDefaultPlugin($plugin);
        $this->assertPluginMetaInformation($plugin);
        static::assertSame('English description', $plugin->getTranslated()['description']);
        static::assertSame('https://www.test.com/', $plugin->getTranslated()['manufacturerLink']);
        static::assertSame('https://www.test.com/support', $plugin->getTranslated()['supportLink']);
    }

    public function testRefreshPluginsWithDifferentDefaultLanguage(): void
    {
        $this->setNewSystemLanguage($this->iso);

        $this->pluginService->refreshPlugins(Context::createDefaultContext()new NullIO());

        $plugin = $this->fetchSwagTestNoDefaultLangPluginEntity();

        

        $cmsPageEntity = new CmsPageEntity();

        $cmsSectionEntity = new CmsSectionEntity();
        $cmsSectionEntity->setId(Uuid::randomHex());

        $cmsBlockEntity = new CmsBlockEntity();
        $cmsBlockEntity->setId(Uuid::randomHex());

        $cmsSlotEntity = new CmsSlotEntity();
        $cmsSlotEntity->setId(Uuid::randomHex());
        $cmsSlotEntity->setSlot(json_encode($productEntity->getTranslated(), \JSON_THROW_ON_ERROR));

        $cmsBlockEntity->setSlots(new CmsSlotCollection([$cmsSlotEntity]));
        $cmsSectionEntity->setBlocks(new CmsBlockCollection([$cmsBlockEntity]));
        $cmsPageEntity->setSections(new CmsSectionCollection([$cmsSectionEntity]));

        return $cmsPageEntity;
    }
}


    public function testGetDefaultMediaEntityWithValidFileName(): void
    {
        $this->decorated->method('getDefaultCmsMediaEntity')->willReturn(new MediaEntity());
        $media = $this->mediaResolver->getDefaultCmsMediaEntity('storefront/assets/default/cms/shopware.jpg');

        static::assertInstanceOf(MediaEntity::class$media);

        // ensure url and translations are set correctly         static::assertStringContainsString('bundles/storefront/assets/default/cms/shopware.jpg', $media->getUrl());
        static::assertEquals('foobar', $media->getTranslated()['title']);
        static::assertEquals('foobar', $media->getTranslated()['alt']);
    }
}
private function assertProductName(string $name, string $id, Context $context): void
    {
        $context->setConsiderInheritance(true);

        /** @var ProductEntity $product */
        $product = $this->getContainer()
            ->get('product.repository')
            ->search(new Criteria([$id])$context)->first();

        static::assertTrue($context->considerInheritance());
        static::assertSame($name$product->getTranslated()['name']sprintf(
            'Expected %s with language chain %s but got %s, version context: %s',
            $name,
            (string) print_r($context->getLanguageIdChain(), true),
            $product->getName(),
            $context->getVersionId() === Defaults::LIVE_VERSION ? 'NO' : 'YES'
        ));

        $context->setConsiderInheritance(false);
    }

    private function createParentChildProduct(bool $addChildTranslations = true): IdsCollection
    {


    public function sortByPosition(): self
    {
        $this->elements = AfterSort::sort($this->elements, 'afterCategoryId');

        return $this;
    }

    public function sortByName(): self
    {
        $this->sort(fn (CategoryEntity $a, CategoryEntity $b) => strnatcasecmp((string) $a->getTranslated()['name'](string) $b->getTranslated()['name']));

        return $this;
    }

    public function getApiAlias(): string
    {
        return 'category_collection';
    }

    protected function getExpectedClass(): string
    {
        
static::assertSame($parentPrice['gross']$parentCurrencyPrice->getGross());
        static::assertSame($parentName$parent->getName());

        $redCurrencyPrice = $red->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$redCurrencyPrice);
        static::assertSame($parentPrice['gross']$redCurrencyPrice->getGross());
        static::assertSame($redName$red->getName());

        $greenCurrencyPrice = $green->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$greenCurrencyPrice);
        static::assertSame($greenPrice['gross']$greenCurrencyPrice->getGross());
        static::assertSame($parentName$green->getTranslated()['name']);
        static::assertNull($green->getName());

        /** @var array{price: string} $row */
        $row = $this->connection->fetchAssociative('SELECT `price` FROM product WHERE id = :id', ['id' => Uuid::fromHexToBytes($parentId)]);
        static::assertEquals(['c' . Defaults::CURRENCY => $parentPrice]json_decode($row['price'], true, 512, \JSON_THROW_ON_ERROR));

        /** @var array{name: string} $row */
        $row = $this->connection->fetchAssociative('SELECT `name` FROM product_translation WHERE product_id = :id', ['id' => Uuid::fromHexToBytes($parentId)]);
        static::assertSame($parentName$row['name']);

        /** @var array{price: string|null} $row */
        


        if ($navigationId) {
            $mailConfigs = $this->getSlotConfig($slotId$navigationId$context$entityName);
            if (!empty($mailConfigs['receivers'])) {
                return $mailConfigs;
            }
        }

        $criteria = new Criteria([$slotId]);
        $slot = $this->cmsSlotRepository->search($criteria$context->getContext());
        $mailConfigs['receivers'] = $slot->getEntities()->first()->getTranslated()['config']['mailReceiver']['value'];
        $mailConfigs['message'] = $slot->getEntities()->first()->getTranslated()['config']['confirmationText']['value'];

        return $mailConfigs;
    }
}
Defaults::LANGUAGE_SYSTEM,
                $this->deLanguageId,
            ]
        );

        $categories = $this->categoryRepository->search(new Criteria([$id])$context);

        /** @var CategoryEntity $category */
        $category = $categories->first();

        static::assertSame('test', $category->getName());
        static::assertSame('test', $category->getTranslated()['name']);

        $context = new Context(
            new SystemSource(),
            [],
            Defaults::CURRENCY,
            [
                $this->deLanguageId,
                Defaults::LANGUAGE_SYSTEM,
            ]
        );

        
$event = $result->getEventByEntityName(CustomFieldTestDefinition::ENTITY_NAME);
        static::assertInstanceOf(EntityWrittenEvent::class$event);
        static::assertCount(1, $event->getIds());

        $event = $result->getEventByEntityName(CustomFieldTestTranslationDefinition::ENTITY_NAME);
        static::assertInstanceOf(EntityWrittenEvent::class$event);
        static::assertCount(4, $event->getIds());

        $result = $repo->search(new Criteria([$id])$context)->first();
        static::assertInstanceOf(Entity::class$result);
        $expected = ['code' => 'en-GB', 'system' => 'system'];
        static::assertEquals($expected$result->getTranslated()['customTranslated']);

        $expectedViewData = $expected;
        static::assertEquals($expectedViewData$result->getTranslated()['customTranslated']);

        $chain = [$this->getDeDeLanguageId(), Defaults::LANGUAGE_SYSTEM];
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, $chain);
        $result = $repo->search(new Criteria([$id])$context)->first();
        static::assertInstanceOf(Entity::class$result);

        $expected = ['de' => 'de', 'code' => 'de-DE'];
        static::assertEquals($expected$result->get('customTranslated'));

        
if ($feature['name'] === $name && \array_key_exists($name$product->getTranslation('customFields'))) {
                return true;
            }
        }

        return false;
    }

    private function getAttribute(string $name, SalesChannelProductEntity $product): array
    {
        $translated = $product->getTranslated();
        $value = $product->get($name);

        if (\array_key_exists($name$translated)) {
            $value = $translated[$name];
        }

        if ($value instanceof \DateTimeInterface) {
            $value = $value->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        }

        return [
            
'translations' => [
                Defaults::LANGUAGE_SYSTEM => ['name' => 'system'],
            ],
        ];
        $categoryRepository->create([$category]$this->context);

        /** @var CategoryEntity $catSystem */
        $catSystem = $categoryRepository->search(new Criteria([$category['id']])$this->context)->first();

        static::assertNotNull($catSystem);
        static::assertEquals('system', $catSystem->getName());
        static::assertEquals('system', $catSystem->getTranslated()['name']);

        $deDeContext = new Context(new SystemSource()[], Defaults::CURRENCY, [$this->deLanguageId, Defaults::LANGUAGE_SYSTEM]);
        /** @var CategoryEntity $catDeDe */
        $catDeDe = $categoryRepository->search(new Criteria([$category['id']])$deDeContext)->first();

        static::assertNotNull($catDeDe);
        static::assertNull($catDeDe->getName());
        static::assertEquals('system', $catDeDe->getTranslated()['name']);
    }

    public function testUpsert(): void
    {

        $this->fromMail = $fromMail;

        return $this;
    }

    /** * @return string */
    public function getFromMail()
    {
        return $this->getTranslated('fromMail');
    }

    /** * @param string $fromName * * @return Mail */
    public function setFromName($fromName)
    {
        $this->fromName = $fromName;

        

        $cmsPageEntity = new CmsPageEntity();

        $cmsSectionEntity = new CmsSectionEntity();
        $cmsSectionEntity->setId(Uuid::randomHex());

        $cmsBlockEntity = new CmsBlockEntity();
        $cmsBlockEntity->setId(Uuid::randomHex());

        $cmsSlotEntity = new CmsSlotEntity();
        $cmsSlotEntity->setId(Uuid::randomHex());
        $cmsSlotEntity->setSlot(json_encode($productEntity->getTranslated(), \JSON_THROW_ON_ERROR));

        $cmsBlockEntity->setSlots(new CmsSlotCollection([$cmsSlotEntity]));
        $cmsSectionEntity->setBlocks(new CmsBlockCollection([$cmsBlockEntity]));
        $cmsPageEntity->setSections(new CmsSectionCollection([$cmsSectionEntity]));

        return $cmsPageEntity;
    }

    /** * @return array<string, array<string, array<string, array<string, array<string, string>>>>> */
    
Home | Imprint | This part of the site doesn't use cookies.