Jump to content

[SOLVED] Add to Cart Buy button in CMS pages


Recommended Posts

Hello everyone ,

 

I need add to cart button inside cms pages of prestashop. I search a lot and one prestashop forum post recomended me to use this method :

 

<p><a onclick="ajaxCart.add(product_id=2, attribute_id=0, true, null, quantity=1, null);">Add to cart</a>

 

But after saving the page it becomes :

 

<a>Add to cart</a> is left. Onclick function is removed after save.

 

Please help . Its urgent.

Link to comment
Share on other sites

Hi Deepak
 
Would you please go to class/Validate.php and find out the function : public static function iscleanhtml  and comment the following bold lines :

public static function isCleanHtml($html, $allow_iframe = false)
       {
               $events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange';
               $events .= '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend';
               $events .= '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove';
               $events .= '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel';
               $events .= '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart';
               $events .= '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange';
               $events .= '|onselectstart|onstart|onstop';

               //if (preg_match('/<[\s]script/ims', $html) || preg_match('/('.$events.')[\s]=/ims', $html) || preg_match('/.*script\:/ims', $html))
                       //return false;

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

               return true;
       }
Link to comment
Share on other sites

Hello,


You need extend tinymce editor in your prestashop shop.


Because by default tinymce removes some kind of scripts and validation class doesn't accept JS scripts in fields that use 'isHtml' validation.


 


Follow the below links to extend tinemce...


http://mypresta.eu/en/art/know-how/tinymce-editor-full-options-all-html-tags.html


http://mypresta.eu/en/art/prestashop-16/extended-rich-text-editor.html


Link to comment
Share on other sites

It's Prestashop 1.6.0.9 and the code looks like this:

public static function isCleanHtml($html, $allow_iframe = false)
	{
		$events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange';
		$events .= '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend';
		$events .= '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove';
		$events .= '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel';
		$events .= '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart';
		$events .= '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange';
		$events .= '|onselectstart|onstart|onstop'; 

		/* if (preg_match('/<[\s]*script/ims', $html) || preg_match('/('.$events.')[\s]*=/ims', $html) || preg_match('/.*script\:/ims', $html))
			return false; 

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

I disabled that validation before because I had to use javascripts on couple of pages (mostly for redirection) and for embedding of YouTube videos.

 

 

But for some reason it turns 

<p><a onclick="ajaxCart.add(product_id=125, attribute_id=0, true, null, quantity=1, null);">Add to cart</a></p>

to this:

<p><a>Add to cart</a></p>

Anyway, I sorted that out other way by adding the class for that link 

<a class="nameoftheclass">Add to Cart</a>

and then in js/tools.js I added this:

$(document).ready(function(){
    $('.nameoftheclass').click(function(){ajaxCart.add(product_id=125, attribute_id=0, true, null, quantity=1, null);});
});

And it's working fine now :)

Edited by shaun_imakr (see edit history)
  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...