contactovisual Posted January 15, 2013 Share Posted January 15, 2013 Prestashop does not allow to define the lang of an attachment. Does anyone knows how to do this? I am working on a 1.4.9 project, and the site has 5 different languages. Some product have a PDF file with instructions. This file is attached to the product, but has to be available to download in the clients active language. When attaching a file to a product, one can define the title and description in the various langs, but not the file itself. If I have a PDF in french and another in english, both files are shown in the product page. This is no good. I made some changes in the database and core files, and succeed to accomplish this, but I wish it would not be necessary to do so. If anyone knows how, please share. What I did: - On the database, table ps_attachment, added a new field (`doc_lang` int(10) default '0') - On file admin/tabs/AdminProducts.php (admin folder might have another name) find function displayFormAttachments($obj, $languages, $defaultLanguage) added around line 2049: echo ' <label>'.$this->l('Document language:').' </label> <div class="margin-form">'; $languages = Language::getLanguages(false); echo ' <select name="doc_lang">'; foreach ($languages as $language) { echo '<option value="'.$language['id_lang'].'">'.$language['name'].'</option>'; } echo ' </select>'; echo ' </div>'; Note: be careful with right formating of divs - On file admin/tabs/AdminAttachments.php find public function displayForm($isMainTab = true) added around line 124: echo ' <label>'.$this->l('Document language:').' </label> <div class="margin-form">'; $languages = Language::getLanguages(false); echo ' <select name="doc_lang">'; foreach ($languages as $language) { echo '<option value="'.$language['id_lang'].'">'.$language['name'].'</option>'; } echo ' </select>'; echo ' </div>'; These two are to define the language of attachement on Administration Product record Now to display on the site only the attachement of the right language: On file classes/Product.php On public static function getAttachmentsStatic($id_lang, $id_product) (around line 2783) Replace return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT * FROM '._DB_PREFIX_.'product_attachment pa LEFT JOIN '._DB_PREFIX_.'attachment a ON a.id_attachment = pa.id_attachment LEFT JOIN '._DB_PREFIX_.'attachment_lang al ON (a.id_attachment = al.id_attachment AND al.id_lang = '.(int)($id_lang).') By return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT * FROM '._DB_PREFIX_.'product_attachment pa INNER JOIN '._DB_PREFIX_.'attachment a ON (a.id_attachment = pa.id_attachment AND a.doc_lang = '.(int)($id_lang).') LEFT JOIN '._DB_PREFIX_.'attachment_lang al ON (a.id_attachment = al.id_attachment AND al.id_lang = '.(int)($id_lang).') WHERE pa.id_product = '.(int)($id_product)); This will make sure that only the active lang attachement is displayed If anyone knows a better solution, without touching the core files, please let me know. Thank you Nelson / Contacto Visual 1 Link to comment Share on other sites More sharing options...
NemoPS Posted January 24, 2013 Share Posted January 24, 2013 You might find this useful: http://nemops.com/prestashop-attachments-language/ Cheers! 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