Prestashop 1.7 add Fields in contact us form - field

I had a little problem on Prestashop 1.7.2.0, I want to add some field in my contact us form but don't know how to proceed.
I just find tuto for PS 1.6.
If someone could help me.
Thanks a lot

Here a no update resistant solution to add a field Name:
I tried the following thing to add a field (and remember this solution is not update proof and the additional fields are not safed in the backoffice):
Update contact.html + contact.txt in the theme/mails folder:
<span style="color:#333"><strong>Name: {contactname}</strong></span><br /><br />
Add the contactname line to the $var_list array in the file contactform.php located in the modules/contactform folder:
$var_list = [
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
'{contactname}' => Tools::nl2br(stripslashes($contactname)),
];
Add a line to the beginning of the function sendMessage(){ in the same file (contactform.php)
$contactname = trim(Tools::getValue('contactname'));
Add the following lines to the part in the file contactform.tpl located in the theme/modules/contactform/views/template/widget folder:
<div class="form-group row">
<label class="col-md-3 form-control-label">{l s='Name' d='Shop.Forms.Labels'}</label>
<div class="col-md-6">
<input
class="form-control"
name="contactname"
type="text"
value="{$contact.contactname}"
placeholder="{l s='Ihr Name' d='Shop.Forms.Help'}"
>
</div>
</div>
I know it's ugly, but hey, it's a start :) as soon as prestashop 1.7 is not buggy anymore I will start programming with proper overrides/modules

Related

How to escape right parenthesis in variable?

How can I escape a round bracket (right parenthesis) without closing it in a fragment?
"fragments/questionaire :: questionaire('00001_c-1',
${
{
'...',
'...',
'First 1) ...'
}
},
${
{
'...',
'...',
'...'
}
},'[0,2]')"
Kind of same effect is if keyword new is somewhere in the string.
already tried: 'First 1\) ...' &rpar; ) inside utext
I use it to iterate over an object with questions and hints like:
th:fragment="questionaire(key, questions, hints, rightIndex)"
It's inside a form
<div th:each="aquestion, iterStat : ${questions}" th:with="qid=${key}+'_q-'+${iterStat.index},name='rb-'+${key}">
<div>
<input type="checkbox" th:name="${name}+${'_q-'+iterStat.index}" th:value="0" th:data-s="${iterStat.index}" th:id="${qid}" autocomplete="off" th:checked="${bucket.read('questionaire.'+name+'_q-'+iterStat.index)}==('' + 1)"/>
<label th:for="${qid}" th:text="${aquestion}"></label>
<input type="hidden" th:name="${name}+${'_q-'+iterStat.index}" value="0">
</div>
<div class="hint" th:id="${qid+'--hint'}" th:text="${hints[iterStat.index]}"></div>
</div>
<p class="submitContainer">
<button th:data-qvalidate="|quest${key}|" th:text="#{q.check}">Check</button>
</p>
Following on from my most recent comment in the question...
The least-worst solution I have is to create a Java string variable and add that to your model:
model.put("cp", ")");
where cp means "close parenthesis".
Then you can create a fragment parameter like this:
|foo 1${cp} bar|
And that passes the string foo 1) bar to the fragment without that "selector syntax" error you are currently getting.
<div th:replace="fragments/frag.html :: frag(|foo 1${cp} bar|)"></div>
And my fragment is just this:
<div th:fragment="frag(key)">
<div th:text="${key}"></div>
</div>
I would be happy to learn of a better solution.

Access custom field in POS Receipt

I am using odoo 15 ; I am trying to customize receipt in point_of_sale module
I have a problem regard access the custom filed in company module as following :
My customized module : custom/models/res_company.py
class rescompany(models.Model):
_name = "res.company"
_inherit = "res.company"
#customized fields
x_industry = fields.Char(string='Compnay Industry', translate=True)
my customized view in xml : custom/static/src/xml/custom_pos.xml
<xpath expr="//t[#t-if='receipt.company.logo']" position="before">
<div>
<span style="font-size: smaller;float: left">
<t t-esc="receipt.company.name" />
</span>
</div>
<div>
<div>
<span style="font-size: smaller;float: left">
<t t-esc="receipt.company.x_industry"/>
</span>
</div>
</div>
</xpath>
</t>
</templates>
manifest.py
...
'assets': {
'web.assets_backend': [
"custom/static/src/js/OrderReceipt.js",
],
'web.assets_qweb': [
'custom/static/src/xml/custom_pos.xml',
],
},
...
Now, I don't know how to access x_industry in OrderReceipt.js ?
I tried to follow this link :
Odoo PoS not showing custom fields in receipts
but it is in odoo 13 and I did not understand the parameters I should add to be modified correctly ;
You cannot access a field in PoS even though it has been added through python code. You need to load the specific field in the javascript files for Point of Sale.
Regarding your question, you need to add a field which is specific for a company. The easiest method is to also add the same field in pos.config model and give a related connection with the new field which you added in res.company.
x_industry = fields.Char(string='Compnay Industry', translate=True, related='company_id.x_industry')
Any field added in the pos.config can be accessed from the PoS and PoS receipt.
<t t-esc="env.pos.config.x_industry"/>

How to format currency input in RoR + AngularJS app

Sorry for my English.
I need to change input value format, for example: from "1000000" to "1 000 000 $".
In my views of rails app, I have this line of code:
<%= ng_text_field('total_price', 'selected.data.total_price', 'Full price', ng_readonly: '!selected.permissions.update') %>
In helper:
def ng_text_field(name, ng_model, placeholder, options = {})
result = <<-HTML
<div class="form-group" ng-class='{"has-error":errors.#{name}}' #{options[:ng_if] && "ng-if=\"#{options[:ng_if]}\""}>
<label for="#{name}" class="col-sm-3 control-label">#{placeholder}</label>
<div class="col-sm-9">
<input id="#{name}"
type="text"
class="form-control"
name="#{name}"
placeholder="#{placeholder}"
ng-model="#{ng_model}"
#{options[:ng_readonly] && "ng-readonly=\"#{options[:ng_readonly]}\""}>
<p class="help-block small" ng-if="errors.#{name}">{{errors.#{name} | join:',' }}</p>
</div>
</div>
HTML
result.html_safe
end
I am know Angular very little, I have tried some ways and all this ways was incorrect. :(
Could anyone give advice of some help?
Thank you in advance
You're going to need to create a new directive that requires ngModel and applies the appropriate $parser/$formatter to it.
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$parsers
A good example of how to do this is (displaying as uppercase but always storing data as lowercase):
ngModel Formatters and Parsers
You should be able to then add the ability to include other directives in your 'options' argument so that they get added correctly to the output.

add formtastic-bootstrap styles to formtastic 3

I have an input that looks like this:
<%= f.input :email %>
The output I get from formtastic(v3.1.5) and rails(v4.2) looks like this.
<li class="email input required stringish" id="applicant_email_input">
<label for="applicant_email" class="label">Email<abbr title="required">*</abbr></label>
<input maxlength="255" id="applicant_email" type="email" value="davedave#gmail.com" name="applicant[email]">
</li>
What I really want is for formtastic to emit:
<div class="email input required stringish form-group" id="applicant_email_input">
<label for="applicant_email" class=" control-label">Email<abbr title="required">*</abbr></label>
<span class="form-wrapper">
<input maxlength="255" id="applicant_email" type="email" value="davedave#gmail.com" name="applicant[email]" class="form-control">
</span>
</div>
This is what this app emmitted with formtastic(v2.3.1) and formtastic-bootstrap(v3.0.0) and rails(v4.1).
I'd love to just include the gem for formtastic-bootstrap and get that old behavior back, but near as I can tell, formtastic-bootstrap dropped out around formtastic 3.
Now I have an app with a couple thousand calls to f.input, and I need to massage the output coming from formtastic. What's the best way to do that?
Maybe you could use formtastic's custom input? Also, these links might help: https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/helpers/input_helper.rb and https://github.com/justinfrench/formtastic/issues/625.
Specifically, Justin French recommends that you monkey patch your app with an initializer in config/initializers/formtastic_patches.rb that would look something like this:
module Formtastic
module Inputs
module Base
module Wrapping
def input_wrapping(&block)
template.content_tag(:li,
[template.capture(&block), error_html, hint_html].join("\n").html_safe,
wrapper_html_options
)
end
end
end
end
end
And then switch the :li for a :div.
Here is a hacked version of formtastic I have named boomtastic which will do what you want.
(This actually includes all that you require except for the form-wrapper. However, the form-wrapper seems to be an element of bootstrap-formtastic only and not part of formtastic or standard bootstrap. If you really want to have the <span class="form-wrapper">, I think you can add this by editing boomtastic/lib/formtastic/inputs/base/wrapping.rb.)
What about a solution that uses jquery to change your form at page reload?
var ready = function () {
var $input = $('#applicant_email');
var input_html = $input.html();
$input.html('<span class="form-wrapper">' + input_html + '</span>');
}
$(document).on('turbolinks:load', ready);
You need to tell me how you want to select those fields, because in your example you did not include the full html and any explanation of the real problem.
I also see that the other divs have some other classes, that can be done with some easy jquery
Otherwise you can edit that gem

Capybara doesn't want to select an input node

My HTML/ERB looks like this
<fieldset class="row notifications">
<legend>
<hr class="dash blue inline">
<%= t :my_notifications %>
</legend>
<label>
<%= f.check_box(:subscribed_to_news) %>
<span></span>
<span class="checkbox-text"><%= t :accepts_to_receive_news %></span>
<br>
</label>
</fieldset>
When I debug my Cucumber test with Capybara, I do find the notification checkbox f.check_box(:subscribed_to_news) in this mess
page.find('.notifications label')['innerHTML']
# => "\n\t\t<input name=\"user[subscribed_to_news]\" type=\"hidden\" value=\"0\"><input type=\"checkbox\" value=\"1\" checked=\"checked\" name=\"user[subscribed_to_news]\" id=\"user_subscribed_to_news\">\n\t\t<span></span>\n\t\t<span class=\"checkbox-text\">blahblahblah</span>\n\t\t<br>\n\t"
But for some reason I cannot find the nested inputs nor find them by ID
page.find('.notifications label input')
# => Capybara::ElementNotFound Exception: Unable to find css ".notifications label input"
page.find('.notifications label #user_subscribed_to_news') # => Capybara::ElementNotFound Exception: Unable to find css ".notifications label #user_subscribed_to_news"
Selecting the label does work though
page.find('.notifications label')
# => #<Capybara::Node::Element tag="label" path="//HTML[1]/BODY[1]/DIV[1]/MAIN[1]/SECTION[1]/FORM[1]/FIELDSET[3]/LABEL[1]">
What am I doing wrong ? I just want to check the damn checkbox :'(
Most likely reason is the checkbox is actually hidden by CSS and then replaced with images to enable identical styling of checkboxes across different browsers. If you're using the latest Capybara you can have it click it the label when the checkbox is hidden by calling
page.check('user_subscribed_to_news', allow_label_click: true) # you can also set Capybara.automatic_label_click = true to default to this behavior
or if using an older capybara you would need to click the label yourself
page.find(:label, "blahblahblah").click #match on labels text
or
page.find(:label, for: 'user_subscribed_to_news').click #match on labels for attribute if set
It would seem that the checkbox is unreachable via normal css /xpath...
I got away using some javascript
page.execute_script(%Q{document.querySelector('#{area} input##{selector}').click()})

Resources