create a library
I will give you examples of how I use mine.
my library name is "Kaizen"
I have many classes in there.
1 class called "Product"
in my libraries/Kaizen folder. I have a php file called. product.php
start the file like so LibrarynameClassname
<?php class KaizenProduct{
// add some functions
// gets a product param from single plugin
//$product , $param_name
// separated , choose a delimeter if you want to separated the strings.
public static function getParam($product,$param,$separated=''){
$return='';
if (!empty($product->customfieldsSorted['addtocart'])) {
foreach ($product->customfieldsSorted['addtocart'] as $field) {
if (!empty($field->$param)){
$split='';
if ($return!=''){$split=$separated;}
$return.=$split.$field->$param;}
}
}
return $return;
// example KaizenProduct::getParam($product,'custom_drop',',');
}
public static function get_product($id,$style,$header='',$thumbnail=150){
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');
$product_model = VmModel::getModel('product');
$product = $product_model->getProduct($id,TRUE,TRUE,TRUE,1);
$product_model->addImages($product);
$customfieldsModel = VmModel::getModel ('Customfields');
$product->customfields = $customfieldsModel->getCustomEmbeddedProductCustomFields ($product->allIds,0,-1, true);
$name=$product->product_name;
$link= JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$id.'&virtuemart_category_id='.$product->virtuemart_category_id.'');
$html='<div class="kaizen_product_display '.$style.'">';
if (!empty($header)){
$html.='<p class="featured_label">'.$header.'</p>';
}
$html.='<a title="'.$product->product_name.'" href="'.$link.'">';
$html.=$product->images[0]->displayMediaThumb('class="product-image"',false,'',true,false,false,$thumbnail,$thumbnail);
$html.='</a>';
$html.='<div class="wrap"></div>';
$html.='<a title="'.$product->product_name.'" href="'.$link.'">';
$html.= '<div class="name">'.$product->product_name.'</div>';
$html.='</a>';
$html.= '<div class="price redtext bold">'.KaizenProduct::priceCheck($product).'</div>';
$html.='<div class="wrap"></div></div>';
return $html;
}
}
?>
THEN, YOU CAN USE THESE CODES ANYWHERE IN YOUR JOOMLA INSTALLATION BY DECLARING THE CLASS, AND USING THE FUNCTION.
You can also pre-register the class with a system plugin.
THE FILE YOU WANT TO USE IT IN.
You call the function by LibrarynameClassname::functionname($parameters);
if(!class_exists('KaizenProduct')){
JLoader::discover('kaizen', JPATH_LIBRARIES . '/kaizen');
}
echo KaizenProduct::get_product($product_id,' center border',' Featured Product');