News:

Support the VirtueMart project and become a member

Main Menu

How to add the reference field?? [SOLVED]

Started by kernel, July 18, 2012, 12:19:54 PM

Previous topic - Next topic

kernel

Hi all!

I have spend time using Virtuemart and the new version works very well (congratulations to all developers :) ).

I'm here to see if anyone can help me.

In my site (Joomla 2.5 and Virtuemart 2.0.6) I need to include the Reference field. This field need to appear in the product details and section of the category. Using the search I found this post:
http://forum.virtuemart.net/index.php?topic=92756.0

The code I have to add is this:
<?php echo $this->product->product_sku ?>
The problem is that when I insert this code does not work.

In the two attached images I indicate where to place the reference field. In the flypage product and category page, the reference field should be just above the price. If is possible, this field should give css styles (I have applied the label "<span class="reference">").
- Flypage:


- Category page:


The code I inserted is as follows:
- Flypage:

<?php
if ($this->showRating) {
    $maxrating VmConfig::get('vm_maximum_rating_scale'5);

    if (empty($this->rating)) {
?>

           
<span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' JText::_('COM_VIRTUEMART_UNRATED'?></span>
    <?php
} else {
     $ratingwidth = ( $this->rating->rating 100 ) / $maxrating//I don't use round as percetntage with works perfect, as for me
    ?>
       

<span class="vote">
<?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' round($this->rating->rating2) . '/' $maxrating?><br/>
    <span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . $this->rating->rating '/' $maxrating?>" class="vmicon ratingbox" style="display:inline-block;">
                    <span class="stars-orange" style="width:<?php echo $ratingwidth.'%'?>">
                    </span>
    </span>
</span>
            <br />
           
           



<span class="reference">
<?php echo $this->product->product_sku ?>
</span>




       
<?php
    }
}
if (is_array($this->productDisplayShipments)) {
foreach ($this->productDisplayShipments as $productDisplayShipment) {
echo $productDisplayShipment '<br />';
}
}
if (is_array($this->productDisplayPayments)) {
foreach ($this->productDisplayPayments as $productDisplayPayment) {
echo $productDisplayPayment '<br />';
}
}

echo "<div class='textoformulario'>Referencia: </div>";

// 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');
}
?>


<?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
?>


<?php
// Availability Image
/* TO DO add width and height to the image */
if (!empty($this->product->product_availability)) {
    $stockhandle VmConfig::get('stockhandle''none');
    if ($stockhandle == 'risetime' and ($this->product->product_in_stock $this->product->product_ordered) < 1) {
?>
<div class="availability">
    <?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability''7d.gif'), VmConfig::get('rised_availability''7d.gif'), array('class' => 'availability')); ?>
</div>
    <?php } else {
?>

<div class="availability">
<?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' $this->product->product_availability$this->product->product_availability, array('class' => 'availability')); ?>
</div>
<?php
    }
}
?>



- Category page:

<h2><?php echo JHTML::link($product->link$product->product_name); ?></h2>
                   

<?php /*?>
<?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 */?>
                       
                   
<span class="reference">
<?php echo $this->product->product_sku ?>
</span>
                       

<div class="product_price_category" 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>";
}
if(empty($product->prices) and VmConfig::get('askprice',1) and empty($product->images[0]->file_is_downloadable) ){
echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE');
}
//todo add config settings
if( $this->showBasePrice){
echo $this->currency->createPriceDiv('basePrice','COM_VIRTUEMART_PRODUCT_BASEPRICE',$product->prices);
echo $this->currency->createPriceDiv('basePriceVariant','COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT',$product->prices);
}
echo $this->currency->createPriceDiv('variantModification','COM_VIRTUEMART_PRODUCT_VARIANT_MOD',$product->prices);
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
echo $this->currency->createPriceDiv('discountedPriceWithoutTax','COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE',$product->prices);
echo $this->currency->createPriceDiv('salesPriceWithDiscount','COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT',$product->prices);
echo $this->currency->createPriceDiv('salesPrice','COM_VIRTUEMART_PRODUCT_SALESPRICE',$product->prices);
echo $this->currency->createPriceDiv('priceWithoutTax','COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX',$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>



Can anyone help me? What am I doing wrong?

Thanks a lot!!

ivus

Hi kernel,

OK I just checked the code and it works... well the elements are all there for it to work, but you placed things in the wrong spots...

I'm assuming you want to simply display the product SKU after Referencia:

<?php

if (
$this->showRating) {
$maxrating VmConfig::get('vm_maximum_rating_scale'5);
if (empty($this->rating)) { ?>

<span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' JText::_('COM_VIRTUEMART_UNRATED'?></span>
<?php } else {
$ratingwidth = ( $this->rating->rating 100 ) / $maxrating//I don't use round as percetntage with works perfect, as for me
?>

            <span class="vote">
                <?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' round($this->rating->rating2) . '/' $maxrating?><br/>
                <span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . $this->rating->rating '/' $maxrating?>" class="vmicon ratingbox" style="display:inline-block;">
                    <span class="stars-orange" style="width:<?php echo $ratingwidth.'%'?>"> </span>
                </span>
            </span>
            <br />
<?php
}
}

if (is_array($this->productDisplayShipments)) {
foreach ($this->productDisplayShipments as $productDisplayShipment) {
echo $productDisplayShipment '<br />';
}
}

if (is_array($this->productDisplayPayments)) {
foreach ($this->productDisplayPayments as $productDisplayPayment) {
echo $productDisplayPayment '<br />';
}
}

echo "<div class='textoformulario'>Referencia: "$this->product->product_sku ."</div>";

// 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');
}

// 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

// Availability Image
/* TO DO add width and height to the image */
if (!empty($this->product->product_availability)) {

$stockhandle VmConfig::get('stockhandle''none');
if ($stockhandle == 'risetime' and ($this->product->product_in_stock $this->product->product_ordered) < 1) { ?>

            <div class="availability"> <?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' VmConfig::get('rised_availability''7d.gif'), VmConfig::get('rised_availability''7d.gif'), array('class' => 'availability')); ?> </div>
<?php } else { ?>
            <div class="availability"> <?php echo JHTML::image(JURI::root() . VmConfig::get('assets_general_path') . 'images/availability/' $this->product->product_availability$this->product->product_availability, array('class' => 'availability')); ?> </div>
<?php
}
}

?>



Try that for the productdetails.php page.

What you did wrong was that (you code is ugly!!) you placed this piece of code

<span class="reference">
<?php echo $this->product->product_sku ?>
</span>


inside the if (empty($this->rating)) { } else {}; loop...

Try my code and see it it works and then you can have a go at fixing the categories page on your own.

I hope this helps.

kernel

Hi ivus!!

Thank you for your help!!.
I tried your code in the default.php file in the "productdetails" folder and works perfectly.  ;)


echo "<div class='textoformulario'>Referencia: ". $this->product->product_sku ."</div>";


For the other default.php file in the category folder (product categories) where would you put the code to work?. I tried to put it on multiple sites but only appears the word "Referencia: " in the front-end (the reference number is not appear).

I'll have to learn php.  :)

Thank you for your help ivus. You've helped a lot!
Greetings!

ivus

Hi kernel,

look for this loop

foreach ( $this->products as $product ) {

as long as it's within that loop it should work perfectly, just remember that the sku is now referenced using

$product->product_sku

a little PHP knowledge goes a long way. Good luck.

kernel

Hi again ivus!!

I tried to do what you have said me in the comment above but I have done something wrong because it does not work. Is there a similar solution to the code that you told me (in your first post: "echo "<div class='textoformulario'>Referencia: ". $this->product->product_sku ."</div>";") and works in the following code (categories page)?:


<h2><?php echo JHTML::link($product->link$product->product_name); ?></h2>
                   

<?php /*?>
<?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 */?>
                       
                   
<span class="reference">
<?php echo $this->product->product_sku ?>
</span>
                       

<div class="product_price_category" 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>";
}
if(empty($product->prices) and VmConfig::get('askprice',1) and empty($product->images[0]->file_is_downloadable) ){
echo JText::_('COM_VIRTUEMART_PRODUCT_ASKPRICE');
}
//todo add config settings
if( $this->showBasePrice){
echo $this->currency->createPriceDiv('basePrice','COM_VIRTUEMART_PRODUCT_BASEPRICE',$product->prices);
echo $this->currency->createPriceDiv('basePriceVariant','COM_VIRTUEMART_PRODUCT_BASEPRICE_VARIANT',$product->prices);
}
echo $this->currency->createPriceDiv('variantModification','COM_VIRTUEMART_PRODUCT_VARIANT_MOD',$product->prices);
echo $this->currency->createPriceDiv('basePriceWithTax','COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX',$product->prices);
echo $this->currency->createPriceDiv('discountedPriceWithoutTax','COM_VIRTUEMART_PRODUCT_DISCOUNTED_PRICE',$product->prices);
echo $this->currency->createPriceDiv('salesPriceWithDiscount','COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT',$product->prices);
echo $this->currency->createPriceDiv('salesPrice','COM_VIRTUEMART_PRODUCT_SALESPRICE',$product->prices);
echo $this->currency->createPriceDiv('priceWithoutTax','COM_VIRTUEMART_PRODUCT_SALESPRICE_WITHOUT_TAX',$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>



Thank you for your help ivus. You're helping me a lot!!
Greetings!!

ivus

Hi kernel,

yeah, you've done everything correct except the very last thing I warned you about.

See not everytime a page loads does it use the same variable array structure. The error in your code exists on the following line where I've highlighted it red:

<span class="reference"><?php echo $this->product->product_sku ?></span>
<div class="product_price_category" id="productPrice<?php echo $product->virtuemart_product_id ?>">

if you compare the red variable to the blue variable, you'll notice that it is different. On this page product values are stored in an array called $product. If you change the code to reflect this, then it will work.

if you need to find out what other information is stored inside any array simple type this into your code:

echo "<pre>"; print_r(XXXX); echo "</pre>";

where you replace XXXX with your variable ($this->products).

Good luck with this, I hope you work it out.

kernel

Hi ivus!!
You're the boss!!  :)

Your last explanation has helped me tremendously. Now it works as I wanted. It´s fantastic!!

Thank you for your help and for your patience!!

Greetings!
kernel.

ivus

Hi kernel,

Thanks, but you're the boss. Now you shouldn't have any issues creating all the overrides you want.

Good luck.