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
<?php echo $product->product_name ?>
Because you have a foreach loop before foreach ( $this->products as $product ) {
Therefore you have $product and not $this->product
BUT: On the product page, you call the product name like this
<?php echo $this->product->product_name ?>
because there is only one product available.
Hi,
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 ?
Regards
Mike
<?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
// Availability Stock Level
?><p></p><?php
$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>
<?php
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,
Volker
Hi Everyone,
If you want to check what available fields you can use, put this before your loop
echo "<pre>"; print_r( $products ); echo "</pre>"; // CATEGORY PAGE
echo "<pre>"; print_r( $this->products ); echo "</pre>"; // PRODUCTS PAGE
You can use this to see the contents of any array/variable/object, just put the name inside the "print_r( $HERE );" tags ...
;D
Hi everyone,
I'm very interested by this thread because I've a problem to display custom fields in the category page ... reccurent question ...
With the command print_r($products) I can see the differents properties I can use ... but there are the properties.
What happends with the methods ?
I want to use the command $product->customfieldsSorted['normal']. This command runs perfectly in the product page (with $this-> ) but not in the category page ...
A (good) idea to progress to find a solution ?
Thank's
Xavier
hi zavier56,
read the code in my previous post CAREFULLY.
Pay particular attention to the comments. It's not hard to figure out when the answer is given.
Hello , i would like to display additionall product images , on my category page , here is the code i use for this :
<?php
if (!empty($product->images) and count ($product->images)>0) {
// List all Images
if (count($product->images) > 0) {
foreach ($product->images as $image)
{
echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image"', true, 'class="modal"', true, true) . '</div>'; //'class="modal"'
}
}
}
?>
My problem is it displays only the first image i added , ignoring all the other ones .
P.S.I make changes in ../category/default.php
Hi Karudi,
Firstly your code has some redundant checks...
<?php
if (!empty($product->images) and count ($product->images)>0) { <-- CHECKS TO MAKE SURE THE ARRAY IS SET AND COUNT IS GREATER THAN 1... NOT REQUIRED AS THE ARRAY WILL ALWAYS BE SET AND CONTAIN AN IMAGE... YES EVEN THE "NO IMAGE" PLACEHOLDER IMAGE IF NONE IS DEFINED
// List all Images
if (count($product->images) > 0) { <-- RECHECKS THAT THE ARRAY COUNT IS GREATER THAN 1... AGAIN! ???
foreach ($product->images as $image)
{
echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image"', true, 'class="modal"', true, true) . '</div>'; //'class="modal"' <-- USELESS COMMENT
}
}
}
?>
// List all Images
foreach ($product->images as $image)
{
echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image"', true, 'class="modal"', true, true) . '</div>';
}
The above code should now work... if the array returned MORE THAN 1 IMAGE...
Change "/components/com_virtuemart/views/category/view.html.php" @ line 171.
// Load the products in the given category
$products = $productModel->getProductsInCategory($categoryId);
$productModel->addImages($products,1);
$this->assignRef('products', $products);
change this line:
$productModel->addImages($products,1);
to
$productModel->addImages($products);
to output all images for each product to the product array.
SAVE. REFRESH. YAY!!!
hello if you want to hide the first picture below on additional image
foreach ($product->images as $image)
{
if (($product->images[0]->file_url_thumb) == ($image->file_url_thumb))
{} else {
echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image-small"', true, 'class="modal"', true, true);
echo '</div>';}
}
Quote from: k0walsky on November 28, 2012, 12:31:48 PM
hello if you want to hide the first picture below on additional image
foreach ($product->images as $image)
{
if (($product->images[0]->file_url_thumb) == ($image->file_url_thumb))
{} else {
echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image-small"', true, 'class="modal"', true, true);
echo '</div>';}
}
if (($product->images[0]->file_url_thumb) == ($image->file_url_thumb))
{continue;}
I want to create a list of child's and their names, availability and price
By adding some code to customfields.php I can read out the names, product_id and availability by reading the $child array. But I can't find an easy way to get the child's salesprice.
Of cause I can get this by an SQL-call, but it can't be true that this i necessary
isn't there an easier method
Great topic,
I am trying to get the parent category name into the category template
(public_html/templates/template/html/com_virtuemart/category/default.php)
<!-- Category title -->
<?php if( !empty($this->category->category_name) ) : ?>
<h1 class="vm-category-title"><?php echo $this->category->category_name; ?></h1>
<?php endif; ?>
The structure of the categories has got 3 levels.
It needs to be [LEVEL 2] [ $this->category->category_name (LEVEL 3)]| Website name... , so just one level up.
I've searched the forum but couldn't find any solution to get this one level up.
Is there something possible like $previous->category->category_name?
EDIT: Working with the latest version of Virtuemart (2.0.18a)
I was also little confuse about Custom field error in my site page, but now I found the way.. Thanks to being here with solution. :)
Hi Ivus,
I read your answer to Karudi about additional images of product in category page. And I have exact problem. But I'm using Virtuemart 2.0.8c. I couldn't fine this lines
// Load the products in the given category
$products = $productModel->getProductsInCategory($categoryId);
$productModel->addImages($products,1);
$this->assignRef('products', $products);
in this path /components/com_virtuemart/views/category/view.html.php
Could you please provide solution for VM 2.0.8c. Because they use a different model of viewing. Thank you at advance.
How can I load the current product into a module? I tried <?php echo $this->product->product_name ?>
I get no error but I get no module text either. The module shows the title shows but it just doesn't load a product name. :(
Quote from: Stonedfury on May 13, 2013, 02:52:16 AM
How can I load the current product into a module? I tried <?php echo $this->product->product_name ?>
I get no error but I get no module text either. The module shows the title shows but it just doesn't load a product name. :(
yopu cant without custom coding
what exactly do you want to do?
I purchased a very crappy module that loads recently purchased products. I have been trying to clean it up and make it load better. I could truly use some help. I don't want to commandeer this post though. I was just checking to make sure I wasn't totally stupid. lol Ill start a new topic.
Hello,
I would show you a picture in the category when a product is not available.
I would use something like this:
<div style="padding:5px;">
<a><?php if ($this->product->product_in_stock == 0) {echo "<img src='http://mysite/images/red2.png' non disponibile' onclick=\"javascript:window.open('/legenda.html','legenda',')\"";}
?></a>
</div>
I used this product in detail and it worked out great in the category but I do not know how to do.
can anyone help me please? :'(
Quote from: antonino78 on June 29, 2013, 15:38:40 PM
Hello,
I would show you a picture in the category when a product is not available.
I would use something like this:
<div style="padding:5px;">
<a><?php if ($this->product->product_in_stock == 0) {echo "<img src='http://mysite/images/red2.png' non disponibile' onclick=\"javascript:window.open('/legenda.html','legenda',')\"";}
?></a>
</div>
I used this product in detail and it worked out great in the category but I do not know how to do.
can anyone help me please? :'(
did you NOT read the first POST in this thread?
$this-> or $product->
There is a place foreach one
Hello,
thanks for your answers.
Since I'm no expert I would be grateful if you could post the solution without sending me to other posts.
The code that I posted it found around ilo web and it worked perfectly for product details.
I simply would like to know how should I modify it to make it work aqnche products in the category.
Can you help me please? :-[
Quote from: antonino78 on June 29, 2013, 17:26:01 PM
Hello,
thanks for your answers.
Since I'm no expert I would be grateful if you could post the solution without sending me to other posts.
The code that I posted it found around ilo web and it worked perfectly for product details.
I simply would like to know how should I modify it to make it work aqnche products in the category.
Can you help me please? :-[
Product variables are called on the category page with $product-> and NOT $this->
SO, CHANGE
$this-> to $product->
Awesome thread! People like me can actually understand a bit more about coding now. Thanks for Pro for starting this and Ivus about great hints too!
Hello,
i am trying to show the stock_level inside a productdetails page bu i cant.
i am using this code:
<span class="vmicon vm2-<?php echo $this->product->stock_level; ?>" title="<?php echo $this->product->stock_tip; ?>"></span>
i copied this code from a category page and changed the $this to work inside a product page...any help??
Quote from: Maxim Pishnyak on September 26, 2013, 14:54:35 PM
Quote from: poisom on September 26, 2013, 13:41:41 PM
i copied this code from a category page
Which code?
<span class="vmicon vm2-<?php echo $this->product->stock_level; ?>" title="<?php echo $this->product->stock_tip; ?>"></span>
you don;t see the code tags??
Nope. I don't see original code. BTW the first pages of each of those two sticked threads about Template Overrides in this forum section could give you a hint.
Hello,
I have Joomla 2.5.14 and VM 2.0.18b. I used this solution http://forum.virtuemart.net/index.php?topic=106732.0 to display related products prices on a product details page. But after I began to use different prices for registered and not registered users the prices of related products disappeared. There were "0" instead of prices. So, as I understand, I need to correct this code somehow:
$product = $model->getProductSingle($field->custom_value,false);
$price = $calculator -> getProductPrices($product);
echo $currency->priceDisplay($price['salesPrice']);
Can you help me with this?
Version is outdated.
Quote from: poisom on September 27, 2013, 09:42:53 AM
you don;t see the code tags??
poisom - did you figure this out yet? I posted a solution here: http://forum.virtuemart.net/index.php?topic=92756.msg409006#msg409006
How can I get to "billTotal" field in order_done.php?
I wrote: print_r($this->cart). Result:
VirtueMartCart Object ( [products] => Array ( ) [_inCheckOut] => [_dataValidated] => [_blockConfirm] => [_confirmDone] => [_redirect] => 1 [_redirect_disabled] => [_lastError] => [vendorId] => 1 [lastVisitedCategoryId] => 0 [virtuemart_shipmentmethod_id] => 0 [virtuemart_paymentmethod_id] => 0 [automaticSelectedShipment] => 1 [automaticSelectedPayment] => [BT] => Array ( [email] => tiko35@o2.pl [company] => Test [first_name] => test [last_name] => test [address_1] => ivan [address_2] => test [zip] => 55-333 [city] => test [phone_1] => ) [ST] => 0 [tosAccepted] => [customer_comment] => [couponCode] => [order_language] => [cartData] => Array ( [VatTax] => Array ( ) [duty] => 1 [payment] => 0 [paymentName] => Przy odbiorze [totalProduct] => 1 [DBTaxRulesBill] => Array ( ) [taxRulesBill] => Array ( ) [DATaxRulesBill] => Array ( ) [shipmentName] => Przy odbiorze [vmVat] => 1 ) [lists] => Array ( [shipTo] => - domyślny (taki sam jak na rachunku)
Shipment
[billTo] => 2 [current_id] => 0 ) [order_number] => [customer_number] => TOfcd7d475a [pricesUnformatted] => Array ( [basePrice] => 75.834 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 75.834 [salesPrice] => 75.834 [taxAmount] => 0 [salesPriceWithDiscount] => 0 [discountAmount] => 0 [priceWithoutTax] => 75.834 [subTotalProducts] => 0 [23] => Array ( [costPrice] => 75.83400 [basePrice] => 75.834 [basePriceVariant] => 75.834 [basePriceWithTax] => 0 [discountedPriceWithoutTax] => 75.834 [priceBeforeTax] => 75.834 [salesPrice] => 75.834 [taxAmount] => 0 [salesPriceWithDiscount] => 0 [salesPriceTemp] => 75.834 [unitPrice] => 0 [discountAmount] => -0 [priceWithoutTax] => 75.834 [variantModification] => 0 [DBTax] => Array ( ) [Tax] => Array ( ) [VatTax] => Array ( ) [DATax] => Array ( ) [subtotal_with_tax] => 75.834 [subtotal_tax_amount] => 0 [subtotal_discount] => 0 [subtotal] => 75.834 ) [salesPriceDBT] => Array ( ) [taxRulesBill] => Array ( ) [DATaxRulesBill] => Array ( ) [shipmentValue] => 20 [shipmentTax] => 0 [salesPriceShipment] => 20 [shipment_calc_id] => 0 [cost] => 0 [salesPriceCoupon] => 0 [withTax] => 75.834 [paymentValue] => 0 [paymentTax] => 0 [paymentTotal] => 0 [salesPricePayment] => 0 [payment_calc_id] => 0 [billSub] => 95.834 [billDiscountAmount] => 0 [billTaxAmount] => 0 [billTotal] => 95.834 ) [pricesCurrency] => 114 [paymentCurrency] => 114 [STsameAsBT] => 1 [productParentOrderable] => 1 [_triesValidateCoupon] => Array ( ) [useSSL] => 0 [useXHTML] => [virtuemart_order_id] => 74 )
I try showing value of "billTotal" field. I write: echo $this->cart->billTotal; but this doesn't work. Why?
Quote from: PRO on November 28, 2012, 19:08:03 PM
Quote from: k0walsky on November 28, 2012, 12:31:48 PM
hello if you want to hide the first picture below on additional image
foreach ($product->images as $image)
{
if (($product->images[0]->file_url_thumb) == ($image->file_url_thumb))
{} else {
echo '<div class="floatleft">' . $image->displayMediaThumb('class="product-image-small"', true, 'class="modal"', true, true);
echo '</div>';}
}
if (($product->images[0]->file_url_thumb) == ($image->file_url_thumb))
{continue;}
Thank you very much :)
Hi sorry if i use this old post but i'm making some modifies on padded.php file of virtuemart 3!
My code is this, and i NEED to add the image of the product i added in the cart
<?php
/**
*
* Layout for the add to cart popup
*
* @package VirtueMart
* @subpackage Cart
* @author Max Milbers
*
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2013 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: cart.php 2551 2010-09-30 18:52:40Z milbo $
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
echo '<a class="continue_link" href="' . $this->continue_link . '" >' . vmText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
echo '<a class="showcart floatright" href="' . $this->cart_link . '">' . vmText::_('COM_VIRTUEMART_CART_SHOW') . '</a>';
if($this->products){
foreach($this->products as $product){
if($product->quantity>0){
echo '<h4>'.vmText::sprintf('COM_VIRTUEMART_CART_PRODUCT_ADDED',$product->product_name,$product->quantity).'</h4>';
[size=24pt]-------> NEED TO ADD THE IMAGE OF THE PRODUCT HERE <--------------[/size]
} else {
if(!empty($product->errorMsg)){
echo '<div>'.$product->errorMsg.'</div>';
}
}
}
}
if(VmConfig::get('popup_rel',1)){
//VmConfig::$echoDebug=true;
if ($this->products and is_array($this->products) and count($this->products)>0 ) {
$product = reset($this->products);
$customFieldsModel = VmModel::getModel('customfields');
$product->customfields = $customFieldsModel->getCustomEmbeddedProductCustomFields($product->allIds,'R');
$customFieldsModel->displayProductCustomfieldFE($product,$product->customfields);
if(!empty($product->customfields)){
?>
<div class="product-related-products">
<h4><?php echo vmText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h4>
<?php
}
foreach($product->customfields as $rFields){
if(!empty($rFields->display)){
?><div class="product-field product-field-type-<?php echo $rFields->field_type ?>">
<div class="product-field-display"><?php echo $rFields->display ?></div>
</div>
<?php }
} ?>
</div>
<?php
}
}
?>
<br style="clear:both">
<p style="background: #9eb618; border-radius:9px; font-weight:600; padding:"> SPEDIZIONE GRATUITA PER ORDINI SUPERIORI A 70€ !</p>
$product->images[0]->file_url (url)
or perhaps
echo $product->images[0]->displayMediaFull("id='main-image'",true,"rel='vm-additional-images'");
for the full html
echo $product->images[0]->displayMediaThumb('class="browseProductImage"', false);
i tried the three proposal but no one works!
The popup does not appear with your codes!
wrong file?
echo out $product
print 'Debug Line '.__LINE__.' $product <pre>'; print_r ($product); print "</pre><br />\n";
no the file is correct,
now appear
[virtuemart_product_id] => 6
[virtuemart_vendor_id] => 1
[product_parent_id] => 0
[product_sku] =>
[product_gtin] =>
[product_mpn] =>
[product_name] => prova2
[slug] => prova-2-4-5
[product_s_desc] =>
[product_desc] =>
[product_weight] =>
[product_weight_uom] => KG
[product_length] =>
[product_width] =>
[product_height] =>
[product_lwh_uom] => M
[product_url] =>
[product_in_stock] => 100
[product_ordered] => 1
no one remind the product image!
Ah .. the image object isn't passed to this view
perhaps
$productModel = VmModel::getModel('product');
$productModel->addImages($this->products, 1);
before the if loop?
Virtuemart 2.6.22
I'm trying to put a script into my product details template. The code was given except the variable I needed to replace with product id (whatever I am referring to the product by in ShopperApproved). I've tried the following and it doesn't seem to be working. Also not quite sure if I put it in the right spot, but I put it in the div that holds the short description and such.
<script type="text/javascript"> var sa_products_count = 3; var sa_date_format = 'F j, Y'; var sa_product = '<?php echo $this->product->product_sku; ?>'; function saLoadScript(src) { var js = window.document.createElement("script"); js.src = src; js.type = "text/javascript"; document.getElementsByTagName("head")[0].appendChild(js); } saLoadScript('//www.shopperapproved.com/product/20541/'+sa_product+'.js'); </script><div id="review_header"></div><div id="product_page"></div><div id="review_image"><a href="www.shopperapproved.com/reviews/Avisbag.com/" target="_blank" rel="nofollow"></a></div>
is it referred by sku?
or id? id is $this->product->virtuemart_product_id
what doesn't work?
Sku. Their placeholder was [Product ID], which I replaced.
Can I basically put this anywhere on the page? Inside of the php tags?
yes.. the $this is available throughout the view
How can i get products by category id in VM 3.0.14? I changed code from sublayout of categories to show all products
$products = $productModel->getProductsInCategory($category_id); but nothing happen