Jump to content

[SOLVED] Property Product->description is not valid


giancarlo.spadini

Recommended Posts

I'm developing a module to import data from an external wholesales to PrestaShop.

 

I have a problem validating field product->description when contains some particular HTML tags.

 

When HTML description contains tag object <object></object> I receive this error:

 

[PrestaShopException]

 

Property Product->description is not valid

at line 878 in file classes/ObjectModel.php

 

872.

873. $message = $this->validateField($field, $value, $id_lang);

874. if ($message !== true)

875. {

876. if ($die)

877. throw new PrestaShopException($message);

878. return $error_return ? $message : false;

879. }

880. }

881. }

882.

 

So, is possible setup PrestaShop to accept HTML description with this tag?

There is a list of HTML tag that can't be used?

 

Thanks

Link to comment
Share on other sites

Hello,

 

The validator used on product descriptions is Validator::isString() (which is only a wrapper for PHP's is_string() method). You could run that method manually on the string to check if it validates. Another reason might be incompatible text encodings. Also, as the description is a multilanguage field, remember to construct it accordingly.

 

Example:

$product->description = array();
foreach (Language::getLanguages(false) as $lang){
 $product->description[$lang['id_lang']] = $[your description source];
}

Link to comment
Share on other sites

Dear jgullstr, thank you for your reply.

 

I have searched in PS classes to understand why field product->description fails when contains some tags.

Is not only a string check.

This field can contains HTML codes.

 

I notice that is validated with this function: isCleanHtml()

 

in class Validate.php at line 405 there is this check:

 

if (!$allow_iframe && preg_match('/<[\s]*(i?frame|form|input|embed|object)/ims', $html))

 

My descriptions contains object and embed tags to display videos from YouTube. So i need these "not clean" tags.

I want to try to enable iframe tag ($allow_iframe). Someone knows where can i set this information?

Edited by giancarlo.spadini (see edit history)
Link to comment
Share on other sites

Good morning,

Yes I do use tinyMCE and insert youtube provided code in HTML or with button "insert media" which result in the same:

<p><iframe src="//www.youtube.com/embed/XXXXXXXXXXXXX" frameborder="0" width="560" height="315"></iframe></p>

For the time being to go on working, I solved this with a dirty trick by changing classes\Validate.php line 392 :

$allow_iframe = true

Thanks a lot in advance.

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

There have been more than 5 releases of PS this year, and every time, I have to spend around a day or more on forums searches and doing again and again the same corrections, instead of the half hour or so advertised for upgrades. So this is unfortunately not satisfactory, also it will indeed do for the moment. Thanks.

Link to comment
Share on other sites

If you want a more clean solution, you can override the Validate class. Paste the following into a new file called Validate.php in your PS_ROOT/override/classes folder. Then clear the class index by deleting class_index.php in the PS_ROOT/cache folder.

<?php

class Validate extends ValidateCore
{
	public static function isCleanHtml($html, $allow_iframe = true)
	{
		return parent::isCleanHtml($html, $allow_iframe);
	}
}

By using this method instead, chances are an upgrade wont break the fix, and if it will, you can see what changes you have made by browsing the override folder (If you, as me, are not keen on documenting each and every fix). I usually create a module that contains shop-specific overrides, in order to better keep track of my core "hacks", to allow for smoother upgrading. 

Link to comment
Share on other sites

Thank you very much for this precise answer, and sharing your methodology, also I did not understand your suggestion on new modules (I am not yet able to build new modules, nor have need for it).

Yes overriding is much cleaner according to PS logic, and also reluctant, I did a few overrides too on controllers ("CategoryController.php" and "CmsController.php" for egg to enable galleries or generate new images sizes), though not yet classes.

I do that and also keep tracks on a WORD workbook. But it is time consuming every 2 months to upgrade, especially compared to Wordpress, were upgrades run smoothly in seconds.

The main problem with overrides or templates based on default, is that if PS do upgrade even slightly the overrided items, our installation will not benefit from it.

 

PS : thank you again for the code: for overriding, I would have copied the whole function, since I am not a php expert.

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

Glad to help  :) 

 

I got some ideas on override management from this thread. I'm going to pry around in core and, if plausible, write a module that hopefully will help a bit with these issues while they exist.

Slightly off-topic: Here's the result of what i came up with ​to help keep track of your overrides from backoffice.

 

http://www.prestashop.com/forums/topic/273789-module-override-manager-ps-15/

 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I have the same problem, but changing the option to "allow iframes" is not solved.

My problem is Im using an special code in the links, like this:
 

<a onclick="showPopup(21); return false;" href="#">

 

insert onclick is not suitable for the newest prestashop 1.5.5.0, when Im trying to save the product details I get the error "description field is not valid"

 

Could anyone give me a little help please?

Thank you

Link to comment
Share on other sites

  • 1 year later...

I have little Query, Can any one help?

 

I am using prestashop 1.56 English version. my site is http://slmobileprice.com 

 

I want to create a button on Product Description Page. I able to create button and share link on that button. But i want to create button like after clicking on button, link can open in new tab and display some popup with text or show text on previous page like "coupon".

 

Thanks,

Somit Srivastava

Link to comment
Share on other sites

I have little Query, Can any one help?

 

I am using prestashop 1.56 English version. my site is http://slmobileprice.com

 

I want to create a button on Product Description Page. I able to create button and share link on that button. But i want to create button like after clicking on button, link can open in new tab and display some popup with text or show text on previous page like "coupon".

 

Thanks,

Somit Srivastava

Why are you posting to a 2 year old solved topic that is completely unrelated to your question. 

 

Follow the forum rules and create a new topic

Link to comment
Share on other sites

  • 2 years later...

hi i need your help

i have this problem with order validation .

every time i want to make a payment with bank-wire or check the system shows me error 500

i reinstalled the bank-kwire module, i have cleaned the cache ,activated the frame for hmtl,and always the same error.changed the permission on files to 755-777 and the same result.

this is the url when error 500 appear :/index.php?fc=module&module=bankwire&controller=validation&id_lang=1

i checked the log file in local files and this is what a get

{Property OrderDetail->product_ean13 is not valid at line 837 in file classes/ObjectModel.php

i neeeeed help with this.

prestashop 1.6.0.5

migration module (icg integration3.0)

thnks

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

hi i need your help

i have this problem with order validation .

every time i want to make a payment with bank-wire or check the system shows me error 500

i reinstalled the bank-kwire module, i have cleaned the cache ,activated the frame for hmtl,and always the same error.changed the permission on files to 755-777 and the same result.

this is the url when error 500 appear :/index.php?fc=module&module=bankwire&controller=validation&id_lang=1

i checked the log file in local files and this is what a get

{Property OrderDetail->product_ean13 is not valid at line 837 in file classes/ObjectModel.php

i neeeeed help with this.

prestashop 1.6.0.5

migration module (icg integration3.0)

thnks

Validate that the "EAN-13 or JAN barcode" for the products in your order have a correct value..

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