web design, England, Britain, UK, belgium
 

Virtuemart Cheat Sheet - Joomla & VirtueMart Tips & How To's

GJC Website Design UK, Joomla Developer, VirtueMart Developer, Template Developer, web site designs, England, Britain, UK, Belgium, search-engine optimisation (SEO). Multilingual.

Home Joomla - VirtueMart Joomla 3.x jPageViews Plugin

Mon

28

Apr

  • Virtuemart 2.0
  • Cheat Sheet

Here's a list of Virtuemart code snippets so that I don't have to search the forums every time I need one!

Virtuemart 2.0

Get cart object

if (!class_exists('VirtueMartCart')) require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
$cart = VirtueMartCart::getCart();
.......................................................

Get address in $cart

if($cart->STsameAsBT == 0){
    $address = (($cart->ST == 0 ) ? $cart->BT : $cart->ST);
    }else{
    $address = $cart->BT;
    }
.......................................................

Loop thru products in $cart

$Total_Length=array();
foreach ($cart->products as $product) {
     if($product->quantity){            #only if array contains values
          $Total_Length[].= $product->product_length;
      }
}

.......................................................

Get shopper Group

$userModel = VmModel::getModel('user');
$vmuser = $userModel->getCurrentUser();
$vmgroup = $vmuser->shopper_groups;
//is an array

.......................................................

Typical query

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('p.virtuemart_product_id', 's.virtuemart_shoppergroup_id')));
$query->from($db->quoteName('#__virtuemart_products', 'p'));
$query->join('LEFT', $db->quoteName('#__virtuemart_product_categories', 'c') . ' ON (' . $db->quoteName('c.virtuemart_product_id') . ' = ' . $db->quoteName('p.virtuemart_product_id') . ')');
 
 $query->join('LEFT', $db->quoteName('#__virtuemart_product_shoppergroups', 's') . ' ON (' . $db->quoteName('s.virtuemart_product_id') . ' = ' . $db->quoteName('p.virtuemart_product_id') . ')');
 
$query->where($db->quoteName('c.virtuemart_category_id') . ' = '. $db->quote('115'));
$query->where($db->quoteName('p.published') . ' = '. $db->quote('1'));
$query->order($db->quoteName('virtuemart_product_id') . ' DESC');
$db->setQuery($query);
$results = $db->loadObjectList();
print 'Debug Line '.__LINE__.' $results <pre>'; print_r ($results); print "</pre><br />\n";

 

.......................................................

Has children in loop

function hasParent($pid){
$productModel = VmModel::getModel('product');
$id = $productModel->getProductParentId($pid);
if (!empty($id)){
return 1;
}
}
 
 
so in category view
products.php
 
after this
   foreach ($products as $product ) {
 
add this
 
              if(hasChilds($product->virtuemart_product_id)==1) continue;

 

.......................................................

Add product by URL

 

yoursite/?index.php&optionvirtumart&view=cart&task=add&quantity[]=5&virtuemart_product_id[]=22&quantity[]=2&virtuemart_product_id[]=55
.......................................................

Selectively show custom fields

<?php
#print 'Debug Line '.__LINE__.' $this->guests <pre>'; print_r ($this->product->customfieldsSorted['resources']); print "</pre><br />\n";
if($this->product->customfieldsSorted['resources']){  ?>
<div name="resources"></div>
<br /><br />
<h3>Additional Resources</h3>
<div id="prodresources">
 
<?php
foreach($this->product->customfieldsSorted['resources'] as $resource){
echo $resource->display;
}
?>
</div>
<br /><br />
<?php } ?>

 .......................................................

Get a product by id

$productModel = VmModel::getModel('Product');

$product = $productModel->getProduct ($field->customfield_value);

if(empty($product)) return false;

$productModel->addImages($product);

.......................................................

Get currency anywhere

$currency = CurrencyDisplay::getInstance( );

Last Updated on Tuesday, 14 September 2021 15:41
 
VirtueMart
Your Cart is currently empty.

Show Images Vertical

This is the GJC Web Design Joomla 1.5 show_images Module

GJC Web Design
GJC Web Design
jPageViews Plugin
jPageViews Plugin
metaNoFollow Plugin J1.5
metaNoFollow Plugin J1.5
VM Live <br/>Product Search
VM Live
Product Search
Show Images Module
Show Images Module
metaNoFollow Plugin J2.5
metaNoFollow Plugin J2.5

Latest Joomla & VirtueMart Tips

See all tips & examples



Virtuemart Cheat Sheet|Joomla & VirtueMart Tips & How To's



GJC Website Design UK, Joomla Developer, VirtueMart Developer, Template Developer, web site designs, England, Britain, UK, Belgium, search-engine optimisation (SEO). Multilingual.


product, virtuemart, cart, quotename, query, print, products, productmodel, resources, array, length, address, getmodel, php, results, add, vmmodel, quantity, customfieldssorted, usermodel, shopper, pid, currency, quote, resource, return, view, join, vmuser, category, virtuemartcart, line, loop, foreach, total, false, value, currencydisplay, customfield, function

|

We use cookies to improve our website and your experience when using it. Cookies used for the essential operation of the site have already been set.
To find out more about the cookies we use and how to delete them, see our privacy policy.

I accept cookies from this site.