VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: welrachid on December 02, 2015, 11:03:22 AM

Title: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution
Post by: welrachid on December 02, 2015, 11:03:22 AM
Joomla 3.4.5

components/com_virtuemart/controllers/plugin.php Line: 72 + 76

jExit();

makes the joomla exit with outputted data. This means no headers are set before output.

Im using example with parameters format=json
Title: Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
Post by: welrachid on December 02, 2015, 12:16:15 PM
And this should be confirming that headers are not SENT before jexit();
they are just prepared

http://joomla.stackexchange.com/questions/1126/return-json-using-the-joomla-framework
Title: Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
Post by: Milbo on December 03, 2015, 11:38:30 AM
So what do you suggest? We used jExit instead of die. So how do we sent the header?
should we use someting like
$this->app->mimeType = 'application/json';
??
Title: Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
Post by: welrachid on December 04, 2015, 08:27:43 AM
Hi Milbo
Sry for the late reply. Im not sure why im not being notified for new entries in my thread. anyway - ill make sure ill check up a couple of times during day

Im not that much into the Joomla platform, but from what i can read around the web the problem that occours is that joomla exists without sending the headers. so the solution is to send the headers yourself.
Doing that lead me to an other problem. The mimetype was not printed either. so i have to manually set the content-type header
See my working code:
         if ($format == 'json') {
            $document->setMimeEncoding ('application/json');
            // Change the suggested filename.
            JResponse::setHeader ('Content-Disposition', 'attachment;filename="' . $type . '.json"');
            JResponse::setHeader("Content-type","application/json");
            JResponse::sendHeaders();
            echo json_encode ($render);
            jExit();
         }

reading the platform api says that this method is deprecated:
https://api.joomla.org/cms-3/classes/JResponse.html#method_sendHeaders

They write that we should :
4.0 Use JApplicationWeb::sendHeaders() instead

However when i write that in that place the JApplicationWeb is not defined or instantiated or something..it fails.. but again i think the whole JResponse class will be deprecated and replaced by JApplicationWeb - so when VM is updated at some point in the future this will be handled by the new class i guess?

Again.. i dont know "much" about what happens in the core of VM, so i cannot say if everything is being dealt with with my code. but please feel free to change it the way you want and let me know if i can be of any assistance.

Have a great friday
Title: Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9
Post by: welrachid on December 07, 2015, 22:14:35 PM
perhaps someone from the development team can confirm this bug and tell me if the proposed fix is good enough, so i can go ahead and upgrade production på newest versions and make those hack (that will be overwritten once u release the next version)
Title: Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution
Post by: Milbo on December 11, 2015, 01:29:23 AM
oh sorry, I thought I answered you already. Yes your fix is quite adequate. I added almost the same now. You may check the svn at http://dev.virtuemart.net/projects/virtuemart/repository
Title: Re: Headers not set in VM 3.0.10-12 Worked in VM 3.0.9 With proposed solution
Post by: welrachid on December 12, 2015, 09:44:14 AM
Great

Thanks