opencartvqmod

How to get user information to .tpl file in opencart using vqmod?


I am new in opencart and I am trying to make some changes using vqmod.I have built a xml file which will add some text on product_list.tpl depending on user's id.The problem is that I cannot get id.I tried a lot but still no success.If anyone knows how can I achieve this please post.I get this notice on browser -> Notice: Undefined property: Loader

Here is my xml file:

<modification>
 <id>GeoDim - add message products depending on user login</id>
 <version>1.0</version>
 <vqmver>2.4.1</vqmver>
 <author>GeoDim</author>

<file path="admin/view/template/catalog/product_list.tpl">
  <operation>
  <search position="after"><![CDATA[div class="pull-right"]]></search>
  <add><![CDATA[
 <?php
 // GeoDim - add message products depending on user login

  $this->load->model('user/user');
   $user_group_id = $this->model_user_user->getUsersGroupId($this->user->getId());

   if ($user_group_id == 1) {

    echo '<p style="background-color: yellow;font-size: 21px;float: left;margin-right: 5px"><i class="fa fa-exclamation-triangle"></i>Είστε στο TEST</p>';
  }else {
    echo '<p style="background-color: orange;font-size: 21px;float:left;margin-right:5px"><i class="fa fa-exclamation-triangle"></i>Είστε στο    LIVE</p>';
    }

 // END GeoDim - add message products depending on user login
   ?>
    ]]></add>
    </operation>
 </file>

 </modification>

Solution

  • Which version of Opencart?

    Since there's no getUsersGroupId function in model/user/user.php on opencart 2.x I used getUser here, I've tested this on opencart 2.1.0.1.

    You must first get user_group_id in controller file and then send it to view file via $data, so edit this file:

    admin/controller/catalog/product.php
    

    Find getList function and add this inside it:

      $this->load->model('user/user');
      $user_group_id = $this->model_user_user->getUser($this->user->getId());
    
    
       if ($user_group_id['user_group_id'] == 1) {
    
        $data['paragraph'] = '<p style="background-color: yellow;font-size: 21px;float: left;margin-right: 5px"><i class="fa fa-exclamation-triangle"></i>Είστε στο TEST</p>';
      }else {
        $data['paragraph'] = '<p style="background-color: orange;font-size: 21px;float:left;margin-right:5px"><i class="fa fa-exclamation-triangle"></i>Είστε στο    LIVE</p>';
        }
    

    and then in admin/view/template/catalog/product_list.tpl use it:

    <?php echo $paragraph; ?>
    

    Here is full code:

    <modification>
     <id>GeoDim - add message products depending on user login</id>
     <version>1.0</version>
     <vqmver>2.4.1</vqmver>
     <author>GeoDim</author>
    
    <file path="admin/controller/catalog/product.php">
      <operation>
      <search position="after"><![CDATA[$results = $this->model_catalog_product->getProducts($filter_data);]]></search>
      <add><![CDATA[
        // GeoDim - add message products depending on user login
    
          $this->load->model('user/user');
          $user_group_id = $this->model_user_user->getUser($this->user->getId());
    
    
           if ($user_group_id['user_group_id'] == 1) {
    
            $data['paragraph'] = '<p style="background-color: yellow;font-size: 21px;float: left;margin-right: 5px"><i class="fa fa-exclamation-triangle"></i>Είστε στο TEST</p>';
          }else {
            $data['paragraph'] = '<p style="background-color: orange;font-size: 21px;float:left;margin-right:5px"><i class="fa fa-exclamation-triangle"></i>Είστε στο    LIVE</p>';
            }
    
         // END GeoDim - add message products depending on user login
        ]]></add>
        </operation>
     </file>
    
    <file path="admin/view/template/catalog/product_list.tpl">
      <operation>
      <search position="after"><![CDATA[div class="pull-right"]]></search>
      <add><![CDATA[
            <?php echo $paragraph; ?>
        ]]></add>
        </operation>
     </file>
    
     </modification>