Same Initial Billing Address and Shipping Address

  • Posts: 109
  • Thank you received: 5
9 years 6 months ago #200629

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.8.11

Hello, there.

Good evening!

In the before_address function in controllers/checkout.php, the following code retrieves the same address ID for both billing address and shipping address (even though the IDs for the existing billing address and shipping address are different).

if($user_id){
	$app = JFactory::getApplication();
	$shipping = $app->getUserState( HIKASHOP_COMPONENT.'.shipping_address',0 );
	$billing = $app->getUserState( HIKASHOP_COMPONENT.'.billing_address',0 );

Please could you let me know where the billing address and shipping address IDs are set in the user states and how to correct this problem?

This problem occurs when the "Checkout" button is clicked.

Thanks.

Take care!

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 6 months ago #200637

Hi,

It's normal that when you access the checkout you get the same address selected by default. The system just take the first address and select it for both billing and shipping.

If you want to change the way the system selects the default shipping and billing addresses on the checkout, you want to change the code:

$db = JFactory::getDBO();
					$db->setQuery('SELECT address_id FROM '.hikashop_table('address').' WHERE address_published=1 AND address_user_id='.$user_id);
					$address_id = $db->loadResult();
					$app->setUserState( HIKASHOP_COMPONENT.'.shipping_address',$address_id );
					$app->setUserState( HIKASHOP_COMPONENT.'.billing_address',$address_id );
in the file components/com_hikashop/controllers/checkout.php
But I can't say what to do since I don't understand what you want. There are no "existing billing address and shipping address" for a user account. All the addresses of a user can be used for both billing and shipping.

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

  • Posts: 109
  • Thank you received: 5
9 years 6 months ago #200692

Thanks for the prompt response, Nicolas. Much appreciated.

However, changing the code that you refer to doesn't help with changing the default shipping and billing addresses.

The default shipping and billing addresses are already set in the __construct function in the file components/com_hikashop/controllers/checkout.php. As a test, I have added the following code into the __construct function.

function __construct($config = array(),$skip=false) {
dumpMessage('in __contstruct in controllers/checkout.php');
$app = JFactory::getApplication();
$temp1 = $app->getUserState( HIKASHOP_COMPONENT.'.shipping_address',0 );
$temp2 = $app->getUserState( HIKASHOP_COMPONENT.'.billing_address',0 );
dump($temp1, '$temp1 in __construct');
dump($temp2, '$temp2 in __construct');

The results are as attached.

As per the results, the default values are already set in the __construct function (presumably when the user logs in).

Please let me know where these values are set; I think they are set even before the before_address function that you refer to in your code below.

Thanks.

Take care!

Attachments:

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

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 6 months ago #200718

Hi,

It depends how you test actually.
But yes, it would be possible that these were already set before.
In that case, you want to look at the code:

					$app->setUserState( HIKASHOP_COMPONENT.'.shipping_address', $address->address_id );
					$app->setUserState( HIKASHOP_COMPONENT.'.billing_address', $address->address_id );
in the onLoginUser function of the plugins/system/hikashopuser/hikashopuser.php file.

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

  • Posts: 109
  • Thank you received: 5
9 years 6 months ago #200936

Thanks, Nicolas.

That's great; exactly what I am after.

Take care!

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

Time to create page: 0.062 seconds
Powered by Kunena Forum