0

I am trying to figure out how to modify this code snippet so I can pull the gstexempt value from the #__kiduka_accounts table, check if it is set to 0 or 1 and apply the tax value accordingly.

$db = JFactory::getDBO();
    $query = 'SELECT a.id, a.gstexempt FROM #__users as u
        LEFT JOIN #__kiduka_accounts as a ON u.id = a.user_id 
        WHERE u.gid < 23';
    if(JRequest::getInt('membertype', 0) > 0)
    {
        $query .= ' AND a.membertype = '.JRequest::getInt('membertype', 0);
    }
    $db->setQuery($query);
    $users = $db->loadResultArray();
    $query = 'SELECT * FROM #__kiduka_products WHERE id = '.JRequest::getVar('purchaseproduct');
    $db->setQuery($query);
    $product   = $db->loadObject();
    $params    = JComponentHelper::getParams('com_kiduka');
    $tax       = $params->get('tax');
    $gstexempt = $users->gstexempt;

    if ($gstexempt != 1) {

        $subtotal   = $product->price;
        $taxtotal   = $subtotal * $tax / 100;
        $finaltotal = $taxtotal + $subtotal;

    } else {

        $subtotal   = $product->price;
        $taxtotal   = "0.00";
        $finaltotal = $subtotal;

    }

Can anyone share some insight on what I need to change to make this work?

Thank you.

Mike

Mike Hermary
  • 346
  • 7
  • 22
  • How is this code functioning differently than what you're looking for it to do? – DaOgre Jan 14 '13 at 23:19
  • @DaOgre Sorry for not being as clear as should have in my first post. I am trying to pull the gstexempt value from the database for each user, but I think the use of the loadResultArray database function is causing this to not work correctly. When I run this function, the gstexempt if statement is ignored and the gst is always being applied. – Mike Hermary Jan 14 '13 at 23:31

1 Answers1

0

Try doublechecking the sql query you're running, and run it directly on the server to verify it's giving the result you're expecting there. One of the lines that looked to me like it might be causing an issue is the join.

If you're doing a join on a hardcoded user row (g.id = 23) are you sure this record doesn't have a value of 1?

Try doing a print_r on users right after you set it and look at the database result structure (and/or post it here)

DaOgre
  • 2,080
  • 16
  • 25
  • I have run the SQL query in phpMyAdmin and the gstexempt value is being selected, whether it is set to 0 or 1. The g.id is the user group id in Joomla, so there could be dozens of users associated with one group. I have tried using the print_r function, but because of the MVC architecture in Joomla, the printed results are not being displayed in the view. – Mike Hermary Jan 16 '13 at 18:59