Prestashop WebService API - save in database HTML rich text

Viewed 264

I am developing a php manager for prestashop via webservice. I have a module created to keep notes about orders.

From the management program I have a form with TinyMCE. But I can't save the text when it has HTML tags

webService class in prestashop module

class sellerNotas extends ObjectModel {

public $id;
public $id_seller;
public $nota;

public static $definition = array(
    'table' => 'seller_notas',
    'primary' => 'id',
    'fields' => array(
        'id'        => array('type' => self::TYPE_INT),
        'id_seller' => array('type' => self::TYPE_INT),
        'nota'     =>array('type' => self::TYPE_HTML, 'lang' => false, 'validate' => 'isCleanHtml'),
    )
);
protected $webserviceParameters = array();

}

MySQL TABLE

I have no problem saving plain text without labels, the problem is when the text has labels. I have tried htmlentities with no correct results.

create note php function

2 Answers

Please make sure you have used CDATA for that HTML node so it not get break due to any any component

$node = dom_import_simplexml($resources ->nota);
$no = $node -> ownerDocument;
$node -> appendChild($no -> createCDATASection($nota)); $resources ->nota= $nota;

SOLVED WITH htmlentities PHP CODE:

 static function nuevaNota($idVendedor, $nota, $tienda) {
        
        try{
            $webService = webService::webServiceTienda($tienda);

            $opt = [
                'resource' => 'seller_notas?schema=blank'
            ];
            $xml = $webService->get($opt);
            $resources = $xml->seller_notas->children();
                        
            $resources->id_seller = intval($idVendedor);
            $resources->nota = htmlentities($nota);
            var_dump( $resources->nota);

            $opt = [
                'resource' => 'seller_notas',
                'postXml' => $xml->asXML(),
            ];
            
            $createdXml = $webService->add($opt);
        }
        catch (PrestaShopWebserviceException $e){
            webService::controlErroresTienda($e, $tienda);
        }

    }
Related