Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Sebastian Langer <sl@scn.cx>
- * @license MIT
- */
- use Shopware\Bundle\StoreFrontBundle\Service\Core\ContextService;
- use Shopware\Bundle\StoreFrontBundle\Gateway\DBAL\MediaGateway;
- use Shopware\Components\Compatibility\LegacyStructConverter;
- use Enlight_Template_Default;
- use InvalidArgumentException;
- /**
- * Get the legacy media struct of the media-object by its id.
- * Returns null if not found.
- *
- * @param array $params
- * @param $template
- * @throws InvalidArgumentException
- */
- function smarty_function_legacyMediaById(array $params, Enlight_Template_Default $template)
- {
- /** @var ContextService $contextService */
- $contextService = Shopware()->Container()->get('shopware_storefront.context_service');
- /** @var MediaGateway $mediaGateway */
- $mediaGateway = Shopware()->Container()->get('shopware_storefront.media_gateway');
- /** @var LegacyStructConverter $legacyStructConverter */
- $legacyStructConverter = Shopware()->Container()->get('legacy_struct_converter');
- if (!array_key_exists('id', $params) || !array_key_exists('assign', $params)) {
- throw new InvalidArgumentException('Arguments id and assign must be given.');
- }
- $id = $params['id'];
- $assign = $params['assign'];
- $context = $contextService->getContext();
- $mediaStruct = $mediaGateway->get($id, $context);
- $legacyMedia = $legacyStructConverter->convertMediaStruct($mediaStruct);
- if (!is_array($legacyMedia)) {
- $template->assign($assign, null);
- } else {
- $template->assign($assign, $legacyMedia);
- }
- }
Add Comment
Please, Sign In to add comment