Vee.K727 Posted August 12, 2021 Share Posted August 12, 2021 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 More sharing options...
Vee.K727 Posted August 13, 2021 Author Share Posted August 13, 2021 I need line breaks at specific points, not at random places. Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 13, 2021 Share Posted August 13, 2021 @Vee.K727 IF you want to give line break of each address field , currently what PrestaShop did. in that case you need to modify the invoice generate class file. If you want to modify the class file, then we can guide you the location to do. Thank you Link to comment Share on other sites More sharing options...
Vee.K727 Posted August 14, 2021 Author Share Posted August 14, 2021 Yes please. Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 14, 2021 Share Posted August 14, 2021 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 More sharing options...
Vee.K727 Posted August 17, 2021 Author Share Posted August 17, 2021 That's a pretty bad way to do it. I can see the function supports passing any kind of line break we want. So the modification should be done where this function is being called. Can you tell me where that is? Link to comment Share on other sites More sharing options...
SmartDataSoft Posted August 17, 2021 Share Posted August 17, 2021 You can check this file line 93 https://github.com/PrestaShop/PrestaShop/blob/develop/classes/pdf/HTMLTemplateDeliverySlip.php Thank you Link to comment Share on other sites More sharing options...
Vee.K727 Posted August 17, 2021 Author Share Posted August 17, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now