First basic plugin: methods not triggered, why?

  • Posts: 6
  • Thank you received: 0
10 years 11 months ago #136303

I'm new to Joomla/Hikashop plugin,
I followed the guide at www.hikashop.com/support/62-hikashop-dev...r-documentation.html and i made a plain basic plugin that it doesn't seem to work, the same code put into the history plugin does work instead, probably i made some mistake during the install process:

1. I made a clone folder of /plugins/hikashop/history
2. I renamed this clone folder in /plugins/hikashop/credits
3. I renamed the xml file in /plugins/hikashop/credits/credits.xml
4. I renamed the php file in /plugins/hikashop/credits/credits.php
5. I opened credits.xml changing name tag, description and author tag, and the following tag:

<filename plugin="credits">credits.php</filename>
6. I went in Joomla extension manager -> discover -> I discovered my credits plugin -> I installed id and activated it
7. I edited /plugins/hikashop/credits/credits.php like this:
<?php
defined('_JEXEC') or die('Restricted access');
?><?php
class plgHikashopCredits extends JPlugin
{
	function plgHikashopCredits(&$subject, $config){
		parent::__construct($subject, $config);
	}

	function onAfterOrderUpdate(&$order,&$send_email){
		if(!empty($order->order_id)){
			$db = JFactory::getDbo();
			$query = $db->getQuery(true);
			$columns = array('value');
			$values = array($db->quote('ugo3333'));
			$query
			    ->insert($db->quoteName('les_test'))
			    ->columns($db->quoteName($columns))
			    ->values(implode(',', $values));
			$db->setQuery($query);
			$db->query();
			}			
		return true;
	}	
}

The plugin does not work, the function is not triggered when updating an order satus.
My code DOES WORK if I paste it directly inside Hikashop History plugin inside its onAfterOrderUpdate function.

So the problem is not my code, what am I doing wrong? Thanks a lot in advance.

Joomla version: 3.2.0
Hikashop version: last free edition

Last edit: 10 years 11 months ago by majere.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 11 months ago #136322

Hi,

You don't mention anywhere in your message that you edited the xml file in order to adapt it to its new name. That's probably why it doesn't work in fact. Joomla looks into the xml to know which php file to launch. If you don't give him the correct, one, he will just ignore it.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
10 years 11 months ago #136328

sorry,
in my previous post I wrote that I edited 'credits.php' while instead I als edited 'credits.xml' changing plugin name and reference to php file:
<filename plugin="credits">credits.php</filename>
Plugin folder, XML file and php file have same name 'credits' and XML refers to credits.php file as shown above. Do I have to name the class inside the php file 'credits' too?
Thank you very much for the support!

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 11 months ago #136330

Then everything looks correct to me.
It must be a stupid thing that you missed at one point but I don't see it in what you described. I would have done the same.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
10 years 11 months ago #136334

I'll double check everything when I'll be back to work, hope to find the mistake soon

Last edit: 10 years 11 months ago by majere.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
10 years 11 months ago #137559

Hi again nicolas,
I found the problem, it was a stupid syntax php mistake inside my plugin.
Now the plugin works, but I'm not able to catch a particoular event, I need my custom code to be executed when the order has been payed using paypal. My paypal mayment method is set to change the status to 'confirmed' when the order is verified and to 'created' when the status of the order is pending.
I tried both:

function onAfterOrderCreate(&$order,&$send_email) { 
if(!empty($order->order_id) && ($order->order_status == "confirmed")) {
--custom code--- }}
and
function onAfterOrderUpdate(&$order,&$send_email) { 
if(!empty($order->order_id) && ($order->order_status == "confirmed")) {
--custom code--- }}
But my custom code is executed only when manually updating order status in administration panel of hikashop, even if the status was already on 'confirmed'.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 11 months ago #137565

Hi,

The onAfterOrderCreate trigger is not useful in your case.
The onAfterOrderUpdate trigger should be triggered when PayPal confirms the order too. The code you gave is correct. How do you know that your custom code is not working ? Because since it's PayPal server's which are confirming the order, it's normal that you don't see any message displayed on the website, and that you can't access the customer's session data in your custom code. I'm guessing that the issue is more something on that end because the trigger is always done and definitely done when PayPal confirms the order, otherwise, HikaSerial and HikaMarket wouldn't work properly.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
10 years 11 months ago #137570

Thank you so much,
the event is actually fired, i tested it writing an 'hello world' inside the db.
what doesn't work is the following:
The full $order object seems to be null when the event is fired from paypal, instead it is defined when manually updating the order status.

if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }
$orderClass = hikashop_get('class.order');
$order = $orderClass->loadFullOrder($order->order_id);
I really need the full $order object because my custom code needs to be executed for each product in the cart and the cart array is only present inside the full $order object, I hope there is a workaround.
Thanks again in advance

Last edit: 10 years 11 months ago by majere.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 11 months ago #137573

That's normal. Look at the definition of loadFullOrder. You need to give the function a false on the third parameter if you want to skip the check on the current user or otherwise it will return null if the current user is not the owner of the order.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
10 years 11 months ago #137625

Thanks it works perfectly now,
I don't see these information mentioned anywhere in the developer documentation page, i think you should add it as it's very useful.
Thank you again, you have a very good support!

Please Log in or Create an account to join the conversation.

Time to create page: 0.076 seconds
Powered by Kunena Forum