Author Topic: Content plugin broken in product_desc  (Read 589 times)

zanardi

  • Contributing Developer
  • Full Member
  • *
  • Posts: 878
    • GiBiLogic
Content plugin broken in product_desc
« on: March 21, 2014, 11:07:43 am »
Using VirtueMart 2.0.26d. I think content plugin processing is broken for product_desc on product_details view.

Here's the code from frontend/views/productdetails/view.html.php (lines 125-127)

Code: [Select]
if (VmConfig::get('enable_content_plugin', 0)) {
shopFunctionsF::triggerContentPlugin($product, 'productdetails','product_desc');
}

And here's the code from frontend/helpers/shopfunctionsf.pgp (lines 698-725)

Code: [Select]
static function triggerContentPlugin(  $article, $context, $field) {
// add content plugin //
$dispatcher =   JDispatcher::getInstance ();
JPluginHelper::importPlugin ('content');
$article->text = $article->$field;
jimport ('joomla.html.parameter');
$params = new JParameter('');

if (JVM_VERSION === 2) {
if (!isset($article->event)) {
$article->event = new stdClass();
}
$results = $dispatcher->trigger ('onContentPrepare', array('com_virtuemart.'.$context, &$article, &$params, 0));
// More events for 3rd party content plugins
// This do not disturb actual plugins, because we don't modify $vendor->text
$res = $dispatcher->trigger ('onContentAfterTitle', array('com_virtuemart.'.$context, &$article, &$params, 0));
$article->event->afterDisplayTitle = trim (implode ("\n", $res));

$res = $dispatcher->trigger ('onContentBeforeDisplay', array('com_virtuemart.'.$context, &$article, &$params, 0));
$article->event->beforeDisplayContent = trim (implode ("\n", $res));

$res = $dispatcher->trigger ('onContentAfterDisplay', array('com_virtuemart.'.$context, &$article, &$params, 0));
$article->event->afterDisplayContent = trim (implode ("\n", $res));
} else {
$results = $dispatcher->trigger ('onPrepareContent', array(& $article, & $params, 0));
}
$article->$field = $article->text;
}

You can see for yourself that $article is not passed as a reference nor it's returned, so of course it will never get modified.

Solution is to alter the signature of the method like this:

Code: [Select]
static function triggerContentPlugin( &$article, $context, $field) {

Hope this helps.
--
Francesco (zanardi)
http://extensions.gibilogic.com
@gibilogic on Twitter

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9973
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Content plugin broken in product_desc
« Reply #1 on: March 29, 2014, 10:08:10 am »
Thank you very much zanardi. I really wonder how this code could work before. But we also have threads in which the content plugin were blocking the pdf creation. Anyway added this way in vm2.5.5, please test.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/