[code]
OK I called my last post product scroller hack only because it seems like that's what people in these forums refer to them as. I would not call it a hack, as it is actually just a modification. So I modify the code to accommodate the features we want.
So these modifications were in response to lucato, a virtuemart forum member. He requested these features be added so I took action to help out virtuemart users as I would want help if I needed it as well. So here it goes.
Product Scroller Modifications include:
1.) Be able to not display featured (on special) products.
2.) Be able to not display products with Zero price.
3.) Be able to not display products not in stock.
Like my other post, you can either download the files and replace the files in the following directory:
modules/mod_productscroller/
Virtuemart forums will not allow me to upload PHP files so I will upload that file as a text file. Just replace the .txt with .php
Also these files include my product specification modification which allows you to specify exactly which products you want to display in the scoller either by product ID, category ID, or parent category ID.
That modification is posted here:
http://forum.virtuemart.net/index.php?topic=57596I would also recommend saving a copy of the original files in case my modification 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:
<param name="featuredProducts" type="radio" default="no"
label="Featured Products Only"
description="Display only products that are featured (marked special)">
<option value="yes">Yes</option>
<option value="no">No</option>
</param>
and REPLACE with the following code:
<param name="featuredProducts" type="list" default="no"
label="Featured Products Display"
description="Display featured (marked special) products alone, with other products, or do not display.">
<option value="yes">Show only featured products</option>
<option value="none">Do not show featured products</option>
<option value="no">Show featured products with other products</option>
</param>
now find the following code:
<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:
<param name="productZeroPrice" type="radio" default="yes"
label="Display products with zero price?"
description="Defines whether or not products with zero price will be displayed.">
<option value="yes">Yes</option>
<option value="no">No</option>
</param>
<param name="productStock" type="radio" default="yes"
label="Display products not in stock?"
description="Defines whether or not products not in stock will be displayed.">
<option value="yes">Yes</option>
<option value="no">No</option>
</param>
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:
/**
* // scroll, alternate, slide
* @var $ScrollBehavior
*/
var $ScrollBehavior = 'scroll';
Add the following code directly ABOVE that code:
/**
* @var $productZeroPrice
*/
var $productZeroPrice = 'yes';
/**
* @var $productStock
*/
var $productStock = 'yes';
Now find the following code:
$this->ScrollSection = $params->get('ScrollSection', $this->ScrollSection);
Add the following code directly ABOVE that code:
[code} //Product Modification
$this->productZeroPrice = $params->get('productZeroPrice', $this->productZeroPrice);
$this->productStock = $params->get('productStock', $this->productStock);
//End of Product Modification[/code]
Ok now find the following code:
function getProductSKU( $limit=0, $how=null, $category_id=0, $featuredProducts='no' ) {
or if you already did my product selector modification then you will see this:
function getProductSKU( $limit=0, $how=null, $category_id=0, $featuredProducts='no', $productSelector='all', $productSelectorText='' ) {
now REPLACE that code with:
function getProductSKU( $limit=0, $how=null, $category_id=0, $featuredProducts='no', $productSelector='all', $productSelectorText='', $productZeroPrice='yes', $productStock='yes' ) {
Now find the following code:
$query .= "\n WHERE p.product_publish = 'Y' AND c.category_publish = 'Y' AND p.product_parent_id=0 ";
add the following code directly ABOVE that code:
//Prodoct Zero Price
$query .= "\nJOIN #__{vm}_product_price as price ON p.product_id=price.product_id";
//End of Product Zero Price
Now find the following code:
if( $featuredProducts=='yes' ) {
$query .= "\n AND product_special = 'Y' ";
}
REPLACE that code with the following code:
if( $featuredProducts=='yes' ) {
$query .= "\n AND product_special = 'Y' ";
//Added Do not Display featured products
} elseif ( $featuredProducts=='none' ) {
$query .= "\n AND product_special != 'Y'";
//End of Do not Display featured products
}
//Product Zero Price
if( $productZeroPrice=='no' ) {
$query .= "\n AND price.product_price != 0 ";
}
//End of Product Zero Price
//Product in Stock
if( $productStock=='no' ) {
$query .= "\n AND p.product_in_stock != 0 ";
}
//End of Product in Stock
Now find the following code:
$rows = getProductSKU( $scroller->NumberOfProducts, $scroller->ScrollSortMethod, $scroller->category_id, $scroller->featuredProducts );
or if you already did my product selector modification then you will see this:
$rows = getProductSKU( $scroller->NumberOfProducts, $scroller->ScrollSortMethod, $scroller->category_id, $scroller->featuredProducts, $scroller->productSelector, $scroller->productSelectorText );
REPLACE that code with the following code:
$rows = getProductSKU( $scroller->NumberOfProducts, $scroller->ScrollSortMethod, $scroller->category_id, $scroller->featuredProducts, $scroller->productSelector, $scroller->productSelectorText, $scroller->productZeroPrice, $scroller->productStock );
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 you now have more flexibility with the product scroller. ENJOY!
-Mike Divine
[attachment cleanup by admin]