Jump to content

retrieve products and prices through the product model with currency and name localized

Recommended Posts

Hello WHMCS Community!

I'm building a custom page on WHMCS that needs to retrieve all the products on a specific product group. In this step so far so good.

But, these products have their names translated into several languages using the dynamic translation and different currency prices, looking into WHMCS Classes Model, I found on Product Model the methods that can retrieve this information in the current language and currency set.

I build a simple loop that catches all the products ID:

  $command = 'GetProducts';
  $productgroupid = 12;
  $postData = array(

    'gid' => $productgroupid,


  $results = localAPI($command, $postData);
  $productsId = array();
  foreach ($results['products']['product'] as $product) {
    $productsId[] = $product['pid'];

After this, I passed this products ID's to Product Model to get the information that I need:

foreach ($productsId as $key => $value) {
  $products[$key] = [
    'name' => Product::find($value)->getNameAttribute(),
    'description' => Product::find($value)->getDescriptionAttribute(),
    'price' => Product::find($value)->pricing(),

This works perfectly well, but the  princing() method return only the default currency. I make a test outside the loop to get only one product and tested with different currencies, and the result is that what I expected:

  $userid = (isset($_SESSION['uid']) ? $_SESSION['uid'] : "");
  $currencyid = (isset($_SESSION['currency']) ? $_SESSION['currency'] : "");
  // $currencyid = 5;
  $currency = getCurrency($userid, $currencyid);

(I have try without the currency variable, and after this passing the ID of currency, and the both cases works good)

Only on the loop the princig() method do not retrieve the correct currency. I'm making a mistake in the loop that is not allowing the currency to recover properly?

Edited by bellafronte
I forgot a link

Share this post

Link to post
Share on other sites

I get this resolved look the Data Feed files architecture. The data feed files can serve as the reference on retrieve this type of information.

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.

  • Similar Content

    • By linux4me
      I noticed in the database that the table tbllog_register has over 89,000 records in it, and tblactivitylog has over 12,000. I have Settings -> General Settings -> Limit Activity Log set to 1000, which apparently doesn't appear to be working for tblactivitylog, although the documentation does say, "Non client related entries will remain."
      I took a look at Utilities -> System -> System Cleanup, and none of the tools there appear to apply to the table tbllog_register. On that page, it shows only 2094 log entries in the Activity Log, so does that mean there are 10,000 non-client-related entries in the table? The Activity Log takes a long time to load even on my dedicated server, so it seems like a good idea to get control of those tables.
      What's the best way to keep the tables tblactivitylog and tbllog_register from getting huge?
    • By ZoXx
      our cronjob made a dataabse backup. 
      The cronjob works fine, but databse backup needs round about 45minutes.
      11.04.2018 08:44    Cron Job: Backup Complete
      11.04.2018 08:44    Cron Job: FTP Backup - Completed Successfully
      11.04.2018 08:44    Cron Job: Backup Generation Completed
      11.04.2018 08:43    Cron Job: Starting Backup Zip Creation
      11.04.2018 08:43    Cron Job: Backup Database Dump Complete
      11.04.2018 08:00    Cron Job: Starting Backup Database Dump
      11.04.2018 08:00    Cron Job: Starting Backup Generation
      11.04.2018 08:00    Cron Job: Completed Daily Automation Tasks
      11.04.2018 08:00    Domain Sync Cron: Completed
      11.04.2018 08:00    Automated Task: Starting WHMCS Updates
      11.04.2018 08:00    Automated Task: Starting Domain Expiry
      11.04.2018 08:00    Automated Task: Starting Client Status Update
      11.04.2018 08:00    Automated Task: Starting Server Usage Stats
      11.04.2018 08:00    Automated Task: Starting Email Marketer Rules
      11.04.2018 08:00    Automated Task: Starting Delayed Affiliate Commissions
      11.04.2018 08:00    Automated Task: Starting Inactive Tickets
      11.04.2018 08:00    Automated Task: Starting Fixed Term Terminations
      11.04.2018 08:00    Automated Task: Starting Overdue Terminations
      11.04.2018 08:00    Automated Task: Starting Overdue Suspensions
      11.04.2018 08:00    Automated Task: Starting Cancellation Requests
      11.04.2018 08:00    Automated Task: Starting Domain Renewal Notices
      11.04.2018 08:00    Automated Task: Starting Invoice & Overdue Reminders
      11.04.2018 08:00    Automated Task: Starting Credit Card Charges
      11.04.2018 08:00    Cron Job: Late Invoice Fees added to 0 Invoices
      11.04.2018 08:00    Automated Task: Starting Late Fees
      11.04.2018 08:00    Automated Task: Starting Invoices
      11.04.2018 08:00    Automated Task: Starting Product Pricing Updates
      11.04.2018 08:00    Automated Task: Starting Currency Exchange Rates
      11.04.2018 08:00    Cron Job: Starting Daily Automation Tasks
      11.04.2018 08:00    Domain Sync Cron: Starting
      Is it normal?
      Is it possible to seperate the cronjob databse to another cronjob that will make a backup maybe at 3 o'clock?
    • By michael24
      i think that "Classes" should get it´s own menu item under developers.whmcs.com. it is somewhat hidden in the footer which is an underrepresentation of something that makes life really easier.
    • By didier1
      Hello, in order to investigate an internittent issue, our SQL admin asked me the table name where we could find every product price - the product price we are looking for falls in the 'other category'
      any help is appreciated
    • By Remitur
      When my server does backup, mysql service is stopped.
      So, for few minutes my WHMCS gives a bad
      Critical Error
      Could not connect to the database.
      It lasts just a couple of minutes, and it's deep inthe night... but it's no nice.
      A custom page with a message like "We're doing system maintenance, for your security... come back soon" (or something like that) would be much better.
      Any idea on how to do it?
  • Recently Browsing   0 members

    No registered users viewing this page.


Important Information

By using this site, you agree to our Terms of Use & Guidelines