Jump to content

Recommended Posts

Hi,

What else I need in order make some custom fields in Product class and save them in columns I created in ps_product table? 

If get some errors like:

Unknown column 'price_recent1' in 'field list'

 

What I have done:

I tweaked Product.php in order to add the three fields:

...

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, 'shop' => true, 'validate' => 'isString'),
'price_recent3' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'),

...

}

 

then in mymodule.php I added the displayAdminProductsExtra hook in order to display a Tab inside the product edit backoffice: 

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/sleed.tpl');
  }
}

 

and finally I display them in 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>

 

price_recent_prestashop.thumb.png.1600a1bfc5cc825153f0b6b449f3a390.png

 

Thanks for your time!
-John

Edited by limitcracker (see edit history)
Link to comment
Share on other sites

11 hours ago, iipa said:

Have you added the new fields into database? Check post below how to do it:

https://www.prestashop.com/forums/topic/288826-solved-installdb-not-created-in-database/

Hi, yes I did.

But I did using ALTER TABLE queries and they are working fine.
I managed to solve the problem by also creating the columns also in ps_product_shop table!

I don't know why it was required though.
I was developing in PS 1.6.1.9

Br, John

Edited by limitcracker (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...