You are here:  » Extras


Extras

Submitted by crounauer on Wed, 2006-04-05 12:33 in

Hi David,

By default the "Extra" fields are added directly after the description. In some cases this causes the text to exceed the current limit and thus cuts it short.

I think it would make more sense to include the "Extra" fields as a seperate entry all together.

I have had a look but am just not sure how it adds these fields on so have been unable to change the location!

Hope this makes sense.

Simon.

Submitted by support on Wed, 2006-04-05 12:40

Hi Simon,

Are you referring to the cropped description on the search results pages? If so, that can be changed in html/searchresults.php (line 17 in the distribution)

Currently:

<p><?php print substr($product["description"],0,250); ?></p>

You can either change the number 250 to reduce or increase the limit, or remove the limit all together and change it to just:

<p><?php print $product["description"]; ?></p>

That would of course only be recommended if you are only working with product feeds that have very short description fields...

Submitted by crounauer on Wed, 2006-04-05 12:49

Hi David,

Yes, I am refereing to the cropped description in the search results.

Would it not however make more sense to be able to include the extra fields no matter if the text was cropped or not?

I think it would make the end result more "constant" for price tapestry as a whole.

<tr>
<td>
.....description....
</td>
</tr>
<tr>
<td>
.....extra fields with no text limit...
</td>
</tr>

Could you perhaps point the way to move the extras please?

Computer Hardware

Submitted by support on Wed, 2006-04-05 12:52

Do you have PHPMyAdmin or Webmin installed so that you can modify the database?

Stage 1 is to add a new field to the products table. Call it "extras", and of type "text", just like the description field.

Let me know if you're OK with that and i'll look at some code hacks for you...

Submitted by crounauer on Wed, 2006-04-05 13:00

Ok, done...

Computer Hardware

Submitted by support on Wed, 2006-04-05 13:26

Ok,

First step is to construct the extra description into a variable instead of appending it to the description. In includes/admin.php, look for the following code inside the admin__importRecordHandler($record) function:

<?php
    
/* apply extras */
    
if ($admin_importExtrasExist)
    {
      foreach(
$admin_importExtras as $k => $v)
      {
        
$record[$admin_importFeed["field_description"]] .= " ".$v." ".$record[$k]." ";
      }
    }
?>

Change this to:

<?php
    
/* apply extras */
    
$extras "";
    if (
$admin_importExtrasExist)
    {
      foreach(
$admin_importExtras as $k => $v)
      {
        
$extras .= " ".$v." ".$record[$k]." ";
      }
    }
?>

Secondly, you have to get this new field into the database. To do this, look for the main create product record SQL construction, which starts on Line 245 of the same file:

<?php
    
/* create product record */
    
$sql sprintf("INSERT INTO `".$config_databaseTablePrefix."products` SET
                    merchant='%s',
                    name='%s',
                    description='%s',
                    image_url='%s',
                    buy_url='%s',
                    price='%s',
                    search_name='%s',
                    category='%s',
                    brand='%s',
                    dupe_hash='%s'
                    "
,
                    
database_safe($admin_importFeed["merchant"]),
                    
database_safe($record[$admin_importFeed["field_name"]]),
                    
database_safe(isset($record[$admin_importFeed["field_description"]])?$record[$admin_importFeed["field_description"]]:""),
                    
database_safe(isset($record[$admin_importFeed["field_image_url"]])?$record[$admin_importFeed["field_image_url"]]:""),
                    
database_safe($record[$admin_importFeed["field_buy_url"]]),
                    
database_safe($record[$admin_importFeed["field_price"]]),
                    
database_safe($searchName),
                    
database_safe($category),
                    
database_safe($brand),
                    
$dupe_hash
                    
);
?>

Change this to:

<?php
    
/* create product record */
    
$sql sprintf("INSERT INTO `".$config_databaseTablePrefix."products` SET
                    merchant='%s',
                    name='%s',
                    description='%s',
                    extras='%s',
                    image_url='%s',
                    buy_url='%s',
                    price='%s',
                    search_name='%s',
                    category='%s',
                    brand='%s',
                    dupe_hash='%s'
                    "
,
                    
database_safe($admin_importFeed["merchant"]),
                    
database_safe($record[$admin_importFeed["field_name"]]),
                    
database_safe(isset($record[$admin_importFeed["field_description"]])?$record[$admin_importFeed["field_description"]]:""),
                    
database_safe($extras),
                    
database_safe(isset($record[$admin_importFeed["field_image_url"]])?$record[$admin_importFeed["field_image_url"]]:""),
                    
database_safe($record[$admin_importFeed["field_buy_url"]]),
                    
database_safe($record[$admin_importFeed["field_price"]]),
                    
database_safe($searchName),
                    
database_safe($category),
                    
database_safe($brand),
                    
$dupe_hash
                    
);
?>

After making those changes, the extra field should now be populated the next time you import.

Finally, to use the new field, you simply refer to $product["extras"] in the same way that the code references $product["description"]. Note that the array name ($product in this case) may vary depending upon where in the code you are working; but in general wherever you see "description", you can use "extras" against the same array. So, to add the new extras field to the search results....

In html/searchresults.php, change:

  <p><?php print substr($product["description"],0,250); ?></p>

to:
  <p><?php print substr($product["description"],0,250); ?></p>
  <p><?php print $product["extras"]; ?></p>

..and you should be in business...!

Hope this helps

Submitted by crounauer on Wed, 2006-04-05 14:01

Thanks for your help David.

Submitted by PriceSpin on Fri, 2006-04-14 22:21

is there no way of adding an extra table called extras so that a product can have multiple extras??? or does this code allow multiple extras?

Submitted by support on Sat, 2006-04-15 06:32

Yes - this mod does enable multiple extras - the selected "extra" fields from the feed are concatenated together into a single value and then loaded into the new "extras" field in the database.