skipping blank lines in the address block

  • Posts: 103
  • Thank you received: 7
10 years 2 months ago #166828

-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3

HI - sorry, I'm not sure which forum to post this one it. It should be simple, but I'm just a beginner.

In the invoice that is printed from the backend, I would like to skip blank lines in the address block. My customers don't always have a company name, and the often don't need address2. Currently, those show up as blank lines in the invoice (and also on the address page during the ordering process)... I'd like it to skip those, both in the invoice and on the address confirmation screen during checkout.

Help? Thanks,
Scott

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
10 years 2 months ago #166857

Hi,

You need to edit the file "invoice" of the view "order" for your backend template, the file "show" of the view "address" and the file "address_view" of the view "checkout" for your frontend template via the menu Display>Views.
There, change the line:

echo str_replace("\n","<br/>\n",str_replace("\n\n","\n", trim(preg_replace('#{(?:(?!}).)*}#i','',$html))));
to:
echo str_replace("\n","<br/>\n",str_replace("\n\n","\n", trim(str_replace("\r\n","\n", preg_replace('#{(?:(?!}).)*}#i','',$html)))));
That should remove the empty lines.

The following user(s) said Thank You: jsyaruss

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

  • Posts: 103
  • Thank you received: 7
10 years 1 month ago #170223

Hello again - previously, in this thread, you told me how to skip blank lines in the address block that appears in the printed invoice. That works great.

Now, I'd like to do the same thing - skip blank lines in the address block - but this time, I'd like to do it in the emails that are sent to the admin and to the customer following an order.

I think I've tracked down the file that needs to be edited -- order_admin_notification.preload.php for the admin email, and I think I've identified the line that needs to be edited: echo str_replace("\n","<br/>\n",str_replace("\n\n","\n", trim(preg_replace('#{(?:(?!}).)*}#i','',$html))));

I'm not sure if that's the case or not... BUT, I'm afraid I'm not sure what the proper syntax is to make it skip the blank lines, e.g., for company name or address 2.

Can you please tell me if I'm on the right track, and what the correct syntax would be for this line?

Also, will edits to this php file be overwritten when updates occur? Is there a different way I should do this? Would the business edition allow me to make these edits through the email dialogue? (I have only the essential now, but I wouldn't mind upgrading if it would be possible to do this a bit easier.)

Any guidance would be appreciated. Thanks! Scott

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
10 years 1 month ago #170234

Hi,

Yes, you're on the right track. It's the correct line you found. And this file is for the order admin notification (you'll find similar files with the same code for the notifications that the user will receive so you'll have to do the modification there too).
You basically need to add the code:
str_replace("\r\n","\n",
before the preg_replace
and add a closing parenthesis at the end of the line with all the other parenthesis, like you changed in the invoice view file.

If you edit these email files directly, you'll indeed loose the changes when you update HikaShop. If you upgrade to the Business edition, you'll be able to do the modifications via the menu System>Emails and you won't loose the modifications when you update later on as they will be saved as overrides.

The following user(s) said Thank You: jsyaruss

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

  • Posts: 103
  • Thank you received: 7
10 years 1 month ago #170271

Excellent. Thanks so much. I'm upgrading to the Business edition now, because it would be nice to not have to remake the edits ;-) As always, I appreciate your help. -Scott

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

  • Posts: 103
  • Thank you received: 7
10 years 1 month ago #170289

Sigh. New problem. I purchased the business version and got that to install. (It took a bit to figure it out.)

Then, I went to edit the emails. Unfortunately, when I try to save the email, I get a Forbidden error:

You don't have permission to access /administrator/index.php on this server.

I see elsewhere on the forum that this happened to somebody else, and the recommendation was that they edit the email notifications directly in the folder instead of via the interface. here is the link to that thread: hikashop.com/forum/2-general-talk-about-...il-notification.html

That is not a good solution for me because the whole reason I bought the upgraded version was to get that interface. Do you have any other solutions? This is the only time I receive this error - and oddly I don't get it for all of the emails (e.g., the "out of stock notification" email can be edited and saved with no forbidden error).

I will look forward to your input. Thank you,
Scott

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

  • Posts: 26146
  • Thank you received: 4026
  • MODERATOR
10 years 1 month ago #170291

Hi,

Please create a new thread for your new problem.

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: 103
  • Thank you received: 7
10 years 1 month ago #170364

Hello - returning to the original topic for this thread - about skipping blank lines in the address block for the emails that are sent following an order.

I have tried to follow the instructions given above, but I'm afraid this did not work for me. I still get the blank lines. I must be doing something wrong.

Can you please tell me the correct syntax for changing the order_admin_notification.preload.php file - if indeed that is the file I'm supposed to change?

I think the lines that I need to change are lines 414 and 424. Here's what they look like now:

414:

$vars['BILLING_ADDRESS'] = str_replace(array("\r\n","\r","\n"),'<br/>',str_replace("\r\n","\n",preg_replace('#{(?:(?!}).)*}#i','',$billing)));

424:
$vars['SHIPPING_ADDRESS'] = str_replace(array("\r\n","\r","\n"),'<br/>',str_replace("\r\n","\n",preg_replace('#{(?:(?!}).)*}#i','',$shipping)));

I tried adding in the str_replace("\r\n","\n", before the preg_replace with the closing parenthesis, but I saw no change in the email output.

Line 414 looked like this:
$vars['BILLING_ADDRESS'] = str_replace(array("\r\n","\r","\n"),'<br/>',str_replace("\r\n","\n",str_replace("\r\n", "\n", preg_replace('#{(?:(?!}).)*}#i','',$billing))));

Perhaps I put it in the wrong place? Any advice would be appreciated.

Note: (I still haven't fixed the forbidden access issue; i'm just doing this in an editor and uploading via FTP.)

Thanks!
Scott

Last edit: 10 years 1 month ago by Jerome. Reason: [code] is nice !

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

  • Posts: 103
  • Thank you received: 7
10 years 1 month ago #170365

aw heck...the editor is changing some of the text to smiley faces, but perhaps you'll be able to tell what it was supposed to be. Thanks.

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

  • Posts: 103
  • Thank you received: 7
10 years 1 month ago #170949

I'm just following up on this issue of the blank lines in the address block for the emails. Any thoughts on this? (note that the forbidden error is in another thread and now fixed, so I'm returning to the original topic). Thank you in advance for any response.
Scott

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

  • Posts: 26146
  • Thank you received: 4026
  • MODERATOR
10 years 1 month ago #172307

Hi,

If you want to remove the blank lines, you want to remove the "double carriage return".
Here the original code in the email :

$vars['BILLING_ADDRESS'] = str_replace(array("\r\n","\r","\n"),'<br/>',preg_replace('#{(?:(?!}).)*}#i','',$billing));

Here some code to replace the double carriage return
$vars['BILLING_ADDRESS'] =  preg_replace('#<br\/>\s*<br\/>#i','',str_replace(array("\r\n","\r","\n"),'<br/>',preg_replace('#{(?:(?!}).)*}#i','',$billing)));
This method support the fact that the "blank line" could contain some blank data (space, tabulations, etc).

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: 103
  • Thank you received: 7
10 years 1 month ago #172733

Hi Jerome - Thanks for sending that code... it almost got me there... As a test, I created an order with an address that has all of the following info:

first
last
company
address1
address2
city
PA (state)
15101 (zip)

As it should, the billing address block in the email came out like this:

first last
company
address1
address2
city, Pennsylvania 15101
USA

I then created another order where I took out the "company" data and the "address2" data, since this how most of my orders come in. Then, the email looked like this:

first lastaddress1city, Pennsylvania 15101
USA

It seems to have gotten rid of all of the carriage returns.

I added company back in, and I got this:

first last
company
address1city, Pennsylvania 15101
USA

(missing the carriage return after address1)


Any suggestions for me? Thanks,
Scott

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #172874

Hi,

Could you try that instead:

$vars['BILLING_ADDRESS'] =  preg_replace('#<br\/>\s*<br\/>#i','<br/>',str_replace(array("\r\n","\r","\n"),'<br/>',preg_replace('#{(?:(?!}).)*}#i','',$billing)));

The following user(s) said Thank You: jsyaruss

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

  • Posts: 103
  • Thank you received: 7
10 years 1 month ago #172979

Aah yes. That did it. Thank you so much! We can at last consider this task complete! Much appreciated!
Scott

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

Time to create page: 0.088 seconds
Powered by Kunena Forum