PRESTASHOP 1.5 に新しい製品フィールドをプログラムで追加する方法は?
これらのフィールドを SQL で作成しましたが、保存する方法がわかりません。
フィールドは 3 bool で、ラジオ ボタン オプション内に保存したいと考えています。
PRESTASHOP 1.5 に新しい製品フィールドをプログラムで追加する方法は?
これらのフィールドを SQL で作成しましたが、保存する方法がわかりません。
フィールドは 3 bool で、ラジオ ボタン オプション内に保存したいと考えています。
Product クラスと ObjectModel クラスに対応する Product.php と ObjectModel.php を見てください。
Product にフィールドを追加する場合は、クラスに属性を追加し、追加した属性の定義を追加してクラスの $definition 変数を更新する必要があります。
ラジオ ボタンについては、コントローラーの一部です。AdminProductsController.php をご覧ください。
それが役に立てば幸い、
Br、
モジュールを使用して新しいフィールドを追加しますか?(これは単なる例です)
作成されたデータベースにフィールドがある場合(私の例では、テーブル「product_lang」を使用しています)。
あなたがskieletonモジュールを持っている場合:
models/ に "ProductField.php" を作成します。
<?php
class ProductField extends ObjectModel
{
/** @var string Name */
public $id_product_field;
/** @var integer */
public $id_product;
/** @var string */
public $new_field;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'product_lang',
'primary' => 'id_product',
'multilang' => false,
'fields' => array(
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => TRUE),
'new_field' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
),
);
public function __construct($ID_PRODUCT) {
$result = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'product_lang WHERE id_product = '. (int) $ID_PRODUCT );
$this->id_product = $ID_PRODUCT;
$this->new_field = $result['new_field'];
}
public function update() {
Db::getInstance()->update( 'product_lang', array( 'new_field' => $this->new_field ), 'id_product = ' . $this->id_product );
}
}
?>
メインファイルにモデルを含めることを忘れないでください。
モジュール追加メソッドのメインファイルで:
public function hookDisplayAdminProductsExtra($params) {
$Fields = new ProductField( Tools::getValue('id_product') );
if( !empty( $Fields ) && isset( $Fields->id_product ) ) {
$this->context->smarty->assign(array(
'new_field' => $Fields->new_field,
) );
}
return $this->display(__FILE__, 'views/admin/admin.tpl');
}
view/admin/admin.tpl を作成
<!-- New Field MODULE -->
<input type="hidden" name="submitted_tabs[]" value="productfields" />
<h4>{l s='Additional Fields' mod='productfields'}</h4>
<div class="separation"></div>
<fieldset style="border:none;">
<table cellspacing="0" cellpadding="5" border="0">
<tbody>
<tr>
<td class="col-left">
<label>{l s='New field' mod='productfields'}<br></label>
<p class="product_description">{l s='description of new field' mod='productfields'}</p>
</td>
<td style="padding-bottom:5px;">
<input type="text" name="new_field" value="{if isset($new_field)}{$new_field}{/if}" />
</td>
<tr>
</tbody>
</table>
</fieldset>
<div class="separation"></div>
<!-- END New Field MODULE -->
何も忘れていないことを願っています。あなたのニーズにのみ適合します。
ここを見てください:https://gist.github.com/kpodemski/21a37617b6b488590dc1
これは PrestaShop 1.5.4 の例ですが、1.5.6 をダウンロードして informations.tpl を新しいバージョンに変更すると、正常に動作するはずです。