General Joomla
This page will feature general articles relating to Joomla and Joomla addons not specifically related to JEvents.
We hope you find them useful.
Custom Prices for Virtuemart Products
In order to pay for event tickets, which have variable prices which depend on event configuration, with Virtuemart we need a mechanism to create a product with a price we can vary programatically or via a custom product attribute. This can be done with a very simple code modificatio and it will enable you to add variable priced product to VM very easily.
Code Modification
Edit the file administrator/components/com_virtuemart/classes/ps_product.php and find the method get_adjusted_attribute_price at line c.1841 in Virtuemart 1.15 scroll down a little further until you find this line of code:
if( isset( $product_attributes[$this_key]['values'][$this_value] )) {
Then insert the following lines just before this:
// gwe mod
if ($this_key=="ManualPrice"){
$adjustment = floatval($this_value);
}
// end gwe mod
Create a Product With Adjustable Price
In your product add an attribute called "ManualPrice".
Now when your purchases enters a value in the ManualPrice field and adds the product to the cart it picks up the variable price.
Virtuemart Products With No Shipping Requirements
If you have the need to sell services or products via Virtuemart that don't require shipping then you are out of luck with Virtuemart out of the box. However with a few simple tweaks to the VM codebasee this can be accomodated.
Virtuemart has a very helpful mechanism for creating downloadable products which we can adapt to skip the shipping step of the checkout.
Code Changes
If you edit the file administrator/components/com_virtuemart/classes/ps_product.php and find the method "is_downloadable" (line 945 in Virtuemart 1.15) and replace it with the following code
function is_downloadable($product_id) {
// GWE mod start
if( empty( $GLOBALS['product_info'][$product_id]['skipshipping'] )) {
$db_check = new ps_DB;
$q_ns = 'SELECT p.product_id from #__{vm}_product as p
LEFT JOIN #__{vm}_product_category_xref as xr on p.product_id=xr.product_id
LEFT JOIN #__{vm}_category as ct on xr.category_id=ct.category_id
where p.product_id='.intval($product_id).' AND LOWER(ct.category_name) = "no shipping"';
$db_check->query($q_ns);
$db_check->next_record();
if( $db_check->num_rows() > 0 ) {
$GLOBALS['product_info'][$product_id]['skipshipping'] = 'Y';
} else {
$GLOBALS['product_info'][$product_id]['skipshipping'] = 'N';
}
}
// GWE mod end
if( empty( $GLOBALS['product_info'][$product_id]['is_downloadable'] )) {
$db_check = new ps_DB;
$q_dl = "SELECT attribute_name,attribute_value
FROM #__{vm}_product_attribute WHERE
product_id=".(int)$product_id." AND attribute_name='download'";
$db_check->query($q_dl);
$db_check->next_record();
if( $db_check->num_rows() > 0 ) {
$GLOBALS['product_info'][$product_id]['is_downloadable'] = 'Y';
} else {
$GLOBALS['product_info'][$product_id]['is_downloadable'] = 'N';
}
}
// GWE mod start
//return $GLOBALS['product_info'][$product_id]['is_downloadable'] == 'Y';
return ($GLOBALS['product_info'][$product_id]['is_downloadable'] == 'Y' || $GLOBALS['product_info'][$product_id]['skipshipping'] == 'Y');
// gwe mod end
}
Creating Non-Shipping Products
If you look at the code above you may notice that there is a test on a product's category name. Basically any product we create if we add it into a category called "No Shipping" then in combination with the code change above Virtuemart will skip the shipping stage of the checkout process.
