Saturday, October 25, 2025
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy
T3llam
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
T3llam
No Result
View All Result
Home Services & Software

Create a Multilanguage file add subject within the PrestaShop

admin by admin
May 14, 2024
in Services & Software
0
Create a Multilanguage file add subject within the PrestaShop
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


On this weblog, we’re going to discover ways to create a multilanguage file add subject within the HelperForm Class of PrestaShop.

So let’s see collectively how to do this with PrestaShop.

Typically, we have to add information language-wise within the module.

We are going to add the file add subject to the module configuration web page utilizing the renderForm operate.

public operate renderForm()
    {
        $fields_form = [
            'form' => [
                'legend' => [
                    'title' => $this->l('Settings'),
                    'icon' => 'icon-cogs',
                ],
                'enter' => [
                    [
                        'type' => 'file_lang',
                        'label' => $this->l('Multilang image'),
                        'name' => 'WK_MULTILANG_IMG',
                        'lang' => true,
                    ]
                ],
                'submit' => [
                    'title' => $this->l('Save'),
                ],
            ],
        ];

        $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));

        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->desk = $this->desk;
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitStoreConf';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->title . '&tab_module=' . $this->tab . '&module_name=' . $this->title;
        $helper->token = Instruments::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = [
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValues(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        ];

        return $helper->generateForm([$fields_form]);
    }

Within the above code, we used the file kind subject and ‘kind’ => ‘file_lang’ as an alternative of ‘kind’ => ‘file’ and added new params ‘lang’ => true for multilanguage.

The remaining code is identical as we used for type creation.

Now we’ll create type.tpl file on the under path

module_name/views/templates/admin/_configure/helpers/type/

We’ve got overridden the shape.tpl file utilizing our module and use the under code within the type.tpl file

 {extends file="helpers/type/type.tpl"}
 {block title="subject"}
     {if $enter.kind == 'file_lang'}
         <div class="col-lg-8">
             {foreach from=$languages merchandise=language}
                 depend > 1
                     <div class="translatable-field lang-{$language.id_lang}" {if $language.id_lang != $defaultFormLanguage}type="show:none"{/if}>
                 {/if}
                 <div class="form-group">
                     <div class="col-lg-6">
                         <enter id="{$enter.title}_{$language.id_lang}" kind="file" title="{$enter.title}_{$language.id_lang}" class="cover" />
                         <div class="dummyfile input-group">
                             <span class="input-group-addon"><i class="icon-file"></i></span>
                             <enter id="{$enter.title}_{$language.id_lang}-name" kind="textual content" class="disabled" title="filename" readonly />
                             <span class="input-group-btn">
                                 <button id="{$enter.title}_{$language.id_lang}-selectbutton" kind="button" title="submitAddAttachments" class="btn btn-default">
                                     <i class="icon-folder-open"></i> {l s='Select a file' mod='wkmultilangfile'}
                                 </button>
                             </span>
                         </div>
                     </div>
                     depend > 1
                         <div class="col-lg-2">
                             <button kind="button" class="btn btn-default dropdown-toggle" tabindex="-1" data-toggle="dropdown">
                                 {$language.iso_code}
                                 <span class="caret"></span>
                             </button>
                             <ul class="dropdown-menu">
                                 {foreach from=$languages merchandise=lang}
                                 <li><a href="https://webkul.com/weblog/create-a-multilanguage-file-upload-field-in-the-prestashop/javascript:hideOtherLanguage({$lang.id_lang});" id="dropdown-lang-item-link-{$lang.id_lang}" tabindex="-1">{$lang.title}</a></li>
                                 {/foreach}
                             </ul>
                         </div>
                     {/if}
                 </div>
                 <div class="form-group">
                     {if isset($fields_value[$input.name][$language.id_lang]) && $fields_value[$input.name][$language.id_lang] != ''}
                     <div id="{$enter.title}-{$language.id_lang}-images-thumbnails" class="col-lg-12">
                         <img src="{$uri}img/{$fields_value[$input.name][$language.id_lang]}" class="img-thumbnail"/>
                     </div>
                     {/if}
                 </div>
                 depend > 1
                     </div>
                 {/if}
                 <script>
                 $(doc).prepared(operate(){
                     $('#{$enter.title}_{$language.id_lang}-selectbutton').click on(operate(e){
                         $('#{$enter.title}_{$language.id_lang}').set off('click on');
                     });
                     $('#{$enter.title}_{$language.id_lang}').change(operate(e){
                         var val = $(this).val();
                         var file = val.cut up(/[/]/);
                         $('#{$enter.title}_{$language.id_lang}-name').val(file[file.length-1]);
                     });
                 });
             </script>
             {/foreach}
             {if isset($enter.desc) && !empty($enter.desc)}
                 <p class="help-block">
                     {$enter.desc}
                 </p>
             {/if}
         </div>
     {else}
         {$smarty.block.dad or mum}
     {/if}
 {/block}

Within the above code, we prolonged the helper type tpl and overridden the sector block.

we’ve checked the if situation for the file_lang kind subject and wrote the multilanguage subject code and within the else half return the dad or mum subject block for different fields.

Now file add subject will seem language-wise.

Image with multi language

Now we’ll save the photographs language-wise utilizing the code under.

public operate postProcess()
    {
        if (Instruments::isSubmit('submitStoreConf')) {
            $languages = Language::getLanguages(false);
            $values = [];
            $update_images_values = false;

            foreach ($languages as $lang) {
                if (isset($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']])
                    && isset($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['tmp_name'])
                    && !empty($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['tmp_name'])) {
                    if ($error = ImageManager::validateUpload($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']], 4000000)) {
                        return $this->displayError($error);
                    } else {
                        $ext = substr($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['name'], strrpos($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['name'], '.') + 1);
                        $file_name = md5($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['name']) . '.' . $ext;

                        if (!move_uploaded_file($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['tmp_name'], dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $file_name)) {
                            return $this->displayError($this->l('An error occurred whereas making an attempt to add the file.'));
                        } else {
                            if (Configuration::hasContext('WK_MULTILANG_IMG', $lang['id_lang'], Store::getContext())
                                && Configuration::get('WK_MULTILANG_IMG', $lang['id_lang']) != $file_name) {
                                @unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . Configuration::get('WK_MULTILANG_IMG', $lang['id_lang']));
                            }

                            $values['WK_MULTILANG_IMG'][$lang['id_lang']] = $file_name;
                        }
                    }

                    $update_images_values = true;
                }
            }

            if ($update_images_values && isset($values['WK_MULTILANG_IMG'])) {
                Configuration::updateValue('WK_MULTILANG_IMG', $values['WK_MULTILANG_IMG']);
            }

            return $this->displayConfirmation($this->l('The settings have been up to date.'));
        }

        return '';
    }

Right here we did it on the configuration web page.

We are able to do the identical step for the admin controller type.

That’s all about this weblog. Hope it would enable you to.

In case you are going through any points or doubts within the above course of, please be at liberty to contact us within the remark part.

We’d be glad to assist.

Additionally, you’ll be able to discover our PrestaShop Improvement Companies & a wide range of high quality PrestaShop Modules.

For any doubt contact us at [email protected].

author-thumb

RelatedPosts

The state of strategic portfolio administration

The state of strategic portfolio administration

June 11, 2025
You should utilize PSVR 2 controllers together with your Apple Imaginative and prescient Professional – however you’ll want to purchase a PSVR 2 headset as properly

You should utilize PSVR 2 controllers together with your Apple Imaginative and prescient Professional – however you’ll want to purchase a PSVR 2 headset as properly

June 11, 2025
Consumer Information For Magento 2 Market Limit Vendor Product

Consumer Information For Magento 2 Market Limit Vendor Product

June 11, 2025


On this weblog, we’re going to discover ways to create a multilanguage file add subject within the HelperForm Class of PrestaShop.

So let’s see collectively how to do this with PrestaShop.

Typically, we have to add information language-wise within the module.

We are going to add the file add subject to the module configuration web page utilizing the renderForm operate.

public operate renderForm()
    {
        $fields_form = [
            'form' => [
                'legend' => [
                    'title' => $this->l('Settings'),
                    'icon' => 'icon-cogs',
                ],
                'enter' => [
                    [
                        'type' => 'file_lang',
                        'label' => $this->l('Multilang image'),
                        'name' => 'WK_MULTILANG_IMG',
                        'lang' => true,
                    ]
                ],
                'submit' => [
                    'title' => $this->l('Save'),
                ],
            ],
        ];

        $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));

        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->desk = $this->desk;
        $helper->default_form_language = $lang->id;
        $helper->module = $this;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitStoreConf';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->title . '&tab_module=' . $this->tab . '&module_name=' . $this->title;
        $helper->token = Instruments::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = [
            'uri' => $this->getPathUri(),
            'fields_value' => $this->getConfigFieldsValues(),
            'languages' => $this->context->controller->getLanguages(),
            'id_language' => $this->context->language->id,
        ];

        return $helper->generateForm([$fields_form]);
    }

Within the above code, we used the file kind subject and ‘kind’ => ‘file_lang’ as an alternative of ‘kind’ => ‘file’ and added new params ‘lang’ => true for multilanguage.

The remaining code is identical as we used for type creation.

Now we’ll create type.tpl file on the under path

module_name/views/templates/admin/_configure/helpers/type/

We’ve got overridden the shape.tpl file utilizing our module and use the under code within the type.tpl file

 {extends file="helpers/type/type.tpl"}
 {block title="subject"}
     {if $enter.kind == 'file_lang'}
         <div class="col-lg-8">
             {foreach from=$languages merchandise=language}
                 depend > 1
                     <div class="translatable-field lang-{$language.id_lang}" {if $language.id_lang != $defaultFormLanguage}type="show:none"{/if}>
                 {/if}
                 <div class="form-group">
                     <div class="col-lg-6">
                         <enter id="{$enter.title}_{$language.id_lang}" kind="file" title="{$enter.title}_{$language.id_lang}" class="cover" />
                         <div class="dummyfile input-group">
                             <span class="input-group-addon"><i class="icon-file"></i></span>
                             <enter id="{$enter.title}_{$language.id_lang}-name" kind="textual content" class="disabled" title="filename" readonly />
                             <span class="input-group-btn">
                                 <button id="{$enter.title}_{$language.id_lang}-selectbutton" kind="button" title="submitAddAttachments" class="btn btn-default">
                                     <i class="icon-folder-open"></i> {l s='Select a file' mod='wkmultilangfile'}
                                 </button>
                             </span>
                         </div>
                     </div>
                     depend > 1
                         <div class="col-lg-2">
                             <button kind="button" class="btn btn-default dropdown-toggle" tabindex="-1" data-toggle="dropdown">
                                 {$language.iso_code}
                                 <span class="caret"></span>
                             </button>
                             <ul class="dropdown-menu">
                                 {foreach from=$languages merchandise=lang}
                                 <li><a href="https://webkul.com/weblog/create-a-multilanguage-file-upload-field-in-the-prestashop/javascript:hideOtherLanguage({$lang.id_lang});" id="dropdown-lang-item-link-{$lang.id_lang}" tabindex="-1">{$lang.title}</a></li>
                                 {/foreach}
                             </ul>
                         </div>
                     {/if}
                 </div>
                 <div class="form-group">
                     {if isset($fields_value[$input.name][$language.id_lang]) && $fields_value[$input.name][$language.id_lang] != ''}
                     <div id="{$enter.title}-{$language.id_lang}-images-thumbnails" class="col-lg-12">
                         <img src="{$uri}img/{$fields_value[$input.name][$language.id_lang]}" class="img-thumbnail"/>
                     </div>
                     {/if}
                 </div>
                 depend > 1
                     </div>
                 {/if}
                 <script>
                 $(doc).prepared(operate(){
                     $('#{$enter.title}_{$language.id_lang}-selectbutton').click on(operate(e){
                         $('#{$enter.title}_{$language.id_lang}').set off('click on');
                     });
                     $('#{$enter.title}_{$language.id_lang}').change(operate(e){
                         var val = $(this).val();
                         var file = val.cut up(/[/]/);
                         $('#{$enter.title}_{$language.id_lang}-name').val(file[file.length-1]);
                     });
                 });
             </script>
             {/foreach}
             {if isset($enter.desc) && !empty($enter.desc)}
                 <p class="help-block">
                     {$enter.desc}
                 </p>
             {/if}
         </div>
     {else}
         {$smarty.block.dad or mum}
     {/if}
 {/block}

Within the above code, we prolonged the helper type tpl and overridden the sector block.

we’ve checked the if situation for the file_lang kind subject and wrote the multilanguage subject code and within the else half return the dad or mum subject block for different fields.

Now file add subject will seem language-wise.

Image with multi language

Now we’ll save the photographs language-wise utilizing the code under.

public operate postProcess()
    {
        if (Instruments::isSubmit('submitStoreConf')) {
            $languages = Language::getLanguages(false);
            $values = [];
            $update_images_values = false;

            foreach ($languages as $lang) {
                if (isset($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']])
                    && isset($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['tmp_name'])
                    && !empty($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['tmp_name'])) {
                    if ($error = ImageManager::validateUpload($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']], 4000000)) {
                        return $this->displayError($error);
                    } else {
                        $ext = substr($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['name'], strrpos($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['name'], '.') + 1);
                        $file_name = md5($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['name']) . '.' . $ext;

                        if (!move_uploaded_file($_FILES['WK_MULTILANG_IMG_' . $lang['id_lang']]['tmp_name'], dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $file_name)) {
                            return $this->displayError($this->l('An error occurred whereas making an attempt to add the file.'));
                        } else {
                            if (Configuration::hasContext('WK_MULTILANG_IMG', $lang['id_lang'], Store::getContext())
                                && Configuration::get('WK_MULTILANG_IMG', $lang['id_lang']) != $file_name) {
                                @unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . Configuration::get('WK_MULTILANG_IMG', $lang['id_lang']));
                            }

                            $values['WK_MULTILANG_IMG'][$lang['id_lang']] = $file_name;
                        }
                    }

                    $update_images_values = true;
                }
            }

            if ($update_images_values && isset($values['WK_MULTILANG_IMG'])) {
                Configuration::updateValue('WK_MULTILANG_IMG', $values['WK_MULTILANG_IMG']);
            }

            return $this->displayConfirmation($this->l('The settings have been up to date.'));
        }

        return '';
    }

Right here we did it on the configuration web page.

We are able to do the identical step for the admin controller type.

That’s all about this weblog. Hope it would enable you to.

In case you are going through any points or doubts within the above course of, please be at liberty to contact us within the remark part.

We’d be glad to assist.

Additionally, you’ll be able to discover our PrestaShop Improvement Companies & a wide range of high quality PrestaShop Modules.

For any doubt contact us at [email protected].

author-thumb

Previous Post

vivo S19 Professional and Motorola X50 Extremely cease by Geekbench on their method to launch

Next Post

Bumble relationship app removes advertisements mocking celibacy after backlash

Next Post
Bumble relationship app removes advertisements mocking celibacy after backlash

Bumble relationship app removes advertisements mocking celibacy after backlash

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • App (3,061)
  • Computing (4,401)
  • Gaming (9,599)
  • Home entertainment (633)
  • IOS (9,534)
  • Mobile (11,881)
  • Services & Software (4,006)
  • Tech (5,315)
  • Uncategorized (4)

Recent Posts

  • WWDC 2025 Rumor Report Card: Which Leaks Had been Proper or Unsuitable?
  • The state of strategic portfolio administration
  • 51 of the Greatest TV Exhibits on Netflix That Will Maintain You Entertained
  • ‘We’re previous the occasion horizon’: Sam Altman thinks superintelligence is inside our grasp and makes 3 daring predictions for the way forward for AI and robotics
  • Snap will launch its AR glasses known as Specs subsequent 12 months, and these can be commercially accessible
  • App
  • Computing
  • Gaming
  • Home entertainment
  • IOS
  • Mobile
  • Services & Software
  • Tech
  • Uncategorized
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.
Cookie settingsACCEPT
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analyticsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functionalThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessaryThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-othersThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performanceThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policyThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Save & Accept