Create or replace with the below content and put it in app\design\frontend\Your-Package\Your-theme\template\catalog\product\view\attributes.phtml
Also make logo named as CE.png,CLASSE II.png, ENEC.png, F.png, IP20.png and place it in skin\frontend\Your-Package\Your-theme\images
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if ($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<?php if ($_data['code'] == "certification_mark"): ?>
<?php $values = explode(',', $_helper->productAttribute($_product, $_data['value'], $_data['code'])); ?>
<td class="data">
<?php foreach ($values as $value): ?>
<div style="float:left;"><img src="<?php echo $this->getSkinUrl("certification_marks/" . trim($value) . ".jpg") ?>"></div>
<?php endforeach; ?>
</td>
<?php endif; ?>
<?php if ($_data['code'] != "certification_mark" ): ?>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif; ?>
It is working for me. Let me know once you tried it.
Investigation
file
input is not implemented in Magento 2.1 yet.
in vendor/magento/module-ui/view/base/web/templates/form/element/media.html
there is only uploader and no view and delete button:
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<input class="admin__control-file" type="file" data-bind="
hasFocus: focused,
attr: {
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled,
form: formId
}"
/>
It will be implemented in next Magento2 release hopefully.
So I thought to implement a custom renderer, but
Solution
Magento2 way is to use UI components and PHP Modifiers
Create 3 files:
etc/adminhtml/di.xml
- dependency injection configuration for adminhtml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="your_module_datasheet" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\Product\Form\Modifier\Datasheet</item>
<item name="sortOrder" xsi:type="number">150</item>
</item>
</argument>
</arguments>
</virtualType>
</config>
your_module_datasheet
can be any name.
With sortOrder
from 10 to 50 it didn't work for me. $meta
variable in Modifier was empty.
Ui/DataProvider/Product/Form/Modifier/Datasheet.php
- php modifier
<?php
namespace Vendor\Module\Ui\DataProvider\Product\Form\Modifier;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\UrlInterface;
/**
* Data provider for "Datasheet" field of product page
*/
class Datasheet extends AbstractModifier
{
/**
* @param LocatorInterface $locator
* @param UrlInterface $urlBuilder
* @param ArrayManager $arrayManager
*/
public function __construct(
LocatorInterface $locator,
UrlInterface $urlBuilder,
ArrayManager $arrayManager
) {
$this->locator = $locator;
$this->urlBuilder = $urlBuilder;
$this->arrayManager = $arrayManager;
}
public function modifyMeta(array $meta)
{
$fieldCode = 'datasheet';
$elementPath = $this->arrayManager->findPath($fieldCode, $meta, null, 'children');
$containerPath = $this->arrayManager->findPath(static::CONTAINER_PREFIX . $fieldCode, $meta, null, 'children');
if (!$elementPath) {
return $meta;
}
$meta = $this->arrayManager->merge(
$containerPath,
$meta,
[
'children' => [
$fieldCode => [
'arguments' => [
'data' => [
'config' => [
'elementTmpl' => 'Vendor_Module/grid/filters/elements/datasheet',
],
],
],
]
]
]
);
return $meta;
}
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
return $data;
}
}
view/adminhtml/web/template/grid/filters/elements/datasheet.html
- knockout js template
<!-- ko if: $parent.source.data.product[code] -->
<div>
<!-- todo: dynamically get path to file from config or controller -->
<a attr="href: '/pub/media/datasheet'+$parent.source.data.product[code]" text="$parent.source.data.product[code]"></a>
<label attr="for: uid+'_delete'">
<!-- todo: generate name -->
<input type="checkbox" attr="name: 'product['+code + '_delete]', id: uid+'_delete', form: formId">
<span data-bind="i18n:'Delete'"></span>
</label>
</div>
<!-- /ko -->
<input class="admin__control-file" type="file" data-bind="
hasFocus: focused,
attr: {
name: inputName,
placeholder: placeholder,
'aria-describedby': noticeId,
id: uid,
disabled: disabled,
form: formId
}"
/>
It is still looks dirty to me and a lot of things to improve.
Alternatives
I found some interesting files, which can bring you other ideas how to solve it:
vendor/magento/module-catalog/view/adminhtml/ui_component/design_config_form.xml
<item name="formElement" xsi:type="string">fileUploader</item>
vendor/magento/module-ui/view/base/ui_component/etc/definition.xml
<fileUploader class="Magento\Ui\Component\Form\Element\DataType\Media">
Best Answer
I'm confused a bit. You state you created a custom attribute. You then speak of using an extension in app/code/local. Why do you need an extension for placing an attribute?
Have you considered adding to
/app/design/frontend/yourtheme/default/template/catalog/product/view.phtml
something like this?