### Author Topic: Custom Development - Virtuemart Rent or Buy  (Read 5246 times)

• Beginner
• Posts: 5
##### Custom Development - Virtuemart Rent or Buy
« on: January 19, 2012, 01:28:09 am »
OK, I have a hard one for the community!

See product page of live site here: http://lenspimp.com.au/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=26&category_id=36&option=com_virtuemart&Itemid=83

I have customised the product page with a date selector for a rental system with "Date From:" and "Date To:" fields. These dates then calculate the total amount based on attribute variables taken from a Attribute "Rent Type" and Properties (under Product Status) of Day, Weekend and Week (with prices applied to each).

In the above example, the Day rental is \$40, a Weekend (Saturday and Sunday) is \$80 and a week is \$150.

For instance, if someone wants to rent the product for 3 days, it will calculate this from the daily rate x 3 = \$120.

Code: [Select]
`echo '<div class="dateRangeBox">';   echo '<div class="row"><label>Rent From: </label> '; \$y = date('Y'); \$m = date('m');  \$d = date('d');  if(\$d > 31 ) {   \$nd = 0; } else {   \$nd = \$d+2; } echo JHTML::calendar(date('Y-m-d'),'rentFrom','rentFrom','%Y-%m-%d',array('class'=>'inputbox')); echo '</div>'; echo '<div class="row"><label>Rent To: </label> '; echo JHTML::calendar("",'rentTo','rentTo','%Y-%m-%d',array('class'=>'inputbox')); echo '</div>';  foreach(\$attributes as \$attribute) {     ?>        <div class="row" id="attList">      <label for="<?php echo \$attribute['titlevar'] ?>_field"><?php echo \$attribute['title'] ?>:</label>        <select class="inputbox rentype" id="<?php echo \$attribute['titlevar'] ?>_field" name="<?php echo \$attribute['titlevar'].\$attribute['product_id'] ?>"> <?php foreach ( \$attribute['options_list'] as \$options_item ) : ?>         <?php if( isset( \$options_item['display_price']) ) : ?>         <option value="<?php echo \$options_item['base_var'] ?>"><?php echo \$options_item['base_value'] ?> (<?php echo \$options_item['sign'].\$options_item['display_price'] ?>)</option>         <?php else : ?>         <option value="<?php echo \$options_item['base_var'] ?>"><?php echo \$options_item['base_value'] ?></option>         <?php endif; ?>        <?php endforeach; ?>        </select>    </div>    </div>    <?php }          ?>`
And the following code in the addtocart_form.tpl.php:

Code: [Select]
`<?phpmm_showMyFileName(__FILE__);// functions imported from older joomla version // they are needed for custom attributes extended hack /* * Loads all necessary files for JS Overlib tooltips */ global  \$mosConfig_live_site, \$mainframe; \$mainframe->addCustomHeadTag( '<script type="text/javascript" src="'. \$mosConfig_live_site . '/includes/js/joomla.javascript.js"></script>' ); if ( !\$mainframe->get( 'loadOverlib' ) ) { // check if this function is already loaded ?> <script language="javascript" type="text/javascript" src="<?php echo \$mosConfig_live_site;?>/includes/js/overlib_mini.js"></script> <script language="javascript" type="text/javascript" src="<?php echo \$mosConfig_live_site;?>/includes/js/overlib_hideform_mini.js"></script> <?php // change state so it isnt loaded a second time \$mainframe->set( 'loadOverlib', true ); } //~ JLoader::import('joomla.html.html.behavior'); //~ JHTMLBehavior::calendar(); JHTML::_('behavior.calendar');// This function lists all product children ( = Items)// or, when not children are defined, the product_id// SO LEAVE THIS IN HERE!  list(\$html,\$children) = \$ps_product_attribute->list_attribute( ( \$product_parent_id > 0 )  ? \$product_parent_id : \$product_id );if (\$children != "multi") {     if( CHECK_STOCK == '1' && !\$product_in_stock ) {      \$notify = true;    } else {     \$notify = false;    }?>    <form action="<?php echo \$mm_action_url ?>index.php" method="post" name="addtocart" id="<?php echo uniqid('addtocart_') ?>" class="addtocart_form" <?php if( \$this->get_cfg( 'useAjaxCartActions', 1 ) && !\$notify ) { echo 'onsubmit="handleAddToCart( this.id );"'; } ?>          onSubmit="return checkDateRange();"><?php}echo \$html;if (USE_AS_CATALOGUE != '1' && \$product_price != "" && !stristr( \$product_price, \$VM_LANG->_('PHPSHOP_PRODUCT_CALL') )) { ?>        <?php if (\$children != "multi") { ?>     <div class="vmAddtoCart" style="float:left;align:left;"> <?php     if (\$children == "drop") {      echo \$ps_product_attribute->show_quantity_box(\$product_id,\$product_id);    }     if (\$children == "radio") { echo \$ps_product_attribute->show_radio_quantity_box();    }    //\$button_lbl = \$VM_LANG->_('PHPSHOP_CART_ADD_TO'); \$button_lbl = '';    \$button_cls = 'rentnow_button';    if( CHECK_STOCK == '1' && !\$product_in_stock ) {      \$button_lbl = \$VM_LANG->_('VM_CART_NOTIFY');      \$button_cls = 'notify_button'; echo '<input type="submit" class="'. \$button_cls .'" value="'. \$button_lbl .'" style="padding-top:3px;" title="'. \$button_lbl .'" />';    } else {    ?>    <input type="submit" class="<?php echo \$button_cls ?>" value="<?php echo \$button_lbl ?>" style="padding-top:3px;" title="Rent Now" /><?php } ?>    </div>    <?php  } ?>        <input type="hidden" name="flypage" value="shop.<?php echo \$flypage ?>" /> <input type="hidden" name="page" value="shop.cart" />    <input type="hidden" name="manufacturer_id" value="<?php echo \$manufacturer_id ?>" />    <input type="hidden" name="category_id" value="<?php echo \$category_id ?>" />    <input type="hidden" name="func" value="cartAdd" />    <input type="hidden" name="option" value="<?php echo \$option ?>" />    <input type="hidden" name="Itemid" value="<?php echo \$Itemid ?>" />    <input type="hidden" name="set_price[]" value="" />    <input type="hidden" name="adjust_price[]" value="" />    <input type="hidden" name="master_product[]" value="" />    <?php}if (\$children != "multi") { ?> </form>.........<?php }     if(\$children == "radio") { ?>        <script language="JavaScript" type="text/javascript">//<![CDATA[    function alterQuantity(myForm) {        for (i=0;i<myForm.selItem.length;i++){            setQuantity = myForm.elements['quantity'];            selected = myForm.elements['selItem'];            j = selected[i].id.substr(7);            k= document.getElementById('quantity' + j);            if (selected[i].checked==true){                k.value = myForm.quantity_adjust.value; }            else {                k.value  = 0;            }        }    } //]]>    </script><?php } ?>`
Now the client wants to add a Buy Now button. I am having some major difficulties in adding this button to relate to the "Product Price (Gross)" field (\$product_price), and I have added this button on my local server - see attached image. The code I have used to call this button is as follows, in the addtocart_form.tpl.php:

Code: [Select]
`    //\$button_lbl = \$VM_LANG->_('PHPSHOP_CART_ADD_TO'); \$button_lbl_buy = '';    \$button_cls_buy = 'buynow_button'; \$product_price1 = preg_replace("/[^0-9]/", "", \$product_price) / 100; \$product_price2 = number_format(\$product_price1, 2, ".", ","); \$product_price = \$product_price2;    if( CHECK_STOCK == '1' && !\$product_in_stock ) {      \$button_lbl_buy = \$VM_LANG->_('VM_CART_NOTIFY');      \$button_cls_buy = 'notify_button'; echo '<input type="button" class="'. \$button_cls_buy .'" value="'. \$button_lbl_buy .'" style="padding-top:3px;" title="'. \$button_lbl_buy .'" />';    } else {    ?>    <hr/><br/><input type="button" class="<?php echo \$button_cls_buy ?>" value="<?php echo \$button_lbl_buy ?>" style="padding-top:3px;" title="Buy Now" onclick='submit()' />Outright Purchase Price: <strong>\$<?php echo \$product_price; ?></strong><?php } ?>    </div>    <?php  } ?>        <input type="hidden" name="flypage" value="shop.<?php echo \$flypage ?>" /> <input type="hidden" name="page" value="shop.cart" />    <input type="hidden" name="manufacturer_id" value="<?php echo \$manufacturer_id ?>" />    <input type="hidden" name="category_id" value="<?php echo \$category_id ?>" />    <input type="hidden" name="func" value="cartAdd" />    <input type="hidden" name="option" value="<?php echo \$option ?>" />    <input type="hidden" name="Itemid" value="<?php echo \$Itemid ?>" />    <input type="hidden" name="set_price[]" value="" />    <input type="hidden" name="adjust_price[]" value="" />    <input type="hidden" name="master_product[]" value="" /> </form>`
Notice that this button type is "button" instead of "submit" and an additional "onclick='submit()'" has been added.

the button does submit and loads the cart page, but does not pass any of the product variables to the cart, simply loads an empty cart with a \$0.00 value (NOTE: it does not show the "Your Cart is currently empty." notification, it shows a \$0.00 cart with no Name, Product ID, or description).

I've been looking at this for the past 4 hours and have not been able to work out why it isn't working.

Any assistance would be greatly appreciated.

Available for any Joomla / VM work.

#### farketmez99

• Beginner
• Posts: 8
##### Re: Custom Development - Virtuemart Rent or Buy
« Reply #1 on: February 24, 2012, 15:54:01 pm »
Hi,

I tried to your instructions but I couldnt do that. should I clear all of codes and put your codes or not?

#### farketmez99

• Beginner
• Posts: 8
##### Re: Custom Development - Virtuemart Rent or Buy
« Reply #2 on: February 24, 2012, 16:09:22 pm »
and I couldnt find how can I change daily, weekly or weekend price?