Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Duplicating the product photo field in admin?


Fyod

Recommended Posts

I've searched around and can't find an answer to my idea.

What I need is each product to be able to have 2 pictures in the product listing, no more or less. The reason being that one will serve as the background, the second will be a regular picture like they are now. I currently have this set up via CSS. The problem is that the background picture has to be the same for every product using CSS, not product dependant.

I am doing this for a shirt store. Background pic will be a certain color shirt, and the regular (foreground) pic will be a transparent PNG with the design.

 

My idea is to do this:

 

in product_listing.php, change from

 

<td align="center" class="vam">'.$p_pic.'</td>

 

to something like

 

<td align="center" class="vam" style="background-image:url('.$p_pic_bkg.')">'.$p_pic.'</td>

 

I'm not sure if that can be done.

 

Then in admin - categories/products - product edit, the field which lets you choose a picture on your local drive would be duplicated.

 

Appropriate changes to the DB would be made, ie. new field for the $p_pic_bkg.

 

Not sure if any others need to be changed.

 

I have standard knowledge od PHP/MySQL so I can imagine how this could be done, but I can't execute that idea.

 

Can anyone help me out?

Link to comment
Share on other sites

The product image would be the colour of the shirt. The overlay image would be the png file.

 

<td align="center" class="vam"><div class="overlay">'.$p_pic.'</div></td>

 

.overlay {

background: url(images/tshirt.png);

}

 

Now the overlay is on top of the image.

 

Please note that as you are using a bought template, this may introduce more difficulties than you first see.

 

I did something a little similar (tshirt overlay, coloured background images) some time ago; http://www.clubosc.com/image-swapping-based-on-attributes-in-oscommerce.html

Link to comment
Share on other sites

  • 2 weeks later...

That's pretty much the way I have it now. But that doesn't allow me to have a different background for each product in the product listings.

What I need is a way to get a database field into the css.

 

For example, in admin, I set the product model to "35.jpg"

So in SQL the table PRODUCTS, row "product 1", field PRODUCTS_MODEL = 35.jpg

 

But I don't know how to get that field into css or plain text.

What I would write in /includes/module/new_products.php like is something like:

 

<td align="center" class="vam"><div style="background:url(images/'.$products_model.');">'.$p_pic.'</div></td>

 

so then the end result will be

 

<td align="center" class="vam"><div style="background:url(images/35.jpg);">'.$p_pic.'</div></td>

 

This way I could set any background for any product.

I don't mind having to upload the backgrounds via FTP, so the admin upload function isn't mandatory.

Link to comment
Share on other sites

Ok, so I'm getting close.

I added this to new_products.php

 

 $p_test = tep_db_query("select products_model from " . TABLE_PRODUCTS . " ");

 

and

 

<div style="background:url('.$p_test.')">'.$p_pic.'</div>

 

but what I get in the result is

 

<div style="background:url(Resource id #116)">

 

What is resource id?

I just want it to write whatever is in the database table "products" and the field "products model" for that one certain product.

Link to comment
Share on other sites

Someone here has got to know how to get an SQL field to show as plain text.

Most of the ones in the php files include href links.

 

So for example if I wanted to show the price, no link, just plain text, how would I tell php to show it based on the database entry?

Link to comment
Share on other sites

Something like this:

 

  //First query the database for the information you want
 $model_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = " . $products_id);

 //Next, retrieve the data. This will be in an array keyed by the database field name.
 $model_array = tep_db_fetch_array ($model_query);

 //Now get the data that you want from the array
 $model = $model_array['products_model'];

 //Finally, output the data
 echo $model;

It appears that you are using the products_model field for something other than the intended purpose. I suggest that you add a new data field instead. All of the existing osC data fields are used in multiple places in the code. Finding and changing all of those locations is more work than adding a new field.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Thank you very much Jim!

I'll try that out asap.

 

Products_model is used in mys tore only in the breadcrumbs, there's no search function for example, I'll be changing the crumbs to products_name anyways.

I've already added a field called "products_bkg" but I don't know how to duplicate the function of the Products model field in admin categories, to set the value. I know how to duplicate the Products model form and the <tr> and <td> in categories.php, but not the function to write into the DB etc.

 

Would you be kind enough to point me in the right direction?

Just a short hint, no need for the coding.

Link to comment
Share on other sites

Search in admin/categories.php for every place that the products_model field is used, and add your new field the same way. It's tedious but not that hard. You can always ask for help on the forum if you don't understand what a chunk of code is doing.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Oh WOW it works!!

At first nothing, then I realized a problem I'd been doing all along, products_id was already changed to $p_id.

Also changed to the new field "products_bkg"

So my resulting code in new_products is:

 

  $product_query = tep_db_query("select products_description, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$new_products['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
 $product = tep_db_fetch_array($product_query);
 $p_id = $product['products_id'];	

 $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';

 $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a>';

 $p_desc = ''.substr($product['products_description'], 0, 97);

 $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</span>';

 //First query the database for the information you want 
 $bkg_query = tep_db_query("select products_bkg, products_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$p_id . "'"); 

 //Next, retrieve the data. This will be in an array keyed by the database field name. 
 $bkg_array = tep_db_fetch_array($bkg_query); 

 //Now get the data that you want from the array 
 $bkg = $bkg_array['products_bkg'];

 

and the frontend code

 

<td align="center" class="vam">
<div style="background:url(images/'.$bkg.'.png); background-repeat:no-repeat; background-position:center; float:;">'.$p_pic.'</div>
</td>

 

Now all I have to do is assign the correct color through the new admin categories.php field, so you just enter 35 (there'll be a table of colors with numbers so you know which number to write).

Resulting in frontend sourcecode:

 

<div style="background:url(images/35.png); background-repeat:no-repeat; background-position:center; float:;">

 

Awesome. And each of them can be changed with a few clicks from within admin.

 

Mad props Jim!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...