akhorasi Posted June 12, 2020 Share Posted June 12, 2020 I am trying to find a way to get a product id in complete.tpl in whmcs. Basically, instead of having a default button for continue to client area, I need to replace it with continue to product detail that the client has just purchased. uri will look something like this: https://[HOSTNAME]/clientarea.php?action=productdetails&id=225 I checked the builtin hooks and I do see ShopingCartCheckoutCompletedPage which sends the variable in complete.tpl but I cant find product id details there. This is what I tried: add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) { /** * select packageid from whmcs_db.tblinvoiceitems, whmcs_db.tblhosting WHERE whmcs_db.tblinvoiceitems.relid = whmcs_db.tblhosting.id and whmcs_db.tblinvoiceitems.type = 'Hosting' and whmcs_db.tblinvoiceitems.invoiceid = '27';. */ $ordernumber = $vars['ordernumber']; $orderid = $vars['orderid']; $invoiceid = $vars['invoiceid']; $productid = Capsule::table('tblinvoiceitems') ->join('tblhosting', 'tblinvoiceitems.relid', '=', 'tblhosting.id') ->where('tblinvoiceitems.invoiceid','=', $invoiceid) ->where('tblinvoiceitems.type', '=', 'Hosting') ->select('tblhosting.packageid') ->get(); return $productid; }); Above query is not working, but when I pass hardcoded value its showing properly in complete.tpl can someone please help? Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 12, 2020 Share Posted June 12, 2020 10 hours ago, akhorasi said: Above query is not working, but when I pass hardcoded value its showing properly in complete.tpl can someone please help? what happens if there are two different products in the invoice ?? are you going to have multiple buttons or links ?? as written that hook should be returning an array - now it might contain 1 value or 100 values - depending on how many products there are on the invoice. the quick fix, if you just want to get the first product value it finds in the invoice, would be to change ->get() to ->first() in the hook and that should return a specific value and not an array... and that is what is sounds as though your template is expecting to receive. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 12, 2020 Share Posted June 12, 2020 Or use raw query 😛 Capsule::select(Capsule::raw('SELECT t1.something FROM table AS t1 LEFT JOIN table2 AS t2 ON t1.id = t2.id')); Instead of... $something = Capsule::table('table') ->join('what', 'do.you', '=', 'want.from') ->where('me.stupid','=', 'laravel.syntax') ->iHateYou() ->select('tblhosting.packageid') ->get()->first()->second()->pluck() .... really???; 1 Quote Link to comment Share on other sites More sharing options...
vpcvishnu Posted April 6, 2022 Share Posted April 6, 2022 On 12/06/2020 at 5:35 AM, akhorasi said: I am trying to find a way to get a product id in complete.tpl in whmcs. Basically, instead of having a default button for continue to client area, I need to replace it with continue to product detail that the client has just purchased. uri will look something like this: https://[HOSTNAME]/clientarea.php?action=productdetails&id=225 I checked the builtin hooks and I do see ShopingCartCheckoutCompletedPage which sends the variable in complete.tpl but I cant find product id details there. This is what I tried: add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) { /** * select packageid from whmcs_db.tblinvoiceitems, whmcs_db.tblhosting WHERE whmcs_db.tblinvoiceitems.relid = whmcs_db.tblhosting.id and whmcs_db.tblinvoiceitems.type = 'Hosting' and whmcs_db.tblinvoiceitems.invoiceid = '27';. */ $ordernumber = $vars['ordernumber']; $orderid = $vars['orderid']; $invoiceid = $vars['invoiceid']; $productid = Capsule::table('tblinvoiceitems') ->join('tblhosting', 'tblinvoiceitems.relid', '=', 'tblhosting.id') ->where('tblinvoiceitems.invoiceid','=', $invoiceid) ->where('tblinvoiceitems.type', '=', 'Hosting') ->select('tblhosting.packageid') ->get(); return $productid; }); Above query is not working, but when I pass hardcoded value its showing properly in complete.tpl can someone please help? Thanks Bro you have to include the below provided code at the top of your hook file use WHMCS\Database\Capsule; The full code block for the hook will be, <?php use WHMCS\Database\Capsule; add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) { $ordernumber = $vars['ordernumber']; $orderid = $vars['orderid']; $invoiceid = $vars['invoiceid']; $productid = Capsule::table('tblinvoiceitems') ->join('tblhosting', 'tblinvoiceitems.relid', '=', 'tblhosting.id') ->where('tblinvoiceitems.invoiceid','=', $invoiceid) ->where('tblinvoiceitems.type', '=', 'Hosting') ->select('tblhosting.packageid') ->get(); return $productid; }); And you can get the productid in the tpl using json_decode. An example is provided below {foreach $addons_html as $addon_html} <div class="order-confirmation-addon-output"> {$array = json_decode($addon_html,1)} {foreach $array as $key=>$item} {if $key == 0} <p>{$item['packageid']}</p> {/if} {/foreach} </div> {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
WaSMS.Net Posted August 6 Share Posted August 6 Hey brian!, i want product id on hook AfterShoppingCartCheckout this is how i'm doing this function hook_handleconnectorders_AfterShoppingCartCheckout($vars) { $productId = $vars['pid'] ?? null; echo $productId; die; } // Register hooks with WHMCS add_hook('AfterShoppingCartCheckout', 1, 'hook_handleconnectorders_AfterShoppingCartCheckout'); is this the right way? i have created the provisioning module and when user order any product save the product in database something like this 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.