Post by 5ulo » Wed Aug 24, 2011 4:36 pm

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

CID, VAT ID / ICO, DIC (vQmod) for OC 1.5.x
Autofill SEO field (vQmod) for OC 1.4.x-1.5.x


User avatar
New member

Posts

Joined
Thu Oct 21, 2010 6:47 am
Location - Trnava, Slovakia, EU

Post by rph » Wed Aug 24, 2011 4:37 pm

Remove the line break.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by opencartisalright » Wed Aug 24, 2011 4:59 pm

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. ???

Active Member

Posts

Joined
Mon Feb 21, 2011 4:09 am

Post by 5ulo » Wed Aug 24, 2011 5:08 pm

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

CID, VAT ID / ICO, DIC (vQmod) for OC 1.5.x
Autofill SEO field (vQmod) for OC 1.4.x-1.5.x


User avatar
New member

Posts

Joined
Thu Oct 21, 2010 6:47 am
Location - Trnava, Slovakia, EU

Post by madimar » Wed Aug 24, 2011 5:28 pm

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).

-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------


User avatar
Active Member

Posts

Joined
Thu Sep 24, 2009 6:27 pm


Post by opencartisalright » Wed Aug 24, 2011 5:29 pm

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?

Active Member

Posts

Joined
Mon Feb 21, 2011 4:09 am

Post by uksitebuilder » Wed Aug 24, 2011 5:36 pm

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
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by JAY6390 » Wed Aug 24, 2011 5:41 pm

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by JAY6390 » Wed Aug 24, 2011 5:47 pm

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by opencartisalright » Wed Aug 24, 2011 5:58 pm

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.

Active Member

Posts

Joined
Mon Feb 21, 2011 4:09 am

Post by Qphoria » Wed Aug 24, 2011 9: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


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Aug 24, 2011 9: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


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JAY6390 » Wed Aug 24, 2011 9: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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by madimar » Wed Aug 24, 2011 9: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

-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------


User avatar
Active Member

Posts

Joined
Thu Sep 24, 2009 6:27 pm


Post by Qphoria » Wed Aug 24, 2011 10: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


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JAY6390 » Wed Aug 24, 2011 10:22 pm

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by madimar » Wed Aug 24, 2011 10: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.

-----------------------------------------------------------------------
My last mods: Partita IVA e CF | Pro EU VAT Number | Sales Agents | Pricelist Pro
-----------------------------------------------------------------------


User avatar
Active Member

Posts

Joined
Thu Sep 24, 2009 6:27 pm


Post by opencartisalright » Thu Aug 25, 2011 2:44 pm

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?

Active Member

Posts

Joined
Mon Feb 21, 2011 4:09 am

Post by JAY6390 » Thu Aug 25, 2011 5:21 pm

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

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by Qphoria » Thu Aug 25, 2011 9:20 pm

madimar wrote:
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.
Well no.. Think about it
You have to search "abc123"
and replace with "abc123-XYZ"

You are replacing the exact same code with the original code plus your new code.
And you are actually bound to rule since your search would have to match in the first place
So another script could use that same search tag without breaking anything

So If you had search "abc123"
and inline-after "-XYZ"
still resulting in "abc123-XYZ"
You'd still end up with all the same pieces of the puzzle
And another script could still search on the tag the same way.

It is 6 vs half-dozen.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 11 guests