Post by daveanderson88 » Thu Jun 28, 2012 1:11 am

Hi Guys,
I am trying to write my first VQMOD script.

What I want to do is find any instance of alt="" (ie a blank alt tag) in product descriptions all product pages, and replace with alt="the product name" or perhaps alt="seo keyword".

So far I have got this:

Code: Select all

	
<file name="???">
		<operation>
			<search position="after">alt=""</search>
			<add>alt="<?php echo $product_name; ?>"</add>
		</operation>		
	</file>
But I am unsure which file name to use because the html product description is not in a template file.
Can anyone help me out please.

Thanks very much.

Dave

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Thu Jun 28, 2012 2:19 am

Unless you're using a custom template that removed the feature OpenCart already automatically populates the alt tags with the product name.

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Thu Jun 28, 2012 2:35 am

.
Last edited by daveanderson88 on Thu Jun 28, 2012 2:37 am, edited 1 time in total.

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by daveanderson88 » Thu Jun 28, 2012 2:36 am

rph wrote:Unless you're using a custom template that removed the feature OpenCart already automatically populates the alt tags with the product name.
yes it populates the ones uploaded through data>image, but I have other images in the html code within General>Description:

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Thu Jun 28, 2012 3:17 am

Then you'll want to modify the catalog product controller.

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Thu Jun 28, 2012 3:29 am

Thanks for your help RPH,

Ok so my complete code is as follows,
<modification>

<id>Populate Blank Alt Tags</id>
<version>1.0.0</version>
<vqmver>2.1.5</vqmver>
<author>Dave Anderson</author>
<file name="/catalog/controller/product/product.php">
<operation>
<search position="replace">alt=""</search>
<add>alt="<?php echo $product_name; ?>"</add>
</operation>
</file>

</modification>
But still I am getting alt="" all though the source code.
What else would I need to change.

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Thu Jun 28, 2012 2:56 pm

No, you need to replace:

Code: Select all

$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
With something like:

Code: Select all

$this->data['description'] = str_replace('alt=""', 'alt="' . $product_info['name'] . '"', html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'));

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Thu Jun 28, 2012 5:44 pm

Thanks so much for your help Ryan, I really appreciate your time, but I am still not getting it to work.

I have the following:

Code: Select all

<modification>

	<id>Populate Blank Alt Tags</id>
	<version>1.0.0</version>
	<vqmver>2.1.5</vqmver>
	<author>Dave Anderson</author>
	
	<file name="/catalog/controller/product/product.php">
      <operation>
         <search position="replace"><![CDATA[$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');]]</search>
         <add><![CDATA[$this->data['description'] = str_replace('alt=""', 'alt="' . $product_info['name'] . '"', html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'));"]]
      </add>      
   </operation>

</file>



</modification>
But it is still not working, also it is throwing up errors in vqmod manager:
Warning: simplexml_load_file(): /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/vqmod/xml/populate_blank_alt_tags.xml:19: parser error : CData section not finished $this->data['description'] = html_entity_decode($p in /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/admin/controller/module/vqmod_manager.php on line 129Warning: simplexml_load_file(): in /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/admin/controller/module/vqmod_manager.php on line 129Warning: simplexml_load_file(): ^ in /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/admin/controller/module/vqmod_manager.php on line 129Warning: simplexml_load_file(): /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/vqmod/xml/populate_blank_alt_tags.xml:19: parser error : Premature end of data in tag search line 10 in /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/admin/controller/module/vqmod_manager.php............ etc
What else is wrong with is.
Thanks again
Dave

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Thu Jun 28, 2012 11:13 pm

Remove the first forward slash from the file name.

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Thu Jun 28, 2012 11:41 pm

rph wrote:Remove the first forward slash from the file name.
Still no luck,

no replacement of the alt tags and still a list of errors.

Code: Select all

<modification>

	<id>Populate Blank Alt Tags</id>
	<version>1.0.0</version>
	<vqmver>2.1.5</vqmver>
	<author>Dave Anderson</author>
	
	<file name="catalog/controller/product/product.php">
      <operation>
         <search position="replace"><![CDATA[$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');]]</search>
         <add><![CDATA[$this->data['description'] = str_replace('alt=""', 'alt="' . $product_info['name'] . '"', html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'));"]]
      </add>      
   </operation>

</file>



</modification>

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Fri Jun 29, 2012 1:34 am

Look in the VQMod error log.

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Fri Jun 29, 2012 10:59 pm

rph wrote:Look in the VQMod error log.
Im getting:
REQUEST URI : /pixel-tc-252-intervalometer-type-n3-for-canon
MOD DETAILS:
modFile : /hsphere/local/home/fastforwardtime/fastforwardtime.co.uk/vqmod/xml/populate_blank_alt_tags.xml
id : Populate Blank Alt Tags
version : 1.0.0
vqmver : 2.1.5
author : Dave Anderson
SEARCH NOT FOUND (ABORTING MOD): alt=""
But the description source code has lots of alt=" tags, why cant it find any?

Thanks

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Fri Jun 29, 2012 11:15 pm

It doesn't matter what the processed HTML source has. VQMod acts on PHP source. The error means it can't find the line of code so you're probably using a different OpenCart version than 1.5.3.1. Look in the referenced controller file and find out what the line of code that assigns product description says.

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Fri Jun 29, 2012 11:53 pm

rph wrote:It doesn't matter what the processed HTML source has. VQMod acts on PHP source. The error means it can't find the line of code so you're probably using a different OpenCart version than 1.5.3.1. Look in the referenced controller file and find out what the line of code that assigns product description says.
I have looked in the file, it has the exact line

Code: Select all

$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
BTW its version 1.5.2.1

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Sat Jun 30, 2012 12:14 am

Okay, it looks like you left the old search line in. There should be only one operation.

-Ryan


rph
Expert Member

Posts

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

Post by daveanderson88 » Sat Jun 30, 2012 2:00 am

rph wrote:Okay, it looks like you left the old search line in. There should be only one operation.
Sorry I don't understand, I though I did only have one operation ????

New member

Posts

Joined
Mon Feb 20, 2012 7:45 am

Post by rph » Sat Jun 30, 2012 3:13 am

Then it's probably an error from your old script. It's searching for 'alt=""' and failing but it shouldn't be looking for that anywhere. Looking at the old code you used it's malformed. Use this:

Code: Select all

<modification>
	<file name="catalog/controller/product/product.php">
		<operation>
			<search position="replace"><![CDATA[$this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');]]></search>
			<add><![CDATA[$this->data['description'] = str_replace('alt=""', 'alt="' . $product_info['name'] . '"', html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8'));]]></add>
		</operation>
	</file>
</modification>

-Ryan


rph
Expert Member

Posts

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

Post by rwalker » Sat Aug 04, 2012 4:53 am

Thank you it works great!!

Discount Golf Clubs and Golf Equipment - Powered by Opencart


New member

Posts

Joined
Fri Jul 01, 2011 8:14 am

Post by bertjebel » Tue Aug 07, 2012 2:30 am

If you do so than also add a title tag to your pictures. Not mandatory yet but good for indexing images. Advice to fill Alt with $product_info['meta_description'] That is what the Alt tag is for, description of the picture. The title tag can be used for summary of the picture

Code: Select all

$this->data['description'] = str_replace('alt=" " ', 'alt= " ' . $product_info['meta_description'] . ' " title= " ' . $product_info['name'] . ' " ', html_entity_decode($product_info[		'description'], ENT_QUOTES, 'UTF-8'));

My shops running Opencart Multistore:
Koptelefoon, audio kabels en speakers kopen
Led lampen en verlichting
Alle kabels- audiokabel, computerkabel, stroomkabel
Koptelefoon en In ear oordopjes / oortjes Apple iPhone, Samsung Smartphone
Smartphone hoesjes en oordopjes Apple iPhone en Samsung
Online Aanbiedingen en Sales
Hoesjes, Covers en accessoires Tablet en smartphone


User avatar
Active Member

Posts

Joined
Tue Jun 21, 2011 11:17 am

Who is online

Users browsing this forum: No registered users and 7 guests