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 Home Alternative Health Practitioners

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?option=com_virtumart&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( );

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

Load helpers etc

<?php
JLoader::register('VirtueMartCart', JPATH_SITE . '/components/com_virtuemart/helpers/cart.php');
JLoader::register('vmPSPlugin', JPATH_ADMINISTRATOR . '/components/com_virtuemart/plugins/vmpsplugin.php');

$oCart = VirtueMartCart::getCart();
$cart  = clone($oCart);

// Reset all cart items.
$cart->cartProductsData = array();

// The virtueart_product_id. Set your desired product ID.
$product_id = 1; 

$cart->cartProductsData[] = array(
'virtuemart_product_id' => (int) $product_id,
'quantity'              => 1,
'customProductData'     => array()
);

// Flag product added
$cart->_productAdded = true;

$cart->prepareCartData();

JPluginHelper::importPlugin('vmshipment');

$shipments        = array();
$selectedShipment = 0;

JFactory::getApplication()->triggerEvent('plgVmDisplayListFEShipment', array($cart, $selectedShipment, &$shipments));

// Print the list of shipment methods.
var_dump($shipments);
?>

Last Updated on Monday, 11 April 2022 13:52
 
VirtueMart
Your Cart is currently empty.

Find a Domain Name!

Enter a domain name:

www.

Select an extension:

Select all
.com.net.org.info
.name.us.biz.eu
.co.uk.be.de.nl

Search Engine Optimisation (SEO)

The importance of having your site "visible" via the important search engines can not be stressed enough.
If your site is invisible to Google then no-one is going to find you no matter how wonderful your website is.

There are methods and techniques that need to be followed to ensure that your site is highly visible to your potential client base. We can do this for you and have had a large measure of success in the web sites that we have optimised.

Searching for a wide range of alternative health practitioner search terms (keywords & key-phrases in the jargon) returns a large number of GJC Web Design maintained and designed websites.
Terms such as alternative health practitioner, colourworks & colour mirrors consistently bring visitors and clients to our target websites.

Try the link below which will take you to a real search result for one or other of our sites.

Google UK search "colour mirrors"
1st, 2nd & 3rd place



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, array, print, products, productmodel, resources, quantity, php, add, customfieldssorted, vmmodel, shipments, address, results, getmodel, length, currency, cartproductsdata, jfactory, category, pid, return, view, line, join, usermodel, quote, resource, true, vmuser, list, loop, virtuemartcart, helpers, selectedshipment, total


guru

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.