Get user address outside hikashop

  • Posts: 1119
  • Thank you received: 114
6 years 8 months ago #274013

Hi,

I am trying to get user address inside easy profile view.
What I want is to show user shipping address street, city, zip and use them to show location on google map....

I have read this topic www.hikashop.com/support/forum/developme...ikashop-address.html and used code below Provided by Nicolas 3 years ago:

// Get a db connection.
$db = JFactory::getDbO();
$db->setQuery('SELECT user_id FROM #__hikashop_user WHERE user_cms_id = ' . (int) $userId);
$hikashop_id = $db->loadResult();

$db->setQuery('SELECT * FROM #__hikashop_address WHERE address_user_id =' . (int) $hikashop_id);
$address = $db->loadObject();

//then you can do like that to get the address_street  for example:
echo $address->address_street;

Issue is that I get address of wrong user. I think some connection between user id is missing but as I have never done something similar I need help here. Could it be that code has changed after 3 years?

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
6 years 8 months ago #274017

Please ignore. Found the issue.

Have a great day

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
6 years 8 months ago #274066

Hi,

It looks like I still need some little help here.

I have customizes profile view and it shows location on google map based on entered address in hikashop address listing...However issue is that if you have 2 or more addresses using "echo $address->address_street;" will give first entered/created address and NOT selected in address listing.

So question. Is it possible to get default selected address using those queries? Else easiest way will be to limit user to have only one address.

Many thanks

Last edit: 6 years 8 months ago by kyratn.

Please Log in or Create an account to join the conversation.

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 8 months ago #274071

Hello,

$query = 'SELECT a.* FROM #__hikashop_address AS a INNER JOIN #__hikashop_user AS u ON a.address_user_id = u.user_id WHERE u.user_cms_id = ' . (int)$userId.' AND a.address_published = 1 AND a.address_default = 1';

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: kyratn

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
6 years 8 months ago #274106

Hi,

Thank you Jerome. It really helped.

Gave a great day

Please Log in or Create an account to join the conversation.

  • Posts: 9
  • Thank you received: 1
6 years 7 months ago #275989

Hi,
I am using Google Matrix API to calculate distance between users address and the pre-difined store addresses, include js code inside checkout.php.

I want to appoligize about my english and php skill, im new at both of them.
My idea is to make a popup or similar when the user is about to order, that inform him about a store near his address location, otherwise he will pay the shipping ports.
As you can see on the code i'll send, on the line 714, there are a variable that should get the user address, so that google api could calculate the distance between the locations and return the shortest one.

Thank you!

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 7 months ago #275990

Hello,

Your customization is based on HikaShop 2.6.0 which is an old version of HikaShop.
You should update to a more HikaShop version.

Please do not edit the HikaShop core files such as the controllers.
HikaShop is based on the MVC system of Joomla and gives you the possibility to override every views.
So it will be safer and better to use a view override instead of modifying a core file.

The previous given code allow to load an address object from the database but in your case, you want a formatted address, which implicates the usage of the HikaShop address class to convert an object into a human readable address such as "displayAddress" function or "miniFormat" (but these two functions also need to load the address custom field).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 9
  • Thank you received: 1
6 years 7 months ago #276100

Hi Jerome,

Thank you for the warning about core files, such checkout.php. When you said that i should override the view(s), you mean files like address_view.php on this path ./components/com_hikashop/views/checkout/tmpl ? ill send you the example.

Sorry again, php is not my strongest. I really need help to finish this.
Thank you for all the support.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
6 years 7 months ago #276101

Hello,

I mean using the view override system provided by Joomla MVC system.
www.hikashop.com/support/documentation/1...-display.html#layout

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: vadim_29

Please Log in or Create an account to join the conversation.

  • Posts: 9
  • Thank you received: 1
6 years 7 months ago #276166

Hi Gerome,
Thank you so much, you are a life saver. Following your wisdom, i managed to get the correct user address.

The following user(s) said Thank You: Jerome

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum