Getting address from Easy Social Profile with php code

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285605

-- HikaShop version -- : 3.2.2
-- Joomla version -- : 3.8.3
-- PHP version -- : PHP 7.1.7 .
-- Browser(s) name and version -- : firefox
-- Error-message(debug-mod must be tuned on) -- : n/a

Hi Hika Shop Team
I am reading documentation for Hika Shops email system.

www.hikashop.com/support/documentation/5...fig.html#main_emails

Address format:

You can specify here the normal format HikaShop will use to display the addresses on invoices, on the checkout, on emails, etc.
The tags used here correspond to the column name of the address fields that you can find via the menu Display->Custom fields.
It is also possible to add custom PHP code and get the address data with such PHP:


When I go to this place in my Joomla back end I see the following:

Mini address format:
{address_lastname} {address_firstname} - {address_street}, {address_state} ({address_country})

Address format:
{address_company}
{address_title} {address_firstname} {address_lastname}
{address_street}
{address_post_code} {address_city} {address_state}
{address_country}
<?php echo JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}');?>

Mark Lee from Stackideas kindly told me that I can pull an address from their component with the following:
<?php
include_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');

// Assuming that $id is the id of the user.
$user = ES::user($id);

$address =  $user->getFieldValue('ADDRESS');

echo $address->address;

Is it possible to get this to work = Hika Shop pulls the dress from Stackideas?

I am not a coder so any help would be gratefully appreciated.

thanks

Paul

Last edit: 6 years 10 months ago by paurray.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 years 10 months ago #285609

Hi,

Supposing that you remove the capability for the customers to edit/create/delete/select addresses on the checkout, you could add such code in the emails/invoice/order details views and replace $id by the id of the customer in the order.
It will be in either $data->cart->customer->user_cms_id, or $this->order->customer->user_cms_id etc based on where you do the change.
But for HikaShop to be able to pull the data of the address of EasySocial in HikaShop so that the addresses of EasySocial can be selected/modified/deleted, etc in HikaShop will require some heavy development for a synchronization system.

However, if you don't know coding at all, even the easy solution won't be possible. I would recommend to ask for help from a PHP developer to help you with that.

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285656

Hi Nicolas

Supposing that you remove the capability for the customers to edit/create/delete/select addresses on the checkout, you could add such code in the emails/invoice/order details views and replace $id by the id of the customer in the order.


I have already done so.

As I am selling digital products the address is not such a big deal.

I just thought that it would be a "nice to have"

I guess that the really quick and dirty solution would be...

to remove the Mini address format:
{address_lastname} {address_firstname} - {address_street}, {address_state} ({address_country})

and remove Address format:
{address_company}
{address_title} {address_firstname} {address_lastname}
{address_street}
{address_post_code} {address_city} {address_state}
{address_country}
<?php echo JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}');?>

And then the address just does not display. Right?

In all fairness Easy Social has amazing profiles etc and any profile integration will go in the other direction.

But for HikaShop to be able to pull the data of the address of EasySocial in HikaShop so that the addresses of EasySocial can be selected/modified/deleted, etc in HikaShop will require some heavy development for a synchronization system.


Kind of lossing you here but I will be looking at the mails at some point & yes will probably need to get a developer to look at this... :whistle:

It will be in either $data->cart->customer->user_cms_id, or $this->order->customer->user_cms_id etc based on where you do the change.


FYI I have made good progress with he help of a developer getting the following working:

  • Register/Login from Hika Shop Page is redirected to Easy Social.

    Some one who purchases a Hika Shop product gets put in an Easy Social Group
.

thanks

Paul

Last edit: 6 years 10 months ago by paurray.

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285679

I tried the code Stackideas suggested and it stripped out the address.

They have not given up on me. :silly:

And I will post a solution if/and when they figure this out.

Last edit: 6 years 10 months ago by paurray.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 years 10 months ago #285657

You can empty the "address format" yet.
Then, you want to edit the "show_block_address" or "address" files of the "checkout" view and add such code at the top:

<?php
include_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');

// Assuming that $id is the id of the user.
$user = JFactory::getUser();
$user = ES::user($user->id);

$address =  $user->getFieldValue('ADDRESS');

echo $address->address;
return;
?>
That way, on the checkout you'll have the address from easysocial displayed.
And you won't have any address on the other views that the customer can access. Then, as I said, you can add that code, changing the $id variable in the emails, etc.
If you're savvy, you might be able to do it without a developer, but a developer will be able to do that easily for you so it should be quite cheap.

Last edit: 6 years 10 months ago by Jerome. Reason: [code] tag

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285723

Ok Stackideas take support to the next levlel again. :woohoo:

Inserting this here takes care of the address being pulled from Easy Social:

<?php
include_once(JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/easysocial.php');

// Assuming that $id is the id of the user.
$user = ES::user($data->cart->customer->user_cms_id);

$address =  $user->getFieldValue('ADDRESS');

echo $address->value->address;

And inserting this in the same place:

$hikaredirect = JFactory::getApplication();

$hikaredirect->redirect(FRoute::profile(), false);

Takes care of the address thing.

So for example clicking:

www.finalbug.net/store/address

When logged in as exampleone

takes me here:

www.finalbug.net/exampleone

And

clicking:

www.finalbug.net/store/address

When logged in as exampletwo

takes me here:

www.finalbug.net/exampletwo

etc

I just thought that i would share this.
Maybe it is useful for some one else.

best

Paul

Attachments:
Last edit: 6 years 10 months ago by paurray.
The following user(s) said Thank You: nicolas

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285800

Ok the last piece of code the redirect code causes more problems than it is worth.

a) Empty Hika Shop Addresses do not get redirected to Easy Social Profiles.
b) Pressing "Finish" in the cart process takes me to my Easy Social Profile.

If any one has any tips I am all ears.

If not I will talk with a developer at some point in the future.

best

Paul

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 years 10 months ago #285806

Hi,

You should try something like that:

if(empty($address->value->address)){
$hikaredirect = JFactory::getApplication();

$hikaredirect->redirect(FRoute::profile(), false);
}
That way, it won't redirect if there is an address but will redirect if there is none.

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285844

Hi Nicolas

Thanks for going the extra mile :cheer:

b) Pressing "Finish" in the cart process takes me to my Easy Social Profile.

This problem is now solved.

The thing is that every user created on the site has:

Country*Germany
State*Baden-Württemberg

I just double checked this with a brand new user account.

Is this normal?

My guess is that I set this somewhere at some point but have no idea!?!

FYI. I can use Easy Social to force the entry of an address on registration.

This will also help make the workflow flow.

thanks

Paul

Attachments:

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285851

Can not help wondering if maybe it is a happy coincidence that their is an address in there in HikaShop!?!

Maybe if the code could the redirect when there is an address:

Country*Germany
State*Baden-Württemberg

And does not mess up the “Finish” part in the shop`

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 years 10 months ago #285847

Hi,

The default country/state on the registration form of HikaShop are the ones that you configured in the corresponding custom fields in the menu Display>Custom fields.
You can have them more dynamic if you configure the HikaShop geolocation plugin. That way, the country will be the country of the IP of the user.

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

  • Posts: 139
  • Thank you received: 10
6 years 10 months ago #285875

Hi Nicolas

Ahhhhh. The geolocation plugin :silly:
This somehow makes a lot of sense.
I will look into this and do some testing.
As a nice side effect I can then post local prices in my shop = $ in the states, Yen in Japane etc.

very nice

Paul

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

Time to create page: 0.054 seconds
Powered by Kunena Forum