Problem on plugin which is not triggered

  • Posts: 9
  • Thank you received: 0
9 years 6 months ago #201976

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.1

Hello,
I would like to get some information.
I have created a new plugin to insert a row in a table after the user confirms his cart with the status 'pending'.
After the Paypal notification, the status has to be set to 'valide'.
I suppose that if all is correct this plugin is called when the event is triggered (at the same time than Paypal plugin)...

And of course, it doesn't work...
I have read a post where the person has the same problem ...but didnt' find the answer...
When I directly code in the paypal plugin, it works !

The plugin is published in Joomla.
PHP : just some basic queries to see if it works...After,i will use data from the order to make my request.

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.3.2
 * @author	hikashop.com
 * @copyright	(C) 2010-2014 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
class plgHikashopFootlisted extends JPlugin{
	function plgHikashopFootlisted(&$subject, $config){
		parent::__construct($subject, $config);
	}

	function onPaymentNotification(&$statuses) {
    
            $db = JFactory::getDbo();
            $query = $db->getQuery(true)
                        ->update($db->qn('#__footlisted_abonnes'))
                        ->set($db->qn('abo_duree').' = 3')
                        ->where($db->qn('id').' = 7');
            try
            {
                $db->setQuery($query)->execute();
            }
            catch (Exception $exc)
            {

            }
            return true;
        }    

        
        function onAfterOrderConfirm(&$order, &$methods, $method_id){
            parent::onAfterOrderConfirm($order, $methods, $method_id);
                                $user = JFactory::getUser();
            $db = JFactory::getDbo();
            $query = $db->getQuery(true)
                        ->update($db->qn('#__footlisted_abonnes'))
                        ->set($db->qn('abo_n_fact').' = "test"')
                        ->where($db->qn('id').' = 7');
            try
            {
                $db->setQuery($query)->execute();
            }
            catch (Exception $exc)
            {

            }
            return true;
	}



}

XML
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.0" method="upgrade" group="hikashop">
	<name>Hikashop Footlisted Plugin</name>
	<creationDate>{__DAY__} {__MONTH__} {__YEAR__}</creationDate>
	<version>{__PLUGIN_VERSION__}</version>
	<author>xxxxxx</author>
	<authorEmail>xxxxxxx</authorEmail>
	<authorUrl>http://www.hikashop.com</authorUrl>
	<copyright>(C) 2010-{__YEAR__} HIKARI SOFTWARE. All rights reserved.</copyright>
	<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
	<description>This plugin enables to create something</description>
	<files>
		<filename plugin="footlisted">footlisted.php</filename>
	</files>
	<params addpath="/components/com_hikashop/params">
	</params>

</extension>

Have you got an idea about my problem?
Thanks a lot/mille merci !
PS : if someone has an example of inserting/updating a row using the data of the order,your welcome ;)

Last edit: 9 years 6 months ago by thlas77.

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
9 years 6 months ago #201982

Hi,

There is no point calling the authorize.net payment plugin when a payment notification is received from PayPal.
So the onPaymentNotification function is only called in the payment plugin which was used for the order.
So that's normal that yours is not called since if it were, you would first have to understand if the payment notification is a valid one or not, etc.

What you want to do instead is to implement the onAfterOrderUpdate trigger. That's the trigger which will be called when the paypal payment plugin (and any other payment plugin) changes the status of the order upon receiving the payment notification in its onPaymentNotification function. In that onAfterOrderUpdate function, you can check the old and new status of the order and if you see that the order has just been changed to the status you want to plug yourself to, then you can run your custom code.

I invite you to look at our developer documentation where the explanations for these triggers explain more or less the same things I just said:
www.hikashop.com/support/support/documen...r-documentation.html

The following user(s) said Thank You: thlas77

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

  • Posts: 9
  • Thank you received: 0
9 years 6 months ago #202044

Merci Nicolas for your quickness and your help,

I tried and of course, it works !;-)
I will try to code my real functionalities, I'm sure i will need your help again, maybe on the french forum :-)
By the way, does it exist a developer documentation in french ? I haven't found it !

Let's go ! looking for how to get the information to explore the $order data...i will have a look in the other plugin to build mine.


Hikashop's hotline is very impressive ! I also saw that on the other topics...congratulations
Thanks

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

  • Posts: 9
  • Thank you received: 0
9 years 6 months ago #202047

Hello,

I try to understand how to get the information I need to feed my 'abonnements' table as from the $order.
I suppose I can access to all the fields of the order table by doing $order->order_status ? right ?

Could you also confirm me that I have to read the Hikashop tables with select orders with join (order_product, then product) depending on the order_id ?

To sum up,

With my order_id
Join between order, order_product, product tables
For each row read => insert in my table abonnement with the data retrieved

Is it the right way to do it or is there a better method ?

And for example, with the order_user_id, to retrieve the jos_user id ?
Thanks

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
9 years 6 months ago #202109

Hi,

1. That's right, you can use $order->something to get the data from the column something of the order table.

2. Yes. Note that you maybe want to do like explained in the developer documentation :

If you want to load the whole information of an order, you can use the code :
$orderClass = hikashop_get('class.order');
$order = $orderClass->loadFullOrder($order_id, true, false);
Similarly to the cart, the products will be available in the attribute as an array of product objects:
$order->products

But you can also do a query with a join if you want.

3. The order_user_id correspond to the user_id of the hikashop_user table. In that table, you'll find the user_cms_id which corresponds to the id of the user in the user table of Joomla.

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

  • Posts: 9
  • Thank you received: 0
9 years 6 months ago #202222

Thanks a lot Nicolas,
I had found the answer in the doc and by reading some topics in the forum.
So simple in fact !
You confirmed what I have experimented, so I can continue my dev.
For all the products in the cart : $order->products[0]->product_id for product 1 for example...
Maybe what would be interesting is to have an example of a plugin which in the doc..
When mine will be completed, i will publish it as an example.
Thanks
see you next time
Thierry

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

  • Posts: 82865
  • Thank you received: 13372
  • MODERATOR
9 years 6 months ago #202226

Hi,

HikaShop comes built-in with close to a hundred plugins. That's a lot of examples you can look at ;)
But we welcome your plugin. It can always help someone.

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

Time to create page: 0.072 seconds
Powered by Kunena Forum