<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; attachments</title>
	<atom:link href="http://nemops.com/tag/attachments/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Creating Multilanguage attachments in PrestaShop 1.7</title>
		<link>http://nemops.com/prestashop-1-7-multilanguage-attachments/</link>
		<comments>http://nemops.com/prestashop-1-7-multilanguage-attachments/#comments</comments>
		<pubDate>Wed, 05 Dec 2018 13:24:30 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[attachments]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[prestashop 1.7]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=3173</guid>
		<description><![CDATA[<p>Attachments are a great way to provide your customers with rich pre-sale information about your products. But what if your site is multilingual? Let’s see how to make Attachments multilanguage in PrestaShop 1.7. Watch the screencast Text Version Step 1 – Adding the attachments Adding attachments with the proper name is fundamental for this technique. [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-1-7-multilanguage-attachments/">Creating Multilanguage attachments in PrestaShop 1.7</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Attachments are a great way to provide your customers with rich pre-sale information about your products. But what if your site is multilingual? Let’s see how to make Attachments multilanguage in PrestaShop 1.7.</p>
<p><span id="more-3173"></span></p>
<h2>Watch the screencast</h2>

	<div class="video-embed">
		<iframe width="640" height="360" src="http://www.youtube.com/embed/zoo6WkY7ouc" frameborder="0" allowfullscreen></iframe><p><a href="https://www.youtube.com/user/NemoPostScriptum/videos" rel="nofollow" title="Subscribe Post Scriptum's Youtube Channel">Subscribe Post Scriptum's Youtube Channel</a></p>	</div>
<h2>Text Version</h2>
<h3>Step 1 – Adding the attachments</h3>
<p>Adding attachments with the proper name is fundamental for this technique. We will append the language ISOs to the names, so that they can later be targeted in the template.</p>
<p>Login to the back office, then navigate to Catalog &gt; Products, and choose one to start with. At the bottom of the <strong>Options </strong>tab, add two test attachments. The file names don’t matter, but the <strong>title </strong>you choose does. Add one attachment for each language it’s translated to, making sure you append the ISO code for that language after the name, like this: <strong>_en</strong>, <strong>_it</strong>, <strong>_fr</strong>.</p>
<p><strong>Note: </strong>If you don’t know what the language code is, hop to International &gt; Localization, and click on Languages. The ISO code is listed in the table:</p>
<p><a href="http://nemops.com/wp-content/uploads/2018/12/prestashop-17-language-iso.jpg"><img class="aligncenter size-full wp-image-3174" src="http://nemops.com/wp-content/uploads/2018/12/prestashop-17-language-iso.jpg" alt="PrestaShop 1.7 Language ISO" width="665" height="361" /></a></p>
<p>&nbsp;</p>
<p>If you need an attachment to display for all of the languages, make sure you <strong>do not</strong> add any language ISO to it.</p>
<div class="separator"></div>
<h3>Step 2 – Editing the template</h3>
<p>&nbsp;</p>
<p>For this tutorial I am using the “classic” template, that ships with PrestaShop 1.7. If you are using a custom theme, be aware that some of the code might be different, or even located in a different file.</p>
<p>Open up <strong>themes/classic/templates/catalog/product.tpl</strong>.</p>
<p>Locate the following code:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{if $product.attachments}
                    &lt;div class=&quot;tab-pane fade in&quot; id=&quot;attachments&quot; role=&quot;tabpanel&quot;&gt;
                       &lt;section class=&quot;product-attachments&quot;&gt;
                         &lt;h3 class=&quot;h5 text-uppercase&quot;&gt;{l s='Download' d='Shop.Theme.Actions'}&lt;/h3&gt;
</pre>
<p>Right afterwards, but before the foreach loop, add the following</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{$lang_checker = &quot;_&quot;|cat: {$language.iso_code}}
{$lang_checker_array = ['en', 'it']}

</pre>
<p><strong>Make sure you use your own ISO codes instead of ‘en’ and ‘it’. Add all of the languages your store supports</strong></p>
<p>Next, wrap the attachment block in the following IF statement</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
                         {if $attachment.name|strstr:{$lang_checker}}
                           &lt;div class=&quot;attachment&quot;&gt;
                             &lt;h4&gt;&lt;a href=&quot;{url entity='attachment' params=['id_attachment' =&gt; $attachment.id_attachment]}&quot;&gt;{$attachment.name|replace:{$lang_checker}:''}&lt;/a&gt;&lt;/h4&gt;
                             &lt;p&gt;{$attachment.description}&lt;/p
                             &lt;a href=&quot;{url entity='attachment' params=['id_attachment' =&gt; $attachment.id_attachment]}&quot;&gt;
                               {l s='Download' d='Shop.Theme.Actions'} ({$attachment.file_size_formatted})
                             &lt;/a&gt;
                           &lt;/div&gt;
{/if}

</pre>
<p>If you don’t need some attachments to display for all languages, you can go ahead and test it, as the basic part if basically done. If you do, you will need to add a little extra condition, and we will use that lang_checker_array for it.</p>
<div class="separator"></div>
<h3>Step 2.1 – Fallback for generic attachments</h3>
<p>Right before the end of the IF statement that checks for our ISO code, add the following:</p>
<pre class="brush: php; html-script: true; title: ; notranslate">

{else}
  {$denier = false}
  {foreach from=$lang_checker_array item=checkr_lang}
                              {if $attachment.name|strstr:{$checkr_lang}}
                              {$denier = true}
                              {/if}
  {/foreach}

</pre>
<p><strong>Explanation: </strong>We are setting a variable (denier) that will prevent displaying the attachment if it contains <strong>any</strong> language ISO. Because of this logic, make sure you use a string that’s unique enough in case your attachment names contain product codes or alike, otherwise they won’t ever display.</p>
<p>Right afterwards, but still inside our main IF, add this last chunk of code</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
                               
{if !$denier}
&lt;div class=&quot;attachment&quot;&gt;
&lt;h4&gt;&lt;a href=&quot;{url entity='attachment' params=['id_attachment' =&gt; $attachment.id_attachment]}&quot;&gt;{$attachment.name|replace:{$lang_checker}:''}&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;{$attachment.description}&lt;/p
&lt;a href=&quot;{url entity='attachment' params=['id_attachment' =&gt; $attachment.id_attachment]}&quot;&gt;
{l s='Download' d='Shop.Theme.Actions'} ({$attachment.file_size_formatted})
&lt;/a&gt;
&lt;/div&gt;
{/if}

</pre>
<p>Which is basically a copy of the standard attachment code. If the attachment does not contain any iso code, it means we can display it normally.</p>
<p>We are done!</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-1-7-multilanguage-attachments/">Creating Multilanguage attachments in PrestaShop 1.7</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-1-7-multilanguage-attachments/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Target specific languages with Prestashop Attachments</title>
		<link>http://nemops.com/prestashop-attachments-language/</link>
		<comments>http://nemops.com/prestashop-attachments-language/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 15:18:28 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[attachments]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=929</guid>
		<description><![CDATA[<p>Attachments are a great way to provide your customers with rich pre-sale information about your products. But what if your site is multilingual? Let&#8217;s see how to make Prestashop Attachments language-specific. Version compatibility: Prestashop 1.4, Prestashop 1.5 Introduction So, you have a multilanguage store. And you also offer detailed spreadsheets of your products, or bonus [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-attachments-language/">Target specific languages with Prestashop Attachments</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Attachments are a great way to provide your customers with rich pre-sale information about your products. But what if your site is multilingual? Let&#8217;s see how to make Prestashop Attachments language-specific.</p>
<p><span id="more-929"></span></p>
<ul>
<li>Version compatibility: <strong>Prestashop 1.4, Prestashop 1.5</strong></li>
</ul>
<h2>Introduction</h2>
<p>So, you have a multilanguage store. And you also offer detailed spreadsheets of your products, or bonus videos, as downloadable attachments in product pages. There is a problem though: Prestashop doesn&#8217;t come with a way of targeting specific languages when adding attachments (even though the attachment name is translatable). How to cope with it, in case your attachments are really language-specific? With a little trick, we will take advantage of the default variables assigned to a product page and only display specific downloadable files.</p>
<div class="separator"></div>
<h2>Step 1 &#8211; Adding attachments</h2>
<p>The first, and most important step is, of course, to add attachments to your products. I will use a demo product, the iPod Nano that comes out of the box with Prestashop. I will also make use of Prestashop 1.5 for this, even though the process can be applied in the same way with 1.4.</p>
<p>Fire up your admin panel and go to <em>Catalog &gt; Attachments</em> (last link). Click on <strong>Add new</strong> in the top right corner</p>
<p>Here is the little secret: we will append the <strong>iso code</strong> for our language to the name of the attachment, so that it can be then targeted in the template. Let&#8217;s call our file <strong>demo_en</strong>. Don&#8217;t worry for the bad look it has, we will remove the useless part when displaying links. Add a description if you want (it&#8217;s not mandatory), and choose a file to upload. When you&#8217;re done, click <em>Save</em>. Note that the actual name of the file doesn&#8217;t matter at all, <strong>the important part is the attachment name</strong>. If you don&#8217;t know the iso code for your language, head over to <em>Localization &gt; Languages</em>, and check the column highlighted in the following image:</p>
<div id="attachment_936" style="width: 690px" class="wp-caption aligncenter"><a href="http://nemops.com/wp-content/uploads/2013/01/Languages_iso.png"><img class="size-large wp-image-936" alt="Prestashop Languages Tab" src="http://nemops.com/wp-content/uploads/2013/01/Languages_iso-680x384.png" width="680" height="384" /></a><p class="wp-caption-text">Prestashop Languages Tab</p></div>
<div class="separator"></div>
<h2>Step 2 &#8211; Attaching our file to the product</h2>
<p>Ok, we have our file, it&#8217;s time to add it to one of our products. Head over to a product page in the back office (I chose iPod Nano), and click on the <strong>Attachments</strong> tab in the left column. Here is what it&#8217;ll look like:</p>
<p><div id="attachment_937" style="width: 690px" class="wp-caption aligncenter"><a href="http://nemops.com/wp-content/uploads/2013/01/product_attachments.png"><img class="size-large wp-image-937" alt="Prestashop Product Attachments" src="http://nemops.com/wp-content/uploads/2013/01/product_attachments-680x613.png" width="680" height="613" /></a><p class="wp-caption-text">Prestashop Product Attachments</p></div><br />
&nbsp;<br />
See the highlighted area? It displays attachments which are currently added to a product. It&#8217;s empty in my case, and I can see the attachment I just created is available in the left hand box. Select it, and click <strong>Add &gt;&gt;</strong> just below the box. <strong>Be sure you save the product now</strong>, otherwise the attachment won&#8217;t be added. If you successfully did this, after the refresh you should see the attachment appearing in the right hand box.<br />
<strong>Note:</strong> You will see that you can also add attachments from this page. if you do, they&#8217;ll automatically be linked to this product, without having to add them from the left box.</p>
<div class="separator"></div>
<h2>Step 3 &#8211; Adding the language-specific logic</h2>
<p>Now that the attachment has been sticked to our product, let&#8217;s head for the front office and check it out. Here it is:</p>
<div id="attachment_938" style="width: 555px" class="wp-caption aligncenter"><a href="http://nemops.com/wp-content/uploads/2013/01/attachment.png"><img class="size-full wp-image-938" alt="Prestashop Attachments in product page" src="http://nemops.com/wp-content/uploads/2013/01/attachment.png" width="545" height="212" /></a><p class="wp-caption-text">Prestashop Attachments in product page</p></div>
<p>&nbsp;</p>
<p>Of course, it will be displayed for every language at this stage. Locate your theme folder, and open up <strong>product.tpl</strong> in your favorite code editor. We will be editing the attachments portion of this file to only display our languaged file.</p>
<p>Locate the following code (Prestashop 1.5.3 &#8211; at about line 518):</p>
<pre class="brush: php; title: ; notranslate">
		{if isset($attachments) &amp;&amp; $attachments}
</pre>
<p>If you&#8217;re on Prestashop 1.4, it will be more like this (default template)</p>
<pre class="brush:php">
		{if $attachments}
</pre>
<p>You will have the following block inside the condition:</p>
<pre class="brush: php; title: ; notranslate">
	&lt;ul id=&quot;idTab9&quot; class=&quot;bullet&quot;&gt;
	{foreach from=$attachments item=attachment}
		&lt;li&gt;&lt;a href=&quot;{$link-&gt;getPageLink('attachment', true, NULL, &quot;id_attachment={$attachment.id_attachment}&quot;)}&quot;&gt;{$attachment.name|escape:'htmlall':'UTF-8'}&lt;/a&gt;&lt;br /&gt;{$attachment.description|escape:'htmlall':'UTF-8'}&lt;/li&gt;
	{/foreach}
	&lt;/ul&gt;	
</pre>
<p>Let&#8217;s start amending it to add some language logic, add this just after the div&#8217;s opening:</p>
<pre class="brush: php; title: ; notranslate">
	{$lang_checker = {&quot;_&quot;|cat:{$lang_iso}}}
	{foreach from=$languages item=language} 
		{$lang_checker_array[] = {&quot;_&quot;|cat:{$language.iso_code}}}
	{/foreach}	
</pre>
<p><strong>Explanation:</strong> We are taking advantage of 2 variables here. First, we create a <em>$lang_checker</em> variable, consisting of an underscore plus the iso code of the current language of the store (this will help us target it in the attachment name); then, we create an array with all the languages&#8217; iso codes, and as before, they&#8217;re prepended of an underscore. You can actually use any special character here, but you&#8217;ll of course need to be consitent with attachment names if you want to do it.</p>
<p>Now, amend the foreach statement as follows:</p>
<pre class="brush: php; title: ; notranslate">
{foreach from=$attachments item=attachment}
	{if $attachment.name|strstr:{$lang_checker}}
			&lt;li&gt;&lt;a href=&quot;{$link-&gt;getPageLink('attachment', true, NULL, &quot;id_attachment={$attachment.id_attachment}&quot;)}&quot;&gt;{$attachment.name|escape:'htmlall':'UTF-8'|replace:{$lang_checker}:''}&lt;/a&gt;&lt;br /&gt;{$attachment.description|escape:'htmlall':'UTF-8'}&lt;/li&gt;			
	{/if}
{/foreach}	
</pre>
<p>Refresh the page. You won&#8217;t see changes if your current language is the same as the attachment&#8217;s one, otherwise, you&#8217;ll notice the attachment is gone! Yep, that&#8217;s it, we are only displaying the attchment if it contains the actual iso code. We are also replacing (<strong>|replace:{$lang_checker}:&#8221;</strong>) the iso so that it&#8217;s removed from the name. <strong>Sweet</strong>.</p>
<p><strong>Note:</strong> on Prestashop 1.4, the getPageLink must refer to <strong>attachment.php</strong>, not only <em>attachment</em>.</p>
<p>And we could stop here, careless of future implementation. But we are smart. The code needs to be more robust in case we change our mind and want to display some attachments to all the audience. At the moment, those ones would not be displayed due to our language restriction.</p>
<div class="separator"></div>
<h2>Step 4 &#8211; Fallback for non-languaged downloads</h2>
<p>Add another attachment to this product, but this time <strong>don&#8217;t append any iso code</strong>. If you refresh the product page, you won&#8217;t be able to see the new attachment, of course. Let&#8217;s amend our previous code the following way:</p>
<pre class="brush:php">
{if isset($attachments) &#038;&#038; $attachments}
	<ul id="idTab9" class="bullet">
	{$lang_checker = {"_"|cat:{$lang_iso}}}
	{foreach from=$languages item=language} 
		{$lang_checker_array[] = {"_"|cat:{$language.iso_code}}}
	{/foreach}			
	{foreach from=$attachments item=attachment}
		{if $attachment.name|strstr:{$lang_checker}}
				<li><a href="{$link->getPageLink('attachment', true, NULL, "id_attachment={$attachment.id_attachment}")}">{$attachment.name|escape:'htmlall':'UTF-8'|replace:{$lang_checker}:''}</a><br />{$attachment.description|escape:'htmlall':'UTF-8'}</li>	
		{else}	
			{$denier = false}
			{foreach from=$lang_checker_array item=checkr_lang}
				{if $attachment.name|strstr:{$checkr_lang}} <!-- Means we found it, don't add to the list -->
					{$denier = true}
				{/if}		
			{/foreach}
			{if !$denier}
				<li><a href="{$link->getPageLink('attachment', true)}?id_attachment={$attachment.id_attachment}">{$attachment.name|escape:'htmlall':'UTF-8'}</a><br />{$attachment.description|escape:'htmlall':'UTF-8'}</li>
			{/if}									
		{/if}
	{/foreach}
	</ul>
{/if}	
</pre>
<p><strong>Explanation:</strong> A bit messy, but don&#8217;t be afraid. We added an <strong>else</strong> condition in case the iso code pattern is not found in the name. Inside it, we first setup a variable to check whether the file name contains <strong>any</strong> of the store languages&#8217; iso codes. Remember we created an array with all the store languages before? it&#8217;s time to use it; the following iterates through it, and, if one of the languages matches, it sets $denier to true.</p>
<pre class="brush:php">
	{$denier = false}
	{foreach from=$lang_checker_array item=checkr_lang}
		{if $attachment.name|strstr:{$checkr_lang}} <!-- Means we found it, don't add to the list -->
			{$denier = true}
		{/if}		
	{/foreach}
</pre>
<p>So basically we&#8217;re tellng the Prestashop: <em>&#8220;If the file is setup to target a specific language, set $denier to true.&#8221;</em>. The next line shows how to make proficient use of our $denier variable:</p
	></p>
<pre class="brush:php">
		{if !$denier}
			<li><a href="{$link->getPageLink('attachment', true)}?id_attachment={$attachment.id_attachment}">{$attachment.name|escape:'htmlall':'UTF-8'}</a><br />{$attachment.description|escape:'htmlall':'UTF-8'}</li>
		{/if}	
</pre>
<p>If $denier is not set (read: <em>if this file is not configured to target a specific language</em>) add it to the list. Save&amp;Refresh.</p>
<p>The non-language file is now added to the list!</p>
<div class="separator"></div>
<h2>Conclusion</h2>
<p>And that&#8217;s it, you can now play around with different iso codes and see they will always show up the correct way. Of course, there are better way to implement such feature, like editing core files to make it seamless with Prestashop. Nonetheless, this is a cleaver way to achieve the result without heavy core modifications.</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-attachments-language/">Target specific languages with Prestashop Attachments</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-attachments-language/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
