Jump to content

Edit History

limitcracker

limitcracker

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

limitcracker

limitcracker

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>

Thanks for your time!
-John

limitcracker

limitcracker

Hi,

I am making a module that has a new Tab in Admin Product backoffice.
It's just 3 text fields that I would like to save in ps_product on Save or Save & Stay. 

  • Do I have to use the Configuration static method as middleware?
  • (if Configuration needed) How I then save in DB after using Configuration?
  • Do I have to make use of actionProductSave in my module?

Thanks for your time!
-John

limitcracker

limitcracker

Hi,

I am making a module that has a new Tab in Admin Product backoffice.
It's just 3 text fields that I would like to save in ps_product on Save or Save & Stay. 

  • Do I have to use the Configuration static method as middleware?
  • (if Configuration needed) How I then save in DB after using Configuration?
  • Do I have to make use of actionProductSave in my module?

Thanks for your time!
-John

×
×
  • Create New...