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 Virtuemart 3.0 Product Review Component

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 } ?>

 

<p>.......................................................</p>
Last Updated on Monday, 26 April 2021 16:01
 



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, array, resources, add, php, address, length, quantity, results, customfieldssorted, vmmodel, usermodel, productmodel, shopper, vmuser, line, category, join, view, pid, quote, getmodel, foreach, virtuemartcart, resource, loop, total, custom, selectively, loadobjectlist, display, fields, additional, desc

|

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.