Jump to content

Error: Cannot use object of type stdClass as array in /var/www/gcristian/data/www/shop/includes/hooks/UsersInvoice.php:16


Recommended Posts

Hey guys,

 

I'm running the following hook:

<?php

use WHMCS\Database\Capsule;

add_hook('ClientAreaPageInvoices', 1, function($vars) {
    global $smarty;
    $invoicedesc = array();

    $userinvoicedescription = CAPSULE::table('tblinvoiceitems')
            ->select('id', 'invoiceid', 'description')
            ->where('type', 'Hosting')
            ->get();
            
    $re = '/.*Username:\s(.*)/m';
    foreach ($userinvoicedescription as $description) {
        $match = preg_match_all($re, $description['description'], $matches, PREG_SET_ORDER, 0);
        $invoicedesc[$description['invoiceid']]['username'] = $matches[1];
    }

    $smarty->assign('usersinvoice', $usersinvoices);
});
?>

And I get the following error:

http://prntscr.com/n7h85e

 

The problem seem to be with line of preg_match_all while using the $description['description'] array.

I tried a couple of things, however, I can not get through it...

 

Can anyone help me out here please?

 

Thanks and kind regards,

Cristian Gheonea

Link to comment
Share on other sites

I know I reply to my own topic but i fixed it and i do not wish anyone else spending time on a thing i do not need anymore. the dummy issue was that the description was a class...

<?php

use WHMCS\Database\Capsule;

add_hook('ClientAreaPageInvoices', 1, function($vars) {
    global $smarty;
    $invoicedesc = array();

    $userinvoicedescription = CAPSULE::table('tblinvoiceitems')
            ->select('id', 'invoiceid', 'description')
            ->where('type', 'Hosting')
            ->where('userid', $_SESSION['uid'])
            ->get();

    foreach ($userinvoicedescription as $description) {
        preg_match('/.*Username:\s(.*)/', $description->{'description'}, $output);
        if (count($output) > 0) {
            $invoicedesc[$description->{'invoiceid'}]['username'] = $output[1];
        }
    }
    $smarty->assign('usersinvoice', $invoicedesc);
});
?>

 

Link to comment
Share on other sites

21 hours ago, cgheonea said:

I know I reply to my own topic but i fixed it and i do not wish anyone else spending time on a thing i do not need anymore. the dummy issue was that the description was a class...

if you say it works, then that's fine - but that seems a long-winded way to get a username to me... 😕

let's ignore that you're using Smarty in the hook which, in this case, shouldn't be necessary (declaring or assigning) in the way that you're doing it... if you're going to query tblinviceitems to get the description, you might as well join it with tblhosting to get the service username - and avoid any use of preg_match.

what's the full purpose of this hook ?

Link to comment
Share on other sites

4 hours ago, brian! said:

if you say it works, then that's fine - but that seems a long-winded way to get a username to me... 😕

 

Stop reading my mind!...?.!  🙂

You can get that via the internal classes:

https://docs.whmcs.com/classes/7.6/WHMCS/Billing/Invoice.html

Loop through invoice items, and then get that item's service and then get that service's username. 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated