Author Topic: display products in the same category on flypage.  (Read 14024 times)

baggiesmad

  • Jr. Member
  • **
  • Posts: 308
display products in the same category on flypage.
« on: April 14, 2010, 12:01:56 pm »
Hi

At the moment I have related products being displayed on the flypage.

All products in the same category are related to each other.

Is there anyway I can get it to display all the products in the same category (including the main flypage product) ?

I do have a demo site setup so let me know if you want me to PM you the link.

Thanks

mmikkel

  • Beginner
  • *
  • Posts: 7
Re: display products in the same category on flypage.
« Reply #1 on: April 23, 2010, 16:53:36 pm »
Sorry, can't help you, but I would also really like to know this.

I need to list other products from the same category as the currently viewed product - on the flypage.

Anybody? :)

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10358
  • VirtueMart Version: 3+
Re: display products in the same category on flypage.
« Reply #2 on: April 23, 2010, 16:55:09 pm »
credit given to RB

<?php   // find all the other products in this category
$q = "SELECT p.product_id, p.product_name, c.category_name, c.category_flypage
   FROM #__{vm}_product p,#__{vm}_product_category_xref pc, #__{vm}_category c
   WHERE p.product_publish='Y' AND pc.product_id = p.product_id AND pc.category_id = c.category_id AND c.category_id = '$category_id' AND p.product_id != '$product_id'
   ORDER BY p.product_name ";
$db = new ps_DB;
$db->query( $q );
if( $db->next_record() )  {
   echo 'Other products in the category "'.$db->f('category_name').'"<br />';
   $flypage = $db->f('category_flypage');
   $db->reset();
   while( $db->next_record() ) {
      ?><a href="<?php  $sess->purl(URL . "index.php?page=shop.product_details&flypage=$flypage&product_id=" . $db->f("product_id") . "&category_id=$category_id" ) ?>"><?php $db->p("product_name"); ?></a><br />
      <?php
   }
}
?>
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

mmikkel

  • Beginner
  • *
  • Posts: 7
Re: display products in the same category on flypage.
« Reply #3 on: April 23, 2010, 16:58:57 pm »
Wow, that was fast. Thanks a lot BanquetTables!

I need to show the product images as well, but I think I can get there myself. :)

baggiesmad

  • Jr. Member
  • **
  • Posts: 308
Re: display products in the same category on flypage.
« Reply #4 on: April 23, 2010, 17:11:00 pm »
Wow, that was fast. Thanks a lot BanquetTables!

I need to show the product images as well, but I think I can get there myself. :)

Just tried that and I also need the thumbnail to show as well.


mmikkel

  • Beginner
  • *
  • Posts: 7
Re: display products in the same category on flypage.
« Reply #5 on: April 23, 2010, 17:13:30 pm »
I'm working on it. I've added p.product_thumb_image to the query, but it doesn't output the value of that database field - only getting "".

This is what the DB gives me: ["product_thumb_image"]=>  string(0) ""

mmikkel

  • Beginner
  • *
  • Posts: 7
Re: display products in the same category on flypage.
« Reply #6 on: April 23, 2010, 17:15:05 pm »
I'm probably being dumb. Can somebody explain the prefixes to the different fields in the db query? In p.product, what's up with the p? Has it got anything to do with data types in the db?

mmikkel

  • Beginner
  • *
  • Posts: 7
Re: display products in the same category on flypage.
« Reply #7 on: April 23, 2010, 17:50:15 pm »
Turns out I was being a gigantic moron. The DB output for product_thumb_image was empty, because... I hadn't added any images for the other products in the category yet. OMG.

Anyway, it worked. To output the thumb image, just add "p.product_thumb_image" to the DB query above:

$q = "SELECT p.product_id, p.product_name, p.product_thumb_image, c.category_name, c.category_flypage
            FROM #__{vm}_product p,#__{vm}_product_category_xref pc, #__{vm}_category c
            WHERE p.product_publish='Y' AND pc.product_id = p.product_id AND pc.category_id = c.category_id AND c.category_id = '$category_id' AND p.product_id != '$product_id'
            ORDER BY p.product_name ";

Then, you can get the value by echoing $db->f("product_thumb_image"). This will give you the filename of the thumb image without the full URL path, though. So you need to add the base url to display the picture.

I did it like this:

while( $db->next_record() ) {
   $thumb = $db->f("product_thumb_image");
   if($image){
      echo "<img src="IMAGEURL."product/".$image;
   } else {
      // display placeholder art instead
}

:)

baggiesmad

  • Jr. Member
  • **
  • Posts: 308
Re: display products in the same category on flypage.
« Reply #8 on: April 23, 2010, 18:02:34 pm »
Brilliant,

Is it possible to also display the product title and thumbnail image for the main product (on this flypage) along with all the others in the same category?

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10358
  • VirtueMart Version: 3+
Re: display products in the same category on flypage.
« Reply #9 on: April 23, 2010, 18:07:36 pm »
now you are going to have to get formatted html to display all the products in a table format.

1 below another will look horrible.

Can anybody fix this up to go 4 wide, and then echo another row if needed?

J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

nosf

  • Beginner
  • *
  • Posts: 1
Re: display products in the same category on flypage.
« Reply #10 on: July 30, 2010, 18:19:45 pm »
Hello,

someone can help me out whit this small question...

Where to put this code exactly

while( $db->next_record() ) {
   $thumb = $db->f("product_thumb_image");
   if($image){
      echo "<img src="IMAGEURL."product/".$image;
   } else {
      // display placeholder art instead
}


Replace this part?

while( $db->next_record() ) {
   
      ?><a href="<?php  $sess->purl(URL . "index.php?page=shop.product_details&flypage=$flypage&product_id=" . $db->f("product_id") . "&category_id=$category_id" ) ?>"><?php $db->p("product_thumb_image"); ?></a><br />
      <?php
   }
}

David McKillen

  • Beginner
  • *
  • Posts: 10
Re: display products in the same category on flypage.
« Reply #11 on: September 23, 2010, 21:13:41 pm »
I just want to say thanks and excellent work to BanquetTables.pro and mmikkel on this one. Your efforts are much appreciated!

Dave

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10358
  • VirtueMart Version: 3+
Re: display products in the same category on flypage.
« Reply #12 on: September 23, 2010, 23:15:45 pm »
nosf what are you trying to do, i dont understand the questiuon
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

smartypants

  • Guest
Re: display products in the same category on flypage.
« Reply #13 on: February 14, 2011, 13:10:00 pm »
I think the question is how to generate a GET request to display the results in the main component.

Vichell10

  • Beginner
  • *
  • Posts: 5
Re: display products in the same category on flypage.
« Reply #14 on: April 12, 2011, 07:27:50 am »
Turns out I was being a gigantic moron. The DB output for product_thumb_image was empty, because... I hadn't added any images for the other products in the category yet. OMG.

Anyway, it worked. To output the thumb image, just add "p.product_thumb_image" to the DB query above:

$q = "SELECT p.product_id, p.product_name, p.product_thumb_image, c.category_name, c.category_flypage
            FROM #__{vm}_product p,#__{vm}_product_category_xref pc, #__{vm}_category c
            WHERE p.product_publish='Y' AND pc.product_id = p.product_id AND pc.category_id = c.category_id AND c.category_id = '$category_id' AND p.product_id != '$product_id'
            ORDER BY p.product_name ";

Then, you can get the value by echoing $db->f("product_thumb_image"). This will give you the filename of the thumb image without the full URL path, though. So you need to add the base url to display the picture.

I did it like this:

while( $db->next_record() ) {
   $thumb = $db->f("product_thumb_image");
   if($image){
      echo "<img src="IMAGEURL."product/".$image;
   } else {
      // display placeholder art instead
}

:)

Hi thank you so much for this :) this is exactly what i'm looking for, but can I ask one more thing..how can I use the pagination for this? hope for your prompt reply, tnx in advance!