News:

Support the VirtueMart project and become a member

Main Menu

show original price, discounted price and discount percentage

Started by arie, January 10, 2012, 14:24:45 PM

Previous topic - Next topic

tichor

Hello.

I was trying to do all steps to to see original price and and discount price. But in my default.php in  template folder html/com_virtuemart/category/ there is no line
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );

I found that line in html/com_virtuemart/productdetails.

This is my code for file default.php in  template folder html/com_virtuemart/category/
<?php
/**
*
* Show the products in a category
*
* @package VirtueMart
* @subpackage
* @author RolandD
* @author Max Milbers
* @todo add pagination
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default.php 5120 2011-12-18 18:29:26Z electrocity $
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
JHTML::_'behavior.modal' );
/* javascript for list Slide
  Only here for the order list
  can be changed by the template maker
*/
$js "
jQuery(document).ready(function () {
jQuery('.orderlistcontainer').hover(
function() { jQuery(this).find('.orderlist').stop().show()},
function() { jQuery(this).find('.orderlist').stop().hide()}
)
});
"
;

$document JFactory::getDocument();
$document->addScriptDeclaration($js);
?>


<div class="category_description">
<?php echo $this->category->category_description ?>
</div>
<?php
/* Show child categories */

if ( VmConfig::get('showCategory',1) ) {
if ($this->category->haschildren) {

// Category and Columns Counter
$iCol 1;
$iCategory 1;

// Calculating Categories Per Row
$categories_per_row VmConfig::get 'categories_per_row');
$category_cellwidth ' width'.floor 100 $categories_per_row );

// Separator
$verticalseparator " vertical-separator";
?>

<div class="category-view">
<?php // Start the Output
if(!empty($this->category->children)){
foreach ( $this->category->children as $category ) {

// Show the horizontal seperator
if ($iCol == && $iCategory $categories_per_row) : ?>

<div class="horizontal-separator"></div>
<?php endif; ?>
<?php 
// this is an indicator wether a row needs to be opened or not
if ($iCol == 1) : 
?>

<div class="row">
<?php endif; ?>
<?php
// Show the vertical seperator
if ($iCategory == $categories_per_row or $iCategory $categories_per_row == 0) {
$show_vertical_separator ' ';
} else {
$show_vertical_separator $verticalseparator;
}

// Category Link
$caturl JRoute::'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' $category->virtuemart_category_id );

// Show Category ?>

<div class="category floatleft<?php echo $category_cellwidth $show_vertical_separator ?>">
<div class="spacer">
<h2 class="catSub">
<a href="<?php echo $caturl ?>" title="<?php echo $category->category_name ?>">
<?php echo $category->category_name ?>


</a>
</h2>
<?php // if ($category->ids) {
echo $category->images[0]->displayMediaThumb("",false);
//} ?>

</div>
</div>
<?php
$iCategory ++;

// Do we need to close the current row now?
if ($iCol == $categories_per_row) { ?>

<div class="clear"></div>
</div>
<?php
$iCol 1;
} else {
$iCol ++;
}
}
}
// Do we need a final closing row tag?
if ($iCol != 1) { ?>

<div class="clear"></div>
</div>
<?php ?>
</div>
<?php }
}

// Show child categories
if (!empty($this->products)) {
if (!empty($this->keyword)) {
?>

<h3><?php echo $this->keyword?></h3>
<?php
}
?>

<?php // Category and Columns Counter
$iBrowseCol 1;
$iBrowseProduct 1;

// Calculating Products Per Row
$BrowseProducts_per_row $this->perRow;
$Browsecellwidth ' width'.floor 100 $BrowseProducts_per_row );

// Separator
$verticalseparator " vertical-separator";
?>

<div class="browse-view">
<h1><?php echo $this->category->category_name?></h1>
<form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id='.$this->category->virtuemart_category_id ); ?>" method="get">
<?php if ($this->search) { ?>
<!--BEGIN Search Box -->
<div class="virtuemart_search">
<?php echo $this->searchcustom ?>
<br />
<?php echo $this->searchcustomvalues ?>
<input style="height:16px;vertical-align :middle;" name="keyword" class="inputbox" type="text" size="20" value="<?php echo $this->keyword ?>" />
<input type="submit" value="<?php echo JText::_('COM_VIRTUEMART_SEARCH'?>" class="button" onclick="this.form.keyword.focus();"/>
</div>
<input type="hidden" name="search" value="true" />
<input type="hidden" name="view" value="category" />

<!-- End Search Box -->
<?php ?>
<div class="orderby-displaynumber">
<?php echo $this->orderByList['orderby']; ?>
<div class="display-number"><?php echo $this->vmPagination->getResultsCounter();?> <?php echo $this->vmPagination->getLimitBox(); ?></div>
</div>
</form>
<?php // Start the Output
foreach ( $this->products as $product ) {

// Show the horizontal seperator
if ($iBrowseCol == && $iBrowseProduct $BrowseProducts_per_row) { ?>

<div class="horizontal-separator"></div>
<?php }

// this is an indicator wether a row needs to be opened or not
if ($iBrowseCol == 1) { ?>

<div class="row">
<?php }

// Show the vertical seperator
if ($iBrowseProduct == $BrowseProducts_per_row or $iBrowseProduct $BrowseProducts_per_row == 0) {
$show_vertical_separator ' ';
} else {
$show_vertical_separator $verticalseparator;
}

// Show Products ?>

<div class="product floatleft<?php echo $Browsecellwidth $show_vertical_separator ?>">
<div class="spacer">
<div>
<?php /** @todo make image popup */
echo $product->images[0]->displayMediaThumb('class="browseProductImage" border="0" title="'.$product->product_name.'" ',true,'class="modal"');
?>


<!-- The "Average Customer Rating" Part -->
<?php if (VmConfig::get('pshop_allow_reviews') == 1) { ?>
<span class="contentpagetitle"><?php echo JText::_('COM_VIRTUEMART_CUSTOMER_RATING'?>:</span>
<br />
<?php
// $img_url = JURI::root().VmConfig::get('assets_general_path').'/reviews/'.$product->votes->rating.'.gif';
// echo JHTML::image($img_url, $product->votes->rating.' '.JText::_('COM_VIRTUEMART_REVIEW_STARS'));
// echo JText::_('COM_VIRTUEMART_TOTAL_VOTES').": ". $product->votes->allvotes; ?>

<?php ?>
</div>
<div>
<h3 class="catProductTitle"><?php echo JHTML::link($product->link$product->product_name); ?></h3>
<?php // Product Short Description
if(!empty($product->product_s_desc)) { ?>

<p class="product_s_desc">
<?php echo shopFunctionsF::limitStringByWord($product->product_s_desc40'...'?>
</p>
<?php ?>
<?php if (!VmConfig::get('use_as_catalog')){?>
<div class="stockLavel">
<span class="vmicon vm2-<?php echo $product->stock->stock_level ?>" title="<?php echo $product->stock->stock_tip ?>"></span>
<span class="stock-level"><?php echo JText::_('COM_VIRTUEMART_STOCK_LEVEL_DISPLAY_TITLE_TIP'?></span>
</div>
<?php }?>
<div class="catProductPrice" id="productPrice<?php echo $product->virtuemart_product_id ?>">
<?php
if ($this->show_prices == '1') {
if( $product->product_unit && VmConfig::get('vm_price_show_packaging_pricelabel')) {
echo "<strong>"JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT').' ('.$product->product_unit."):</strong>";
}


echo $this->currency->createPriceDiv('salesPrice','',$product->prices);
echo $this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices);
echo $this->currency->createPriceDiv('taxAmount','COM_VIRTUEMART_PRODUCT_TAX_AMOUNT',$product->prices);

?>

</div>
<?php // Product Details Button
echo JHTML::link($product->linkJText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'catProductDetails'));
?>

</div>
</div>
</div>
<?php
$iBrowseProduct ++;

// Do we need to close the current row now?
if ($iBrowseCol == $BrowseProducts_per_row) { ?>

</div>
<?php
$iBrowseCol 1;
} else {
$iBrowseCol ++;
}
}
// Do we need a final closing row tag?
if ($iBrowseCol != 1) { ?>

<div class="clear"></div>
</div>
<?php
}
?>

<div class="pagination">
<?php echo str_replace('</ul>''<li class="counter">'.$this->vmPagination->getPagesCounter().'</li></ul>'$this->vmPagination->getPagesLinks()); ?>
</div>
</div>
<?php ?>


Thx in advance for replay

adrianpaun

I've finaly found a solution for productdetailed discount show with the baseprice, the new price (with discount) and the discount ammount.

First of all we need to activate in the virtuemart back-end in Configuration - > Pricing : Baseprice, Salesprice without tax, Final salesprice and Discount amount

What we will do is to create two pages for displaying the product detailet view, so first thing first:

1. Copy from component/com_virtuemart/views/productdetails/tmpl/default.php to  your template to make an override template for vm2: templates/your_template/html/com_virtuemart/productdetails/default.php

2. Edit this page

3. Find this code:


// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    echo $this->loadTemplate('showprices');

}

?>


4. Replace it with this one wich  (you will find the full form in component/com_virtuemart/views/productdetails/tmpl/default_showprices.php if you need other strings)


// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    ?>

//mod
//the standard line was <div class="product-price" id="productPrice<?php echo $this->product->virtuemart_product_id ?>">
//i've change the <?php echo $this->product->virtuemart_product_id ?> to class insead of id and create a unique id for this one calld productPriceDiscount (for css ussage)

<div class="product-price-detailed<?php echo $this->product->virtuemart_product_id ?>" id="productPriceDiscount">

//END mod

    <?php

    
if ($this->product->product_unit && VmConfig::get('price_show_packaging_pricelabel')) {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT') . ' (' $this->product->product_unit "):</strong>";

    } else {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE') . "</strong>";

    }

    if (empty(
$this->product->prices) and VmConfig::get('askprice'1)) {

?>


        <a class="ask-a-question bold" href="<?php echo $url ?>" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE'?></a>

    <?php

    
}

//mod
// i've put baseprice, salesprice and discountamount to be shown.

    
echo $this->currency->createPriceDiv('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$this->product->prices);

//END mod
    
?>


               

</div>

<?php }

?>




6. We need to modify the css file so we have to add:


.PricediscountAmount{color:#FF0000;}
#productPriceDiscount { font-size:48px; letter-spacing:-2px; line-height:42px;border: 1px solid #E9E8E8;border-radius: 12px 12px 12px 12px; text-align:center; padding:10px 0; font-weight:700; color:#0066FF; }
#productPriceDiscount .PricebasePrice {text-decoration:line-through;color:#666;}


7. After we did this we will save this page with the name default_discount.php

8. now edit again the new page default_discount.php:

Find


    echo $this->currency->createPriceDiv('basePrice', 'COM_VIRTUEMART_PRODUCT_BASEPRICE', $this->product->prices);

    echo $this->currency->createPriceDiv('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $this->product->prices);

    echo $this->currency->createPriceDiv('discountAmount', 'COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT', $this->product->prices);


Replace it with:


echo $this->currency->createPriceDiv('salesPrice', '', $this->product->prices);


9. Save this page under default.php

10. Go to Virtuemart Back-End -> Products -> Select a product you want to make a discount -> select on Product Details Page -> default_discount and then put your discount in product Pricing - Override and check the box.

This should be it and you cand update you're Virtuemart without losing youre modifications.



[attachment cleanup by admin]

szeor

Hi,
tobisagt, your code is brilliant, thank you.. but this code work only on category page and on homepage (new products, top ten products), but doesnt work product page (one product).

I dont understand something, or this code really doesnt work on only one product page? If is really doesnt work on one product page, what is the solution?

Thank you for answer.

tobisagt

Quote from: szeor on April 22, 2012, 12:52:32 PM
Hi,
tobisagt, your code is brilliant, thank you.. but this code work only on category page and on homepage (new products, top ten products), but doesnt work product page (one product).

I dont understand something, or this code really doesnt work on only one product page? If is really doesnt work on one product page, what is the solution?

Thank you for answer.

Whats your code in productdetails?

For me, it works fine!

szeor

Hi, thanks for the quick answer..
I had 3 files in components/com_virtuemart/view/productdeatil folder (pdf.php, default_pdf.php, ), where is this code:
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
but i changed in every files this code:
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }


and of course changed codes in currencydisplay.php and in category folder, default.php, and work, except product details.

szeor

adrianpaun, i test solution of your, but wrong code, or i dont know..
image:
http://kepfeltoltes.hu/120422/wrong_code_www.kepfeltoltes.hu_.jpg

code in file (+/- 2-3 line):
if (is_array($this->productDisplayPayments)) {
    foreach ($this->productDisplayPayments as $productDisplayPayment) {
echo $productDisplayPayment . '<br />';
    }
}
// Product Price

if ($this->show_prices and (empty($this->product->images[0]) or $this->product->images[0]->file_is_downloadable == 0)) {

    ?>

//mod
//the standard line was <div class="product-price" id="productPrice<?php echo $this->product->virtuemart_product_id ?>">
//i've change the <?php echo $this->product->virtuemart_product_id ?> to class insead of id and create a unique id for this one calld productPriceDiscount (for css ussage)

<div class="product-price-detailed<?php echo $this->product->virtuemart_product_id ?>" id="productPriceDiscount">

//END mod

    <?php

    
if ($this->product->product_unit && VmConfig::get('price_show_packaging_pricelabel')) {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE_PER_UNIT') . ' (' $this->product->product_unit "):</strong>";

    } else {

echo "<strong>" JText::_('COM_VIRTUEMART_CART_PRICE') . "</strong>";

    }

    if (empty(
$this->product->prices) and VmConfig::get('askprice'1)) {

?>


        <a class="ask-a-question bold" href="<?php echo $url ?>" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE'?></a>

    <?php

    
}

//mod
// i've put baseprice, salesprice and discountamount to be shown.

    
echo $this->currency->createPriceDiv('basePrice''COM_VIRTUEMART_PRODUCT_BASEPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('salesPrice''COM_VIRTUEMART_PRODUCT_SALESPRICE'$this->product->prices);

    echo 
$this->currency->createPriceDiv('discountAmount''COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT'$this->product->prices);

//END mod
    
?>


               

</div>

<?php }

?>




<?php
// Add To Cart Button
//  if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
if (!VmConfig::get('use_as_catalog'0) and !empty($this->product->prices)) {
    echo $this->loadTemplate('addtocart');
}  // Add To Cart Button END
?>

tobisagt

Quote from: szeor on April 22, 2012, 19:01:39 PM
Hi, thanks for the quick answer..
I had 3 files in components/com_virtuemart/view/productdeatil folder (pdf.php, default_pdf.php, ), where is this code:
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
but i changed in every files this code:
if ($this->currency->createPriceDiv('discountAmount','COM_VIRTUEMART_PRODUCT_DISCOUNT_AMOUNT',$product->prices)) {
    echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices); }


and of course changed codes in currencydisplay.php and in category folder, default.php, and work, except product details.

Dont you have a "default.php" in product details? Or is the "default_pdf.php" the default for your template?

szeor

QuoteDont you have a "default.php" in product details? Or is the "default_pdf.php" the default for your template?
of course i have default.php, and default_pdf.php, but i dont found this code in the default.php file,
echo $this->currency->createPriceDiv ( 'basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $this->product->prices );
i changed codes only default_pdf, pdf and default_showprices.php files.

when i say default template is default or pdf, vm do nothing (i dont see old price with promotional product), but when i say default template is default_showprices, i see old price with promotional product, but i see with non promotional product, and i see double default price (I see the same price two).

tobisagt


szeor

Quotemaybe you have a "default_showprices.php" ?
im sorry, but i dont understand..
when i say default template is default.php or pdf.php, vm do nothing (i dont see old price with promotional product), but when i say default template is default_showprices, i see old price with promotional product, but i see with non promotional product, and i see double default price (I see the same price two).

Now? default is simple default, because
default template is default_pdf: no old price, custom fields, and cart button,
pdf: no old price and cart button (custom fields yes)
default_showprice: only price (no cart button, custom fields, image), but old price see with non promotional product (i see the same price two)

szeor


adrianpaun

default_pdf ?, i think that is for the other purpose not for a default frontpage wich is: default.php and includes both default_category.php and default_products.php.

For other information read this post http://forum.virtuemart.net/index.php?topic=101110.0, and it's working, maybe you dont have the show price active (all of them) in vm backend.

szeor

other forum help do nothing, the problem is same.. if is work on promotional product page, i se same price to the non promotional product page, and i see on other forum, on example page...

http://andrei.peacock.ro/produse/produse-medicale/electrocardiografe/electrocardiograful-taidoc-td-8202-4-5-detalii

szeor

Do you share your modified files? And your vm settings (files in rapidshare or something, setting is only written, ofc :) )?
I have no idea, but this thing doesnt work, i am forced to delete new version of virtuemart  :(

Genius WebDesign

Hi tobisagt,

Thx for the awesome code!

After following your instructions and altering the currencydisplay.php and the default.php in both the "category" and "productdetails" folder in my template I have a few problems..

I'm using Joomla 2.5, Virtuemart 2.0.6 and I have the "Explore" template from http://www.virtuemarttemplates.net/ installed.

My problems are:

1. The decimals in my currency settings are set to 2 digits but after applying the code the "pricewithouttaxes" is shown with 4 digits decimals. Without the code-alteration it shows with 2 decimals correctly.
2. After applying the code alteration to the "productdetails"ยด default.php file the "pricewithouttaxes" dont show up at all on the product details page.. Once I remove the altered code from the default-php file the pricewithouttaxes show up again but they of course do not disappear when there is no discount.

So, the code works, almost, perfectly in the "category" file but the same code makes problems in the "productdetails" file.

Pls. advice