Author Topic: How do I display a custom field in related product ?  (Read 11417 times)

kuli-kode

  • Beginner
  • *
  • Posts: 3
How do I display a custom field in related product ?
« on: April 05, 2013, 10:31:15 am »
Hi, how do I display a custom field and detail/add to cart button in related product ?
I have been searching for this issue in the forum but have not been successful, as for the code I have done [default_relatedproducts.php] :

Code: [Select]
<div class="product-related-products">
<h4><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h4>
    <?php
    foreach (
$this->product->customfieldsRelatedProducts as $field) {
    if(!empty($field->display)) {
?>

<div class="">
    <span class="product-field-display-vm">
    <?php 
     echo $field->display str_replace'</a>'' <div class="produk-detail-vm">Detail</div></a>'$field->display );
?>

    </span>
</div>
<?php 
}

?>

</div>

I use j2.5 and vm 2.0.20b

Sorry for my bad english, i'm from Indonesia

Thanks  :)

kuli-kode

  • Beginner
  • *
  • Posts: 3
Re: How do I display a custom field in related product ?
« Reply #1 on: April 06, 2013, 18:57:57 pm »
ops, to date there is still no answer, ok I'll update my own and it turns out the problem is finished, just a matter of code sharing for those who suffered the same problem with me, the following code that I have developed:

[default_relatedproducts.php]

copy and paste the following code :

Code: [Select]
<?php
defined '_JEXEC' ) or die ( 'Restricted access' );

$model = new VirtueMartModelProduct();
$calculator calculationHelper::getInstance();
$currency CurrencyDisplay::getInstance();
?>


<div class="product-related-products">
<h4><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h4>

    <?php
    foreach (
$this->product->customfieldsRelatedProducts as $field) {
    if(!empty($field->display)) {
?>

<div class="product-field product-field-type-<?php echo $field->field_type ?>">
    <span class="product-field-display">
    <?php echo $field->display ?>
    </span>
</div>
<div>
</div>


<span class="product-field-desc">
<?php
echo jText::_($field->custom_field_desc);
$product $model->getProductSingle($field->custom_value,false);
$price $calculator -> getProductPrices($product);
echo $currency->priceDisplay($price['salesPrice']);
?>

</span>

<?php // This is the beginning of "Add to cart" ?>

<div>
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<div class="addtocart-bar">

<?php echo $this->product->virtuemart_product_id;?>
<span class="quantity-box">
<input type="text" class="quantity-input" name="quantity[]" value="1" />
</span>

<?php // Display the quantity box END ?>

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" id="addtocart-button" name="addtocart" class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>
</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>
</div>

<?php // Product Short Description
if (!empty($product->product_s_desc)) {
?>

<div class="product_s_desc">
<?php echo shopFunctionsF::limitStringByWord ($product->product_s_desc60' ...'?>
</div>
<?php ?>


<?php 
$custom_title null

if (!empty($product->customfields)) {
foreach ($product->customfields as $field) {
if ($field->is_hidden )
continue;
if ($field->display) { ?>


<?php 
echo $field->display;
?>

<?php ?>
<?php ?>
<?php ?>

<?php 
}


?>

</div>

nb :
- work for me to vm 2.0.20b
- if there is a better way please post here, let's learn together

sorry for my bad english.

old_fritz

  • Beginner
  • *
  • Posts: 36
Re: How do I display a custom field in related product ?
« Reply #2 on: May 10, 2013, 11:39:01 am »
hey kuli,

got kind of same problem:



the problem which I ran into, is that a vendor logo (gustini) is not shown.
just a option box with the file selected.

what it should show is actually the gustini logo like in the above detailed view.


i generated that with the custom field "custom title" with the default value "shipping_icon".
for the "custom_value" i set the default value to 43 that´s the id for the logo.

so that works pretty good for the details view. i don´t have any idea why the input of the exact same custome code to the related products result an other appereance.
i guess there´s just something in the code, that tells the related view to show an option box instead of an image.
hopefully not a big thing.

here´s the custome code i insert in the "related_products.php":


Code: [Select]
<div><?php $custom_title null
if (!empty(
$product->customfields)) {
foreach (
$product->customfields as $field) {
if (
$field->is_hidden //OSP http://forum.virtuemart.net/index.php?topic=99320.0
continue;
if (
$field->display) { ?>

<div><span class="product-field-display"><?php echo $field->display ?></span></div>
<?php ?> <?php ?> <?php }  ?>
</div>


may you or anybody else have an idea?!
thanks a lot in advance!!!

[attachment cleanup by admin]

babouz

  • Beginner
  • *
  • Posts: 22
Re: How do I display a custom field in related product ?
« Reply #3 on: May 15, 2013, 10:04:31 am »
Hi everybody,
this post is really interesting ! I'm happy to see this, because that's the only one about this subject :)

I tried to modified my default_relatedproducts.php but without succes...

What I would like to do is simply change
Code: [Select]
<?php echo $field->display ?>
by something more "modular" like this :

Code: [Select]
<h3><span itemprop="name"><?php echo JHTML::link ($field->link$field->product_name); ?></span></h3>
        <a title="<?php echo $field->link ?>" href="<?php echo $field->link?>" itemprop="url">
          <?php echo $field->images[0]->displayMediaThumb?>
        </a>

Does somebody know how to do this ? and is it possible to do ?

Related product are really important for SEO and by default they are unexploited... should be great to make this modification :)
Where is mum? She is in the bathroom. Where is dad? He is not at home. Why? I don’t know.

d0ublezer0

  • Jr. Member
  • **
  • Posts: 209
Re: How do I display a custom field in related product ?
« Reply #4 on: May 16, 2020, 17:20:00 pm »
I tried to modified my default_relatedproducts.php but without succes...
Because you need to modify sublayouts\related.php
I have same problem, but don't know, how to fix it

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1298
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: How do I display a custom field in related product ?
« Reply #5 on: May 16, 2020, 19:57:39 pm »
Really?

Quote
Because you need to modify sublayouts\related.php
I have same problem, but don't know, how to fix it

The reason is maybe you don't read this post correctly :D
I'm looking for VM j2.5 and vm 2.0.20b and sublayouts don't exist (only for VM3).

P.S.
For VM3 we don't use sublayouts related but Modul VirtueMart Products Extended.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates