Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

VirtueMart Global parameters

VirtueMart Global parameters

Hi,

I have just purchased the Pro versions of your 2 products and I am very enthusiastic about them.

I am trying to turn on or off two of the global parameters of VirtueMart depending on the menu item selected.
Specifically I want to modify the following parameters:

-Use only as catalogue
-Show Prices


-I know how to identify the menu items;
-I read the page "Control parameters of other modules on the page";
-I examined the "mod_virtuemart.XML" file under "\modules\mod_virtuemart" but I don't see those parameters listed.

How do I go about modify those parameters?
I suspect that I am dealing with parameters of a component rather than those of a module. If so, are component parameters supported by your product?

Robert

rakagod
Beginner Modder
ranks
useravatar
Offline
10 Posts
Administrator has disabled public posting

Re: VirtueMart Global parameters

Hi Robert,

unfortunately, bad news: the Global parameters in VirtueMart are just that - global parameters, and there's no standard way to override these, at least that I know of!

Module parameters are a different matter - they proved to be reasonably easy to override.

I think you'll probably have to hack VirtueMart in order to toggle these parameters in various situations.

For showing prices, the constant that controls this is called _SHOW_PRICES. So you can search around VirtueMart for files that contain this text, and put in additional checks for additional conditions.

e.g. in ps_product.php, ps_product_attribute.php, shop.browse.php, shop.product_details.php in /adminsitrator/components. There are also a number of occurrences in /components.

For "use only as catalog" you'll need to look at ps_product.php, shop.browser.php, and possibly ps_session.php in /administrator/compoinents, plus some other files in /components, if you want to change whether the cookie check is required when you set things to catalog(ue) mode. The constant you are looking for is USE_AS_CATALOGUE.

Although I don't like hacking VirtueMart, it's unfortunately the only way to do this.

In general I'd approach it this way:

- in the SUCCEED or FAIL actions I would use the PHP boxes to create a specific constant if a rule succeeds or fails.

e.g.
define("EVENT_1_HAPPENED", true);

Then later in VM, if there's a line like this:

if (_SHOW_PRICES == '1') {   ...  }

I'd change this to:

if (_SHOW_PRICES == '1' or defined("EVENT_1_HAPPENED") ) {   ...  }

That would allow you to trigger the prices to be shown as a result of the MetaTemplate rule.

If you want to be able to force the prices to NOT be shown then you could change the line to:

if (_SHOW_PRICES == '1' and defined("EVENT_1_HAPPENED") ) {   ...  }

That way, the code will only run if both _SHOW_PRICES is set in the global config, AND if your even has happened. So if your event hasn't happened then the prices won't show.


Just a last thought that could simplify things: since _SHOW_PRICES and USE_AS_CATALOGUE are set in a PHP file, then you *could* just alter the PHP to build in more of the conditions there. This would mean that you only have to alter it in 1 place, and all the rest of VM would obey the value of these constants.

There's just 1 problem with this:
- the file would get overwritten every time someone changes one of the global variables in the admin part of VM. So it would be very easy for your changes to get wiped.

If you can avoid that happening (good luck!) then you could modify virtuemart.cfg.php like this:

Find this line:

define('_SHOW_PRICES', '1');

Replace with:

if (defined("EVENT_1_HAPPENED") ) define('_SHOW_PRICES', '');
else define('_SHOW_PRICES', '1');

That will allow you to turn off prices by doing a define("EVENT_1_HAPPENED") in a succeed or fail action.


Find this line:

define('USE_AS_CATALOGUE', '');

Replace with:

if (defined("EVENT_2_HAPPENED") ) define('USE_AS_CATALOGUE', '1');
else define('USE_AS_CATALOGUE', '');

That will allow you to turn ON catalogue mode by doing a define("EVENT_2_HAPPENED") in a succeed or fail action.


Sorry for the rambling reply... at first I thought this was going to be more or less impossible, but it turns out it's not so hard after all - as long as you can stop people altering the global config and overwriting your changes.

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: VirtueMart Global parameters

Thank you for that extensive and very helpful reply.

USER wrote:

There's just 1 problem with this:
- the file would get overwritten every time someone changes one of the global variables in the admin part of VM. So it would be very easy for your changes to get wiped.

If you can avoid that happening (good luck!) then you could modify virtuemart.cfg.php like this..

Unfortunately I think that over time I would forget and my changes would get wiped out.

A) Am I correct to understand that the changes would NOT get wiped out if I made changes to the other VirtueMart files as suggested in the beginning of the reply?

B) Could I make the changes mostly in the VirtueMart template that I purchased?

Basically I am trying to provide a site that will accommodate anonymous shoppers for both wholesale clients and retail customers.
The retail side shows prices and allows purchases.
The wholesale side does not allow prices or purchases for the same products but has a few of its own products.
You get to one or the other from separate menu items in the main menu.

I am thinking that I can hide or show the cart module with MetaMod and hide or show elements like "Add to cart", "prices" and such in the templates category and flypage files. This presupposes that I can code logic in those files that has access to which menu item was pressed (like Metamod code) and can allow or disallow the display of those elements.

Robert

rakagod
Beginner Modder
ranks
useravatar
Offline
10 Posts
Administrator has disabled public posting

Re: VirtueMart Global parameters

Hi Robert,

A - if you made changes to the other internal VM files, then you would not need to change the config file, and the changes would not get wiped out by config changes.
HOWEVER... as soon as you start to do this, then you're probably never going to upgrade VirtueMart again, as you'll be too afraid of messing up the edits you made. (I speak from experience).

B - Yes... sort of. I'm not very familiar with commercial VM templates, so I am not sure to what extent you can simply refuse to display the price by altering the code. Hopefully that's easy to do, but you might find that the price is embedded into some other structure that's created within VM, and is not so easy to remove at the template level. I really don't know, but it's worth looking at.

More serious however is that as I was looking at the VM code I saw that there are quite a few related bits of info that get included or excluded depending on whether USE_AS_CATALOGUE is set. e.g. links to shopping cart, number of products in stock and a few other bits and pieces. So, you might be able to get away with simply editing the template to not show some things, but it may be difficult to get things looking exactly like proper catalogue mode.

C - Dynamic changes to the cart module

This is actually a specialty of MetaMod. When you include a module, you can also dynamically alter any of the module parameters (the ones you would normally set up when editing a module in the module manager).

Therefore you could use MetaMod to include the same VM module but with some different parameters depending on which menu item you are on.

Or, of course you could just set up 2 VM modules, each with a different setup, and selectively include one or the other of them depending on which menu item (or page type etc) you are on. If you just have 2 of them it's probably easier this way, but if you're going to need multiple copies with different setups, then it might be easier to do it dynamically.

Resources:
1 - dynamic module control:
http://www.metamodpro.com/metamod/contr … parameters

2 - identifying which VM category/page type you are on:
http://www.metamodpro.com/jomgenius/parameters#vmobject

Using these techniques you shouldn't have to hack the VM Module, even if you're hacking the rest of VM!


Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: VirtueMart Global parameters

Thank you.

I'll try a few things and keep you posted.
No reply required.

Robert

rakagod
Beginner Modder
ranks
useravatar
Offline
10 Posts
Administrator has disabled public posting

Re: VirtueMart Global parameters

The solution I found to my problem.

I have been able to solve my problem without modifying Virtuemart files.
I do it by modifying my Virtuemart templates and using a MetaTemplatePro rule and a MetaMod module.

I am posting here to describe the Metatemplate rule needed to overcome a problem I encountered with the approach I am using.  The problem is that multiple references to the Virtuemart component cause the wrong itemId to be used.

My requirements are:

  • allow any anonymous user to view both the wholesale part of the store and the retail part of the store;
  • the wholesale store is simulating Virtuemart in Catalog mode (no cart) and has no prices showing;
  • the retail store has a cart for purchases and shows prices.

  • The solution is:
    To allow my Virtuemart template to suppress the display of Prices and AddToCart elements depending on which menu item was pressed (Shop or Wholesale).

    I do this with a MetaTemplate rule that sets a session variable based on the menu item selected and a MetaMod module that controls the display of the shopping cart.

    The problem:
    Unfortunately, multiple references to the Virtuemart component cause the wrong itemId to be used after the initial menu item selection.

    I link to Virtuemart from 2 menu items - labeled “Our Shop” and “Wholesale”.

    The menu item “Our Shop” has Id 7
    and links to Virtuemart with “index.php?option=com_virtuemart”.
    The menu item “Wholesale” has Id 2
    and also links to Virtuemart with “index.php?option=com_virtuemart”.

    From Metamod debug mode is the proof that the itemId is lost with this approach.

    After pressing the “Wholesale” menu item.

    Code:

    if ( 
    
    $option == 'com_virtuemart'
    and $Itemid == '2'
    and JRequest::getVar('lang')== 'en'
    ) return XXX;

    $ItemId value is ‘2’

    and then pressing a category choice

    Code:

    if ( 
    
    $option == 'com_virtuemart'
    and JRequest::getVar('page')== 'shop.browse'
    andJRequest::getVar('category_id')== '239'
    and $Itemid == '2'
    and JRequest::getVar('lang')== 'en'
    ) return XXX;

    $ItemId value is still ‘2’

    After pressing the “Our Shop” menu item.

    Code:

    if ( 
    
    $option == 'com_virtuemart'
    and $Itemid == '7'
    andJRequest::getVar('vmcchk')== '1'
    and JRequest::getVar('lang')== 'en'
    ) return XXX;

    $ItemId value is ‘7

    and then pressing a category choice

    Code:

    if ( 
    
    $option == 'com_virtuemart'
    and JRequest::getVar('page')== 'shop.browse'
    andJRequest::getVar('category_id')== '239'
    and $Itemid == '2'
    and JRequest::getVar('lang')== 'en'
    ) return XXX;

    The $ItemId value is now ‘2’ rather than ‘7’.
    And it will stay as ‘2’ for further categories and product selection.

    Solution:
    Solution details-Part 1 of 3.
    Because the itemId can get a wrong value as you click your way to viewing a product, then the session variable must be set only when the menu item is pressed and never after.

    I do this with one rule that is activated only for Menu items: “Our Shop” and “Wholesale”.
    In the RUN PHP box of the SUCCEED actions I added:

    Code:

    session_start();
    
    $varRetail = '7';
    $varWholesale = '2';
    if (($option == 'com_virtuemart' and JRequest::getVar('page') == '' and $Itemid == $varRetail ) or
         ($option == 'com_virtuemart' and JRequest::getVar('page') == '' and $Itemid == $varWholesale)){
        $instance_name = "wholesale-retail";
        if (!isset($_SESSION[$instance_name])) {
                // no session variable exist so create one
            $vide = array();
            $_SESSION[$instance_name]=$vide;
        }
        if ($Itemid == $varRetail) {
            $_SESSION[$instance_name] = "retail";
        } else {
            $_SESSION[$instance_name] = "wholesale";
        }
    }

    The JRequest::getVar('page') == '' is what limits the creation or modification of the session variable to only when the menu item is first pressed.

    Solution details-Part 2 of 3.
    The template contains this additional code:

    Code:

    <?php
    
    session_start();  //must be  at very top
    .
    .
    .
    If ($_SESSION["wholesale-retail"] == "retail") {
         $is_retail = true;
    }else{
         $is_retail = false;
    }
    ?>

    The above says; make the local variable $is_retail equal true if the Session variable has the value “retail”.

    Code:

    .
    
    .
    .
    <div class=" vm_s_desc">
        <?php echo $product_s_desc; ?>
    </div>                 
    <div class=" vm_price">
        <?php if ($is_retail == true):?>
            <?php echo $product_price ?>
        <?php endif;?>   
    </div>
    <div class=" vm_atc">
        <?php if ($is_retail == true):?>
            <?php echo $addtocart ?>
        <?php endif;?>
    </div>

    The above displays the Price and the AddToCart elements when the value of the local variable “$is_retail” is true.

    Solution details-Part 3 of 3:
    Control display of cart:
    I create a Metamod module called “MetaMod-Cart” which controls the display of my shopping cart (Id=20) and contains the following PHP:

    Code:

    session_start();
    
    $instance_name = "wholesale-retail";
    if (isset($_SESSION[$instance_name])) {
        if ($_SESSION[$instance_name] == "retail") {
            return 20;
        }
    }

    The above code says:
    If the Session variable “wholesale-retail” exists and has the value of “retail” then display the shopping cart (return 20).

    the end

    rakagod
    Beginner Modder
    ranks
    useravatar
    Offline
    10 Posts
    Administrator has disabled public posting

    Re: VirtueMart Global parameters

    rakagod, that's amazing. Great work. Thank you for posting such a comprehensive solution here!

    The $Itemid handling in VirtueMart is a very, very weak part of their product. They have made the decision in their code to almost always use the Itemid of the 1st VirtueMart menu item in the system, rather than the currently-set Itemid, if one is set. This leads to innumerable problems such as the one you are having to work around here. I wish I was in a position to influence VirtueMart's development in this area...

    Stephen Brandon
    MetaMod / Chameleon developer
    If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

    metamodguy
    useravatar
    Offline
    3313 Posts
    User info in posts
    Administrator has disabled public posting

    Board Info

    Board Stats:
     
    Total Topics:
    1679
    Total Polls:
    6
    Total Posts:
    5913
    Dormant:
    User Info:
     
    Total Users:
    10796
    Newest User:
    mokao3
    Members Online:
    0
    Guests Online:
    179

    Online: 
    There are no members online

    Forum Legend:

     Topic
     New
     Locked
     Sticky
     Active
     New/Active
     New/Locked
     New Sticky
     Locked/Active
     Active/Sticky
     Sticky/Locked
     Sticky/Active/Locked