How to check problem when read a table in plugin ?

  • Posts: 9
  • Thank you received: 0
9 years 5 months ago #204550

-- HikaShop version -- : 2.4.0

Hello,

I wrote a plugin which is correctly triggered after paypal confirmation.
I insert a row in one of my table. This insert is ok.
But, one of the field is not correctly fed when i'm in the production website,whereas in the developement website it is ok.
The value is calculated as from a field read in a table.
As in production, I have 0 in the field, I conclude that the reading of the table is not ok and my process continues with 0.
So,how I can check the mysql error ?
As this process is done when paypal payment is confirmed, I can't see any message on the screen.
How can I debug this ? turning debug mode of the paypal plugin to yes ? and after, where do I have to look into ?
Thanks for your help.
Thierry

my order is :
            $db = JFactory::getDbo();
            $query = $db->getQuery(true)
            ->select(array('cal_n_sem','cal_c_j'))
            ->from($db->quoteName('#__mytable_calendar'))
            ->where($db->quoteName('cal_d').' = "'.$date_com_d.'"');
            $db->setQuery($query);

            $date_calendar = $db->loadObject();

Last edit: 9 years 5 months ago by thlas77.

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 5 months ago #204551

Hi,

You can debug that by changing the status of the order from the backend orders manager.

Also, if you echo stuff in your plugin during payment notifications sent by your payment gateway, it will be stored automatically in the payment log file of HikaShop that you can see in the Files section of the HikaShopc configuration.

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

  • Posts: 9
  • Thank you received: 0
9 years 5 months ago #204633

I tryed to set debug to yes but do not succeed.I saw nothing in the log regarding my plugin (is it in "Fichier de log pour les paiements" button "voir le rapport" that "echo" should be displayed ? )
I will try to continue to understand how it works ...

But what I have discovered is that it works fine when I complete the payment in the Admin Hikashop part but not when it is triggered from paypal (on localhost, I only tested with the admin part, so I have the same behavior as when i am in live mode).

Does someone have an explanation ? Thanks

My query is on a function...maybe a clue ?
my code below (Ihave deleted some non interesting parts)

class plgHikashopMonsite extends JPlugin{
	function plgHikashopMonsite(&$subject, $config){
		parent::__construct($subject, $config);
	}

	function onAfterOrderUpdate(&$order,&$send_email) {
            
            $orderClass = hikashop_get('class.order');
            $order = $orderClass->loadFullOrder($order->order_id, true, false);
                
            $db = JFactory::getDbo();

            if($order->order_status === 'confirmed')
            {
                foreach($order->products as $product) {
                    
...

                    $n_sem = $this->CalculSemaines($order->history[0]->history_created,$nb_sem);                   

                    for($ind = 1; $ind < $nbre_indice; $ind++)//insert a row in Abonnes for each product
                    {
                        $object = (object)array(
...

                        );

                        $db->insertObject('#__monsite_abonnes', $object);
                    }
                }   
            }

            return true;
        }    

        /* calcul de la semaine de fin abonnement = semaine de départ + nbre de semaine */
        /*-----------------------------------------------------------------------------*/
        [b]public function CalculSemaines($fn_date_order,$fn_nb_sem) [/b]
	{
            // récupération de la date & heure limite maxi d'acceptation de la commande (paramétrée côté admin).
            $fl_param_n_jour = JComponentHelper::getParams('com_monsite) ->get('fl_Jour_limite_pari');
            $fl_param_heure = JComponentHelper::getParams('com_monsite') ->get('fl_heure_limite_pari');
            
            //recup date & heure de la commande
            $date_com_d = gmdate("Y-m-d", $fn_date_order);
            $date_com_h = gmdate("H:i:s", $fn_date_order);
            
            //recherche du numero du jour de la commande 
            $tabDate = explode('-', $date_com_d);
            $timestamp = mktime(0, 0, 0, $tabDate[1], $tabDate[2], $tabDate[0]);
            $n_jour_commande = date('w', $timestamp);
       
            //recherche de la semaine liée à la date de la commande dans la table Calendar.
[b]            $db = JFactory::getDbo();
            $query = $db->getQuery(true)
            ->select(array('cal_n_sem','cal_c_j'))
            ->from($db->quoteName('#__footlisted_calendar'))
            ->where($db->quoteName('cal_d').' = "'.$date_com_d.'"');
            $db->setQuery($query);

            $date_calendar = $db->loadObject();[/b][color=#bb4444] => seems that get nothing when coming from paypal, ok when in admin part.[/color]


...
            
        }

Last edit: 9 years 5 months ago by thlas77.

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

  • Posts: 9
  • Thank you received: 0
9 years 5 months ago #204636

I succed in displaying the log. What I could see when it comes from Paypalis :

SELECT cal_n_sem,cal_c_j
FROM `#__footlisted_calendar`
WHERE `cal_d` = "1970-01-01"

my date is not correct so that means that I retrieve the bad date in :

$n_sem = $this->CalculSemaines($order->history[0]->history_created,$nb_sem);

Is it the right date to take ? I'd like the date for the "completed" status..
Thanks

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 5 months ago #204649

Hi,

I'm not following you. You say that you want the date of when the order is confirmed. And you also say that your plugin is triggered during the paypal payment notification.
So this means that your plugin is triggered at the moment the order is confirmed.
In that case, why not simply use time() which will return you the current date.

Also, instead of :

$orderClass = hikashop_get('class.order');
            $order = $orderClass->loadFullOrder($order->order_id, true, false);
                
            $db = JFactory::getDbo();

            if($order->order_status === 'confirmed')
you probably want instead:
            $db = JFactory::getDbo();

            if( @$order->order_status === 'confirmed' && @$order->old->order_status === 'created' )
That way, you don't have to load the full order unnecessarily, you do your process only once, when the order is being confirmed, and you get the correct date.

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 5 months ago #204672

:oops:
Sometimes, sleeping is good for the brain ! :-)
So evident, of course ...I will update my coding asap.

Nevertheless I need some information inside the order (ex code of the product)
@$order contains only some fields ? What is the list ?
What does mean the @ before $order ?
Thanks

Sorry if my questions sounds stupid but I m a beginner ...

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 5 months ago #204684

Hi,

If you need to get information from the order, then yes, you'll want to use the loadFullOrder function but please load that in another variable than $order or you'll loose the $order->old object to do your check.

The @ will prevent warnings display. When an order is modified, the onAfterOrderUpdate function is called. But there are many things which can change an order, not only changing its status. So it's well possible that the order_status attribute doesn't exist in $order. The check will still work, but I added the @ to avoid the warning.
Another method would have been to write:
if( isset($order->order_status) && $order->order_status === 'confirmed' && isset($order->old->order_status) && $order->old->order_status === 'created' )
but I went for the easy to write solution.

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 5 months ago #204731

Thanks Nicolas for your explanations. It works now !
See you next Time for another problem :-)

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

Time to create page: 0.065 seconds
Powered by Kunena Forum