Jump to content

[SOLVED]How to get customer id...


Layn

Recommended Posts

Hello,

i have next piece of code:

       public function hookShoppingCart($params)
       {
           $afa_cart = $params['cart'];
           $car_id = intval($afa_cart->id);
       }



How could i get customer id from there ?

Maybe $customer_id = intval($afa_cart->customer); ?

Link to comment
Share on other sites

Hi,

I already got it with: intval($afa_cart->id_customer)

But now, I'm trying to get a row from the database with the same code:

               $afa_prev_aff = Db::getInstance()->getRow("
                       SELECT affiliate FROM `"._DB_PREFIX_."affiliatesforall`
                       WHERE id_customer = ".intval($afa_cart->id_customer)." order by id_afa desc limit 0,1");
               $affiliate = intval($afa_prev_aff['affiliate']);


The result always is, affiliate=0, and i know is incorrect, because in mysql:


mysql> SELECT affiliate FROM ps_affiliatesforall WHERE id_customer = 18 order by id_afa desc limit 0,1;
+-----------+
| affiliate |
+-----------+
| 3 |
+-----------+



Why always get affiliate=0 ?
Link to comment
Share on other sites

if you just wanna get one value of field `affiliate` from DB table `ps_affiliatesforall` , use this query:

$afa_prev_aff = Db::getInstance()->getValue('SELECT `affiliate` FROM `'._DB_PREFIX_.'affiliatesforall` WHERE `id_customer` = \''.intval($afa_cart->id_customer).'\' ');



But if you wanna get an array value of field `affiliate` from DB table `ps_affiliatesforall` , use this query:

$afa_prev_affs = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'affiliatesforall` ORDER BY id_afa limit 0,1 ');



And to display all `affiliate` value you can use this example :

foreach($afa_prev_affs AS $row)
     echo $row['affiliate']."/n";



Hope this help ...

Link to comment
Share on other sites

Thank you Gonebdg,

I use your code with some modifications :) and it works perfectly.

               $afa_prev_affs = Db::getInstance()->ExecuteS('SELECT affiliate FROM `'._DB_PREFIX_.'affiliatesforall` ORDER BY id_afa desc limit 0,1 ');
               $affiliate = $afa_prev_affs[0]['affiliate'];

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...