Select type of receipt on checkout

  • Posts: 6
  • Thank you received: 0
3 years 6 months ago #332121

-- HikaShop version -- : 4.4.0
-- Joomla version -- : 3.9.23
-- PHP version -- : 7.3

Hello,

I would like help with the following:

1) I have a live e-shop where, like many e-shops in my country needs an option in the checkout for what type of receipt the customer wants.
It can be "plain receipt" or "Invoice". If he choses Invoice, some extra fields are needed for the billing (VAT, Company name, tax office, profession). This does not have to do with retail or wholesale. A retail customer may still wish to have an invoice issued instead of a plain receipt. The price will be the same, its just the type or receipt he wants to receive.

So far, I used a custom field in the table "order" for implementing the "type of receipt" option, because this is order specific (a client may sometimes want a plain receipt and another time he may want an invoice).
However, that way, the extra fields in the address are always available. What I really need is those fields to be invisible if he chooses plain receipt.
So I figured that the solution would be to use a custom field in the table "address" for the "receipt type" option (instead of table order ) so I can have the Vat, company, tax office and profession dependent on that field. So they will appear in the form only if he chooses invoice.

This is ok with guests. However, for registered users, the address is not in edit mode during checkout. It should be in edit mode so that the registered clients are forced to choose a receipt type every time they buy something. I saw another post in the forum on that, with instructions on how to display the address in edit mode, but it did not work, maybe because it was 6 years ago. It was about editing the file checkout - address select...

The other solution would be to use the field that I have now for the receipt type, in the order column, but is it possible to have fields from the address table depend on it? I yes, how?

I can't find a similar post, haven't anyone had this issue before? Am I missing something?

2) Also I would like to know how i can distinguish between the Address format of billing address and shipping address. The fields about vat etc do not belong in the shipping address. Ok I have chosen inside the fields options to only be on billing address BUT when I want to fix the format in the "Address format" box I want to put some labels for those fields. And the labels appear in both the billing and the shipping address even though in the shipping address the values of the fields are not there. How can I fix that?

Thank you

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 6 months ago #332130

Hi,

1. What you can try is to add the line:

<?php $this->options['edit_address'] = (!empty($this->cart_addresses['data']) ? key($this->cart_addresses['data']) : true); ?>
at the beginning of the show_block_address view file via the menu Display>Views.
That will force the address block to always be in edit mode with either the first address of the customer in edit mode or a new address if the customer doesn't have any addresses. Hopefully, it should still allow the user to proceed to the next step.

To do the display/hidding of the fields based on a different type of custom field poses two problems:
- You need to add custom javascript to the page to hide/display the address fields based on the order field, and you still have the issue of what happens when an address is already there and the user doesn't edit it.
- If, among the fields you hide, you have required fields, that will still be enforced by the server side. So that would require extra development.

2. You need to add PHP code to it. Same as is done by default for the telephone field:
<?php if(!empty($this->address->address_telephone)) echo JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}');?>
That code will display the text of the TELEPHONE_IN_ADDRESS and the tag address_telephone only if there is something in the address_telephone field.
So if you want to check the type of the address, you could change the condition to be $this->address->address_type == 'shipping' instead of !empty($this->address->address_telephone)

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

  • Posts: 6
  • Thank you received: 0
3 years 6 months ago #332263

1. Thank you but this doesn't work. Also, we don't need to have it always open, just when the user first enters the checkout step. As if he clicked the pencil icon.

2. Thank you, I can use that.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 6 months ago #332266

Hi,

Then you need to adapt the condition.
For example:

<?php 
if(!isset($_SESSION['first_time_for_current_session']))
 $_SESSION['first_time_for_current_session'] = true;
if( $_SESSION['first_time_for_current_session'] && !empty($this->cart_addresses['data']) ){
 $this->options['edit_address'] = key($this->cart_addresses['data']);
$_SESSION['first_time_for_current_session'] = false;
}?>
This will do it only the first time for the current user session, like you said. However, if the user refreshes the page, or if the address view is refreshed in ajax for some reason, then it won't be the first time anymore.... So what is "first" is hard to decide programatically.
That's why I proposed to always have it in edit mode.
The system is not made to work like that so I guess it would require proper development of a custom solution with a few hundred lines of code, outside of the scope of this forum.

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

  • Posts: 18
  • Thank you received: 0
3 years 6 months ago #332510

Thank you, I put this piece of code at the beginning of the file and there was no change. Never mind I will not implement this.

One last question about point 2:
While the custom Address format is shown in checkout and order e-mail, it is not shown in the address on the User profile in the area of "Addresses". Am I missing something?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 6 months ago #332518

Hi,

That would be strange. It's the same view file address / address_template.php which is used for all the frontend where an address needs to be displayed.
Could you provide some screenshots to illustrate the issue ?

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

  • Posts: 18
  • Thank you received: 0
3 years 6 months ago #332529

I think that the reason of this is the condition you suggested about checking if the address is billing or shipping.

Could you please check this and tell me if I am doing it wrong? For example with the following code the address in the checkout works as expected but in the user profile -> addresses it doesnt show the telephone on the billing address

{address_firstname} {address_lastname}
{address_street}
{address_post_code} {address_city} {address_state}
{address_country}
<?php if($this->address->address_type == 'billing') echo JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}');?>

Please advise

Edit. Also I noticed that when I try to edit the shipping address in the user profile, the mini address is not updated.

Last edit: 3 years 6 months ago by kathrin20.

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

  • Posts: 6
  • Thank you received: 0
3 years 6 months ago #332533

following

Last edit: 3 years 6 months ago by attenzo.

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

  • Posts: 18
  • Thank you received: 0
3 years 6 months ago #332536

Nicolas,
I bought the latest version and updated it. It now works as it should.

What I noted about the mini address remains: the mini address is not updated until someone refreshed the page. But I guess this does not have to do with the address format.

Thank you

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 6 months ago #332542

Hi,

Ah yes, that was a bug we fixed recently for the billing / shipping address display.
Regarding the update of the mini address, that's normal. The goal of the address selector is just to select the default address. If the wording in it is not updated after you change the address, the id of the default address doesn't change so it's still working ok.

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

Time to create page: 0.086 seconds
Powered by Kunena Forum