Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Options as Images in Shopping Cart


colinchar

Recommended Posts

Hi

 

We are looking for some advice on tackling a problem we have on our version 2.2 site [www.walton-rugs.co.uk] that we believe is causing the majority of shopping carts to be abandoned. We sell rugs and in about half the products there are colour/design alternatives so we have 'Options as Images' enabled. When the customer selects a colour/design option and then procedes to shopping cart page the thumbnail image is the very first image loaded for the product and not the colour/design option selected [though the option text is listed as No 1 against the product description]

 

We've trawled these forums but can't find a solution though tanterlising there have been mentions/people with similar needs though their threads seem to peter out [unsolved?]

 

We have determined the following;

 

Images and thumbnails for Products are uploaded to ..\images\products\{directory_named_for_supplier}\....

Images for Option are uploaded to ..\images\options\.... Do not see this as a problem since it can be worked around by uploading Option images to Products folders

 

The Option image filename is stored in the database as the field product_option_values_thumbnail in table product_option_values. We think the joining of relevent database tables is like this products.product_id = products_attributes.product_id, products_attributes.option_value_id = product_options_values.product_option_values_id but we are unsure where an additional many to many table product_options_values_to_prod fits in and we suspect that products_attributes.option_id needs to be in the WHERE part of SQL.

 

The piece of coding that we suspect needs changing is the function get_products() in includes\classes\shopping_cart.php with additions of a SQL to get a value for $option_image [if it exists - remember some products come without alternative colour/design options]

 

We include the section of coding below with comments where we think the changes should be and would appreciate some help from more experienced coders.

 


function get_products() {
     global $languages_id;

     if (!is_array($this->contents)) return false;

     $products_array = array();
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_carrot, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
       if ($products = tep_db_fetch_array($products_query)) {
         $prid = $products['products_id'];
         $products_price = $products['products_price'];

         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
         if (tep_db_num_rows($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }

//*****************************************************************************
//option_image_query to return $option_image and handle error if not existing
//*****************************************************************************

         $products_array[] = array('id' => $products_id,
                                   'name' => $products['products_name'],
                                   'model' => $products['products_model'],
                                   'image' => $products['products_image'],
								'carrot' => $products['products_carrot'],
                                   'price' => $products_price,
                                   'quantity' => $this->contents[$products_id]['qty'],
                                   'weight' => $products['products_weight'],
                                   'final_price' => ($products_price + $this->attributes_price($products_id)),
                                   'tax_class_id' => $products['products_tax_class_id'],
                                   'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
       }
     }

//*****************************************************************************
//code to $products_array[] = array('image' => $option_image) if $option_image exists otherwise leave as products_image
//*****************************************************************************


     return $products_array;
   }

Link to comment
Share on other sites

Hi All

 

Suprises me that no responses to this question after 30+ hours. Can't tell whether question is to complicated or to trivial.

 

I'm going to try and make copy of site on a XAMP local computer [sSL on live site - do I need to disable this for local site?].

 

Found some code by Community member fixdeo that outputs Session variables so that I can determine parameters for SQL.

 

Would still appreciate some advice though.

Link to comment
Share on other sites

Hello,

 

I got almost the same problem. I like to have an extra column ( product_condition) in my shoppingcart. But it don't get the information from the database. I got no problem with product listing of order history. Only I don't see the column in my shoppingcart. Does somebody knows where the information for the shoppingcart is defined? I got this product function in includes\classes\shopping_cart.php

 

function get_products() {
     global $languages_id;
     // BOF Separate Pricing Per Customer
// global variable (session) $sppc_customer_group_id -> class variable cg_id
 global $sppc_customer_group_id;

 if(!tep_session_is_registered('sppc_customer_group_id')) {
 $this->cg_id = '0';
 } else {
  $this->cg_id = $sppc_customer_group_id;
 }
// EOF Separate Pricing Per Customer

     if (!is_array($this->contents)) return false;

     $products_array = array();
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
     //MVS start - added v.vendors_id, v.vendors_name, and v.vendors_id = p.vendors_id
       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_condition, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id, v.vendors_id, v.vendors_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_VENDORS . " v where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and v.vendors_id = p.vendors_id and pd.language_id = '" . (int)$languages_id . "'");
       //MVS end

       if ($products = tep_db_fetch_array($products_query)) {
         $prid = $products['products_id'];
         $products_price = $products['products_price'];


  $specials_price = tep_get_products_special_price($prid);
 if (tep_not_null($specials_price)) {
 $products_price = $specials_price;
     } elseif ($this->cg_id != 0){
       $customer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$prid . "' and customers_group_id =  '" . $this->cg_id . "'");
       if ($customer_group_price = tep_db_fetch_array($customer_group_price_query)) {
       $products_price = $customer_group_price['customers_group_price'];
       }
 }
// EOF Separate Pricing Per Customer

         $products_array[] = array('id' => $products_id,
                                   'name' => $products['products_name'],
											'condition' => $products['products_condition'],
                                   'model' => $products['products_model'],
                                   'image' => $products['products_image'],
                                   'price' => $products_price,
                                   'quantity' => $this->contents[$products_id]['qty'],
                                   'weight' => $products['products_weight'],
                                   'final_price' => ($products_price + $this->attributes_price($products_id)),
                                   'tax_class_id' => $products['products_tax_class_id'],
                                   //MVS start
                                   'vendors_id' => $products['vendors_id'],
                                   'vendors_name' => $products['vendors_name'],
                                   //MVS end

                                 'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''),
'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''));
       }
     }

 

Hope somebody can help us..

Link to comment
Share on other sites

Hello,

 

I got almost the same problem. I like to have an extra column ( product_condition) in my shoppingcart. But it don't get the information from the database. I got no problem with product listing of order history. Only I don't see the column in my shoppingcart. Does somebody knows where the information for the shoppingcart is defined? I got this product function in includes\classes\shopping_cart.php

 

Hi

 

Is product_condition = New or Used Condition and there is a price difference between conditions?

 

The OSC application I'm using is customised for us by Eshopfitters so that when I'm adding a product I've got a lot more options than the vanilla OSC. For example there are product Options I can define with different prices, data saved to product_options, product_options_values database tables. These give the customer a dropdown option to select before adding to basket, so for example I can set New condition at twice the price of Old.

 

Also there are 5 additional summary fields that get saved in products_description database table. Could say New or Old in one of these though cannot have a price difference unless duplicate product with alternative condition.

 

The snippet of code I included in my question is merely to do with how should I get the Options image there is code further up in the shopping_cart class that deals with attributes. This may be where you should be looking though if you do not have the Options enabled when you add/edit a product nothing will be saved to the fields in the database tables.

 

Regards

Link to comment
Share on other sites

Yes that's what I like. But make it another way. I copied products_model in my database to products_models_2. I manual fill the table.

With some copy past I get this information showed in the product listing, invoice, packingslip etc. of course you have to do somewhere

 

$product_query = tep_db_query("select pd.products_name, p.products_id, p.products_price, p.products_quantity, p.products_model, p.products_image, p.products_condition,  p.products_quantity, p.products_weight from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and pd.products_name like '".$_REQUEST['prod_search']."%'");

 

to

 

$product_query = tep_db_query("select pd.products_name, p.products_id, p.products_price, p.products_quantity, p.products_model, p.products_model_2,p.products_image, p.products_condition,  p.products_quantity, p.products_weight from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and pd.products_name like '".$_REQUEST['prod_search']."%'");

 

But I realy don't know where to look to make an extra column in the shoppingcart. The column itself is not the problem, also the title is easy. But to fill this with the database information from products_model_2 ..... I realy don't know which file I have to edit.

 

Hope you can help me..

Link to comment
Share on other sites

Yes that's what I like. But make it another way. I copied products_model in my database to products_models_2. I manual fill the table.

With some copy past I get this information showed in the product listing, invoice, packingslip etc. of course you have to do somewhere

 

$product_query = tep_db_query("select pd.products_name, p.products_id, p.products_price, p.products_quantity, p.products_model, p.products_image, p.products_condition,  p.products_quantity, p.products_weight from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and pd.products_name like '".$_REQUEST['prod_search']."%'");

 

to

 

$product_query = tep_db_query("select pd.products_name, p.products_id, p.products_price, p.products_quantity, p.products_model, p.products_model_2,p.products_image, p.products_condition,  p.products_quantity, p.products_weight from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and pd.products_name like '".$_REQUEST['prod_search']."%'");

 

But I realy don't know where to look to make an extra column in the shoppingcart. The column itself is not the problem, also the title is easy. But to fill this with the database information from products_model_2 ..... I realy don't know which file I have to edit.

 

Hope you can help me..

 

Hi Simpel

 

Do you mean you have added extra field to PRODUCT table called products_model_2 then fill it using phpMyadmin? or do you have a Product Model 2 text box below the Product Description textarea on your add new product form? I don't think we are talking about quite the same thing since my OSC has been customised by eshopfitters. I've added a screendump of top half of my add new product form to show the add Options feature.

 

add_new_product_screen.jpg

 

Can't see anything wrong with your $products_query SQL so have you done following modifications further on as follows, you are just loading a value into an array

 

$products_array[] = array('id' => $products_id, 
                                   'name' => $products['products_name'], 
                                   'condition' => $products['products_condition'], 
                                   'model' => $products['products_model'],
                                   'model_2' => $products['products_model_2'], 
                                   'image' => $products['products_image'], 
                                   'price' => $products_price, 
                                   'quantity' => $this->contents[$products_id]['qty'], 
                                   'weight' => $products['products_weight'], 
                                   'final_price' => ($products_price + $this->attributes_price($products_id)), 
                                   'tax_class_id' => $products['products_tax_class_id'], 
                                   //MVS start 
                                   'vendors_id' => $products['vendors_id'], 
                                   'vendors_name' => $products['vendors_name'], 
                                   //MVS end 

                                 'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''), 
'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : '')); 
       }

 

This is not giving me answers to my problem and I would suggest that you start a thread of your own since someone else will probably be more knowledgeable on this topic.

 

Good Luck

 

Colin

Link to comment
Share on other sites

....But I realy don't know where to look to make an extra column in the shoppingcart. The column itself is not the problem, also the title is easy. But to fill this with the database information from products_model_2 ..... I realy don't know which file I have to edit.

 

Hope you can help me..

 

Hi Simpel

 

quick search of add ons and this looks promising Products Extra Fields

 

Hope this Helps

 

Bye

 

Colin

Link to comment
Share on other sites

Eventually cracked this, took a big hammer and coding is not pretty but seems to work so so.

 

To refresh your memories the problem was to show the image of the product colour/design option in the shopping cart. We seemed to be having quite a lot of abandoned carts were the potential customer repeatedly reloaded the cart. We assume that because only the first product image was displayed were as they had selected a different colour/design option they assumed that they would not receive their choice.

 

I could not get the OOP approach of trying to modify includes/classes/shopping_cart.php just got to complicate with the many bolt-ons handling image calls. So KISS took the hammer to shopping_cart.php in root, code snippet is below with changes I made commented.

 

For those that are interested the KPI of sales to unique shopping cart views was 8.3% during last 31 days prior to making modification [Google analytics], don't know how this compares with everyone else but a couple of percentage points increase is hoped for.

 

As promised below is the relevent section of hacked code, if anyone can suggest a neater solution it would be greatly appreciated. The changes can be viewed at www.walton-rugs.co.uk when a product is added to the shopping basket.

 

$products = $cart->get_products();
   for ($i=0, $n=sizeof($products); $i<$n; $i++) {
// Push all attributes information in an array
     if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
       while (list($option, $value) = each($products[$i]['attributes'])) {
         echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);

//Colin changed SQL to get 'products_options_values_thumbnail' = option image jpg

         $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, poval.products_options_values_thumbnail, pa.options_values_price, pa.price_prefix
                                     from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                     where pa.products_id = '" . (int)$products[$i]['id'] . "'
                                      and pa.options_id = '" . (int)$option . "'
                                      and pa.options_id = popt.products_options_id
                                      and pa.options_values_id = '" . (int)$value . "'
                                      and pa.options_values_id = poval.products_options_values_id
                                      and popt.language_id = '" . (int)$languages_id . "'
                                      and poval.language_id = '" . (int)$languages_id . "'");
         $attributes_values = tep_db_fetch_array($attributes);

         $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
         $products[$i][$option]['options_values_id'] = $value;
         $products[$i][$option]['products_options_values_name'] = $attributes_values['products_options_values_name'];
         $products[$i][$option]['products_options_values_thumbnail'] = $attributes_values['products_options_values_thumbnail'];          $products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
         $products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];
       }
     }
   }

   for ($i=0, $n=sizeof($products); $i<$n; $i++) {
     if (($i/2) == floor($i/2)) {
       $info_box_contents[] = array('params' => 'class="productListing-even"');
     } else {
       $info_box_contents[] = array('params' => 'class="productListing-odd"');
     }

     $cur_row = sizeof($info_box_contents) - 1;

     $info_box_contents[$cur_row][] = array('align' => 'center',
                                            'params' => 'class="productListing-data" valign="center"',
                                            'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'],'','style="border:0px"'));

    //<!--BOF dangling carrot v2.0--> 

if ($products[$i]['carrot'] == "1"){
   			$products_name = '<table border="0" cellspacing="2" cellpadding="2">' .
	'  <tr>' .
	'    <td class="productListing-data" align="center">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</td>' .
	'    <td class="productListing-data" valign="top"><b>' . $products[$i]['name'] . '</b>';
}
else{
     $products_name = '<table border="0" cellspacing="2" cellpadding="2">' .
                      '  <tr>' .
                      '    <td class="productListing-data" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '">' . tep_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>' .
                      '    <td class="productListing-data" valign="top"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><b>' . $products[$i]['name'] . '</b></a>';

}
//<!--EOF dangling carrot v2.0--> 

     if (STOCK_CHECK == 'true') {
       $stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
       if (tep_not_null($stock_check)) {
         $any_out_of_stock = 1;

         $products_name .= $stock_check;
       }
     }

     if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
       reset($products[$i]['attributes']);
       while (list($option, $value) = each($products[$i]['attributes'])) {
         $products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';

//Colin added simple switch to show option image if it exists

	  if(strlen($products[$i][$option]['products_options_values_thumbnail']) >1 ) {

	  $products_name .= '<br><img src="images/options/' .$products[$i][$option]['products_options_values_thumbnail'].'" width="80" height="80" border="0" alt="' .$products[$i][$option]['products_options_values_name'] .'" title="' .$products[$i][$option]['products_options_values_name'] .'">';

	  }        }
     }

     $products_name .= '    </td>' .
                       '  </tr>' .
                       '</table>';

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...