Search

Change Language

Friday, April 8, 2011

Showing Product Image on Virtuemart Cart Page


Edit 4 files to show product thumbnails in shopping cart and the checkout process:

1. basket_b2c.html.php
2. ro_basket_b2c.html.php
3. basket.php
4. ro_basket.php

Files 1 & 2 are in:  /components/com_virtuemart/theme/templates/basket
Files 3 & 4 are in: /administrator/components/com_virtuemart/html

basket_b2c.html.php and ro_basket_b2c.html.php are themplates files used to display the chart.

At about line 32, add the following code to the 2 theme files:


Code:

<td><?php echo $product['product_thumb_image'] ?></td>


Then you have to add code to create the field 'product_thumb_image' in the product records.  To do that you must edit basket.php and ro_basket.php and add this code at line 90:

Code:

//prepare thumb image

if( $ps_product->get_field($_SESSION['cart'][$i]["product_id"], "product_thumb_image") ) {
$product_thumb_image = $ps_product->get_field($_SESSION['cart'][$i]["product_id"], "product_thumb_image");
}
else {
$product_thumb_image = 0;
}

if( $product_thumb_image ) {
if( substr( $product_thumb_image, 0, 4) != "http" ) {
if(PSHOP_IMG_RESIZE_ENABLE == '1') {
$product_thumb_image = $mosConfig_live_site."/components/com_virtuemart/show_image_in_imgtag.php?filename=".urlencode($product_thumb_image)."&newxsize=".PSHOP_IMG_WIDTH."&newysize=".PSHOP_IMG_HEIGHT."&fileout=";
}
else {
if( file_exists( IMAGEPATH."product/".$product_thumb_image )) {
$product_thumb_image = IMAGEURL."product/".$product_thumb_image;
}
else {
$product_thumb_image = IMAGEURL.NO_IMAGE;
}
}
}
}
else {
$product_thumb_image = IMAGEURL.NO_IMAGE;
}

$product_rows[$i]['product_thumb_image'] = "<a href=\"$url\">"
. "<img width=100 src= $product_thumb_image />"
. "</a><br />";
//end of prepare thumb image 

Getting Virtuemart Product Attributes Use Radio Buttons

Replace the complete code of the file:
components/com_virtuemart/themes/default/templates/product_details/includes/addtocart_advanced_attribute.tpl.php

with the following:
 

<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

foreach($attributes as $attribute) {      
    ?>
    <div class="vmAttribChildDetail" style="float: left;text-align:right;margin:3px;">
        <label for="<?php echo $attribute['titlevar'] ?>_field"><?php echo $attribute['title'] ?></label>:
    </div>
    <div class="vmAttribChildDetail" style="float: left;text-align:left;margin:3px;">
    <?php
    $chek = 1;
    foreach ( $attribute['options_list'] as $options_item )  { ?>
          <?php if( isset( $options_item['display_price']) ) : ?>
           <input type="radio" style="margin-top: 15px;"
            id="<?php echo $attribute['titlevar'] ?>_field"
            name="<?php echo $attribute['titlevar'].$attribute['product_id'] ?>"
            value="<?php echo $options_item['base_var'] ?>"
            <?php if ($chek==1) { echo " checked"; $chek=0; }; ?>
            >
            <?php echo $options_item['base_value'] ?> (
            <?php echo $options_item['sign'].$options_item['display_price']
            ?>)
          <br />
           <?php else : ?>
           <input type="radio" style="margin-top: 15px;"
            id="<?php echo $attribute['titlevar'] ?>_field"
            name="<?php echo $attribute['titlevar'].$attribute['product_id'] ?>"
            value="<?php echo $options_item['base_var'] ?>"
            <?php if ($chek==1) { echo " checked"; $chek=0; }; ?>
            >
            <?php echo $options_item['base_value']
            ?><br />
           <?php endif; ?>
    <?php } ?>
    </div>
    <br style="clear:both;" />
   
<?php
} ?>



Remember to save a coy of the original code just in case!
 

Showing Attributes in Product Browse page (Virtue Mart)

in home/administrator/components/com_virtuemart/html/shop.browse.php

// Add-to-Cart Button
      if (USE_AS_CATALOGUE != '1' && $product_price != ""
         && !stristr( $product_price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )
         && !ps_product::product_has_attributes( $db_browse->f('product_id'), false )
         && $tpl->get_cfg( 'showAddtocartButtonOnProductList' ) ) {

---> Change 'true' by 'false'

home/components/com_virtuemart/themes/default/templates/browse/includes/addtocart_form.tpl.php

<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); [

$button_lbl = $VM_LANG->_('PHPSHOP_CART_ADD_TO');
$button_cls = 'addtocart_button';

require_once(CLASSPATH . 'ps_product_attribute.php' ); //Add this line
$ps_product_attribute = new ps_product_attribute; //Add this one too

if( CHECK_STOCK == '1' && !$product_in_stock ) {
   $button_lbl = $VM_LANG->_('VM_CART_NOTIFY');
   $button_cls = 'notify_button';
}
?>

<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 )) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
    <?php echo $ps_product_attribute->list_advanced_attribute($product_id,$product_id); ?><br />
    <?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br />
   <input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl   ?>" title="<?php echo $button_lbl ?>" />
    <input type="hidden" name="category_id" value="<?php echo  @$_REQUEST['category_id'] ?>" />
    <input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
    <input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
    <input type="hidden" name="page" value="shop.cart" />
    <input type="hidden" name="func" value="cartadd" />
    <input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
    <input type="hidden" name="option" value="com_virtuemart" />
    <input type="hidden" name="set_price[]" value="" />
    <input type="hidden" name="adjust_price[]" value="" />
    <input type="hidden" name="master_product[]" value="" />
</form>


Add the two commented lines on line 6 (as shown above) And add this line

<?php echo $ps_product_attribute->list_advanced_attribute($product_id,$product_id); ?><br />
on line 16, just above

<?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br /> 

Showing Addtocart in Browsepage (Virtuemart)

In administrator/components/com_virtuemart/html/shop.browse.php, look for these lines (400-404):



// Add-to-Cart Button 
  if (USE_AS_CATALOGUE != '1' && $product_price != "" 
   && !stristr( $product_price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )
   && !ps_product::product_has_attributes( $db_browse->f('product_id'), true )
   && $tpl->get_cfg( 'showAddtocartButtonOnProductList' ) ) {

1. Change the second parameter of product_has_attributes() to false:



// Add-to-Cart Button 
  if (USE_AS_CATALOGUE != '1' && $product_price != "" 
   && !stristr( $product_price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )
   && !ps_product::product_has_attributes( $db_browse->f('product_id'), false )
   && $tpl->get_cfg( 'showAddtocartButtonOnProductList' ) ) {

(this allows the add-to-cart button on products with only simple attributes).
2. Remove the attribute check completely:


// Add-to-Cart Button 
  if (USE_AS_CATALOGUE != '1' && $product_price != "" 
   && !stristr( $product_price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )
   && $tpl->get_cfg( 'showAddtocartButtonOnProductList' ) ) {

This allows the add-to-cart button on everything.