VirtueMart 2 + 3 > Templating & Layouts

$this-> VS $product->

(1/9) > >>

When templating product page and category page.

$this->    Refers to the CURRENT object

The current Object is not hard to figure out. It is a VmView and usually defined in the url for example as &view=productdetails.  =>VmViewProductdetails

SO, in the category template. $this-> is going to call variables created in view.html.php for the category view.

In the product details template. $this->   is going to call variables from THAT view.

Product variables are called on the category page with   $product->

For example
On the category page
You call the product name like this

--- Code: ---<?php echo $product->product_name ?>
--- End code ---

Because you have a foreach loop before 
--- Code: ---foreach ( $this->products as $product ) {
--- End code ---
Therefore you have $product and not $this->product

BUT: On the product page, you call the product name like this

--- Code: ---<?php echo $this->product->product_name ?>
--- End code ---
because there is only one product available.


Following your example I tried to put the category name in the browse page.

<p class="prodcat"><?php echo $product->category_name; ?></p>

But nothing appears.

I'm working with J1.5.26 + V1.1.19

Could you please help me ?


<?php echo $product->category_name ?>

^^ that just worked for me

I'm trying to show child's stock level in parent product details.

I work with a "VM Custom, stockable variants" plugin. In the parent product you can choose different child products with a drop down menu.
First try was to insert following code in the stockable.php

--- Code: ---
// Availability Stock Level
$stato = "";
$statotip = "";
if ($field->child[$child_id]['in_stock'] < 1) {
$stato = "nostock";
$statotip = "Hurry! Very low items stock!";
} else {
if ($field->child[$child_id]['in_stock'] < 2) {
$stato = "lowstock";
$statotip = "Low items in stock!";
} else {
$stato = "normalstock";
$statotip = "Items in stock available!";
} ?>
<span class="vmicon vm2-<?php echo $stato ?>" title="<?php echo $statotip ?>"></span>

--- End code ---

Now I receive correct stock level of child products above category and product view, but no single stock level of the current chosen child within the parent view.

I'd welcome any help to get the result I wanted.

Thanks a lot,

Hi Everyone,

If you want to check what available fields you can use, put this before your loop

--- Code: ---
    echo "<pre>"; print_r( $products ); echo "</pre>"; // CATEGORY PAGE

    echo "<pre>"; print_r( $this->products ); echo "</pre>"; // PRODUCTS PAGE

--- End code ---

You can use this to see the contents of any array/variable/object, just put the name inside the "print_r( $HERE );" tags ...



[0] Message Index

[#] Next page

Go to full version