Jump to content

how add custom field in products prestashop 1.5.4


giwrgos

Recommended Posts

Hello I'm searching a way to add custom fields to the product page on the back office. I was used this example (which is what i'm looking for) but it is for an old version of prestashop

http://strife.pl/2011/12/how-to-add-new-custom-field-in-prestashop/

 

I found also this example which doesn't help because is not english!!

http://www.webbax.ch/2011/06/24/comment-ajouter-un-nouveau-champ-sur-la-fiche-produit-et-dans-le-back-office-prestashop/

 

Does anyone know how i can do the first url on the newest versions of prestashop?

 

 

Thank you

Link to comment
Share on other sites

Way that described in my article is better. With it you don't need to make changes in core files. Data will be saved in own table, it will make your upgrade easier in future.

 

can you make an example with input field instead of text area?

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

(..)

do you want display error in admin? you can save some errors messages into cookie variable

Thanks for the reply ;)

 

Yes - display error and prevent updating product in case of invalid value.

 

I'm looking where write error message in $this->context->cookie and Cookie class, but I still don't know where do it?

Link to comment
Share on other sites

Hi, first of all thank for comment on our blog :)

 

public function hookActionProductUpdate($params) {
...
$this->context->cookie->belvg_pp_errors = NULL;
if (!empty($errors) {
$this->context->cookie->belvg_pp_errors = $this->displayError($this->l('One of the dates you entered is incorrect'));
continue;
}
...
}

public function hookDisplayAdminProductsExtra($params) {
...
$this->context->smarty->assign(array(
'belvg_pp_errors' => ((isset($this->context->cookie->belvg_pp_errors) && !empty($this->context->cookie->belvg_pp_errors)) ? $this->context->cookie->belvg_pp_errors : ''),
));
...
}

 

after smarty assign, you can display error message in your .tpl file

 

Regards

  • Like 1
Link to comment
Share on other sites

Hi, first of all thank for comment on our blog :)

(...)

I must say, that your tutorials are very helpful ;)

 

Your solution above is a part of my question.

I want to keep user in edit page, when input is invalid.

Like this case:

post-642808-0-17164900-1374840606_thumb.jpg

I have got this error when I trying save product with invalid name.

 

EDIT:

Finally, I found solution with overriding controller.

mymodule/mymodule.php

public function hookActionProductUpdate($params) {
	// validation values code here
	Configuration::updateValue('MYMODULE_VALID', $valid);
}

mymodule/override/controllers/admin/AdminProductsController.php

class AdminProductsController extends AdminProductsControllerCore
{
public function checkProduct()
{
	if( Configuration::get('MYMODULE_VALID') )
		$this->errors[] = Tools::displayError('Error msg');
	return parent::checkProduct();
}

Changes appear after install/reinstall module.

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

  • 1 month later...
  • 3 weeks later...
  • 2 weeks later...

Hello Everyone

 

I am struggling with an issue here. Hope a prestashop expert can help me out. 

 

I want to create a custom form with drop down list in product page and send the data to cart just as the product customization details are sent. I have created the form but I don't know the code that should be put to send the form data/details to the cart. 

 

 

Please can anyone help me?? I am a newbie and m lost. Please help. 

 

Thanks so much.

 

Mira

Link to comment
Share on other sites

  • 2 weeks later...

Way that described in my article is better. With it you don't need to make changes in core files. Data will be saved in own table, it will make your upgrade easier in future.

 

Is it possible to rename a tab? Right now it's using a module name, I'd like to change it to something else without changing module name.

 

Thanks in advance!

Link to comment
Share on other sites

Hello Everyone

 

I am struggling with an issue here. Hope a prestashop expert can help me out. 

 

I want to create a custom form with drop down list in product page and send the data to cart just as the product customization details are sent. I have created the form but I don't know the code that should be put to send the form data/details to the cart. 

 

 

Please can anyone help me?? I am a newbie and m lost. Please help. 

 

Thanks so much.

 

Mira

 

 

Is it possible to rename a tab? Right now it's using a module name, I'd like to change it to something else without changing module name.

 

Thanks in advance!

 

 

First ... help yourself, don't post out of topic.

Then believe me ... there are a lot of prestashop user within this forum who happy to help you

Link to comment
Share on other sites

First ... help yourself, don't post out of topic.

Then believe me ... there are a lot of prestashop user within this forum who happy to help you

 

Why do you think my question was out of topic?  

 

Alexander Simonchik has replied to original post author and has shown a better way to add custom field to product in PS1.5. I'm using a method he's presented, but there is a small problem with that - it creates a tab in product edit page and that tab is named according to module name. So I asked Alexander if it's possible to rename it to something else (and quoted a right post).

 

No offence, as I don't want to start a flame here, but after my explanation do you still think that my question was out of topic?

Link to comment
Share on other sites

you will need to rename the module

 

That's an easy way  :)   I'd like to have one name in modules list and another in tab name. Is it possible to change it without renaming the module? I've looked at the PS sources, but it looks like it's a mission impossible :-(

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

  • 6 months later...

Hi, i've added a new custom filed in back end using newfieldstut module, it add a new coloumn in prodouct_lang table.

 

It work fine only in product-list.tpl

<a itemprop="url" class="btn btn-default" href="{$product.custom_field}">Vedi la demo Live{$product.custom_field}</a></div>

but not work in product.tpl

<a class="btn btn-default" href="{$product->custom_field}">Vedi la demo Live</a></div>

why?

Link to comment
Share on other sites

  • 3 months later...

I'm using this free module sample to add new video url field to the product. Everything works fine, I can see new data in product.tpl, but I cant get data to product-list.tpl what is very important to me, I want to add play button to each product. I found that for this purpose I have to use hookActionProductListOverride function but no luck with that. Anyone can help me?

    public function hookDisplayAdminProductsExtra($params) {
        $id_product = Tools::getValue('id_product');
        $sampleObj = Belvg_Sample::loadByIdProduct($id_product);
        if(!empty($sampleObj) && isset($sampleObj->id)){
            $this->context->smarty->assign(array(
                'belvg_textarea' => $sampleObj->textarea,
            ));
        }
        
        return $this->display(__FILE__, 'views/admin/sample.tpl');
    }
    
    public function hookActionProductUpdate($params) {
        $id_product = Tools::getValue('id_product');
        $sampleObj = Belvg_Sample::loadByIdProduct($id_product);
        $sampleObj->textarea = Tools::getValue('belvg_sample');
        $sampleObj->id_product = $id_product;
        
        if(!empty($sampleObj) && isset($sampleObj->id)){
            $sampleObj->update();
        } else {
            $sampleObj->add();
        }
    }
    
    public function hookDisplayFooterProduct($params) {
        $id_product = Tools::getValue('id_product');
        $sampleObj = Belvg_Sample::loadByIdProduct($id_product);
        if(!empty($sampleObj) && isset($sampleObj->id)){
            $this->context->smarty->assign(array(
                'belvg_textarea' => $sampleObj->textarea,
            ));
        }
        
        echo $sampleObj->textarea;
    }
        
}

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

  • 2 months later...

Alex Simonchik BelVG, I was looking at http://schema.org/Offer for the parameter category which could be http://schema.org/Thing with an additionalType parameter to define the category from say goodrelations or use the sameAs field to define the prototypycal classifcation the semantic category concept.

 

Using the default template and hooks in the category creation menu, how would you see extending prestashop further for semantic SEO?

Link to comment
Share on other sites

First of all a big big thank you to Alex Simonchik BelVG This module saved me a lot of hours working!

 

I would like to add few notes for those who need to add save buttons on the end of the admin buttons and enable the tinymce editor

 

HOW TO ADD SAVE BUTTONS

 

Open the /views/admin/sample.tpl file and at the bottom of the file place this piece of code

	<div class="panel-footer">
		<a href="{$link->getAdminLink('AdminProducts')|escape:'html':'UTF-8'}" 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"><i class="process-icon-save"></i> {l s='Save'}</button>
		<button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save and stay'}</button>
	</div>

HOW TO TURN ON THE TinyMCE EDITOR

 

1. On the /views/admin/sample.tpl file replace the <textarea>.... </textarea> piece of code with this

<textarea class="autoload_rte" name="belvg_sample" rows="10" cols="45">{if isset($belvg_textarea)}{$belvg_textarea}{/if}</textarea>

2. On the /views/front/sample.tpl replace the code that you see there with this (actually you just remove some piece of coding but I am pasting the entire code in order to avoid confusions)

{if isset($belvg_textarea)}
<!-- Belvg_SampleModule -->
	{$belvg_textarea}
<div class="clear"> </div>
<!-- /Belvg_SampleModule -->
{/if}

And here is the new back office http://prntscr.com/5c3x98 and live shop http://prntscr.com/5c3xu6 (I didn't hooked it yet to the right position, I just wanted to show you how it looks)

 

Prestashop version 1.6.0.9

Link to comment
Share on other sites

  • 2 years later...

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...