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 Tips Virtuemart Cheat Sheet

Mon

28

Apr

Virtuemart Cheat Sheet
  • 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 } ?>


Or ->
<?php echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'explain')); ?>

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

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 Thursday, 04 November 2021 15:05
 
VirtueMart
Your Cart is currently empty.

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, productmodel, products, print, resources, array, quantity, customfieldssorted, php, vmmodel, length, add, address, getmodel, results, foreach, usermodel, view, return, vmuser, total, shopper, loop, virtuemartcart, currency, line, quote, category, resource, pid, join, continue, haschilds, children, getproductparentid, url

|

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.