Monday, April 26, 2010

virtuemart letest module customization

1. How to insert detail link in letest module:
open the file,
components/com_virtuemart/themes/default/templates/common/productsnapshot.tpl.php
last of the file insert the following code

<a title="<?php echo $product_name ?>" href="<?php echo $product_link ?>">[Product Details]</a>

2. Module "latest product" with description products
The following hack will allow you to dispaly a product's description in the "Latest Products" module. Since the "Latest Products" module uses the common "product snapshot" template, this hack will also cause all other usages of "product snapshot" to show the description. If you do not want this behavior, do not install this hack.
There are two tasks involved in this hack. The first is to modify the "product snapshot" template and the second is to modify the class "ps_product" with a user class.
To modify the snapshot, first make a copy of, then edit this file (assuming you're using the Default theme; if not, substitute your theme's name for Default):
components/com_virtuemart/themes/default/templates/common/productsnapshot.tpl.php

Let's say you want to put the Description after the price. Find these lines:

Code:
<!-- The product price DIV. -->
<div style="width: 100%;float:left;text-align:center;">
<?php
if( !empty($price) ) {
echo $price;
}
?>
</div>
Right after that, add these lines:
Code:
<!-- The product Description DIV. -->
<div style="width: 100%;float:left;text-align:center;">
<?php
if( !empty($product_desc) ) {
echo $product_desc;
}
?>
</div>
Save the file and you're done with task one.
Next we need to change the function (method) called "product_snapshot" in the class called "ps_product". Instead of changing the core class, this fix uses VM's "Extended User Class" functionality which became available with VM 1.1.4.
There are 4 steps involved in this task.
Step 1 - copy the following code and save it into a file named "ps_product.php" (but don't overwrite your existing ps_product.php file).
Code:
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
class ps_product extends vm_ps_product {
/**
* Alternative product_snapshot method which reads the product's description and
* puts it into the template
*/
/**
* Returns HTML code for a snapshot of a product based on the product sku.
* This was written to provide a quick way to display a product inside of modules
*
* @param string $product_sku The SKU identifying the product
* @param boolean $show_price Show the product price?
* @param boolean $show_addtocart Show the add-to-cart link?
* @param boolean $show_product_name Show the product name?
*/
function product_snapshot( $product_sku, $show_price=true, $show_addtocart=true, $show_product_name = true ) {
global $sess, $mm_action_url;
$db = new ps_DB;
require_once(CLASSPATH.'ps_product_category.php');
$ps_product_category = new ps_product_category;
$q = "SELECT product_id, product_name, product_parent_id, product_thumb_image, product_desc FROM #__{vm}_product WHERE product_sku='$product_sku'";
$db->query( $q );
if ($db->next_record()) {
$product_id = $db->f("product_id" );
$tpl = new $GLOBALS['VM_THEMECLASS']();
$cid = $ps_product_category->get_cid( $product_id );
$tpl->set( 'product_id', $product_id);
$tpl->set( 'product_name', $db->f("product_name") );
$tpl->set( 'product_desc', $db->f("product_desc") );
$tpl->set( 'show_product_name', $show_product_name );
if ($db->f("product_parent_id")) {
$url = "?page=shop.product_details&category_id=$cid&flypage=".$this->get_flypage($db->f("product_parent_id"));
$url .= "&product_id=" . $db->f("product_parent_id");
} else {
$url = "?page=shop.product_details&category_id=$cid&flypage=".$this->get_flypage($db->f("product_id"));
$url .= "&product_id=" . $db->f("product_id");

}

$product_link = $sess->url($mm_action_url. "index.php" . $url);

$tpl->set( 'product_link', $product_link );

$tpl->set( 'product_thumb_image', $db->f("product_thumb_image"), "alt=\"".$db->f("product_name")."\"");
if (_SHOW_PRICES == '1' && $show_price) {

// Show price, but without "including X% tax"

$price = $this->show_price( $db->f("product_id"), true );

$tpl->set( 'price', $price );

}
if (USE_AS_CATALOGUE != 1 && $show_addtocart
&& isset( $GLOBALS['product_info'][$product_id]['price']['product_price_id'] ) // Product must have a price to add it to cart

&& !$this->product_has_attributes($product_id, true) // Parent Products and Products with attributes can't be added to cart this way

) {

$url = "?page=shop.cart&func=cartAdd&product_id=" . $db->f("product_id");
$addtocart_link = $sess->url($mm_action_url. "index.php" . $url);
$tpl->set( 'addtocart_link', $addtocart_link );
}
return $tpl->fetch( 'common/productsnapshot.tpl.php');

}
return '';
}

}

?>
Step 2 - Create a directory in
components/com_virtuemart/themes/your_theme_name/

and call it user_class (unless you already have one)
Step 3 - Move the file from Step 1 into this new directory so the file path looks like this:

components/com_virtuemart/themes/your_theme_name/user_class/ps_product.php
Step 4 - Admin->Configuration->Security tab->Security Settings box

enable "Allow the inclusion of extended classes from the theme-directory"


Test it. If you have any problems, just delete the file user_class/ps_product.php



Important note: if you actually wanted to show the "short description" instead of the full product description, then in both tasks, change all occurrances of "product_desc" to "product_s_desc" in the file also in the class .

2 comments:

  1. It looks great but I didn’t understand it well.
    Virtuemart Website Themes

    ReplyDelete
  2. Awesome information. I am really surprised with this topic. Keep up the good work and post more here to read. Business Logo Design

    ReplyDelete