如何在PRESTASHOP 1.5上增加新的產品領域?添加新的產品領域Prestashop 1.5
我在SQL上創建了這些字段,但我不知道如何保存它?
這些字段是3布爾,我想將它保存在單選按鈕選項中。
如何在PRESTASHOP 1.5上增加新的產品領域?添加新的產品領域Prestashop 1.5
我在SQL上創建了這些字段,但我不知道如何保存它?
這些字段是3布爾,我想將它保存在單選按鈕選項中。
您應該查看與Product類和ObjectModel類相對應的Product.php和ObjectModel.php。
如果要在Product中添加字段,則必須在類中添加屬性,並通過添加所添加屬性的定義來更新類中的$ definition變量。
關於單選按鈕,它是控制器的一部分,看看AdminProductsController.php
希望它能幫助,
BR,
Mayby你將托盤使用模塊添加新的領域? (這只是舉例)
如果你有創建的數據框中的字段(在我的例子中,我使用表「product_lang」)。
當u有skieleton模塊:
在模型創建 「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);
}
}
?>
REMEBER還應包括型號在主文件。
在模塊添加方法的主要文件:
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');
}
創建視圖/管理/ 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
這是例如,從1.5.4的PrestaShop但如果你下載1.5.6,改變informations.tpl到它應該工作正常更新的版本。
好的,但是...例如: 我需要保存一個名稱爲「選擇」的單選按鈕,並有3個選項:是,否,也許。 而且我在sql和Product類($定義變量)上創建了3個字段,我需要根據單選按鈕選擇保存TRUE(1)或FALSE(0)。我如何做到這一點? – gazapko
你應該看看AdminProductsController,$ this-> fields_list。例如:'active'=> array(...) – Brice