VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: Peter Möller on November 21, 2021, 22:13:24 PM

Title: GTIN layout question
Post by: Peter Möller on November 21, 2021, 22:13:24 PM
A Virtuemart Newbee question ;-)

I was searching in the forum howto output gtin, learned best way is a template override. Just gave it a try with product details.

It worked fine with this code:
<?php // Product GTIN/ISBN   ?>
    <?php 
if (!empty(
$this->product->product_gtin)) {
        echo 
'<div class="product-fields">';
echo '<div class="product-field product-field-type-S">';
echo '<span class="product-fields-title-wrapper"><span class="product-fields-title"><strong>ISBN</strong></span></span>';
echo '<div class="product-field-display">' .  $this->product->product_gtin '</div></div>';
        echo 
'</div>';
    }
?>

<?php // Product GTIN/ISBN END ?>


I wonder, if those class details could be handled by virtuemart itself and I just would call something like
shopFunctionsF::renderVmSubLayout()

Is there a standard layout or sublayout, that I may use?

Thx alot in advance for suggestions and hints :-)
Title: Re: GTIN layout question
Post by: pinochico on November 22, 2021, 01:20:44 AM
Why complicate and complicate code?

Of course you can use sublayout, but who would do it because of one unused field?

If anyone needed it, another field could have been long overdue and you would have 20 sublayouts at once - do you really want me not to know them either?
Title: Re: GTIN layout question
Post by: Peter Möller on November 22, 2021, 18:52:13 PM
@pinochico: Thx for your answer :-). I see the point and you are right . I should have asked more precisely.

Since I have a couple of custom fields, I would like the gtin layout to be the same like the custom fields. There is a existing call of type

echo shopFunctionsF::renderVmSubLayout('customfields',...);

Why would i like to do so?

If there is a change in the SubLayout of custom fields, then my private code from the first post would get different from the SubLayout.

Please take into account, that this is my first virtuemart project and I just try to do it in a clean way ;-)

[UPD] In other words: May I use a function, where I name the field, that I want to display and the format to use, for instance 'custom field'?
Title: Re: GTIN layout question
Post by: Studio 42 on November 24, 2021, 16:09:43 PM
renderVmSubLayout is to reuse the same code for different cases.
If it's only to render a single field, that's not appropriate.
Title: Re: GTIN layout question
Post by: GJC Web Design on November 24, 2021, 16:39:39 PM
QuoteIn other words: May I use a function, where I name the field, that I want to display and the format to use, for instance 'custom field'?

you could of course ignore the GTIN field and just make a text custom field named ISBN ... many ways to skin a cat ..  this is the advantage of VM .. so many ways to make it bespoke..  :)