how to put opencart 3.0 customer name on header? - opencart

Can Any one help me how to display customer name in header after
customer's login
I also try some code but dosen't work
in controller>common>header.php
$data['customer_firstname'] = $this->customer->getFirstName();
$data['customer_lastname'] = $this->customer->getLastName();
Thank you in advance

You need to edit these files:
Controller catalog/controller/common/header.php
Find: return $this->load->view('common/header', $data);
Add before it:
if($this->customer->isLogged()){
$data['text_customer_name'] = sprintf($this->language->get('text_customer_name'), $this->customer->getFirstName(), $this->customer->getLastName());
} else {
$data['text_customer_name'] = $this->language->get('text_account');
}
Language catalog/language/*/common/header.php
Add: $_['text_customer_name'] = 'Hi %s %s';
View catalog/view/theme/*/template/common/header.twig
Find: {{ text_account }}
Replace with: {{ text_customer_name }}

Related

How do i get site url dynamically in admin twig file in opencart?

I am trying to get my site url like; https://www.example.com/ in admin twig file for my custom module.
Can anyone help me please?
I tried this, but no result;
{{ HTTPS_CATALOG }}
In your corresponding controller file define:
$data['site_url'] = $_SERVER['HTTP_HOST'];
in corresponding twig file you can call this data:
{{ site_url }}
If the answer are useful for you, can you mark it "This answer is useful"

Opencart 3.0.2.0 and Journal 3 theme customer name in Top Menu

I want to add customer first name on Journal theme top menu module. I am adding {{ text_logged }} in top-menu.twig but it can not get text_logged from controller. How can I get text_logged from catalog/controller/common/header.php?
{% if logged %}
{{ text_logged }}
{% endif %}
$data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', true), $this->customer->getFirstName(), $this->url->link('account/logout', '', true));
I want to see "Hello John Do" on Journal theme top menu $ US Dollar instead
I had contacted the developer regarding the same issue for the journal theme v3. They told me that it can be displayed using this:
Welcome back, {{ $customer_firstname }} {{ $customer_lastname }} !
to show customer firstname and lastname in menu items.
I have integrated that into my code, and it now shows the customer name, when logged in. No need to edit OC MOD
You need to add your code using ocmod or vqmod to the Journal theme common/header.tpl. I highly recommend do not change the Journal's core codes because of ridiculous cache system (even devs couldn't get rid of it). Also here is a solution : You can edit this one for your purpose

How to display contact information in footer template Open Cart?

I use new version of OpenCart 3.
In administrativ part I can set default phone/email data.
Then in footer.twig I tried to display phone number like:
{{ config.get('config_phone') }}
In catalog/controller/common/footer.php
$data['telephone_number'] = $this->config->get('config_telephone');
In catalog/view/theme/default/template/common/footer.twig
{{ telephone_number }}

How to execute Django uri template tags from within client side Java Script?

When we have a url tag in our java template it executes on a click
{% url 'product_details' pk=soproduct.id %} and it it is used inside the hyper link the destination will be full path including domain and path.
{{ soproduct.id }}
and works perfect and generate
http://127.0.0.1:8000/production/subproduct/details/7/
But if we want to use same template tag inside client side java script
var destination = {% url 'product_details' pk=soproduct.id %}
there is a problem that the link that will be generated will include the path but will not include the domain
/production/subproduct/details/7/
How this can be resolved?
UPDATE:
This is the script I try to execute it is located in the for loop in the django template .
<script>
var currentLocation = window.location.href;
function AddCardToTrello() {
Trello.addCard({
url: currentLocation,
name: "{{ soproduct.product }}",
due: {{ soproduct.required_date|date:"SHORT_DATE_FORMAT" }}
});
}
function addCardThenGo(url) {
AddCardToTrello();
window.location.href = url;
}
</script>
And right after the script I have my call
<a onclick="addCardThenGo({% url 'add_to_production_board' pk=soproduct.id uri=request.build_absolute_uri %})">Add to Trello</a>
So script will be repeated in the code as many times as loop goes with new parameters
Oh, I think I got it. If the code you provided is exactly the same you are using, then you forgot about quotes. It should be like this:
var destination = "{% url 'product_details' pk=soproduct.id %}";
And after that you can make this:
window.location.href = destination;
UPDATE
Please, try to do this:
<a onclick="addCardThenGo('{% url 'add_to_production_board' pk=soproduct.id uri=request.build_absolute_uri %}')">Add to Trello</a>

flask admin datepicker localization

1. Problem
This is the datepicker in my flask admin form, all the month and week names are in English, but I want customize the names also the start week number. like this question: How do I localize the jQuery UI Datepicker?. I searched a lot, but all I got is about how to customize date format in flask.
2. My code
class Receipt(db.Model):
delivery_time = db.Column(db.Date,index=True)
It's a date column can view and edit in admin form.
Is there any way to config the month、week names ? And how to make the start week number to Monday not Saturday, thanks a lot.
You could change locale globally in your templates, by adding:
<script>moment.locale(#YOURLOCALESTRING);</script>
This would guarantee that any other script loaded after this one that uses moment would use the global locale setting. You can find more details about setting locale here.
That code is not a good solution, but it can be helpful:
{% block tail_js %}
{{ super() }}
<script>
$(document).ready(function () {
var el = $('#your_element_id'); // change this selector
el.daterangepicker({
timePicker: true,
showDropdowns: true,
timePickerIncrement: 1,
timePicker12Hour: false,
separator: ' to ',
format: el.attr('data-date-format'),
locale: {
format: "MM/DD/YYYY",
separator: " - ",
applyLabel: "Выбрать",
cancelLabel: "Закрыть",
fromLabel: "От",
toLabel: "До",
customRangeLabel: "Custom",
weekLabel: "W",
daysOfWeek: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
monthNames: [ "Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Октябрь", "Сентябрь", "Ноябрь", "Декабрь"],
firstDay: 1
},
});
});
</script>
{% endblock %}
P.S.
Need to add this code into your master.html
I find a quick way to fix this issue, but I know there are better ways to do this. just modify the code in path:lib/python2.7/site-packages/flask_admin/static/vendor/daterangepicker.js to below:
this.locale = {
applyLabel: 'Apply',
cancelLabel: 'Cancel',
fromLabel: 'From',
toLabel: 'To',
weekLabel: 'W',
customRangeLabel: 'Custom Range',
// daysOfWeek: moment.weekdaysMin(),
daysOfWeek: ["日","一","二","三","四","五","六"],
// monthNames: moment.monthsShort(),
monthNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",],
// firstDay: moment.localeData()._week.dow
firstDay: 1
};