Author Topic: Product Scroller Modification! Specify exactly which products you want!  (Read 10131 times)

MikeDivine

  • Beginner
  • *
  • Posts: 49
I wanted the product scroller module to be able to have exactly which products you wanted to scroll either by specifying for product ID's or Category ID's or Parent Category ID's. This didn't exist, so I spent some time and created the modification to make it work. Also the scroll align was not working properly, so I fixed that as well.

Ok you can either download the files and replace the files in the following directory:
modules/mod_productscroller/

I can't upload PHP files so I will upload that file as a text file. Just replace the .txt with .php
I would also recommend saving a copy of the original files in case my hack somehow doesn't get along with your version.

Or you can go into the files and add some code:

(Take aware the fact that I use the terms ABOVE and BENEATH when talking about adding code. I also use the term REPLACE, so take note as to what I say each time or your code will not function correctly)

First file is:
modules/mod_productscroller/mod_productscroller.xml

Find the following code:

Code: [Select]
<param name="ScrollSortMethod" type="radio" default="random"
label="In which Order the products shall be displayed?"
description="Defines the display order of the products.">
<option value="newest">Newest</option>
<option value="oldest">Oldest</option>
<option value="random">Random</option>
</param>

Add the following code directly ABOVE that code:

Code: [Select]
<param name="productSelector" type="list" default="all"
label="Select products to display"
description="Select products to be displayed in scroller either by Product or Category. Then enter the Product ID or Category ID below. If multiple, seperate by commas.">
<option value="all">All</option>
<option value="parent">Parent Category</option>
<option value="category">Category</option>
<option value="product">Product</option>
</param>
<param name="productSelectorText" type="text" default=""
label="Product ID or Category ID"
description="Enter the Product ID or Category ID. If multiple, seperate by commas." />

That is all you have to modify with that file.
Now open the following file:

modules/mod_productscroller/mod_productscroller.php

I will go in order down the page so to not make you jump around.

Find the following code:

Code: [Select]
var $featuredProducts = false;
Directly BENEATH add the following code:

Code: [Select]
/**
* @var $productSelector
*/
var $productSelector = 'all';
/**
* @var $productSelectorText
*/
var $productSelectorText = '';

Then find the following code:

Code: [Select]
$this->featuredProducts = $params->get('featuredProducts', $this->featuredProducts);
Directly BENEATH add the following code:

Code: [Select]

//Product Selector Hack
$this->productSelector          = $params->get('productSelector', $this->productSelector);
$this->productSelectorText = $params->get('productSelectorText', $this->productSelectorText);
//End of Product Selector Hack

The next 2 code adds are to fix the alignment feature which never seemed to work. These are optional if you don't want to.

Find the following code:

Code: [Select]

$show_product_name = ( $this->show_product_name == "yes" ) ? true : false;
$show_addtocart = ( $this->show_addtocart == "yes" ) ? true : false;
$show_price = ( $this->show_price == "yes" ) ? true : false;

Directly ABOVE add the following code:

Code: [Select]

// scroll align fix
echo "<div align=\"".$this->ScrollAlign."\">";
// end scroll align fix

Find the following code:

Code: [Select]

   echo "    </marquee>
            </div>";
} // end displayScroller

Directly ABOVE this code add:

Code: [Select]
// scroll align fix
echo "</div>";
// end scroll align fix

OK back to finishing the scroller hack.

Find the following code:

Code: [Select]
function getProductSKU( $limit=0, $how=null, $category_id=0, $featuredProducts='no' ) {
and REPLACE with the following code:

Code: [Select]
function getProductSKU( $limit=0, $how=null, $category_id=0, $featuredProducts='no', $productSelector='all', $productSelectorText='' ) {
Now find the following code:

Code: [Select]
$query .= "\nJOIN #__{vm}_category as c ON pc.category_id=c.category_id";
Directly BENEATH add the following code:

Code: [Select]
//Product Selector Hack
$query .= "\nJOIN #__{vm}_category_xref as cat ON pc.category_id=cat.category_child_id";
//End of Product Selector Hack

Find the following code:

Code: [Select]
switch( $how ) {
case 'random':
$query .= "\n ORDER BY RAND() $limit";
break;
case 'newest':
$query .= "\n ORDER BY p.cdate DESC $limit";
break;
case 'oldest':
$query .= "\n ORDER BY p.cdate ASC $limit";
break;
default:
$query .= "\n ORDER BY p.cdate DESC $limit";
break;
}

Directly ABOVE add the following code:

Code: [Select]
//*************************************************************************
//          Begin Product Selector Hack                                 ***
//*************************************************************************

if( $productSelector=='parent' ) {
$pulledApart = explode(",", $productSelectorText);
if ( count($pulledApart) < 2 ) {
$query .= "\n AND cat.category_parent_id=$productSelectorText";
} else {
$query .= "\n AND cat.category_parent_id=$pulledApart[0]";
$x = 1;
do {
  $query .= "\n OR cat.category_parent_id=$pulledApart[$x]";
  $x++;
} while ( $x < count($pulledApart) );
}
} elseif ( $productSelector=='category' ) {
$pulledApart = explode(",", $productSelectorText);
if ( count($pulledApart) < 2 ) {
$query .= "\n AND pc.category_id=$productSelectorText";
} else {
$query .= "\n AND c.category_id=$pulledApart[0]";
$x = 1;
do {
  $query .= "\n OR pc.category_id=$pulledApart[$x]";
  $x++;
} while ( $x < count($pulledApart) );
}
} elseif ( $productSelector=='product' ) {
$pulledApart = explode(",", $productSelectorText);
if ( count($pulledApart) < 2 ) {
$query .= "\n AND p.product_id=$productSelectorText";
} else {
$query .= "\n AND p.product_id=$pulledApart[0]";
$x = 1;
do {
$query .= "\n OR p.product_id=$pulledApart[$x]";
$x++;
} while ( $x < count($pulledApart) );
}

}
//*************************************************************************
//          End of Product Selector Hack                                ***
//*************************************************************************

Now find the following code:

Code: [Select]
$rows = getProductSKU( $scroller->NumberOfProducts, $scroller->ScrollSortMethod, $scroller->category_id, $scroller->featuredProducts );
and REPLACE with the following code:

Code: [Select]
$rows = getProductSKU( $scroller->NumberOfProducts, $scroller->ScrollSortMethod, $scroller->category_id, $scroller->featuredProducts, $scroller->productSelector, $scroller->productSelectorText );
And that should be it! Now goto your modules in admin and either create a new module with the productScroller type or goto the default one and choose products to display and enter the id or if multiple id's then seperate by commas. ENJOY!

[attachment cleanup by admin]

Luciffere

  • Jr. Member
  • **
  • Posts: 66
  • Web Design de Calitate
    • Web Design de Calitate
Re: Product Scroller Modification! Specify exactly which products you want!
« Reply #1 on: August 12, 2009, 15:55:35 pm »
Thank's fot this hack.
With your hack or the original files, the arrea of scroller is empty first for 2 sec, and then the first products start to scroll from the right (in my case).

I need to arrea shown 6 products on start, and start scroll with the 7 product.



[attachment cleanup by admin]
Gift based on total order
Web design, logo, branding, joomla, virtuemart, flash. Portofoliu web design: http://www.luciffere.ro/portofoliu.html

lily fairy

  • Beginner
  • *
  • Posts: 1
Re: Product Scroller Modification! Specify exactly which products you want!
« Reply #2 on: September 01, 2009, 14:41:11 pm »
Hello

all is ok for me
i've add the id categories and it's going well  ;)

but i could not 'align' the items with the title and the price
i don't understand before these changes, it was align center :(

sorry for my english, i'm french ;)
Sorry for my poor english
and thank you very much for this marvellous forum :)

andre`

  • Beginner
  • *
  • Posts: 8
Re: Product Scroller Modification! Specify exactly which products you want!
« Reply #3 on: September 09, 2009, 12:29:09 pm »
Hi MikeDivine im trying your mod because in the default module my products appeared duplicated (when i insert a product i select more than one category). Writing directly the ID of the product don't solve the problem of duplication if a product is in more categories. Do you have any idea for fix this?

yarilo

  • Beginner
  • *
  • Posts: 4
Re: Product Scroller Modification! Specify exactly which products you want!
« Reply #4 on: October 27, 2009, 13:24:31 pm »
@MikeDivine:
First of all, thanks for sharing this useful informations with us... I was wondering, could you give me a hint how to extend this hack so I don't need to enter the category_ID manually, but when a user clicks on a specific category, the Product Scroller to scroll products only from that category, and yet, when the user then clicks on another category, the Scroller to start showing products only from that category... Which files and variables should be changed and how to pass the product_id value to those files so i can do some changes...

Thanks in advance

Regards,
Darko

lecer

  • Beginner
  • *
  • Posts: 22
Re: Product Scroller Modification! Specify exactly which products you want!
« Reply #5 on: November 12, 2011, 22:45:36 pm »
Hi,
i've got an error

Warning: Invalid argument supplied for foreach() in /homepages/36/d269782856/htdocs/mysite/modules/mod_productscroller/mod_productscroller.php on line 236.

Somebody know why ?

Perhaps now, in 2011 there's an another Hack somewhere ?