Jump to content

Add line breaks to address in invoice


Vee.K727

Recommended Posts

I have added my address through backend - Shop Parameters > Contact > Stores. In there, there are different fields for address line 1, line 2, city, state and so on. In the invoice, this address is displayed in a single line. Is there a way to add some line breaks between different fields I filled out? 

In pdf/footer.php I have

{if isset($shop_details)}
    {$shop_details|escape:'html':'UTF-8'}<br />
{/if}

Where does this $shop_details come from? Can it be messed with? Or are there separate variables available for the different fields?

Thanks

Link to comment
Share on other sites

1 hour ago, Vee.K727 said:

Yes please.

/1.7.7.0/classes/AddressFormat.php line  440 generateAddress

    public static function generateAddress(Address $address, $patternRules = [], $newLine = self::FORMAT_NEW_LINE, $separator = ' ', $style = [])
    {
        $addressFields = AddressFormat::getOrderedAddressFields($address->id_country);
        $addressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($address, $addressFields);

        $addressText = '';
        foreach ($addressFields as $line) {
            if (($patternsList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY))) {
                $tmpText = '';
                foreach ($patternsList as $pattern) {
                    if ((!array_key_exists('avoid', $patternRules)) ||
                                (is_array($patternRules) && array_key_exists('avoid', $patternRules) && !in_array($pattern, $patternRules['avoid']))) {
                        $tmpText .= (isset($addressFormatedValues[$pattern]) && !empty($addressFormatedValues[$pattern])) ?
                                (((isset($style[$pattern])) ?
                                    (sprintf($style[$pattern], $addressFormatedValues[$pattern])) :
                                    $addressFormatedValues[$pattern]) . $separator) : '';
                    }
                }
                $tmpText = trim($tmpText);
                $addressText .= (!empty($tmpText)) ? $tmpText . $newLine : '';
            }
        }

        $addressText = preg_replace('/' . preg_quote($newLine, '/') . '$/i', '', $addressText);
        $addressText = rtrim($addressText, $separator);

        //return "this is first name and last name";
        return $addressText;
    }

You can modify this line and add your new line or what you want in $addressText variable

Thank you

Link to comment
Share on other sites

Close. That's the delivery address though. The actual place where shop address is coming from is classes/pdf/HTMLTemplate.php Line 82.

protected function getShopAddress()
{
  $shop_address = '';

  $shop_address_obj = $this->shop->getAddress();
  if (isset($shop_address_obj) && $shop_address_obj instanceof Address) {
  $shop_address = AddressFormat::generateAddress($shop_address_obj, [], ' - ', ' ');
  }

  return $shop_address;
}

Tried adding `<br />` tag here but it gets literally printed in the invoice. Not sure why.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...