BlueAngelHost Posted December 22, 2020 Share Posted December 22, 2020 Hi, I check data feeds option but I cannot find any option to display the stock status on my html front website. example : https://prnt.sc/w7sd37 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 22, 2020 Share Posted December 22, 2020 1 hour ago, BlueAngelHost said: I check data feeds option but I cannot find any option to display the stock status on my html front website. it would have to be custom written - though it should literally only take a few lines of code... if I quickly modify the productsinfo.php feed to have a stock option, then the code would look like... <?php use WHMCS\Application; use WHMCS\Config\Setting; use WHMCS\Exception\ProgramExit; use WHMCS\Product\Product; use WHMCS\Session; use WHMCS\User\Client; use WHMCS\Database\Capsule; require("../init.php"); /* *** USAGE SAMPLES *** <script language="javascript" src="feeds/productsinfo.php?pid=1&get=name"></script> <script language="javascript" src="feeds/productsinfo.php?pid=1&get=description"></script> <script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly¤cy=1"></script> <script language="javascript" src="feeds/productsinfo.php?pid=1&get=orderurl&carttpl=web20cart"></script> */ $whmcs = App::self(); $pid = (int) $whmcs->get_req_var('pid'); $get = $whmcs->get_req_var('get'); $language = $whmcs->get_req_var('language') ?: null; $data = array(); $name = $description = ''; // Verify user input for pid exists, is greater than 0, and as is a valid id if ($pid > 0) { $data = Capsule::table('tblproducts') ->where('id', '=', $pid) ->first(); $pid = (int) $data->id; $qty = (int) $data->qty; // If there is a user logged in, we will use the client language if (((int) $userId = Session::get('userid'))) { $language = Client::find($userId, array('language'))->language ?: null; } $name = Product::getProductName($pid, $data->name, $language); $description = Product::getProductDescription($pid, $data->description, $language); } // Verify that the pid is not less than 1 to in order to continue. if ($pid < 1) { widgetOutput('Product ID Not Found'); } if ($get=="name") { widgetOutput($name); } elseif ($get=="description") { $description = str_replace(array("\r", "\n", "\r\n"), "", nl2br($description)); widgetOutput($description); } elseif ($get=="configoption") { $configOptionNum = $whmcs->get_req_var('configoptionnum'); if (!$configOptionNum) { widgetOutput('The variable configoptionnum is required when get is configoption.'); } widgetoutput($data['configoption' . (int) $configOptionNum]); } elseif ($get=="orderurl") { $cartTemplate = $whmcs->get_req_var('carttpl'); if ($cartTemplate == "ajax") { $cartTemplate = "ajaxcart"; } $systemUrl = App::getSystemUrl(); if (!$cartTemplate) { $cartTemplate = Setting::getValue('OrderFormTemplate '); } widgetOutput("{$systemUrl}cart.php?a=add&pid={$pid}&carttpl={$cartTemplate}"); } elseif ($get=="price") { // Verify user input for currency exists, is numeric, and as is a valid id $billingCycle = $whmcs->get_req_var('billingcycle'); $currencyID = $whmcs->get_req_var('currency'); if (!is_numeric($currencyID)) { $currency = array(); } else { $currency = getCurrency('', $currencyID); } if (!$currency || !is_array($currency) || !isset($currency['id'])) { $currency = getCurrency(); } $currencyID = $currency['id']; $data = Capsule::table('tblpricing') ->where('type', '=', 'product') ->where('currency', '=', $currencyID) ->where('relid', '=', $pid) ->first(); $price = $data->$billingCycle; $price = formatCurrency($price); widgetOutput($price); } elseif ($get=="qty") { widgetOutput($qty); } else { widgetOutput('Invalid get option. Valid options are "name", "description", "configoption", "orderurl", "qty" or "price"'); } /** * The function to output the widget data to the browser in a javascript format. * * @throws WHMCS\Exception\ProgramExit * @param string $value the data to output */ function widgetOutput($value) { echo "document.write('".addslashes($value)."');"; throw new ProgramExit(); } however, do not modify the existing productsinfo.php file as it will get overwritten during an update... create a new .php file in the feeds folder, call it productstock.php (or whatever) and then to display a stock quantity for a given product, you would call the feed using... <script language="javascript" src="feeds/productstock.php?pid=1&get=qty"></script> the feed will return the stock quantity for the product, but will not contain any styling (unlike your image) - you can add your styling to the template or the feed, whichever you're more comfortable doing. 1 Quote Link to comment Share on other sites More sharing options...
BlueAngelHost Posted December 22, 2020 Author Share Posted December 22, 2020 thank you very much 🙂 0 Quote Link to comment Share on other sites More sharing options...
cahdx Posted December 22, 2020 Share Posted December 22, 2020 5 hours ago, brian! said: it would have to be custom written - though it should literally only take a few lines of code... if I quickly modify the productsinfo.php feed to have a stock option, then the code would look like... <?php use WHMCS\Application; use WHMCS\Config\Setting; use WHMCS\Exception\ProgramExit; use WHMCS\Product\Product; use WHMCS\Session; use WHMCS\User\Client; use WHMCS\Database\Capsule; require("../init.php"); /* *** USAGE SAMPLES *** <script language="javascript" src="feeds/productsinfo.php?pid=1&get=name"></script> <script language="javascript" src="feeds/productsinfo.php?pid=1&get=description"></script> <script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly¤cy=1"></script> <script language="javascript" src="feeds/productsinfo.php?pid=1&get=orderurl&carttpl=web20cart"></script> */ $whmcs = App::self(); $pid = (int) $whmcs->get_req_var('pid'); $get = $whmcs->get_req_var('get'); $language = $whmcs->get_req_var('language') ?: null; $data = array(); $name = $description = ''; // Verify user input for pid exists, is greater than 0, and as is a valid id if ($pid > 0) { $data = Capsule::table('tblproducts') ->where('id', '=', $pid) ->first(); $pid = (int) $data->id; $qty = (int) $data->qty; // If there is a user logged in, we will use the client language if (((int) $userId = Session::get('userid'))) { $language = Client::find($userId, array('language'))->language ?: null; } $name = Product::getProductName($pid, $data->name, $language); $description = Product::getProductDescription($pid, $data->description, $language); } // Verify that the pid is not less than 1 to in order to continue. if ($pid < 1) { widgetOutput('Product ID Not Found'); } if ($get=="name") { widgetOutput($name); } elseif ($get=="description") { $description = str_replace(array("\r", "\n", "\r\n"), "", nl2br($description)); widgetOutput($description); } elseif ($get=="configoption") { $configOptionNum = $whmcs->get_req_var('configoptionnum'); if (!$configOptionNum) { widgetOutput('The variable configoptionnum is required when get is configoption.'); } widgetoutput($data['configoption' . (int) $configOptionNum]); } elseif ($get=="orderurl") { $cartTemplate = $whmcs->get_req_var('carttpl'); if ($cartTemplate == "ajax") { $cartTemplate = "ajaxcart"; } $systemUrl = App::getSystemUrl(); if (!$cartTemplate) { $cartTemplate = Setting::getValue('OrderFormTemplate '); } widgetOutput("{$systemUrl}cart.php?a=add&pid={$pid}&carttpl={$cartTemplate}"); } elseif ($get=="price") { // Verify user input for currency exists, is numeric, and as is a valid id $billingCycle = $whmcs->get_req_var('billingcycle'); $currencyID = $whmcs->get_req_var('currency'); if (!is_numeric($currencyID)) { $currency = array(); } else { $currency = getCurrency('', $currencyID); } if (!$currency || !is_array($currency) || !isset($currency['id'])) { $currency = getCurrency(); } $currencyID = $currency['id']; $data = Capsule::table('tblpricing') ->where('type', '=', 'product') ->where('currency', '=', $currencyID) ->where('relid', '=', $pid) ->first(); $price = $data->$billingCycle; $price = formatCurrency($price); widgetOutput($price); } elseif ($get=="qty") { widgetOutput($qty); } else { widgetOutput('Invalid get option. Valid options are "name", "description", "configoption", "orderurl", "qty" or "price"'); } /** * The function to output the widget data to the browser in a javascript format. * * @throws WHMCS\Exception\ProgramExit * @param string $value the data to output */ function widgetOutput($value) { echo "document.write('".addslashes($value)."');"; throw new ProgramExit(); } however, do not modify the existing productsinfo.php file as it will get overwritten during an update... create a new .php file in the feeds folder, call it productstock.php (or whatever) and then to display a stock quantity for a given product, you would call the feed using... <script language="javascript" src="feeds/productstock.php?pid=1&get=qty"></script> the feed will return the stock quantity for the product, but will not contain any styling (unlike your image) - you can add your styling to the template or the feed, whichever you're more comfortable doing. Is there a way to do the same but with the price of a product with X currency? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 23, 2020 Share Posted December 23, 2020 15 hours ago, Eldremor said: Is there a way to do the same but with the price of a product with X currency? if you just wanted to show a product price using a feed, then you can already do that... <script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly¤cy=1"></script> or are you looking to return both a product price and it's stock quantity at the same time to be used together? 0 Quote Link to comment Share on other sites More sharing options...
Shamon Posted December 23, 2020 Share Posted December 23, 2020 (edited) On 12/22/2020 at 7:10 PM, brian! said: <script language="javascript" src="feeds/productsinfo.php?pid=1&get=price&billingcycle=monthly¤cy=1"></script> Hi @brian! How can I change currency based on country in it? Edited December 23, 2020 by HEROCLOUDS 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 24, 2020 Share Posted December 24, 2020 13 hours ago, HEROCLOUDS said: How can I change currency based on country in it? are you thinking of a free geolocation solution such as ModulesGarden's ? https://marketplace.whmcs.com/product/3150-geolocation-hook-for-whmcs 0 Quote Link to comment Share on other sites More sharing options...
Shamon Posted December 24, 2020 Share Posted December 24, 2020 1 hour ago, brian! said: are you thinking of a free geolocation solution such as ModulesGarden's ? It will change currency automatically when we using <script language="javascript" src="feeds/productstock.php?pid=1&get=price"></script> ?? Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 25, 2020 Share Posted December 25, 2020 once you know the current currency, then you can use that in the feed... 1 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted December 28, 2020 Share Posted December 28, 2020 On 12/24/2020 at 8:57 PM, brian! said: are you thinking of a free geolocation solution such as ModulesGarden's ? https://marketplace.whmcs.com/product/3150-geolocation-hook-for-whmcs I have two currencies one my Country currency and another is USD. Will this Geolocation Hook For WHMCS work fine for me ? Thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 29, 2020 Share Posted December 29, 2020 23 hours ago, ManagedCloud-Hosting said: I have two currencies one my Country currency and another is USD. Will this Geolocation Hook For WHMCS work fine for me ? if you wanted new users from your country to default to that country's currency and other users to be shown USD prices, then it should work for that (assuming the users weren't using a VPN) - obviously existing users wouldn't be affected as they can't change their currencies. 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.