<?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; ean</title>
	<atom:link href="http://nemops.com/tag/ean/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>Displaying the EAN/JAN barcode in PrestaShop&#8217;s product page</title>
		<link>http://nemops.com/ean-barcode-prestashop-product-page/</link>
		<comments>http://nemops.com/ean-barcode-prestashop-product-page/#comments</comments>
		<pubDate>Thu, 14 Jan 2016 10:49:33 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Theming]]></category>
		<category><![CDATA[barcode]]></category>
		<category><![CDATA[ean]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[products]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2685</guid>
		<description><![CDATA[<p>In this tutorial we will learn how to display the EAN13 or JAN barcode field in product pages in PrestaShop. * You can apply the same process to the UPC barcode, if that is the one you need, just by changing every occurrence of ean13 to upc 1 &#8211; Amending the product.tpl file The first, [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/ean-barcode-prestashop-product-page/">Displaying the EAN/JAN barcode in PrestaShop&#8217;s product page</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In this tutorial we will learn how to display the EAN13 or JAN barcode field in product pages in PrestaShop.</p>
<p><span id="more-2685"></span></p>
<p><span style="color:#e13125"><strong>*</strong> You can apply the same process to the UPC barcode, if that is the one you need, just by changing every occurrence of <strong>ean13 </strong>to <strong>upc</strong></span></p>
<h2>1 &#8211; Amending the product.tpl file</h2>
<p>The first, obvious step is to modify the product page template. <strong>If you are not using Attribute Combinations, this is actually the only step you need to complete!</strong> </p>
<p>Therefore, open up your theme&#8217;s <strong>product.tpl</strong>, and decide where you want to add the field. Above or below the reference (or instead of it) might be a good spot.</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
&lt;p id=&quot;product_ean13&quot;{if empty($product-&gt;ean13) || !$product-&gt;ean13} style=&quot;display: none;&quot;{/if}&gt;
	&lt;label&gt;{l s='Ean13:'} &lt;/label&gt;
	&lt;span {if !empty($product-&gt;ean13) &amp;&amp; $product-&gt;ean13} content=&quot;{$product-&gt;ean13}&quot;{/if}&gt;{$product-&gt;ean13|escape:'html':'UTF-8'}&lt;/span&gt;
&lt;/p&gt;
</pre>
<p>Save and refresh to see the field pop up where you placed it. As mentioned above, if you are not using product combinations, you can stop here. Otherwise, there are a couple of other modifications you need to do.</p>
<div class="separator"></div>
<h2>2 &#8211; Getting the new field for combinations</h2>
<p>In order to display the proper ean when changing attributes, having each combination its own, we need to ensure the field is assigned to the javascript that handles the page update on select. Sadly, PrestaShop only grabs a limited number of fields with the default combinations query, and <strong>we therefore need to override/modify both the Product class and controller.</strong></p>
<h3>Extending the Product Plass in PrestaShop</h3>
<p>Create a new file named <strong>Product.php</strong> inside <em>override/classes</em>, that will serve as Product class override. Begin by writing some standard override code:</p>
<pre class="brush: php; title: ; notranslate">
class Product extends ProductCore
{

}
</pre>
<p>We want to extend the <strong>getAttributesGroups</strong> method. Mine, grabbed from a clean 1.6.1.2 version, looks like this:</p>
<pre class="brush: php; title: ; notranslate">
    public function getAttributesGroups($id_lang)
    {
        if (!Combination::isFeatureActive()) {
            return array();
        }
        $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name,
					a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, product_attribute_shop.`id_product_attribute`,
					IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`,
					product_attribute_shop.`default_on`, pa.`reference`, product_attribute_shop.`unit_price_impact`,
					product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type`
				FROM `'._DB_PREFIX_.'product_attribute` pa
				'.Shop::addSqlAssociation('product_attribute', 'pa').'
				'.Product::sqlStock('pa', 'pa').'
				LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
				LEFT JOIN `'._DB_PREFIX_.'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
				LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
				LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute`)
				LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group`)
				'.Shop::addSqlAssociation('attribute', 'a').'
				WHERE pa.`id_product` = '.(int)$this-&gt;id.'
					AND al.`id_lang` = '.(int)$id_lang.'
					AND agl.`id_lang` = '.(int)$id_lang.'
				GROUP BY id_attribute_group, id_product_attribute
				ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC';
        return Db::getInstance()-&gt;executeS($sql);
    }
</pre>
<p>Copy and paste your own inside the override, then add another column to the SELECT statement, right after ag.`group_type`: <strong>, pa.`ean13`</strong></p>
<h3>Extending the Product Controller in PrestaShop</h3>
<p>Create and initialize a file called <strong>ProductController.php</strong> inside <em>override/controllers/front</em>.</p>
<pre class="brush: php; title: ; notranslate">
class ProductController extends ProductControllerCore
{

}
</pre>
<p>This time <strong>we have to copy the whole assignAttributesGroups method</strong>, so make sure you really grab yours from the original ProductController.<br />
After pasting it, locate the following snippet</p>
<pre class="brush: php; title: ; notranslate">
$combinations[$row['id_product_attribute']]['reference'] = $row['reference'];
</pre>
<p>Right after it, add</p>
<pre class="brush: php; title: ; notranslate">
$combinations[$row['id_product_attribute']]['ean13'] = $row['ean13'];
</pre>
<p>Save, then reach <em>cache/</em> and erase the class_index.php file, so that the overrides take place</p>
<div class="separator"></div>
<h2>Step 3 &#8211; displaying the EAN 13 field with Javascript</h2>
<p>So far, so good. The very last thing we need to do it modifying <strong>product.js</strong>, located inside the theme folder, /js/, in order for the field to be displayed for the current combination, and to change when selecting attributes. <strong>Make sure the combinations you select have the field filled in; otherwise you might get misleading results.</strong></p>
<p>The first block of code to locate is the following, around line 93 in PrestaShop 1.6.1.2:</p>
<pre class="brush: jscript; title: ; notranslate">
combinationsJS[k]['reference'] = combinations[i]['reference'];
</pre>
<p>I am sure you can already bet what we need to add:</p>
<pre class="brush: jscript; title: ; notranslate">
combinationsJS[k]['ean13'] = combinations[i]['ean13'];
</pre>
<p>Then, around line 427</p>
<pre class="brush: jscript; title: ; notranslate">
selectedCombination['reference'] = combinations[combination]['reference'];
// add the following
selectedCombination['ean13'] = combinations[combination]['ean13'];
</pre>
<p>Lastly, the very code that acts on the switch:</p>
<pre class="brush: jscript; title: ; notranslate">
	if (selectedCombination['reference'] || productReference)
	{
		if (selectedCombination['reference'])
			$('#product_reference span').text(selectedCombination['reference']);
		else if (productReference)
			$('#product_reference span').text(productReference);
		$('#product_reference:hidden').show('slow');
	}
	else
		$('#product_reference:visible').hide('slow');
</pre>
<p>Right after, add</p>
<pre class="brush: jscript; title: ; notranslate">
	if (selectedCombination['ean13'] || productean13)
	{
		if (selectedCombination['ean13'])
			$('#product_ean13 span').text(selectedCombination['ean13']);
		else if (productean13)
			$('#product_ean13 span').text(productean13);
		$('#product_ean13:hidden').show('slow');
	}
	else
		$('#product_reference:visible').hide('slow');
</pre>
<p>We do not obviously have that <strong>productean13</strong> variable. That needs to be added to <strong>product.tpl</strong>. So, back to it, locate</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{addJsDef productReference=$product-&gt;reference|escape:'html':'UTF-8'}
</pre>
<p>And add</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{addJsDef productean13=$product-&gt;ean13|escape:'html':'UTF-8'}
</pre>
<p>Right after that.</p>
<p>Save and refresh, <strong>we are done!</strong></p>
<p>The post <a rel="nofollow" href="http://nemops.com/ean-barcode-prestashop-product-page/">Displaying the EAN/JAN barcode in PrestaShop&#8217;s product page</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/ean-barcode-prestashop-product-page/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
