Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 2nd, 2011, 06:48 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default Substituting words in product descriptions

Hi Eric,

What would be the best way to substitute a particular word in all product descriptions and names?

My site is in another language than the product feed and I'd ilke to substitute say all occurrences of the word "boot" with the language equivalent, so my site gets more weight for the relevant key terms.

I tried doing an SQL replace on the word in the product table for the name and description fields, and although that seems to work fine I am concerned that that change will be overwritten on the next shop update...

Can you recommend a good way of achieving this?

Thanks,

Anders
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #2  
Old May 2nd, 2011, 08:43 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

You could try running the product descriptions through your own PHP function which would make the replacements for you:

<?php echo mysubstitute($product->description); ?>

And in your mysubstitute(), you could use http://php.net/manual/en/function.str-replace.php
  #3  
Old May 3rd, 2011, 09:45 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Hi Eric,

That works quite well - very clever :-)

I added this function to the top of any views containing the text:
Code:
<?php
  function mysubstitute($text_string) {
    $search = array("Boots", "boots");
    $replace = array("Stovler", "stovler");
    return str_replace($search, $replace, $text_string);
}
?>
And then I changed all occurrences of:
Code:
[product.description]
to:
Code:
<?php echo mysubstitute($product->description); ?>
And similarly for [product.name].

It seems to work quite well... however this piece of work is carried out every time the data is shown, i.e. for a category up to 2 * 48 times. The breadcrumb does not reflect the change in the data and you cannot search for the changed word either. This is not a problem for me as this is my main keyword, but you have to be aware of this.

Could I load up the database with a copy of the original text in the table for custom text and do the conversion there? That would retain the new description on store updates? Or is the custom text not stored in the local database? (I couldn't seem to find a table for it)...

Once again thanks for this brilliant idea...

Cheers,

Anders
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #4  
Old May 3rd, 2011, 09:59 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Thanks for posting your solution.

There's really no way to store the new data in the database and have that data reflected in breadcrumbs and search results. The only thing that will work is to take the new description and add it as a custom description in the Factory.

Or, after running an update, do a massive REPLACE on your database, making the necessary search and replaces. If done correctly, will allow you to have the new content in searches and breadcrumbs.

Eric
  #5  
Old May 3rd, 2011, 10:01 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Oh, how can I set the image alt text?

I can set the title on the link, but the alt text is automatically set to product.name (I am using [product.image tag='1'] in the code now).

Thanks,

Anders
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #6  
Old May 3rd, 2011, 10:03 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Hi again Eric...

Thanks for you reply...

One of the major benefits of v3 is the auto-update of the shops, and I don't want to have to re-run database updates every 3 days ;-)

Anyways, the solution you provided will be fine for my purposes, so thanks a bunch for your help!
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #7  
Old May 3rd, 2011, 10:10 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Got it...

Substitute
Code:
[product.image tag='1']
with
Code:
<img src="[product.image]" alt="<?php echo mysubstitute($product->name); ?>" title="<?php echo mysubstitute($product->name); ?>">
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #8  
Old May 4th, 2011, 04:55 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Okay, after a bit of messing around this is what I have ended up with...

At the top of the product list on the store front page, the category and search pages and on the product detail page I have added this piece of code:
Code:
<?php
  function mysubstitute($text_string) {
    $search = array("Boots", "boots");
    $replace = array("Stovler", "stovler");
    return str_replace($search, $replace, $text_string);
}
?>
Note! It is not a coincidence that I have not added this code to the top of the Related Products widget. It uses the function added in the product detail view.

Of course you will need to change the Boots example to fit your site.

In the product list code on the store front page, the category and search page and in the related products custom view I have made the following changes (note that some of the code here is my custom code, so yours might vary a bit):
Code:
<!-- Product list -->
<div class="pl">
  [product.each]
  <?php $myproductname = mysubstitute($product->name); ?>
  
  <div class="t1 col3">
  <div class="bdr">
    <div class="thmb"><a href="[product.link]" alt="<?php echo $myproductname; ?>" title="<?php echo $myproductname; ?>"><img src="[product.image]" alt="<?php echo $myproductname; ?>" title="<?php echo $myproductname; ?>"></a></div>
    <div class="prc"><strong>[product.currency mode="sign"][product.price]</strong></div>
    <br>
    <p class="desc" align="center">[product.brand]<br><?php echo $myproductname; ?></p>
    <div class="prc">[product.merchant_logo]</div>
    <div class="btns">
    <a href="[product.url direct='0']" title="Køb <?php echo $myproductname; ?>" class="dfbutton dforange dfmedium" target="_blank" onClick="_gaq.push(['_trackEvent', 'BuyButton', 'Click']);">Køb</a>
    <a href="[product.link]" title="Mere info om <?php echo $myproductname; ?>" class="dfbutton dforange dfmedium">Info</a>
    </div>
    <div class="clearingdiv"> </div>
  </div>
  </div>
  [product.end]
  <div class="clearingdiv"> </div>
</div>
<!-- /Product list -->
And on the product detail page I have (full code):
Code:
<?php
  function mysubstitute($text_string) {
    $search = array("Boots", "boots");
    $replace = array("Stovler", "stovler");
    return str_replace($search, $replace, $text_string);
}     
?>

<?php $myproductname = mysubstitute($product->name); ?>

<br />
<!-- Single Product -->
<div class="sp">
    <div class="thmb">
      <a href="[product.url direct='0']" title="<?php echo $myproductname; ?>" target="_blank" onClick="_gaq.push(['_trackEvent', 'BuyButton', 'Click']);"><img src="[product.image]" alt="<?php echo $myproductname; ?>" title="<?php echo $myproductname; ?>"></a>
    </div>
  <br />  <br />
    <h2><a href="[product.url direct='0']" title="<?php echo $myproductname; ?>" target="_blank" onClick="_gaq.push(['_trackEvent', 'BuyButton', 'Click']);"><?php echo $myproductname; ?></a></h2>
  <br><br>
  <p class="desc"><?php echo mysubstitute($product->description); ?></p>
  <br><br>
  <p class="desc">Leverandør: [product.merchant]</p>
  <br><br>
  <h3><div class="prc">Pris: [product.currency mode="sign"][product.price]</div></h3>
    <br><br>
    <div class="btns" align="center">
      <a href="[product.url]" class="dfbutton dforange dflarge" title="Køb dette produkt" target="_blank" onClick="_gaq.push(['_trackEvent', 'BuyButton', 'Click']);">Køb</a>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:window.history.go(-1)" class="dfbutton dforange dflarge" title="Gå tilbage til den forrige side">Tilbage</a>
  </div>
  <div class="clearingdiv"> </div>
</div>
<!-- /Single Product -->
This should take care of things...

I have not noticed any performance hit.

As the database is not changed your users will not find anything if they search for the words you have changed.

The bread crumbs and urls are not updated by this.

Why is this important?

Google reads your site and decides what it is all about. In Google Webmaster tools you can see how significant Google thinks your site is for different keywords.

If you sell products on a web site in one language with product descriptions in another language Google will be 'mislead' to think that your site is about 'Boots' instead of 'Stovler' as in my example.

On the site in question Google found 62,635 occurrences of the word Boots and 16,027 occurrences of the word Stovler. With this code change Google should see my site being all about Stovler... hopefully with about 80,000 occurrences of the word...

Hope this helps :-)
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #9  
Old May 4th, 2011, 08:34 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

One tip I can provide... You can put your function mysubstitute($text_string) { ... } in your theme's functions.php file. This will give you access to the function everywhere without putting that functionality into your views. You can write any functions you want in your functions.php file and Datafeedr will be able to access them.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:45 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.