Post by AlanARG » Sat Oct 17, 2020 11:12 am

Hey everyone, how's it going? :)

I found this extension that adds "order history" in the customers page.
Thing is it's quite old, so I downloaded the file and start looking around on how to adapt it.

I found two threads (this one and this one) where someone mentions that OpenCart 3.X works with both .tpl and .twig files so, I have two options:
1. I adapt the .tpl file from the extension and convert it somehow to .twig (I guess I need to change the code variables, etc.)
2. Try something like this extension that maybe helps with the .twig/.tpl thing?

Any ideas? :)
Thanks a lot!

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by AlanARG » Sat Oct 17, 2020 3:17 pm

xxvirusxx wrote:
Sat Oct 17, 2020 2:35 pm
https://php2twig.com/
Hey! Thanks for the help!

I've tried that and I also modified the code so it points out in the right direction (it said .tpl and I changed it to .twig since I changed the file to that format).

Didn't work though :(

Should I maybe install it manually?

Thanks!

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by khnaz35 » Sat Oct 17, 2020 4:44 pm

Alan OC 3.x is using twig. So make sure you convert your .tpl to twig the url is already provided above.

What error you are seeing? Just saying didn't work is not enough to understand .

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia

Post by by mona » Sat Oct 17, 2020 5:08 pm

Converting an extension from php OC2 to twig OC3 is out of your skill set at this stage.
It depends on what it is, but these things can range from 30 seconds to days.

It is a little like saying I have some French and I need English
A line in french to English (except it has to be perfect English to work) takes 30 seconds
A novel will take days

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Sun Oct 18, 2020 4:08 am

by mona wrote:
Sat Oct 17, 2020 5:08 pm
Converting an extension from php OC2 to twig OC3 is out of your skill set at this stage.
It depends on what it is, but these things can range from 30 seconds to days.

It is a little like saying I have some French and I need English
A line in french to English (except it has to be perfect English to work) takes 30 seconds
A novel will take days
With Google search, it only takes between 5-10 secs regardless.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by by mona » Sun Oct 18, 2020 4:48 am

straightlight wrote:
Sun Oct 18, 2020 4:08 am
:laugh:
I can’t type that fast .. I might break a nail ...
standards must be maintained even in these difficult times !

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by straightlight » Sun Oct 18, 2020 5:46 am

by mona wrote:
Sun Oct 18, 2020 4:48 am
straightlight wrote:
Sun Oct 18, 2020 4:08 am
:laugh:
I can’t type that fast .. I might break a nail ...
standards must be maintained even in these difficult times !
No worries. That's why it takes the right people to do it without breaking a nail. ;)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by AlanARG » Sun Oct 18, 2020 6:51 am

by mona wrote:
Sun Oct 18, 2020 4:48 am
straightlight wrote:
Sun Oct 18, 2020 4:08 am
:laugh:
I can’t type that fast .. I might break a nail ...
standards must be maintained even in these difficult times !
You can always use speech to text to protect ur nails :P

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by AlanARG » Sun Oct 18, 2020 6:52 am

by mona wrote:
Sat Oct 17, 2020 5:08 pm
Converting an extension from php OC2 to twig OC3 is out of your skill set at this stage.
It depends on what it is, but these things can range from 30 seconds to days.

It is a little like saying I have some French and I need English
A line in french to English (except it has to be perfect English to work) takes 30 seconds
A novel will take days
Seems like a mess and is not that important anyway, not at the moment at least.

Way to go would be to change the variables so they match with .twig "format"?

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by AlanARG » Sun Oct 18, 2020 7:00 am

khnaz35 wrote:
Sat Oct 17, 2020 4:44 pm
Alan OC 3.x is using twig. So make sure you convert your .tpl to twig the url is already provided above.

What error you are seeing? Just saying didn't work is not enough to understand .
There's nothing on the customer's tab, no order history at all. No errors at all and the log on Extensions > Modifications doesn't say anything related to this extension.

What I did was modify the "vqmod/xml/order_history.xml" so it matches with the correct file paths.

I highlighted what I changed:

Code: Select all

<modification>
	<id>Add orders tab to customer page</id>
	<version>1.0.2</version>
	<vqmver>2.x</vqmver>
	<author>Dennis Mortensgaard (DoWEB I/S)</author>
	<file name="admin/view/template/customer/[b]customer_form.twig (it said .tpl)[/b]">
		<operation> 
		<search position="after"><![CDATA[<li><a href="#tab-ip" data-toggle="tab"><?php echo $tab_ip; ?></a></li>]]></search>
		<add>
			<![CDATA[<li><a href="#tab-orders" data-toggle="tab"><?php echo $tab_orders; ?></a></li>]]>
		</add>
	</operation>
	<operation>
		<search position="before"><![CDATA[$('#ip').load('index.php?route=customer/customer/ip&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>');]]></search>
		<add>
			<![CDATA[$('#orders').load('index.php?route=customer/customer/orders&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>&sort=o.date_added');]]>
		</add>
	</operation> 
	<operation>
		<search position="before"><![CDATA[<div class="tab-pane" id="tab-ip">]]></search>
		<add>
			<![CDATA[ 
			<div class="tab-pane" id="tab-orders">
              <div id="orders"></div>
            </div>
			]]>
		</add>
	</operation> 
	</file>
	<file name="[b]admin/language/*/customer/customer.php (I replaced the * with "es-es")[/b]">
		<operation> 
		<search position="before"><![CDATA[$_['heading_title']]]></search>
		<add>
			<![CDATA[$_['tab_orders']         = 'Order history';]]>
		</add>
	</operation> 
	</file>


	<file name="admin/controller/customer/customer.php">
	<operation> 
		<search position="after"><![CDATA[$data['tab_ip'] = $this->language->get('tab_ip');]]></search>
		<add>
			<![CDATA[$data['tab_orders'] = $this->language->get('tab_orders');]]>
		</add>
	</operation>
		
	<operation> 
		<search position="before"><![CDATA[public function ip() {]]></search>
		<add>
			<![CDATA[
				public function orders() {
					$this->load->language('sale/order');

					$this->load->model('sale/order');

					$data['text_no_results'] = $this->language->get('text_no_results');
					$data['text_see_order'] = $this->language->get('text_see_order');
					$data['text_loading'] = $this->language->get('text_loading');

					$data['column_order_id'] = $this->language->get('column_order_id');
					$data['column_status'] = $this->language->get('column_status');
					$data['column_date_added'] = $this->language->get('column_date_added');
					$data['column_date_modified'] = $this->language->get('column_date_modified');
					$data['column_total'] = $this->language->get('column_total');
					$data['column_action'] = $this->language->get('column_action');

					if (isset($this->request->get['page'])) {
						$page = $this->request->get['page'];
					} else {
						$page = 1;
					}

					$data['orders'] = array();

					$results = $this->model_sale_order->getOrders(array('filter_customerid' => $this->request->get['customer_id'], 'sort' => $this->request->get['sort'], 'order' => 'DESC'));

					foreach ($results as $result) {
						
						$data['orders'][] = array(
							'id'         => $result['order_id'],
							'status'      => $result['order_status'],
							'date_added' => date('d/m/y', strtotime($result['date_added'])),
							'date_modified' => date('d/m/y', strtotime($result['date_modified'])),
							'action_view'  => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'], 'SSL'),
							'action_edit'  => $this->url->link('sale/order/edit', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'], 'SSL'),
							'total'     => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value'])
						);
					}

					$this->response->setOutput($this->load->view('[b]customer/customer_orders.twig (it said .tpl)[/b]', $data));
				}
			]]>
		</add>
	</operation> 

	</file>
	<file name="admin/model/sale/order.php">
		<operation> 
		<search position="before"><![CDATA[if (!empty($data['filter_customer'])) {]]></search>
		<add>
			<![CDATA[
			if (!empty($data['filter_customerid'])) {
				$sql .= " AND o.customer_id = " . $this->db->escape($data['filter_customerid']);
			}
			]]>
		</add>
	</operation> 
	<operation>
		<search position="before"><![CDATA[public function getTotalOrdersByOrderStatusId($order_status_id) {]]></search>
		<add>
			<![CDATA[
				public function getTotalOrdersByCustomerId($customer_id) {
					$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE customer_id = '" . (int)$customer_id . "' AND order_status_id > '0'");

					return $query->row['total'];
				}
			]]>
		</add>
	</operation>
	</file>
	

	
</modification>
And I also converted the php code into twig with the link someone provided up here. The original code is:

Code: Select all

<table class="table table-bordered">
  <thead>
    <tr>
      <td class="text-left"><?php echo $column_order_id; ?></td>
      <td class="text-left"><?php echo $column_status; ?></td>
      <td class="text-left"><?php echo $column_date_added; ?></td>
      <td class="text-left"><?php echo $column_date_modified; ?></td>
      <td class="text-left"><?php echo $column_total; ?></td>
      <td class="text-left"><?php echo $column_action; ?></td>
    </tr>
  </thead>
  <tbody>
    <?php if ($orders) { ?>
    <?php foreach ($orders as $order) { ?>
    <tr>
      <td class="text-left">#<?php echo $order['id']; ?></td>
      <td class="text-left"><?php echo $order['status']; ?></td>
      <td class="text-left"><?php echo $order['date_added']; ?></td>
      <td class="text-left"><?php echo $order['date_modified']; ?></td>
      <td class="text-left"><?php echo $order['total']; ?></td>
      <td class="text-right">
          <a href="<?php echo $order['action_view']; ?>" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="View"><i class="fa fa-eye"></i></a> 
          <a href="<?php echo $order['action_edit']; ?>" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="Edit"><i class="fa fa-pencil"></i></a> 
      </td>
    </tr>
    <?php } ?>
    <?php } else { ?>
    <tr>
      <td class="text-center" colspan="6"><?php echo $text_no_results; ?></td>
    </tr>
    <?php } ?>
  </tbody>
</table>
And this is the result:

Code: Select all

<table class="table table-bordered">
  <thead>
    <tr>
      <td class="text-left">{{ column_order_id }}</td>
      <td class="text-left">{{ column_status }}</td>
      <td class="text-left">{{ column_date_added }}</td>
      <td class="text-left">{{ column_date_modified }}</td>
      <td class="text-left">{{ column_total }}</td>
      <td class="text-left">{{ column_action }}</td>
    </tr>
  </thead>
  <tbody>
    {% if orders %}
    {% for order in orders %}
    <tr>
      <td class="text-left">#{{ order.id }}</td>
      <td class="text-left">{{ order.status }}</td>
      <td class="text-left">{{ order.date_added }}</td>
      <td class="text-left">{{ order.date_modified }}</td>
      <td class="text-left">{{ order.total }}</td>
      <td class="text-right">
          <a href="{{ order.action_view }}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="View"><i class="fa fa-eye"></i></a> 
          <a href="{{ order.action_edit }}" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="Edit"><i class="fa fa-pencil"></i></a> 
      </td>
    </tr>
    {% endfor %}{% endif %}
     {% else %}
    <tr>
      <td class="text-center" colspan="6">{{ text_no_results }}</td>
    </tr>

  </tbody>
</table>
Thanks :)
Last edited by AlanARG on Mon Oct 19, 2020 2:02 pm, edited 2 times in total.

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by xxvirusxx » Sun Oct 18, 2020 2:26 pm

If you use VQMOD then you need to add Vqmod modification fix...

https://www.opencart.com/index.php?rout ... n_id=39911

And the last code is not converted one...

Example:
<?php echo $column_order_id; ?> = {{ column_order_id }}

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by AlanARG » Mon Oct 19, 2020 2:45 pm

xxvirusxx wrote:
Sun Oct 18, 2020 2:26 pm
If you use VQMOD then you need to add Vqmod modification fix...

https://www.opencart.com/index.php?rout ... n_id=39911

And the last code is not converted one...

Example:
<?php echo $column_order_id; ?> = {{ column_order_id }}
My bad, the code was not converted. Now it is, I edited the post.

After installing that Vqmod modification fix, should I just proceed to replace the code with the converted one? Thanks!

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by khnaz35 » Mon Oct 19, 2020 2:49 pm

AlanARG wrote:
Mon Oct 19, 2020 2:45 pm
After installing that Vqmod modification fix, should I just proceed to replace the code with the converted one? Thanks!
Give it a shot first if it didn’t work system will let you know which line has a error, generally in development when writing the code its easy to test them by running instead of reading them over and over again :)

Urgent Questions shoot here: khnaz35@gmail.com
Enjoy nature ;) :) :-*


User avatar
Active Member

Posts

Joined
Mon Aug 27, 2018 11:30 pm
Location - Malaysia
Who is online

Users browsing this forum: Nordikota and 127 guests