Post by Rebecka » Thu Nov 03, 2011 8:11 pm

Better? I have not counted the lines yet, that's why I wrote a question mark in offset.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Replace categories with information</id>
        <version>1.5.1.3</version>
        <vqmver>2.1.4</vqmver>
        <author>Rebecka</author>
        
        <file name="catalog/controller/common/header.php">
                <operation>
                
                        <search position="replace" offset="?"><![CDATA[
                        $var = '$this->load->model('catalog/category');';
                        ]]></search>

                        <add><![CDATA[
                        $var = '$this->load->model('catalog/information');
$this->data['informations'] = array();

foreach ($this->model_catalog_information->getInformations() as $result) {
$this->data['informations'][] = array(
       'title' => $result['title'],
   'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
);
}
$this->language->load('module/information');
   
   $this->data['text_contact'] = $this->language->get('text_contact');

$this->load->model('catalog/information');

$this->data['informations'] = array();

foreach ($this->model_catalog_information->getInformations() as $result) {
$this->data['informations'][] = array(
       'title' => $result['title'],
   'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
);
}
$this->data['contact'] = $this->url->link('information/contact');';
                        ]]></add>

                </operation>
        </file> 

        <file name="catalog/view/theme/mystockimages/template/common/header.tpl">
                <operation>
                
                        <search position="replace" offset="?"><![CDATA[
                        $var = '<?php if ($categories) { ?>';
                        ]]></search>

                        <add><![CDATA[
                        $var = '<?php if ($informations) { ?>
            <div id="menu">
               <ul>
               <!-- Menu Links Starts -->
                  <?php foreach ($informations as $information) { ?>
                     <li><a href="<?php echo $information['href']; ?>"><?php echo $information['title']; ?></a></li>
                  <?php } ?>
<li><a href="<?php echo $contact; ?>"><?php echo $text_contact; ?></a></li>
               <!-- Menu Links Ends -->
               </ul>
            </div>
         <?php } ?>';
                        ]]></add>
                        
                </operation>
        </file>
</modification>
Last edited by Rebecka on Fri Nov 04, 2011 4:03 am, edited 2 times in total.

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Xsecrets » Thu Nov 03, 2011 8:35 pm

It should be

Code: Select all

<version>{yourversionhere}</version>  at the top. Currently there is no field for the opencart version, but I suppose you could use the opencart version there if you wanted to. The field is not actually used for anything.

offset should not be "?" It is used if you want to move where your inserted text goes by a certain number of lines. If you don't need an offset you leave it out.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Rebecka » Fri Nov 04, 2011 12:03 am

Xsecrets wrote:It should be [ code ]<version>{yourversionhere}</version> at the top. Currently there is no field for the opencart version, but I suppose you could use the opencart version there if you wanted to. The field is not actually used for anything.
I know it's not for my OpenCart version. :)
Xsecrets wrote:offset should not be "?" It is used if you want to move where your inserted text goes by a certain number of lines. If you don't need an offset you leave it out.
I have not counted the lines yet, that's why I wrote a question mark in offset.

This is how I did from the beginning

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Replace categories with information</id>
        <version>1.5.1.3</version>
        <vqmver>2.1.4</vqmver>
        <author>Rebecka</author>
        
        <file name="catalog/controller/common/header.php">
                <operation>
                
                        <search position="replace"><![CDATA[
                        $var = '$this->load->model('catalog/category');
      $this->load->model('catalog/product');
      
      $this->data['categories'] = array();
               
      $categories = $this->model_catalog_category->getCategories(0);
      
      foreach ($categories as $category) {
         if ($category['top']) {
            $children_data = array();
            
            $children = $this->model_catalog_category->getCategories($category['category_id']);
            
            foreach ($children as $child) {
               $data = array(
                  'filter_category_id'  => $child['category_id'],
                  'filter_sub_category' => true   
               );      
                  
               $product_total = $this->model_catalog_product->getTotalProducts($data);
                           
               $children_data[] = array(
                  'name'  => $child['name'] . ' (' . $product_total . ')',
                  'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])   
               );               
            }
            
            // Level 1
            $this->data['categories'][] = array(
               'name'     => $category['name'],
               'children' => $children_data,
               'column'   => $category['column'] ? $category['column'] : 1,
               'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
         }
      }';
                        ]]></search>
                        
                        <add><![CDATA[
                        $var = '$this->load->model('catalog/information');
$this->data['informations'] = array();

foreach ($this->model_catalog_information->getInformations() as $result) {
$this->data['informations'][] = array(
       'title' => $result['title'],
   'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
);
}
$this->language->load('module/information');
   
   $this->data['text_contact'] = $this->language->get('text_contact');

$this->load->model('catalog/information');

$this->data['informations'] = array();

foreach ($this->model_catalog_information->getInformations() as $result) {
$this->data['informations'][] = array(
       'title' => $result['title'],
   'href'  => $this->url->link('information/information', 'information_id=' . $result['information_id'])
);
}
$this->data['contact'] = $this->url->link('information/contact');';
                        ]]></add>
                        
                </operation>
        </file> 

        <file name="catalog/view/theme/mystockimages/template/common/header.tpl">
                <operation>
                
                        <search position="replace"><![CDATA[
                        $var = '<!-- Main Menu Starts -->
         <?php if ($categories) { ?>
            <div id="menu">
               <ul>
               <!-- Menu Links Starts -->
                  <?php foreach ($categories as $category) { ?>
                     <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
                        <?php if ($category['children']) { ?>
                        <!-- Dropdown Menu Links Starts -->
                           <div>
                              <?php for ($i = 0; $i < count($category['children']);) { ?>
                                 <ul>
                                    <?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
                                    <?php for (; $i < $j; $i++) { ?>
                                       <?php if (isset($category['children'][$i])) { ?>
                                          <li>
                                             <a href="<?php echo $category['children'][$i]['href']; ?>">
                                                <?php echo $category['children'][$i]['name']; ?>
                                             </a>
                                          </li>
                                       <?php } ?>
                                    <?php } ?>
                                 </ul>
                              <?php } ?>
                           </div>
                        <!-- Dropdown Menu Links Ends -->
                        <?php } ?>                  
                     </li>
                  <?php } ?>
               <!-- Menu Links Ends -->
               </ul>
            </div>
         <?php } ?>
      <!-- Main Menu Ends -->';
                        ]]></search>
                        
                        <add><![CDATA[
                        $var = '<!-- Main Menu Starts -->
         <?php if ($informations) { ?>
            <div id="menu">
               <ul>
               <!-- Menu Links Starts -->
                  <?php foreach ($informations as $information) { ?>
                     <li><a href="<?php echo $information['href']; ?>"><?php echo $information['title']; ?></a></li>
                  <?php } ?>
<li><a href="<?php echo $contact; ?>"><?php echo $text_contact; ?></a></li>
               <!-- Menu Links Ends -->
               </ul>
            </div>
         <?php } ?>
      <!-- Main Menu Ends -->';
                        ]]></add>
                        
                </operation>
        </file>
</modification>
Until Qphoria mentioned that <search> only contain a single line.
I shall instead use the offset.

So my question is if I have done right, if you ignore my question mark that will be replaced by the number of lines that I have not yet counted?

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Rebecka » Fri Nov 04, 2011 4:03 am

It did not work. I wish someone could teach me.

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Qphoria » Fri Nov 04, 2011 4:25 am

best to download some of the free vqmods here in the forum and look at how they do things and try to reverse engineer them. Look at some of mine to see some creative ways of getting around using offset when you don't need to.

For example if you have:

Code: Select all

public function x() {
    some code here
}

public function z() {
    some code here
}
and you want to insert this between them

Code: Select all

public function y() {
    some code here
}
Instead of doing

Code: Select all

<search position="after" offset="2">public function x() {</search>
You could do

Code: Select all

<search position="before">[code]public function z() {</search>
There are other tricks of the trade to be learned from the existing scripts

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by marvmen21 » Fri Nov 04, 2011 4:30 am

maybe I am wrong but I thought offset is also used to look for a single line. For example, if you have the following code:

Code: Select all

Line 1
Line2
Line3
If you use <search position="replace" offset: "2"><![CDATA[line1 ]]></search> the vqmod will not replace Line1 but two lines below (Line 3). Not sure about this though. I'll try it later.

If you are deleting a lot and adding a lot, you could try replacing the whole page, though this is a workaround rather than a solution.

You want to thank me for my time! :) Click here to donate


Active Member

Posts

Joined
Tue Nov 09, 2010 4:54 am

Post by Qphoria » Fri Nov 04, 2011 4:33 am

marvmen21 wrote:maybe I am wrong but I thought offset is also used to look for a single line. For example, if you have the following code:

Code: Select all

Line 1
Line2
Line3
If you use <search position="replace" offset: "2"><![CDATA[line1 ]]></search> the vqmod will not replace Line1 but two lines below (Line 3). Not sure about this though. I'll try it later.

If you are deleting a lot and adding a lot, you could try replacing the whole page, though this is a workaround rather than a solution.
No.. replace with offset 2 means replace the main line PLUS 2 extra

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by marvmen21 » Fri Nov 04, 2011 4:36 am

Cool! We learn something new everyday. Thanks. I was confusing it with "after" and "before".

You want to thank me for my time! :) Click here to donate


Active Member

Posts

Joined
Tue Nov 09, 2010 4:54 am

Post by Rebecka » Sat Nov 05, 2011 12:03 am

I soon begins to think that I'm doing everything wrong.

I was going to try to make a simple modification. Getting the Continue button to the left instead of right.

I did this

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Left instead of right</id>
        <version>1.5.1.3</version>
        <vqmver>2.1.4</vqmver>
        <author>Rebecka</author>
        
        <file name="catalog/view/theme/default/template/information/contact.tpl">
                <operation>
                
                        <search position="replace"><![CDATA[
                        $var = '<div class="right">';
                        ]]></search>
                        
                        <add><![CDATA[
                        $var = '<div class="left">';
                        ]]></add>
                        
                </operation>
        </file> 
</modification>
Is this wrong? :o

I even tried this

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Left instead of right</id>
        <version>1.5.1.3</version>
        <vqmver>2.1.4</vqmver>
        <author>Rebecka</author>
        
        <file name="catalog/view/theme/default/template/information/contact.tpl">
                <operation>
                
                        <search position="replace" offset="2"><![CDATA[
                        $var = '<div class="buttons">';
                        ]]></search>
                        
                        <add><![CDATA[
                        $var = '<div class="buttons">
      <div class="left">';
                        ]]></add>
                        
                </operation>
        </file> 
</modification>
But this did not work either.

Feels like I have not understood anything at all. :-\

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Qphoria » Sat Nov 05, 2011 1:07 am

Yea the first one looks fine. What does vqmod/vqmod.log file show?
Be sure you have files in the vqmod/vqcache folder... that is your sanity check to ensure vQmod is at least working.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Rebecka » Sat Nov 05, 2011 1:54 am

I have files in vqmod/vqcache and already uses an extension that works (though not my own extension). :(

There are a lot in vqmod.log
Last edited by Rebecka on Sat Nov 05, 2011 1:59 am, edited 1 time in total.

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Xsecrets » Sat Nov 05, 2011 1:58 am

well that's not working because there is no "$var = " anything in that file.

my guess is that what you want is.

Code: Select all

<operation>
                
                        <search position="replace"><![CDATA[
                        <div class="right">
                        ]]></search>
                        
                        <add><![CDATA[
                        <div class="left">
                        ]]></add>
                        
                </operation>

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Rebecka » Sat Nov 05, 2011 2:02 am

Thank you Xsecrets! It worked!

When it is thought that one should use "$var ="?

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Rebecka » Sat Nov 05, 2011 2:22 am

I discovered I could not do the same on products (get Continue button to the left instead of right below the review form).

If I do like this

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Left instead of right</id>
        <version>1.5.1.3</version>
        <vqmver>2.1.4</vqmver>
        <author>Rebecka</author>
        
        <file name="catalog/view/theme/mystockimages/template/product/product.tpl">
                <operation>
                
                        <search position="replace"><![CDATA[
                        <div class="right">
                        ]]></search>
                        
                        <add><![CDATA[
                        <div class="left">
                        ]]></add>
                        
                </operation>
        </file> 
</modification>
Continue button is on the left side but the whole product side also disrupted.

I tried this instead

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <id>Left instead of right</id>
        <version>1.5.1.3</version>
        <vqmver>2.1.4</vqmver>
        <author>Rebecka</author>
        
        <file name="catalog/view/theme/mystockimages/template/product/product.tpl">
                <operation>
                
                        <search position="replace" offset="2"><![CDATA[
                        <div class="buttons">
                        ]]></search>
                        
                        <add><![CDATA[
                        <div class="buttons">
				<div class="left">
                        ]]></add>
                        
                </operation>
        </file> 
</modification>
But the Continue button only disappears.

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by Qphoria » Sat Nov 05, 2011 5:03 am

oh yea.. sorry.. didn't see that you had the "$var = "

that was only in the example... assuming the file has a $var in it

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Xsecrets » Sat Nov 05, 2011 5:09 am

yes you would only use "$var =" if the file you were wanting to change actually had "$var =" in it basically the only thing that goes in the search is exactly what you are searching for from the original file, so you can just copy and paste what you want to search for.

As far as messing up the whole page I would imagine that there are several places in that file that have "<div class="right">" and the way you have it written would replace them all which could cause some craziness. In order to only change one you need to find something more specific to search on (if you are not already searching on the whole line) or use index="3" where the three represents the occurrence of the search term. So if you put your cursor at the top of the file and then do a search for <div class="right"> if the one you want to change is the first one found you would use offset="1" if it's the fifth one found you would use offset="5"

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Rebecka » Sat Nov 05, 2011 7:24 am

Xsecrets wrote:yes you would only use "$var =" if the file you were wanting to change actually had "$var =" in it basically the only thing that goes in the search is exactly what you are searching for from the original file, so you can just copy and paste what you want to search for.
Now I feel stupid.
Thought it was something that it would begin with but now I realize that it was only with the example.
Sorry about that.
Xsecrets wrote:As far as messing up the whole page I would imagine that there are several places in that file that have "<div class="right">" and the way you have it written would replace them all which could cause some craziness. In order to only change one you need to find something more specific to search on (if you are not already searching on the whole line) or use index="3" where the three represents the occurrence of the search term. So if you put your cursor at the top of the file and then do a search for <div class="right"> if the one you want to change is the first one found you would use offset="1" if it's the fifth one found you would use offset="5"
Thank you so much again! It worked!

Rebecka went over to PrestaShop.


Active Member

Posts

Joined
Sun Sep 18, 2011 4:49 am
Location - Sweden

Post by thbr02 » Wed Feb 15, 2012 4:58 am

I've read your discussion about "offset". Can you tell me what

<search position="bottom" offset="2"></search>

means?

Active Member

Posts

Joined
Wed Jun 22, 2011 10:30 pm
Location - Sweden
Who is online

Users browsing this forum: No registered users and 3 guests