Add video to each product using s_articles_attributes.

Hello everyone,

Objective:  Add a video for each product and show it on product detail page.

Development type: Plugin

Explaination:  I am trying to add a video for each product so it is available in the frontend detail page of the plugin. I am extending s_articles_attributes  table. The plugin is able to add a video to each product in the backend.

Problem:  When I try to fetch the video link in the frontend it appears as an integer and not as a link. How can I make it available as a link in the frontend detail template ?

 

My code:  

 public function install(InstallContext $context) { $attributeService = $this-\>container-\>get('shopware\_attribute.crud\_service'); $attributeService-\>update('s\_articles\_attributes', 'prod\_video', 'single\_selection', ['displayInBackend' =\> true, 'entity' =\> Media::class, 'label' =\> 'Product Video']); $this-\>container-\>get('models')-\>generateAttributeModels(['s\_articles\_attributes']); $context-\>scheduleClearCache(InstallContext::CACHE\_LIST\_ALL); }

At frontend:

 

<video controls>
    {if !empty($sArticle['prod_video'])}
        <source src="%7B%24sArticle%5B'prod_video'%5D%7D" type="video/mp4">

    {else}
        <source src="http://somerandom.mp4" type="video/mp4">

    {/if}

    Your browser does not support the video tag.
</source></source></video>

Hi,

 

it’s a bit wrong. It’s under the attributes key inside sArticle, so in Smarty it will look like this:

{$sArticle.attributes.core->get('prodvideo')}

I’m not sure, if this calls is 100% correct. But basically, you call arrays in Smarty with the dot notation. Object are called as in php with the arrow. Under attributes you got all your attributes in a few objects.

Hello derwunner,

Thanks for your reply. I tried your suggested solutions still but no luck. The smarty debug console also shows the value as “571” and not as the video url/location. 

 

That’s your media id. You need to get the corresponding dataset from s_media. Then you got the virtual path, so you need to parse into an real url using the media serivce: MediaService

1 Like