如何在DB(ps_product)Prestashop中保存自定义字段?

要在Product类中创建一些自定义字段并将它们保存在我在ps_product表中创建的列中,我还需要什么?

如果出现以下错误:

Unknown column 'price_recent1' in 'field list'

如何在DB(ps_product)Prestashop中保存自定义字段?



我所做的:


我调整了** Product.php **以便添加三个字段:
...

class ProductCore extends ObjectModel

{

...

public $price_recent1;

public $price_recent2;

public $price_recent3;

...

'price_recent1' => array('type' => self::TYPE_STRING,'shop' => true,'validate' => 'isString'),'price_recent2' => array('type' => self::TYPE_STRING,'price_recent3' => array('type' => self::TYPE_STRING,...

}

然后在** mymodule.php **中,我添加了displayAdminProductsExtra钩子,以便在产品编辑后台中显示一个Tab:
public function hookDisplayAdminProductsExtra($params)

{
  global $smarty;

  $product = new Product((int)Tools::getvalue('id_product'));

  if (Validate::isLoadedObject($product)) 
  {
    $this->context->smarty->assign(array(

          'price_recent1' => $product->price_recent1,'price_recent2' => $product->price_recent2,'price_recent3' => $product->price_recent3));

    return $this->display(__FILE__,'views/templates/admin/mymodule.tpl');
  }
}

最后我将它们显示在** mymodule.tpl **中:
<div id="mymodule" class="panel product-tab">

    <input type="hidden" name="submitted_tabs[]" value="mymodule" />

    <h3 class="tab"><i class="icon-info"></i> {l s='MyModule'}</h3>

    <div class="form-group">

        <label class="control-label col-lg-3" for="price_recent1">

            <span class="label-tooltip" data-toggle="tooltip" title="{l s='Recent Price #1'}"> {l s='Recent Price #1'}

            </span>

        </label>

        <div class="col-lg-9">

            <input type="text" id="price_recent1" name="price_recent1" value="{$product->price_recent1|htmlentitiesUTF8}"/>

        </div><br>

        <label class="control-label col-lg-3" for="price_recent2">

            <span class="label-tooltip" data-toggle="tooltip" title="{l s='Recent Price #2'}"> {l s='Recent Price #2'}

            </span>

        </label>

    <div class="col-lg-9">

        <input type="text" id="price_recent2" name="price_recent2" value="{$product->price_recent2|htmlentitiesUTF8}"/>

    </div><br>

    <label class="control-label col-lg-3" for="price_recent3">

        <span class="label-tooltip" data-toggle="tooltip" title="{l s='Recent Price #3'}"> {l s='Recent Price #3'}

        </span>

    </label>

    <div class="col-lg-9">

        <input type="text" id="price_recent3" name="price_recent3" value="{$product->price_recent3|htmlentitiesUTF8}"/>

    </div><br>

</div>



<div class="panel-footer">

    <a href="{$link->getadminLink('AdminProducts')|escape:'html':'UTF-8'}{if isset($smarty.request.page) && $smarty.request.page > 1}&submitFilterproduct={$smarty.request.page|intval}{/if}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a>

    <button type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> {l s='Save'}</button>

    <button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> {l s='Save and stay'}

    </button>

</div>

我还在ps_product **表中做了相应的列。
iCMS 回答:如何在DB(ps_product)Prestashop中保存自定义字段?

您的替代无效。

应该是:

class Product extends ProductCore

记住有关cache / class_index.php中的缓存的信息

本文链接:https://www.f2er.com/1772914.html

大家都在问