Community Forums

[MOD] - VirtualQMod "vQmod" Virtual File Modification System

Community created contributions & mods for OpenCart 1.x

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby opencartisalright » Wed Aug 24, 2011 8:28 am

First, where do I get vQmod 2.0?

Secondly, I'm using 1.2.3 now and I'm wondering can vQmod be used to modify db quires? I am trying to modify the following db query

Code: Select all
$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'");


to be

Code: Select all
$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'");


and it's telling me that the search failed (aborted). I'm copying and pasting this db query directly from the core file (admin/model/catalog/product.php) into the vQmod so i'm not sure why it's saying it can't find the code.

Any ideas? Here's what that section of the vQmod looks like.

Code: Select all
<file name="admin/model/catalog/product.php">
      <operation>
         <search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'");
         ]]></search>
         <add><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'");
         ]]></add>
      </operation>
Last edited by opencartisalright on Wed Aug 24, 2011 9:05 am, edited 1 time in total.
opencartisalright
 
Posts: 375
Joined: Sun Feb 20, 2011 8:09 pm

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby 5ulo » Wed Aug 24, 2011 8:36 am

I usually use the same method without any problems. Try this:
Code: Select all
<file name="admin/model/catalog/product.php">
  <operation>
    <search position="replace" index="1"><![CDATA[ $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" ]]></search>
    <add><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'"); ]]></add>
  </operation>
</file>

I suppose you know how to use the index attribute
User avatar
5ulo
 
Posts: 69
Joined: Wed Oct 20, 2010 10:47 pm
Location: Trnava, Slovakia, EU

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby rph » Wed Aug 24, 2011 8:37 am

Remove the line break.
-Ryan
VQMod Manager: FREE extension to fully manage your VQMods from Admin!
Admin Enhancement Suite: Powerful Admin features and enhancements
Dependent Options: Option values displayed based on customer input
Catalog Mode: Disable "Add to Cart" and display your store in view-only
Unofficial OpenCart Wiki | Commercial Support and Development
User avatar
rph
 
Posts: 2695
Joined: Thu Jan 07, 2010 9:05 pm
Location: Lincoln, Nebraska

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby opencartisalright » Wed Aug 24, 2011 8:59 am

rph wrote:Remove the line break.


There is no line break in my vQmod file, I just broke the line here to try and make it easier to read.

5ulo wrote:I usually use the same method without any problems. Try this:
Code: Select all
<file name="admin/model/catalog/product.php">
  <operation>
    <search position="replace" index="1"><![CDATA[ $this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" ]]></search>
    <add><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'"); ]]></add>
  </operation>
</file>

I suppose you know how to use the index attribute


I tried the above and it doesn't work. I didn't use the index attribute because I want to replace all instances of that line, and in Q's documentation it says to leave out the index attribute if you want to replace all instances.

This is driving me bonkers, not only is it not working, but when I try to go to the product page in my admin panel, i'm getting a blank white screen. As soon as I remove the vQmod the blank white screen goes away and I can navigate to my product page as normal.

I don't understand why it won't replace this db query. ???
opencartisalright
 
Posts: 375
Joined: Sun Feb 20, 2011 8:09 pm

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby 5ulo » Wed Aug 24, 2011 9:08 am

blank screen usually means that there is an error.. so the error.log may be helpful in your case
User avatar
5ulo
 
Posts: 69
Joined: Wed Oct 20, 2010 10:47 pm
Location: Trnava, Slovakia, EU

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby madimar » Wed Aug 24, 2011 9:28 am

opencartisalright wrote:
This is driving me bonkers, not only is it not working, but when I try to go to the product page in my admin panel, i'm getting a blank white screen. As soon as I remove the vQmod the blank white screen goes away and I can navigate to my product page as normal.

I don't understand why it won't replace this db query. ???


Hi man, I can't understand if you were able or not applying the modification to your file. I mean, at the beginning of the post you were talking about a failed search, now you talk about a blank screen.
Usually a blank screen is caused by some errors in the modified file, but it should mean your vqmod replacement is ok. If so, try to check related cache file in order to find the error.

Another possibility is some error in your xml syntax (sometimes it happens...). You can try to check your xml file opening in Internet Explorer (it has a good syntax validator).
User avatar
madimar
 
Posts: 989
Joined: Thu Sep 24, 2009 10:27 am

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby opencartisalright » Wed Aug 24, 2011 9:29 am

5ulo wrote:blank screen usually means that there is an error.. so the error.log may be helpful in your case


That's the problem, i'm getting a blank white screen when I visit the admin products page, so no error is being generated, not in the error.log or in the vqmod.log file. :-\

The below code is what I have

Code: Select all
<file name="admin/model/catalog/product.php">
      <operation>
         <search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'");]]></search>
         <add><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'");]]></add>
      </operation>
      
      <operation>
         <search position="after"><![CDATA['meta_description' => $result['meta_description']
         ]]></search>
         <add><![CDATA['specs'            => $result['specs']
         ]]></add>
      </operation>
   </file>


I have the ); in both the search and add tag. Plus i'm using the replace attribute, so shouldn't it just replace the search field with whatever I put in the add field?
opencartisalright
 
Posts: 375
Joined: Sun Feb 20, 2011 8:09 pm

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby uksitebuilder » Wed Aug 24, 2011 9:36 am

In the your second operation, you are missing a comma

would be better written as:

Code: Select all
      <operation>
         <search position="replace"><![CDATA['meta_description' => $result['meta_description']
         ]]></search>
         <add><![CDATA['meta_description' => $result['meta_description'],
'specs'            => $result['specs']
         ]]></add>
      </operation>
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby JAY6390 » Wed Aug 24, 2011 9:41 am

If you get a blank white screen, you are getting an error, its just that OC isn't catching it. This is something I've come across quite a bit and it really annoys me, so I just do the following. Open your index.php file, find the line with startup.php and after that line add
Code: Select all
ini_set('display_errors'1);
error_reporting(E_ALL); 

and save. This should be done for the admin/index.php if you are having trouble with that, and for the one in the root directory if you're having trouble with that one. Note for a production environment you should comment these two lines out for the root index.php at least, so that errors are hidden to the general public
ImageImageImage

Better Product SEO URL's - Perfectly structured product links
Better Category SEO URL's - Give subcategories the same SEO keyword
SEO URL's Route Editor - Fix all of your index.php links


Image
User avatar
JAY6390
 
Posts: 4633
Joined: Wed May 26, 2010 3:47 pm
Location: United Kingdom

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby JAY6390 » Wed Aug 24, 2011 9:47 am

Also forgot to say that vQmod 2.0 is still in testing. Just waiting for Q to upload 1.2.3 to the repo and then I'll commit 2.0 to the repo and release for the general public to play with and give feedback on it
ImageImageImage

Better Product SEO URL's - Perfectly structured product links
Better Category SEO URL's - Give subcategories the same SEO keyword
SEO URL's Route Editor - Fix all of your index.php links


Image
User avatar
JAY6390
 
Posts: 4633
Joined: Wed May 26, 2010 3:47 pm
Location: United Kingdom

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby opencartisalright » Wed Aug 24, 2011 9:58 am

uksitebuilder wrote:In the your second operation, you are missing a comma

would be better written as:

Code: Select all
      <operation>
         <search position="replace"><![CDATA['meta_description' => $result['meta_description']
         ]]></search>
         <add><![CDATA['meta_description' => $result['meta_description'],
'specs'            => $result['specs']
         ]]></add>
      </operation>


Success!

Thank you so much. I'm no longer getting a blank white page and the vQmod is modifying the product.php file successfully. ;D

Sometimes you just need a second pair of eyes. :)

If you were next to me i'd high five you man, but since you're not I'll just buy one of your mods from the extension store. The Admin Email Alerts & Dashboard Alerts mod looks good.

Thanks again.
opencartisalright
 
Posts: 375
Joined: Sun Feb 20, 2011 8:09 pm

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby Qphoria » Wed Aug 24, 2011 1:38 pm

opencartisalright wrote:
Code: Select all
<file name="admin/model/catalog/product.php">
      <operation>
         <search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'");
         ]]></search>
         <add><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'");
         ]]></add>
      </operation>


Remember the golden rule.. less is more. Changing this much code means that other mods may not match. In reality you are only changing one small part of the query so try to match on less if possible.

Try this instead:
Code: Select all
<file name="admin/model/catalog/product.php">
      <operation>
         <search position="replace"><![CDATA[$this->db->escape($value['description']) . "'");
         ]]></search>
         <add><![CDATA[$this->db->escape($value['description']) . "', specs = '" . $this->db->escape($value['specs']) . "'");
         ]]></add>
      </operation>

That will actually match in both places that you need it with the single operation (add and edit). And it lessens the chance that another vQmod that alters a different part of that query from breaking.

But other than that, yes you can alter ANY code in ANY php or tpl file except the main index.php file
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18199
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby Qphoria » Wed Aug 24, 2011 1:39 pm

JAY6390 wrote:If you get a blank white screen, you are getting an error, its just that OC isn't catching it. This is something I've come across quite a bit and it really annoys me, so I just do the following. Open your index.php file, find the line with startup.php and after that line add
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL); 

and save. This should be done for the admin/index.php if you are having trouble with that, and for the one in the root directory if you're having trouble with that one. Note for a production environment you should comment these two lines out for the root index.php at least, so that errors are hidden to the general public


This is the best advice I could give anyone... the blank screen is so frustrating. Almost as frustrating as the new and useless 1.5.x "JSON Syntax error"
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18199
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby JAY6390 » Wed Aug 24, 2011 1:45 pm

lmao very true. I'm still disappointed that the JSON return code for things like the add to cart is HTML rather than JSON data that can be used to update the page. This is a must for the design to be scalable IMO
ImageImageImage

Better Product SEO URL's - Perfectly structured product links
Better Category SEO URL's - Give subcategories the same SEO keyword
SEO URL's Route Editor - Fix all of your index.php links


Image
User avatar
JAY6390
 
Posts: 4633
Joined: Wed May 26, 2010 3:47 pm
Location: United Kingdom

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby madimar » Wed Aug 24, 2011 1:59 pm

Qphoria wrote:Remember the golden rule.. less is more. Changing this much code means that other mods may not match. In reality you are only changing one small part of the query so try to match on less if possible.

That will actually match in both places that you need it with the single operation (add and edit). And it lessens the chance that another vQmod that alters a different part of that query from breaking.

But other than that, yes you can alter ANY code in ANY php or tpl file except the main index.php file


You are totally right Q. In these days I'm more and more trying to code optimized vqmod scripts with a particular care in order to avoid conflicts with other mods. To do so, I'm try to avoiding, as much as possible, "replace" function.
For this reason, I think a very good improvement could be the implementation of inline "after", "before" functions (listed in future features). What about their implementation?

At the moment I'm experimenting a sort of workaround in some cases... I'm not sure it is the best way to do things. Let me give you an example for your opinion/feedback.

Code: Select all
   <operation>
            <search position="after"><![CDATA[
      $sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
         ]]></search>
            <add><![CDATA[
      // madimar mod   
      $sql = str_replace (' FROM `', ', sr.name AS sales_rep FROM `', $sql);
      $sql .= " LEFT JOIN " . DB_PREFIX . "sales_rep sr ON (o.sales_rep_id = sr.sales_rep_id) ";
      // madimar mod end      
         ]]></add>
        </operation>


Basically in this way I mantain the original line unchanged in the code, limiting, hopefully the conflicts with other scripts.

What do you think about? Q, Jay?

Regards,

M
User avatar
madimar
 
Posts: 989
Joined: Thu Sep 24, 2009 10:27 am

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby Qphoria » Wed Aug 24, 2011 2:20 pm

Yes it is true, inline after/before would be good. But it can be done in a pseudo-way like I showed above.. by using replace and finding the line and replacing the same line with code after it. Since if that line changed anyway, it wouldn't match anyway so the same effect still happens.
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18199
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby JAY6390 » Wed Aug 24, 2011 2:22 pm

Inline before/after would become a bit of a nightmare if there are multiple matches
ImageImageImage

Better Product SEO URL's - Perfectly structured product links
Better Category SEO URL's - Give subcategories the same SEO keyword
SEO URL's Route Editor - Fix all of your index.php links


Image
User avatar
JAY6390
 
Posts: 4633
Joined: Wed May 26, 2010 3:47 pm
Location: United Kingdom

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby madimar » Wed Aug 24, 2011 2:54 pm

Qphoria wrote:Yes it is true, inline after/before would be good. But it can be done in a pseudo-way like I showed above.. by using replace and finding the line and replacing the same line with code after it. Since if that line changed anyway, it wouldn't match anyway so the same effect still happens.


I'm not sure I understood correctly. If you replace the line, you will have a different code in your file.
Adding directly in the file those str_replace operations (as in my example), mantains the original line unchanged in the file.
If all the other mods work in the same way, I think the conflict risk is minor even if not completely avoided.
User avatar
madimar
 
Posts: 989
Joined: Thu Sep 24, 2009 10:27 am

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby opencartisalright » Thu Aug 25, 2011 6:44 am

Qphoria wrote:That will actually match in both places that you need it with the single operation (add and edit). And it lessens the chance that another vQmod that alters a different part of that query from breaking.

But other than that, yes you can alter ANY code in ANY php or tpl file except the main index.php file


Thanks Q. Less is more, got it. Will change it now in my vQmod file.

Also one more question, can vQmod be used to change the javascript files? Like if I want to modify common.js, can I use vQmod to modify it?
opencartisalright
 
Posts: 375
Joined: Sun Feb 20, 2011 8:09 pm

Re: [MOD] - VirtualQMod "vQmod" Virtual File Modification Sy

Postby JAY6390 » Thu Aug 25, 2011 9:21 am

No you can't modify JS unfortunately, JS doesn't get routed through the opencart MVC, it's just sent directly to your browser
ImageImageImage

Better Product SEO URL's - Perfectly structured product links
Better Category SEO URL's - Give subcategories the same SEO keyword
SEO URL's Route Editor - Fix all of your index.php links


Image
User avatar
JAY6390
 
Posts: 4633
Joined: Wed May 26, 2010 3:47 pm
Location: United Kingdom

PreviousNext

Return to Free Contributions

Who is online

Users browsing this forum: No registered users and 11 guests

Hosted by Arvixe Web Hosting