VirtueMart Zero Cost Downloads
April 3, 2008 by OctavA few days ago, we wanted to have one of our custom made components included in Joomla Extensions Directory.
Toni Marie, chief of Joomla Extensions Directory said:
One of the requirements is that we are able to successfully download and install the product according to the intent of the listing. In this case, we cannot download because PayPal demands a payment higher than zero. It is at that point that the transaction breaks down.
So we had to find a solution to fix this. After some investigation, we found it:
1) Open /administrator/components/com_virtuemart/classes/ps_product.php and find line 2286
} // ENd of CLASS ps_product
Just before this line insert the following code:
function downloadable($product_id) {
$db_check = new ps_DB;
$q_dl = “SELECT attribute_name, attribute_value FROM #__{vm}_product_attribute WHERE “;
$q_dl .= “product_id=’”.$product_id.”‘ AND attribute_name=’download’ “;
$db_check->query($q_dl);
$db_check->next_record();
if ($db_check->num_rows() > 0) {
return true;
} else {
return false;
}
}
2) Open /administrator/components/com_virtuemart/classes/ps_checkout.php and find line 157
if ( NO_SHIPPING != “1″ && (CHECKOUT_STYLE==’1′ || CHECKOUT_STYLE==’3′) ) {
Replace this line with
if ( NO_SHIPPING != “1″ && empty($_SESSION[’noCheck’]) && (CHECKOUT_STYLE==’1′ || CHECKOUT_STYLE==’3′) ) {
Find line 191
if (NO_SHIPTO != ‘1′) {
Replace this line with
if (NO_SHIPTO != ‘1′ && empty($_SESSION[’noCheck’])) {
Find line 770
————————
Order Total: ‘.$order_total.’
—————————-’
);
// Check to see if Payment Class File exists
$payment_class = $ps_payment_method->get_field($d[”payment_method_id”], “payment_class”);
$enable_processor = $ps_payment_method->get_field($d[”payment_method_id”], “enable_processor”);
if (file_exists(CLASSPATH . “payment/$payment_class.php”) ) {
Replace this lines with
————————
Order Total: ‘.$order_total.’
—————————-’
);
$payment_class = “”;
if($order_total > 0) {
// Check to see if Payment Class File exists
$payment_class = $ps_payment_method->get_field($d[”payment_method_id”], “payment_class”);
$enable_processor = $ps_payment_method->get_field($d[”payment_method_id”], “enable_processor”);}
if (file_exists(CLASSPATH . “payment/$payment_class.php”) ) {
Find line 1062
$_SESSION[’coupon_redeemed’] = false;
After this line insert the following code
$_SESSION[’noCheck’] = ”;
$_SESSION[’bypass’] = ”;
3) Open /administrator/components/com_virtuemart/html/shop.cart.php and find line 87 (go to the end of the file)
?>
Just before this line insert:
if ($order_total ==0 ) {
$_SESSION[’noCheck’] = true;
} else {
$_SESSION[’noCheck’] = ”;
}
4) Open /administrator/components/com_virtuemart/html/checkout.thankyou.php and find line 67
if ($db->f(”order_status”) == “P” ) {
Replace this line with:
$order_status = $db->f(”order_status”);
if($db->f(”order_total”) <= 0) {
require_once ( CLASSPATH . ‘ps_order.php’ );
$ps_order= new ps_order;
$d = array();
$d[’order_id’] = $order_id;
$d[’notify_customer’] = “N”;
$d[’order_status’] = ‘C’;
$ps_order->order_status_update($d);
$order_status = “C”;
}
if ($order_status == “P”) {
5) Open /administrator/components/com_virtuemart/html/checkout.index.php and find line 19
require_once( CLASSPATH . “ps_checkout.php” );
After this line add:
require_once( CLASSPATH . “ps_product.php” );
Find line 51
/* Decide, which Checkout Step is the next one
Before this line add:
/* Determine If cart only has downloadable products and check the cart total */
$downloads_only=true;
for($i=0;$i<$_SESSION[’cart’][’idx’];$i++) {
if(!ps_product::downloadable($_SESSION[’cart’][$i][’product_id’])) {
$downloads_only = false;
if($_SESSION[’noCheck’]) {
$checkout_this_step = 2;
}
}
}
if($downloads_only) {
$_SESSION[’noCheck’] = true;
} else {
$_SESSION[’noCheck’] = ”;
}
Find line 68:
if (CHECKOUT_STYLE == ‘1′)
$checkout_next_step = CHECK_OUT_GET_SHIPPING_METHOD;
elseif (CHECKOUT_STYLE == ‘2′) {
$checkout_next_step = CHECK_OUT_GET_PAYMENT_METHOD;
} elseif (CHECKOUT_STYLE == ‘3′) {
$checkout_this_step = CHECK_OUT_GET_SHIPPING_METHOD;
$checkout_next_step = CHECK_OUT_GET_PAYMENT_METHOD;
} elseif (CHECKOUT_STYLE == ‘4′) {
$checkout_this_step = CHECK_OUT_GET_PAYMENT_METHOD;
$checkout_next_step = CHECK_OUT_GET_FINAL_CONFIRMATION;
}
Replace this lines with:
if (CHECKOUT_STYLE == ‘1′ && empty($_SESSION[’noCheck’]))
$checkout_next_step = CHECK_OUT_GET_SHIPPING_METHOD;
elseif (CHECKOUT_STYLE == ‘2′ && empty($_SESSION[’noCheck’])) {
$checkout_next_step = CHECK_OUT_GET_PAYMENT_METHOD;
} elseif (CHECKOUT_STYLE == ‘3′ && empty($_SESSION[’noCheck’])) {
$checkout_this_step = CHECK_OUT_GET_SHIPPING_METHOD;
$checkout_next_step = CHECK_OUT_GET_PAYMENT_METHOD;
} elseif (CHECKOUT_STYLE == ‘4′ || @$_SESSION[’noCheck’]) {
$checkout_this_step = CHECK_OUT_GET_PAYMENT_METHOD;
$checkout_next_step = CHECK_OUT_GET_FINAL_CONFIRMATION;
}

You must be logged in to post a comment.