Jump to content

Shopping Cart Variables


Recommended Posts

7 hours ago, UWH - David said:

I have used the debug tag and found variable outputs but I require one for product ID or name and the number of items purchased. How can I gather this information for rendering on the complete.tpl ?

if the information you want isn't directly available (or inferred) from the Smarty variables, then you may need to use an action hook to obtain it - two spring to mind, "AfterShoppingCartCheckout" and "ShoppingCartCheckoutCompletePage" - from your description of what you want, I think the AfterShoppingCartCheckout hook will be the more appropriate, but you may still need to query the db for additional details if they're not directly provided by the hook variables.

 

Link to comment
Share on other sites

13 hours ago, brian! said:

if the information you want isn't directly available (or inferred) from the Smarty variables, then you may need to use an action hook to obtain it - two spring to mind, "AfterShoppingCartCheckout" and "ShoppingCartCheckoutCompletePage" - from your description of what you want, I think the AfterShoppingCartCheckout hook will be the more appropriate, but you may still need to query the db for additional details if they're not directly provided by the hook variables.

 

It seems using php hooks are not going through the .tpl file. How would this be performed?

Link to comment
Share on other sites

Unfortunately, this hook file doesn't seem to be working. I must be missing something simple:

<?php
add_hook('CartTotalAdjustment', 1, function ($vars)
{
    $productid = $vars['pid'];

});

add_hook('AfterShoppingCartCheckout', 1, function ($vars)
{
    $serviceids = $vars['ServiceIDs'];

});

complete.tpl

list={$serviceids}{$productid}

Gives me a blank output, list=

 

Link to comment
Share on other sites

12 hours ago, UWH - David said:

From WHMCS Settings: 

Tick to allow use of the Smarty {php} tag in templates. This is considered a security risk. 
Enabled 

*Looks like I am creating a .php in /includes/hooks/

as a general rule, you should never need to use {php} in templates.

11 hours ago, UWH - David said:

Unfortunately, this hook file doesn't seem to be working. I must be missing something simple:

I couldn't get it working on v7.4.1 either - so I must be missing it too. :roll:

if you had to, you could use ClientAreaPageCart as a means of querying the db and passing the results back to the template...

<?php

# After Shopping Cart Checkout Hook
# Written by brian!

function complete_page_hook($vars){
	
	if ($vars['templatefile'] == 'complete'){
		$invoiceid = $vars['invoiceid'];
	}
	return array("brian" => $invoiceid);
}
add_hook("ClientAreaPageCart", 1, "complete_page_hook");

the above hook is practically useless, as it will take the invoiceID value from the template, assign it to a variable $brian and pass it back for you to use in the template {$brian) - but it at least shows you that you can grab the invoiceID or orderID from the template and with that, you can query the db and get the information you need.

also, remember that the complete.tpl page still has access to the cart session variables/arrays - so to get a count of products in the order, you can use the following Smarty in the template...

{$smarty.session.orderdetails.Products|@count}

and you can get similar counts for Domains, Addons & Renewals by replacing "Products" in the above code (which you could add together for a grand total).

these are arrays, so you can access their contents in Smarty, but the products array will only give you serviceIDs (the id value for the order from tblhosting), it won't directly give you product IDs or names - to get that, you'd have to query the database via a hook.

Link to comment
Share on other sites

10 hours ago, brian! said:

as a general rule, you should never need to use {php} in templates.

I couldn't get it working on v7.4.1 either - so I must be missing it too. :roll:

if you had to, you could use ClientAreaPageCart as a means of querying the db and passing the results back to the template...


<?php

# After Shopping Cart Checkout Hook
# Written by brian!

function complete_page_hook($vars){
	
	if ($vars['templatefile'] == 'complete'){
		$invoiceid = $vars['invoiceid'];
	}
	return array("brian" => $invoiceid);
}
add_hook("ClientAreaPageCart", 1, "complete_page_hook");

the above hook is practically useless, as it will take the invoiceID value from the template, assign it to a variable $brian and pass it back for you to use in the template {$brian) - but it at least shows you that you can grab the invoiceID or orderID from the template and with that, you can query the db and get the information you need.

also, remember that the complete.tpl page still has access to the cart session variables/arrays - so to get a count of products in the order, you can use the following Smarty in the template...


{$smarty.session.orderdetails.Products|@count}

and you can get similar counts for Domains, Addons & Renewals by replacing "Products" in the above code (which you could add together for a grand total).

these are arrays, so you can access their contents in Smarty, but the products array will only give you serviceIDs (the id value for the order from tblhosting), it won't directly give you product IDs or names - to get that, you'd have to query the database via a hook.

This is very intriguing. From what was ordered, how would you go about getting a or the package IDs from that?

Link to comment
Share on other sites

12 hours ago, UWH - David said:

This is very intriguing. From what was ordered, how would you go about getting a or the package IDs from that?

from the session, you can't - not without querying the database.... which you could do with {php} tags in the template, but i've already rightly told you not to go down that road, so you're left with hooks.

<?php

# Shopping Cart Complete Page Output Hook
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) {
	
	$orderID = $vars['orderid'];
	$myproducts = Capsule::table('tblhosting')
				->join('tblproducts', 'tblhosting.packageid', '=', 'tblproducts.id')
				->where('orderid',$orderID)
				->pluck('tblhosting.packageid','tblproducts.name');

	$output = 'The Following Products (Names & IDs) have been ordered<br>';
	
	foreach ($myproducts as $name => $id) {
		$output .= $name . ' -> ' . $id.'<br>';
	}
	
    return $output;
});

sMlJmSD.png

the above hook will give you a list of Product Names (and their package IDs) in the order and output it on the complete.tpl template - i've not added any html layout code or css to it, nor have I used language strings, but you can add them to $output if required.

btw - I assume you'd only need name or ID as the client won't need to know both... also, bear in mind, this example just covers products, you'd have to expand it to check for domains, addons etc.

alternatively, you could use the invoiceID value, and search the invoiceitems table to get a list of line items of the order and output that instead (or in addition to).

your best bet is to think clearly about what information you want and how you want to output it - then work out the best (simplest/quickest) way to get that information to the template.

9 hours ago, UWH - David said:

I would pay for consulting at this point to get this figured out. 

then you'd either need to post in Service Offers & Requests and get quotes from developers, or contact a developer directly by PM... but to do that last step, you'd need to enable Private Messaging in your profile settings! :idea:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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