Всем доброго дня!

Подскажите, что не так в этой инструкции. В админке, на странице самого товара(вкладка 'information') выводится пустое поле, в коде выводится просто value.

В админке на странице списка товаров всё отлично отображается, на фронт странице товара также все норм.

При изменении в строчке
Код:
<input type="text" id="warranty" name="warranty" value="{$product->warranty|escape:html:'UTF-8'}" />

escape:html:'UTF-8' на htmlentitiesUTF8 виводит value="array"

Код:
Создадим дополнительное поле ГАРАНТИЯ в карточке товара для Prestashop 1.6

1. Создадим поле в базе данных, для этого делаем SQL запрос

ALTER TABLE `ps_product_lang` ADD `warranty` text AFTER `description_short`;


2. Открываем файл /classes/Product.php и после строк

/** @var string Short description */
public $description_short;


добавляем

/** @var string Warranty */
public $warranty;


3. После строки

'description_short' =>  array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),


добавляем

'warranty' =>  array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),


4. Открываем файл product.tpl и в нужном месте вставляем

{if $product->warranty}
       <p><b>{l s='Warranty: '}</b><span>{$product->warranty|escape:'html':'UTF-8'}</span></p>
{/if}


5. Открываем файл /admin/themes/default/template/controllers/products/informations.tpl и после блока

<div class="form-group">
<label class="control-label col-lg-3" for="reference">
<span class="label-tooltip" data-toggle="tooltip"
title="{l s='Your internal reference code for this product.'} {l s='Allowed special characters:'} .-_#\">
{$bullet_common_field} {l s='Reference code'}
</span>
</label>
<div class="col-lg-5">
<input type="text" id="reference" name="reference" value="{$product->reference|htmlentitiesUTF8}" />
</div>
</div>


вставляем

<div class="form-group">
           <label class="control-label col-lg-3" for="warranty">
                     <span class="label-tooltip" data-toggle="tooltip" title="{l s='Warranty'}">
                               {l s='Warranty'}
                     </span>
           </label>
           <div class="col-lg-5">
                     <input type="text" id="warranty" name="warranty" value="{$product->warranty|escape:html:'UTF-8'}" />
           </div>
</div>


6. Открываем файл /controllers/admin/AdminProductsController.php и после блока

$this->fields_list['reference'] = array(
'title' => $this->l('Reference'),
'align' => 'left',
);


вставляем

$this->fields_list['warranty'] = array(
'title' => $this->l('Warranty'),
'align' => 'left',
);


7. Создаём файл /override/controllers/admin/AdminProductsController.php следующего содержания

<?php

class AdminProductsController extends AdminProductsControllerCore
{

protected function copyFromPost(&$object, $table)
{
parent::copyFromPost($object, $table);
if (get_class($object) != 'Product')
return;

$object->warranty = (int)Tools::getValue('warranty');
}
}


8. Создаём файл /override/classes/Product.php следующего содержания

<?php

class Product extends ProductCore
{
public $warranty;

public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
Product::$definition['fields']['warranty'] = array('type' => self::TYPE_HTML, 'lang' => true);
parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
}
}


9. Чистим кеш и удаляем файл /cache/class_index.html



Сообщение отредактировал Anmert (03-12-2015 02:27)