Jump to content

Pulling Pricing from WHMCS database


Ragonz

Recommended Posts

1 hour ago, Ragonz said:

Is there a way to pull the pricing (Set in Products/Services > Configurable options > option name > configurable option) and display it on a web page?

on a WHMCS page, pull it from the db in an action hook...

outside of WHMCS, as @DougK94 suggests, it would be a data feed... again by querying the db.

Link to comment
Share on other sites

Its a page outside of WHMCS and I've verified that a data feed works but only for products where pricing is set within the product.

Most of our products pricing comes from configurable options as the total price is customer selected value x price per slot

so for example, if the slot price is £0.50 in a configurable option thats what I need to display on an external page

Edited by Ragonz
Link to comment
Share on other sites

5 hours ago, Ragonz said:

Its a page outside of WHMCS and I've verified that a data feed works but only for products where pricing is set within the product.

if you're using the productsinfo feed, it's only written for products, you'd have to hack it's code, or rewrite a feed from scratch to get a config option price.

as a rough starting point, the data feed below should give you a configurable option price...

<?php

use WHMCS\Application;
use Illuminate\Database\Capsule\Manager as Capsule;

require("../init.php");

/*
*** USAGE SAMPLES ***

<script language="javascript" src="feeds/configprice.php?config=1&billingcycle=monthly&currency=1"></script>

*/
$whmcs = Application::getInstance();
$config = $whmcs->get_req_var('config');
$billingCycle = $whmcs->get_req_var('billingcycle');
$currencyID = $whmcs->get_req_var('currency');
$price = Capsule::table('tblpricing')->where('tblpricing.type','configoptions')->where('tblpricing.currency',$currencyID)->where('tblpricing.relid',$config)->value($billingCycle);
$price = formatCurrency($price);

echo "document.write('".$price."');";

you just need to pass it three variables...

  1. configurable option ID.
  2. billingcycle.
  3. currency.

and then pass them like this...

<script language="javascript" src="feeds/configprice.php?config=1&billingcycle=monthly&currency=1"></script>

O8gUsqE.png

I say it's only rough because i'm not currently doing any validation on the passed fields, e.g checking it's a valid config option and/or currency etc... you can add them in if you need them...

Link to comment
Share on other sites

Excellent as always Brian :)

Only question is where to find the config option ID?

I go to Setup > Products/Services > Configurable options then select the config option and it tells me the ID is 55 then I click on the configurable option within that "group" for the actual pricing and it tells me its ID is 69 however both 55 and 69 do not give the price set within

Link to comment
Share on other sites

9 minutes ago, Ragonz said:

Only question is where to find the config option ID?

there are a few ways - looking in the db tables; taking the cid value from the popup window when editing the config option...

Quote

configproductoptions.php?manageoptions=true&cid=16

... but I suppose one of the simplest would be to view the source in the browser, inspect element on the config option...

so let's say we use "7 Ways to Die" and look at the Additional Memory dropdown...

3QtichQ.png

so if you wanted the 2GB price, the config id would be 578 and depending on whether you pass "monthly" or "annually" as the billingcycle, it should give you the correct price...

I think there may be an issue with sliders, but have a play with the other options and let me know if there is...

Link to comment
Share on other sites

12 minutes ago, Ragonz said:

Yea its the game slot one I'm after which is a slider, according to that it should be id 69 but that returns a value of £0.70 when its set within the config option to be £0.80 per slot

ok, leave it with me - I can see the relationship in the tables now...

are you happy to pass that it's a slider in the feed URL or would you want the feed to detect whether it's a slider ?

Link to comment
Share on other sites

15 hours ago, Ragonz said:

Whatever is the least work for you bud, appreciate all the effort you put in.

ok, to keep it simple there are two quick ways to get the config value of a slider - either add {debug} to the template and you can see if it the $configurableoptions array...

eHCcbEM.png

or in the admin area, setup -> products/services -> configurable options -> *choose config option group* and then in the popup window, Inspect Element on the slider name...

kTquH4G.png

... and in the source, it will show the config option iD value that you can use in the feed...

<script language="javascript" src="feeds/configprice.php?config=23&billingcycle=monthly&currency=1"></script>

iBtyBwP.png

i've also tweaked the data feed code to give it a quantity option, in case you need to show the price for x number of a particular option.

<?php

use WHMCS\Application;
use Illuminate\Database\Capsule\Manager as Capsule;

require("../init.php");

/*
*** USAGE SAMPLES ***

<script language="javascript" src="feeds/configprice.php?config=1&billingcycle=monthly&currency=1"></script>

*/
$whmcs = Application::getInstance();
$config = $whmcs->get_req_var('config');
$billingCycle = $whmcs->get_req_var('billingcycle');
$currencyID = $whmcs->get_req_var('currency');
$qty = $whmcs->get_req_var('qty');
$price = Capsule::table('tblpricing')->where('type','configoptions')->where('currency',$currencyID)->where('relid',$config)->value($billingCycle);
if ($qty) {$price = $price * intval($qty);}
$price = formatCurrency($price);

echo "document.write('".$price."');";

and then to pass it in the feed...

<script language="javascript" src="feeds/configprice.php?config=23&billingcycle=monthly&currency=1&qty=24"></script>

iewBO1q.png

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