Author Topic: A module to let user chose whether (s)he wants to see Out of Stock items  (Read 3470 times)

hobby.lego

  • Beginner
  • *
  • Posts: 2
By default, only the administrator can chose whether or not products out of stock are to be shown.

I've developed a little module to let users chose whether they want to see or not Out of Stock items. This module requieres some little changes in core files. Here they are.


1/ Download zip file with module and class file.
https://docs.google.com/uc?id=0B-_NtOhgeBRAMjU2OGI0ZjMtYTIzMC00NGE2LTgwOGMtZGQwN2FlY2YxOGQ2&export=download&hl=fr

3/ In administrator\components\com_virtuemart\global.php, add at row 105
require_once(CLASSPATH."ps_shownotinstock.php");

4/ Replace every occurrence of
if( CHECK_STOCK && PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS != "1") {
by
if( getShowOnlyInStock()) {

That is in following files:
administrator\components\com_virtuemart\classes\ps_product.php
administrator\components\com_virtuemart\classes\ps_product_attribute.php
administrator\components\com_virtuemart\classes\ps_product_category.php
administrator\components\com_virtuemart\html\shop.ask.php
administrator\components\com_virtuemart\html\shop.product_details.php
administrator\components\com_virtuemart\html\shop_browse_queries.php
modules\mod_productscroller\mod_productscroller.php
modules\mod_virtuemart_featureprod\mod_virtuemart_featureprod.php
modules\mod_virtuemart_latestprod\mod_virtuemart_latestprod.php
modules\mod_virtuemart_randomprod\mod_virtuemart_randomprod.php
plugins\search\vmxsearch.plugin.php


5/ Add the following at beginning (row 40 i.e.)
  of administrator\components\com_virtuemart\html\shop.browse.php
$show_not_in_stock= $vmInputFilter->safeSQL( vmGet( $_REQUEST, 'shownotinstock', null ));
if ($show_not_in_stock==0) {
   setShowNotInStock(false);
} elseif ($show_not_in_stock==1) {
   setShowNotInStock(true);
}

- Louis Bronne

hobby.lego

  • Beginner
  • *
  • Posts: 2
In point 5)
better use
$show_not_in_stock= $vmInputFilter->safeSQL( vmGet( $_REQUEST, 'shownotinstock', 2 ));
than
$show_not_in_stock= $vmInputFilter->safeSQL( vmGet( $_REQUEST, 'shownotinstock', null ));

In mod_virtuemart_shownotinstock.php, code for form_action was also erroneous. Here is the correction:
if (!strpos($_SERVER['QUERY_STRING'],"page=shop.browse")) {
   $sess->purl( $mm_action_url."index.php?".$_SERVER['QUERY_STRING']."&shownotinstock=".($show_not_in_stock?0:1));
} else {
   $sess->purl($mm_action_url."index.php?page=shop.browse&shownotinstock=".($show_not_in_stock?0:1) );

IntraX

  • Jr. Member
  • **
  • Posts: 87
Re: A module to let user chose whether (s)he wants to see Out of Stock items
« Reply #2 on: September 14, 2010, 17:15:29 pm »
Can you please review your posting if you have forgotten something? The thing is that:

1. All codes correctly inserted, no breaking site, there seem to be no errors in the code or changes

AND

It does not work on the browse page

this is what happens in the url:

Code: [Select]
/index.php?page=shop.browse&category_id=7&option=com_virtuemart&Itemid=195&shownotinstock=0&Itemid=195&shownotinstock=0&Itemid=195&shownotinstock=0&Itemid=195&shownotinstock=0&Itemid=195
When changing the 0 to a 1 first, also nothing happens.

Whenever hitting the change this button another "&shownotinstock=0&Itemid=195" is added to the url, the site reloads but nothing else happens. The text changes to "not shown" or "shown" but still all products are shown on the browse page. Is there maybe one more file in the browse region that needs to be adjusted as it works in the modules just perfectly?

BUT

It works in a module, only products in stock are shown

Is there a way that you can change if products out of stock are shown in modules now, as after the changes those wont be displayed in modules anymore at all?

Like adding some parameters to the module XML to decide if to show products in stock or not for individual modules. Some module should also show products out of stock while some should only display products in stock?

IntraX

  • Jr. Member
  • **
  • Posts: 87
Re: A module to let user chose whether (s)he wants to see Out of Stock items
« Reply #3 on: October 11, 2010, 17:36:20 pm »
Okay, I do not know if anyone is watching this topic, but it is really a valuable one, so I now know that this error is caused by login status. When I enter the site as logged in user the module and function does not work as I described above. When not being a registered user the function works. As I rarely check the store not being logged in this error seemed to be a global one.

Does anyone have a solution to get over this restriction that only logged out users can use this function?

P.S.: The issue with url creation still persists.