Author Topic: Product Scroller "Requests" Fulfilled (zero price, in stock, and featured)  (Read 13152 times)

MikeDivine

  • Beginner
  • *
  • Posts: 49
Code: [Select]
[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=57596

I 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:

Code: [Select]
<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:

Code: [Select]
<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:

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="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:

Code: [Select]
/**
* // scroll, alternate, slide
* @var $ScrollBehavior
*/
var $ScrollBehavior = 'scroll';

Add the following code directly ABOVE that code:

Code: [Select]
/**
* @var $productZeroPrice
*/
var $productZeroPrice = 'yes';
/**
* @var $productStock
*/
var $productStock = 'yes';

Now find the following code:

Code: [Select]
$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:

Code: [Select]
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:

Code: [Select]
function getProductSKU( $limit=0, $how=null, $category_id=0, $featuredProducts='no', $productSelector='all', $productSelectorText='' ) {
now REPLACE that code with:

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

Code: [Select]
$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:

Code: [Select]
//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:

Code: [Select]
if( $featuredProducts=='yes' ) {
$query .= "\n AND product_special = 'Y' ";
}

REPLACE that code with the following code:

Code: [Select]
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:

Code: [Select]
$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:

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

Code: [Select]
$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]

lucato

  • Jr. Member
  • **
  • Posts: 205
Hey Mike, that is "Divine". :0) thanks a lot for your efforts. Unfortunatelly I'll have to report that there is some bugs in the code. The products that should show on my scroll are set as:
- Zero price,
- Zero Stock,
- and as featured products.

So, your code is working weird because it is showing some products twice or hidding a product that has the same settings of the other ones that are showing and it shouldn't hide it and the setting in your "hack" were as:
- Show only Featured products;
- Display products with zero price? (YES);
- Display products not in stock? (YES);

So, IMHO, It should show my products only once and souldn't hide any of them once all had the same settings (Zero price, Zero Stock, and featured). Maybe this combination is driving the code crazy. :0)

Once you know about coding and if you have some extra free time, I donk know if you would get to solve this issue on the scroller too regarding working under IE8. Check this thread: http://forum.virtuemart.net/index.php?topic=57225.msg187144#msg187144

Thanks in advance, and I hope you get to fix these setings. It was exactly what I was looking for. ;0)

MikeDivine

  • Beginner
  • *
  • Posts: 49
OK lucato,

I would need to see your database because the code will not show the same product twice unless it is in the database twice. It pulls SKUs from one table and only pulls once. So I would have to see your database to see why it would be acting that way. I tested the code before I put it up and it is working fine on my local site with joomla 1.5.9 and virtuemart 1.1.2.

Make sure that number of products is set to the amount you want or it will limit itself to only choosing those. The dafault is 5. So if you want more then set it to higher, that could be causing of some of your products missing.

Also make sure that->Select products to display     is set to "All"

Also the scroller scrolls around over and over so if you wait long enough you will see the same products over again. Is this what you meant by displaying the same products more than once?

If you still are having issues I would be happy to take a look at you site if you want to give me some access to your site. I will message you for messenger contact details.

Thank you,
Mike Divine

lucato

  • Jr. Member
  • **
  • Posts: 205
OK lucato,
I would need to see your database because the code will not show the same product twice unless it is in the database twice. It pulls SKUs from one table and only pulls once. So I would have to see your database to see why it would be acting that way. I tested the code before I put it up and it is working fine on my local site with joomla 1.5.9 and virtuemart 1.1.2.
Hi Mike, thanks for your feedback. Mike regarding the database table, I've checked it in the source and there is no double data nor ID#/SKU#. I'm not programmer, but IMHO I think this code does a check/print each product into the scrool like a loop, maybe in this loop it's repeating the product for some reason. Have you tried this code with the settings I've mentioned. I mean, try to set tree products as Zero Price, Zero Stock and Featured and leave the options as I mentioned above in the previous post.

Quote
Make sure that number of products is set to the amount you want or it will limit itself to only choosing those. The dafault is 5. So if you want more then set it to higher, that could be causing of some of your products missing.
- I had only 3 products set this way and it was just showing 2 and 1 doubled. So, the 5 amount isn't an issue in this case.

Quote
Also make sure that->Select products to display     is set to "All"
- Well, I don't think so, once I just want to show the featured products, I should select "Show only Featured products" shouldn't I?

Quote
Also the scroller scrolls around over and over so if you wait long enough you will see the same products over again. Is this what you meant by displaying the same products more than once?
- Nope, I know it shows like a loop and starts over. It is show in a horizontal line and has just 2 or 3 products, so there is a huge gap to start over again and give the impression that was double due that. What I meant was that it was really printing the product twice.

Quote
If you still are having issues I would be happy to take a look at you site if you want to give me some access to your site. I will message you for messenger contact details.
- I don't think it will make any difference once you won't see anything different than I've mentioned here. If you want I can send you the product database that is very small. So, you will see that there is no duplicated register. Just drop me a sitemail with your e-mail.

Thanks,
Lucato.

MikeDivine

  • Beginner
  • *
  • Posts: 49
Quote
Hi Mike, thanks for your feedback. Mike regarding the database table, I've checked it in the source and there is no double data nor ID#/SKU#. I'm not programmer, but IMHO I think this code does a check/print each product into the scrool like a loop, maybe in this loop it's repeating the product for some reason. Have you tried this code with the settings I've mentioned. I mean, try to set tree products as Zero Price, Zero Stock and Featured and leave the options as I mentioned above in the previous post.

When it is pulled from the database there is no loop. A query is run with all the settings specified and every product is pulled from the database that meets the settings criteria and stored in an array. But then when it is output from the array it goes through each product and displays the product content.

So for some reason it is pulling the same product twice from the database. That is what needs to be figured out. Did you download my files and replace yours or did you go into the code and edit? Let me know.

Mike Divine said "Also make sure that->Select products to display     is set to "All" "
Quote
Well, I don't think so, once I just want to show the featured products, I should select "Show only Featured products" shouldn't I?

If you copied my files and used them then underneath the featured products display setting there is a Select products to display setting. That setting needs to be set to All or it will pull using whatever ID's are in the box below using the setting above. Either Product ID's, category ID's or parent category ID's.

I will send you my email through VM Forum messaging system so you can send me a copy of the database.

Thank you,
Mike Divine

MikeDivine

  • Beginner
  • *
  • Posts: 49
OK I think I figured out why they are showing the products twice is because it pulls the product from each category, so if it is assigned to another category it pulls it again using that category. I will work on fixing this.

lucato

  • Jr. Member
  • **
  • Posts: 205
Quote
Did you download my files and replace yours or did you go into the code and edit? Let me know.
I've deleted my 2 files from the server and placed your 2 files. Nope, they weren't edited.

Quote
Mike Divine said "Also make sure that->Select products to display     is set to "All" "
Quote
Well, I don't think so, once I just want to show the featured products, I should select "Show only Featured products" shouldn't I?
Ops, my fault, I made a mistake with the other field above it. The "Show only Featured products" is other option, I'm sorry about that.
Yup, it was set as "ALL".


OK I think I figured out why they are showing the products twice is because it pulls the product from each category, so if it is assigned to another category it pulls it again using that category. I will work on fixing this.
Mike, what I have noticed/figured out is, if the product price is set as NONE/EMPTY and in the product list its price column shows the price as 0,00, the product shows only once, but if I set the product price as 0,00 and my Brazilian currency, and in the product list its price column shows the price as 0,00 BRL, the product shows twice. Weird it, isn't? Regardind the hidden product, I noticed that if the product price is set as NONE/EMPTY and in the product list its price column shows the price as 0,00, and if there is another product in the same category the product gets hidden. If I change it's price to 0,00BRL, it shows the hidden product of the same category. Weird too.

Exchanging the subject and keeping in the main subject... :0) Just to don't forget to mention another suggestion for this ProductScroller module. I don't know if it would be easy and possible to develope, but It would be amazing if it was possible to count the number of clicks that each product in the scroller has received. So, we would have this data list in the back-end or also an option to show only on the back-end or opt to show under the product in the scroller. We would opt to show in both back-end and under product, or just only on back-end. Well just a suggestion.

Thanks in advance,
Lucato.


MikeDivine

  • Beginner
  • *
  • Posts: 49
OK I edited the query to only pull distinct product meaning no duplicates will be shown. I also edited the query for blank fields and not just 0. So if show zero price products is set to no then it won't pull products with 0 or blank price fields and same for stock. So download this new file and replace. Let me know how it goes. Remember to change .txt to .php

Quote
Exchanging the subject and keeping in the main subject... :0) Just to don't forget to mention another suggestion for this ProductScroller module. I don't know if it would be easy and possible to develop, but It would be amazing if it was possible to count the number of clicks that each product in the scroller has received. So, we would have this data list in the back-end or also an option to show only on the back-end or opt to show under the product in the scroller. We would opt to show in both back-end and under product, or just only on back-end. Well just a suggestion.

Would the clicks be counted overall? Or per customer? I think overall would be fairly easy. But let me know what you meant.

Thank you,
Mike Divine

[attachment cleanup by admin]

rdhinman

  • Beginner
  • *
  • Posts: 38
Hi Mike.  Can you tell me if this mod includes the modifications from "Product Scroller Modification! Specify exactly which products you want!".  Or do you have a version which incorporates both modifications?

lucato

  • Jr. Member
  • **
  • Posts: 205
Hey Mike, I'm sorry, I just noticed today that my post wansn't posted. Weird, i remember that I've read the lates reply to you. :0)

Well, regarding your question. I think that the counted overall would be fine and once it is easier too. ;0)

Thanks for the file update! It seems to be working great now! Any news I'll post again and if you get the click counter added, please post the new file here.

A hug.

MikeDivine

  • Beginner
  • *
  • Posts: 49
RDhinman,

Yes the files include both sroller mods.

Lucato,

sorry, been real busy. I'll see if I can get that counter added.

rdhinman

  • Beginner
  • *
  • Posts: 38
Thanks Mike.

hendrix

  • Beginner
  • *
  • Posts: 39
Re: Product Scroller "Requests" Fulfilled (zero price, in stock, and featured)
« Reply #12 on: September 25, 2009, 18:35:51 pm »
Thank you Mike. Your code helped me not to get duplicted products due to multiple category allocation :)

However, now my scroll text is aligned at the left, not center as I want. Do you have an idea how to change this?

Thank you.

Hendrik
Joomla! 1.5.14 and VirtueMart 1.1.4 stable

hendrix

  • Beginner
  • *
  • Posts: 39
Re: Product Scroller "Requests" Fulfilled (zero price, in stock, and featured)
« Reply #13 on: September 25, 2009, 18:47:16 pm »
Got it:
I marked out the scroll align fix in lines 241 and 268...
Joomla! 1.5.14 and VirtueMart 1.1.4 stable

Eden

  • Beginner
  • *
  • Posts: 14
Re: Product Scroller "Requests" Fulfilled (zero price, in stock, and featured)
« Reply #14 on: February 04, 2010, 01:46:04 am »
Can only seem to get this to work on one single parent category, will not let me specify multiple categories or other categorys other than 1.

:(

Any help would be most apprecaited as this scroller rocks!