Jump to content

Pull current prices for display on homepage.tpl


jmbronson

Recommended Posts

Good day all,

I've familiarized myself a bit with the Smarty template language, and I see that many variables are only available depending on what page is being viewed. I've used {debug} within homepage.tpl but of course, this template does not include variables used within any product pricing.

 

I'm trying to display the latest prices, particularly current domain prices, on the main page (homepage.tpl). Instead of hard-coding these prices, I'd like to make the dynamic so that if I change the price within the admin panel, the price is updated within the template.

 

So, my question is, how can I pull current domain prices from the database to display outside of the product page (in this case, homepage.tpl)?

 

Any help is appreciated! Thanks folks!

Link to comment
Share on other sites

21 hours ago, jmbronson said:

So, my question is, how can I pull current domain prices from the database to display outside of the product page (in this case, homepage.tpl)?

if you were doing this on a page outside of WHMCS, you would have one option - the Domain Pricing Table Data Feed...

<style type="text/css">
table.domainpricing {
    width: 600px;
    background-color: #ccc;
}
table.domainpricing th {
    padding: 3px;
    background-color: #efefef;
    font-weight: bold;
}
table.domainpricing td {
    padding: 3px;
    background-color: #fff;
    text-align: center;
}
</style>
<script language="javascript" src="feeds/domainpricing.php"></script>

inside WHMCS pages, you have at least two options - using the data feed in the template as above, or writing an action hook to query the database to get the domain prices in multiple currencies... that's not going to be a simple query, so unless you're familiar with writing hooks, i'd recommend using the data feed. 🙂

you may need to make css changes to suit your site though.

if you want to show product prices, descriptions etc, then these too are available using other feeds - though I wouldn't recommend using too many feeds on the same page... i've also posted hooks that can show product details too on the homepage... actually custom domain pricing feeds too... there all out there in the community somewhere!

also, and it's not widely publicised, but there is a page on WHMCS that shows domain pricing...

you couldn't embed it into the homepage, but it's another option if you want to show a more complete domain pricing table outside of the cart.

Link to comment
Share on other sites

Thanks for the reply. The feeds will work just fine for domain pricing.

 

However, now I'm wondering how to pull product pricing - the feeds won't work with what I'd be trying to accomplish. I think I'll need to pull the prices from the DB instead so I can manipulate exactly what is shown on the page. For example, I'd like to show the monthly price for a triennial plan for a specific PID so I'd need to do some calculation here, however I'd need to original raw value. Also, the Product Pricing feed ironically includes currency info despite their being a separate URL parameter to display those (currency=2).

 

I tried doing a search but couldn't find any examples of database query hooks. Can you link me to a basic example hook that queries the database? I can edit it to suit my needs.

Link to comment
Share on other sites

6 hours ago, jmbronson said:

However, now I'm wondering how to pull product pricing - the feeds won't work with what I'd be trying to accomplish. I think I'll need to pull the prices from the DB instead so I can manipulate exactly what is shown on the page.

you could duplicate the feed code and manipulate it before returning the result back in the feed... never edit an original data feed though as the automatic updater would just replace it during an update! 🙄

6 hours ago, jmbronson said:

For example, I'd like to show the monthly price for a triennial plan for a specific PID so I'd need to do some calculation here, however I'd need to original raw value.

the feed would get that value from it's own db query - you'd just need to manipulate it before the final output.

6 hours ago, jmbronson said:

Also, the Product Pricing feed ironically includes currency info despite their being a separate URL parameter to display those (currency=2). 

it a currency isn't passed to it, it has to default to using a currency - otherwise there would be no way for it to get an accurate price... if you wanted to, you could get it to return a result with no currency symbols just by removing the formatCurrency code... the domainprice.php feed has an option on whether to format the output or not... that could be duplicated in the product pricing feed if required.

6 hours ago, jmbronson said:

I tried doing a search but couldn't find any examples of database query hooks.

i've posted 2 in the last 48 hours - and i'm not even really here! 🎄

going back to the feeds, if we take productsinfo.php as an example, we can get pricing from there... imagine we duplicate the feed code in a new feed php file and tweak the output, you then have a second feed available to show monthly pricing... so let's say we want to show monthly pricing equivalent for a triennial product - we're basically just dividing the price by 36...

    $result = select_query("tblpricing", "", array("type" => "product", "currency" => $currencyID, "relid" => $pid));
    $data = mysql_fetch_array($result);
    $price = $data[$billingCycle];
	if ($billingCycle == "triennially") {
		$price = formatCurrency($price/36);
	}
	else {
		$price = formatCurrency($price);
	}
    widgetOutput($price);
} else {
    widgetOutput('Invalid get option. Valid options are "name", "description", "configoption", "orderurl" or "price"');
}

and then if we call the feed, we can display the monthly price (should be £60 GBP triennially)..

<script language="javascript" src="feeds/productsinfo2.php?pid=45&get=price&billingcycle=triennially&currency=1"></script>

obviously the above is just a quick example, and you should ideally complete that if statement to include all cycles.. in fact, you should really add another option to allow you to show monthly equivalent pricing or not, and that wouldn't be too difficult to do.

and just for completeness, if you wanted to use a hook to get a monthly price for a triennial product, then it would be along the lines of...

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_get_product_price($vars) {
    
    $productprice = Capsule::table('tblpricing')->where('relid','45')->where('type','product')->where('currency','1')->value('triennially');
	$prod45price = formatCurrency($productprice/36);
	return array("product45price" => $prod45price);
    
}
add_hook('ClientAreaPageHome', 1, 'hook_get_product_price');

.. that would give you a Smarty variable on the homepage {$product45price} that you can output as per any other Smarty variable.

X45dnQX.png

as you can see, both the feed and the hook are giving the same correct result (60/36).

now in practical terms, you likely would never use a hook like above in that you are more likely to be getting prices for a number of products and then outputting them in a loop... so your db result would be an array which you could then loop through in the template...

if I understand your situation correctly, I would imagine that you'd never really need to use a hook for this - just modify the feeds to suit your desired outcomes.... but if you go down the hook road, plan out what you need before coding and don't be using a separate hook or query for each price! 🙂

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