Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how to show next product in array


Guest

Recommended Posts

Hi...

 

I am playing around with the display of products. I've gone into product_listing.php and have copied the code used to display the product image into where the code to display the Buy Now button used to be - so it now looks like:

 

case 'PRODUCT_LIST_BUY_NOW':

$lc_align = 'center';

if (isset($HTTP_GET_VARS['manufacturers_id'])) {

$lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';

} else {

$lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a> ';

}

break;

 

You can see what I mean at: http://www.caffebianchi.com/catalog/index.php?cPath=1_17

 

I did this because I want to display more than one product in a row - but all my change has done is create 2 images of the same product in the same row.

 

How can I tell it to show Product A and then Product B in the same row? Is it something to do with adding a +1 to the array listing? Any help with this would be really wonderful.

 

Thanks,

J

Link to comment
Share on other sites

Undo what you did (i.e. return to the original). In includes/modules/product_listing.php, around lines 79-85, replace

      if (($rows/2) == floor($rows/2)) {
       $list_box_contents[] = array('params' => 'class="productListing-even"');
     } else {
       $list_box_contents[] = array('params' => 'class="productListing-odd"');
     }

     $cur_row = sizeof($list_box_contents) - 1;

with

      if (($rows/2) == floor($rows/2)) {
       if (($rows/4) == floor($rows/4)) {
         $list_box_contents[] = array('params' => 'class="productListing-even"');
       } else {
         $list_box_contents[] = array('params' => 'class="productListing-odd"');
       }
     }

     $cur_row = (sizeof($list_box_contents) - 1)/2;

See if this gets you closer to what you want.

 

Hth,

Matt

Link to comment
Share on other sites

Do you mean like this?

 

$cur_row = (sizeof($list_box_contents))/2;

 

Doing this makes the image cells move around... the header row still appears in the first cell though ;/

 

I tried a few other combinations (no logic behind my combinations though).

 

Combinations such as:

 

$cur_row = (sizeof($list_box_contents) - - 1)/2;

 

$cur_row = (sizeof($list_box_contents) + 3)/2;

 

These combinations moved the image cells around - some even put the header in the top row, but it only ever extended across one column instead of across the entire top row.

 

More confused :huh:

J

Link to comment
Share on other sites

This should fix your header problem (it's a hack job, but it works):

Near the top of the page find this code:

  $list_box_contents = array();
 for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
   switch ($column_list[$col]) {

and add this just after it:

      case 'PRODUCT_LIST_IMAGE':
       $lc_text = TABLE_HEADING_IMAGE;
       $lc_align = 'center';
       break;

Then look down the page for this:

    if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') {
     $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
   }

and replace it with this:

      $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);

That gives you the header for the image column. Now you need to duplicate the column headers as many times as you have image columns. Find this code just below the above:

    $list_box_contents[0][] = array('align' => $lc_align,
                                  'params' => 'class="productListing-heading"',
                                    'text' => ' ' . $lc_text . ' ');

and add this after it:

    $list_box_contents[1][] = array('align' => $lc_align,
                                  'params' => 'class="productListing-heading"',
                                    'text' => ' ' . $lc_text . ' ');
   $list_box_contents[2][] = array('align' => $lc_align,
                                  'params' => 'class="productListing-heading"',
                                    'text' => ' ' . $lc_text . ' ');
   $list_box_contents[3][] = array('align' => $lc_align,
                                  'params' => 'class="productListing-heading"',
                                    'text' => ' ' . $lc_text . ' ');

I did say this was a hack, didn't I? But it does work.

 

I also did a mod to give you three columns (as you showed me before); please post here if you want to see it. I'm afraid that it is no more elegant than the above, but it also works.

 

Regards

Jim

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

Link to comment
Share on other sites

Hi Jim,

 

Will give this a shot... if you could post that 3 column solution here as well I'd love to see it. Hack or no hack, it'd be much better than what I've come up with... none of which has worked! <_<

 

Thanks,

J

Link to comment
Share on other sites

Ok, here it is. All of these modifications are in includes/classes/boxes.php (It made sense to me to modify the function that produces the HTML for the product list.)

 

Find this code near line 22:

    function tableBox($contents, $direct_output = false) {

and change it to this:

    function tableBox($contents, $direct_output = false, $product_listing = false) {      

Now find this code starting around line 30:

          $tableBox_string .= '  <tr';
         if (tep_not_null($this->table_row_parameters)) $tableBox_string .= ' ' . $this->table_row_parameters;
         if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) $tableBox_string .= ' ' . $contents[$i]['params'];
         $tableBox_string .= '>' . "\n";

and change it to this:

        if ((($i/3) == floor($i/3)) || ($product_listing == false)) {
         $tableBox_string .= '  <tr';
         if (tep_not_null($this->table_row_parameters)) $tableBox_string .= ' ' . $this->table_row_parameters;
         if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) $tableBox_string .= ' ' . $contents[$i]['params'];
         $tableBox_string .= '>' . "\n";
       }

Now find this code around line 65:

          $tableBox_string .= '  </tr>' . "\n";

and change it to this:

        if (((($i+1)/3) == floor(($i+1)/3)) || ($product_listing == false)) {
         $tableBox_string .= '  </tr>' . "\n";
       }

Note the /3 in the above two replacements. This is what changes the number of column sets. If you wanted four sets of product & price columns you can change this to /4. This could easily be set up with an admin interface to change the numbers if anyone wants.

 

One last change -- find this code near line 176:

  class productListingBox extends tableBox {
   function productListingBox($contents) {
     $this->table_parameters = 'class="productListing"';
     $this->tableBox($contents, true);

and change that last line to this:

      $this->tableBox($contents, true, true);

and we have it. Crude but working well; I tested this on my development box.

 

Let me know if this does or does not do what you wanted.

 

Regards

Jim

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

Link to comment
Share on other sites

Hmmmm.... I just reloaded the default versions of:

 

product_listing.php

boxes.php

split_page_results.php

 

and then made the changes prescribed in the last two posts by kymation.

 

It is getting there... I have more than 1 product listed per row... but some new errors are appearing.

 

Maybe I'm doing something wrong? I don't think so though ;/

 

You can see what I mean by visiting:

http://www.caffebianchi.com/catalog/index....d47e8d99caef20d

Link to comment
Share on other sites

Just wanted to say thanks to Matt and Jim for taking the time to try and help me out on this one. Both your solutions helped me to finally figure out how to list three products per row (although the way I've done it is shonky - it works - yay!).

 

If anyone wants to see how I butchered the code to make it work for me, you can message me and I'll post it up.

Link to comment
Share on other sites

Thx Jim,

 

Here are the changes I made - talk about Hacksville! ;)

 

At approximately line 30, just before

      case 'PRODUCT_LIST_MODEL':
       $lc_text = TABLE_HEADING_MODEL;
       $lc_align = '';
       break;

I added the following (as suggested)

     case 'PRODUCT_LIST_IMAGE':
      $lc_text = TABLE_HEADING_IMAGE;
      $lc_align = 'center';
      break;

 

 

At approximately line 64, I deleted the following

    if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
     $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
   }

 

 

At approximately line 68, I changed the following

    $list_box_contents[0][] = array('align' => $lc_align,
                                   'params' => 'class="productListing-heading"',
                                   'text' => ' ' . $lc_text . ' ');

to what's below

    $list_box_contents[0][] = array('params' => 'class="productListing-odd"');
    $list_box_contents[1][] = array('params' => 'class="productListing-even"');

 

 

And at approximately line 85, I changed the following

      $cur_row = sizeof($list_box_contents) - 1;

to what's below

      $cur_row = sizeof($list_box_contents)/3;

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...