Thursday, December 15, 2011

Request For Quote Only products in Virtuemart

This applies to Joomla 1.5.20 (with Legacy 1.0 mode on) running Virtuemart 1.1.4 stable

This hack I developed allows you to delete the price from a product in the Virtuemart backend admin area (not assign it 0.00, but actually delete it blank, and save it like that) and that will make it show up as a Request For Quote Only product where the customer will not see any price (not even $0.00) it will just say Request For Quote Only, and the customer can still Add To Cart and select any attributes that you may have set.  This is a perfectly functional Request For Quote products setup.

1) edit file: /components/com_virtuemart/themes/YOUR_THEME/templates/product_details/includes/addtocart_form.tpl.php
 => located around line 20 find this:
if (USE_AS_CATALOGUE != '1'.......
and change this line to look like this:
if (USE_AS_CATALOGUE != '1' /*&& $product_price != "" &&  !stristr( $product_price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )*/) {

(notice I commented out the price check and product price string check, you could delete them but just comment them out - who knows, you may need them later.)

2) edit file: /components/com_virtuemart/themes/YOUR_THEME/templates/common/price.tpl.php
 => located around line 8 find this:
echo vmCommonHTML......
and change it to this:
// echo vmCommonHTML::hyperLink( $link, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') );
    echo "This product is Request For Quote Only";

(notice the hyperlink is commented out and replaced with an echo that prints my request for quote sentence.)

3) edit file: /administrator/components/com_virtuemart/html/shop.browse.php
 => located around line 421 find this:
// Add-to-Cart Button
and all the lines below it that start with this: $tpl->set
within the IF statement, copy and paste them into the ELSE statement, so that either way all those lines get processed:
         $tpl->set( 'i', $i );
         $tpl->set( 'product_id', $db_browse->f('product_id') );
         $tpl->set( 'product_in_stock', $db_browse->f('product_in_stock') );
         $tpl->set( 'ps_product_attribute', $ps_product_attribute );
         $products[$i]['form_addtocart'] = $tpl->fetch('browse/includes/addtocart_form.tpl.php' );
         $products[$i]['has_addtocart'] = true;

(This will make it so that even on the category browse page the Add To Cart button is active, but when you click it, it brings you to the product's flypage with a note to please first specify the attributes.  And that note can be customized also by editing the variable called "PHPSHOP_CART_SELECT_ITEM" inside this file: /administrator/components/com_virtuemart/languages/common/english.php)

If your customer doesn't need to specifiy quantity for your Request For Quote Only items, you can hide the qty box in the product's admin area within the Virtuemart backend:  Pull up the product in the Virtuemart backend, click the [Display Options] tab, and at the bottom select Hide Quantity Box.  Then save.

Now go through your products in the Virtuemart backend admin area, and every single product that you want to be a Request For Quote product - simply delete the price from these two fields: "Product Price (Net)" and "Product Price (Gross)". And save them with those fields blank.    All your other products that do have real prices in them will remain unaffected.

[ I have attached all 3 referenced php files to this post to help you see the code I am referencing.  But do NOT, I repeat do NOT, just place these into your Joomla/Virtuemart installation and overwrite your current server files.  I have other custom code and modules running that possibly you do not, and it could potentially break your site.  As always, BACKUP your site before attempting any type of code hacking. ]

No comments: