Page 1 of 1

Percentage of sales from location on map

Posted: Sun Aug 09, 2020 3:36 am
by nightwing
Hello Team,
I would like to display the percentage of sales from each location in the tooltip on the map when you hover. I am using 3.0.3.2.
This should be

Code: Select all

current number of orders for the location / total number of completed orders across the store * 100
ocmod could be used:

Code: Select all

	
<file path="admin/view/template/extension/dashboard/map_info.twig">
<operation error="log">
<search><![CDATA[	label.html('<strong>' + label.text() + '</strong><br />' + '{{ text_order }} ' + json[code]['total'] + '<br />' + '{{ text_sale }} ' + json[code]['amount']);]]></search>
<add position="replace"><![CDATA[label.html('<strong>' + label.text() + '</strong><br />' + '{{ text_order }} ' + json[code]['total'] + '<br />' + '{{ text_sale }} ' + json[code]['amount']  <br> CALCULATION HERE );]]></add>
</operation>
</file>
In

Code: Select all

admin/view/template/extension/dashboard/map_info.twig

We could add the calculation at the end, I just cant figure out how to gather the data on the total orders, I already have the orders for the current location here

Code: Select all

+ json[code]['total']
Thanks

Re: Percentage of sales from location on map

Posted: Wed Aug 12, 2020 9:35 pm
by nightwing
Anyone able to shed some light on this one? I am still stuck.

Re: Percentage of sales from location on map

Posted: Wed Aug 12, 2020 10:17 pm
by letxobnav
you have to get the total orders in the controller admin/controller/extension/dashboard/map.php function map and add that to the returned json record.
currently that function returns an array with the total and amount per iso code.

Code: Select all

			$json[strtolower($result['iso_code_2'])] = array(
				'total'  => $result['total'],
				'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency'))
			);

just invoke the function to get the total orders, I believe there is such a function somewhere.
then add

Code: Select all

$json['total'] = that total;
after the code above then you can access that value json['total'] in your twig file.

or you can change this in the twig file:

Code: Select all

		success: function(json) {
			data = [];
			
			for (i in json) {
				data[i] = json[i]['total'];
			}

to

Code: Select all

		success: function(json) {
			data = [];
			total = 0;
			
			for (i in json) {
				data[i] = json[i]['total'];
				total = total + parseInt(data[i]);
			}

and which sums up the individual totals and use that total.

Re: Percentage of sales from location on map

Posted: Wed Aug 12, 2020 11:23 pm
by nightwing
letxobnav, thank you, I will test and get back to you!
letxobnav wrote:
Wed Aug 12, 2020 10:17 pm
you have to get the total orders in the controller admin/controller/extension/dashboard/map.php function map and add that to the returned json record.
currently that function returns an array with the total and amount per iso code.

Code: Select all

			$json[strtolower($result['iso_code_2'])] = array(
				'total'  => $result['total'],
				'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency'))
			);

just invoke the function to get the total orders, I believe there is such a function somewhere.
then add

Code: Select all

$json['total'] = that total;
after the code above then you can access that value json['total'] in your twig file.

or you can change this in the twig file:

Code: Select all

		success: function(json) {
			data = [];
			
			for (i in json) {
				data[i] = json[i]['total'];
			}

to

Code: Select all

		success: function(json) {
			data = [];
			total = 0;
			
			for (i in json) {
				data[i] = json[i]['total'];
				total = total + parseInt(data[i]);
			}

and which sums up the individual totals and use that total.