News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Using Custom Field for URL, need raw field data?

Started by ukphotoguy, March 08, 2016, 00:21:28 AM

Previous topic - Next topic

ukphotoguy

I am using a custom productdetails override on VM 3.0.12.
My aim is to add into the product description a small image to allow users to link to the same product on Amazon. So in effect a unique link for each product that till form a link on the amazon "Buy on Amazon" logo image.
I can create the custom fields in the products using the string option and the simply display them where I want using a custom layout position and code like this:

<?php echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'amazon')); ?> 

where amazon is the layout position defined in the custom field. Shows me a neat text line but hard to strip and make into a link. But it proves I can do most of what I want. But of course the resulting output is formatted by the function to be inside of the <div class="product-field-display">.

Two Questions to the forum:
[1] I need a way to echo just the custom field in its raw form. Then I can add this code to form the link of an image. Something like <?php echo nl2br($this->product->product_s_desc); ?> but for a custom string field in a defined position.
[2] It it can be done I would also like the same thing but as an if statement so I can test there is something in that custom field to turn on or off the image I want to link.

Please try to help me out, I am relatively new to VM3 and documentation is hard to get.

GJC Web Design

there is various ways to do this but I assume the amazon stuff is always the same except part of the link?

so just have the change part as the custom field value and just test if set and insert

e.g. to show different badges I use for a custom field pos madein

if ( !empty($this->product->customfieldsSorted['madein']) ) {
  foreach($this->product->customfieldsSorted['madein'] as $theseones){
  ?>
<div class="gjcmadein">
<img src="/images/<?php echo $theseones->customfield_value.'_small.png' ?>" />
</div>
  <?php }  }
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ukphotoguy

Fantastic, not quite what I need but the $this->product->customfieldsSorted['madein'] is the key bit I needed.
I already have shown I can get the basic URL I need, so the rest is just coding.
My bad for not being clear, I needed the same image on each product with a different URL taken from the custom field. But I have the key I needed so thanks so much. I could not find such an example.

ukphotoguy

If it helps anybody, this is what I ended up with:
          <div class="buy-from">
                <h5><?php echo vmText::_ ('COM_VIRTUEMART_EBOOKLINKS') ?></h5>
                    <div>
                    <?php if ( !empty($this->product->customfieldsSorted['amazon']) ) {
                 foreach($this->product->customfieldsSorted['amazon'] as $theseones){?>                     
                    <a href="<?php echo $theseones->customfield_value ?>" target="_blank"><img src="images/stories/virtuemart/amazon-shop-link.png" alt="amazon-shop" /></a>
               <?php }}?>
                    <?php if ( !empty($this->product->customfieldsSorted['BNlink']) ) {
                 foreach($this->product->customfieldsSorted['BNlink'] as $theseones){?>                     
                    <a href="<?php echo $theseones->customfield_value ?>" target="_blank"><img src="images/stories/virtuemart/BN-shop-link.png" alt="B&N-shop" /></a>
               <?php }}?>                       
                    <?php if ( !empty($this->product->customfieldsSorted['iBook']) ) {
                 foreach($this->product->customfieldsSorted['iBook'] as $theseones){?>                     
                    <a href="<?php echo $theseones->customfield_value ?>" target="_blank"><img src="images/stories/virtuemart/ibook-shop-link.png" alt="iBook-shop" /></a>
               <?php }}?>                       
                    <?php if ( !empty($this->product->customfieldsSorted['kobo']) ) {
                 foreach($this->product->customfieldsSorted['kobo'] as $theseones){?>                     
                    <a href="<?php echo $theseones->customfield_value ?>" target="_blank"><img src="images/stories/virtuemart/kobo-shop-link.png" alt="kobo-shop" /></a>
               <?php }}?>                       
                    </div>
   </div>

Works fine and if there is a custom string fields in the layout positions (amazon, BNlink, iBook or kobo) that string becomes the image/logo link. Underpopulated logos/images do not show.