VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: kory27 on July 19, 2012, 18:06:30 PM

Title: Populate $productarray with custom fields
Post by: kory27 on July 19, 2012, 18:06:30 PM
Hello,

I am really trying to use remote images for my thumbnail on the category page and full size image on the product detail page.  VM 2 doesn't support it, which sucks.

I understand the views and have setup my template override structure.  I understand that $this will return the variables on the current page and that using, for instance, $product will return variables returned with the $productarray on the category page.

I have 2 custom fields:

Image_small  virtuemart_custom_id=3
Image_large  virtuemart_custom_id=4

I have 2 questions:

1.  Can I change the custom field code to return only the custom field ID I want to place? If I can do that, I should be able to make it display the image, not just the url.  They are currently showing in the custom field position on http://www.urbanposters.com/index.php/shop/art/fine-art/fine-art-views/fine-art-by-artist/modern-masters/marilyn-1967-on-red-detail (http://www.urbanposters.com/index.php/shop/art/fine-art/fine-art-views/fine-art-by-artist/modern-masters/marilyn-1967-on-red-detail)

2.  Where can I change the variables returned by $productarray.  I think this would be the product Model, but I am pretty new to php. 

In summary, does anyone have hints, ideas, or strategies to how in the end I can get these stored url fields to show an image on my pages?

Any code snippets are appreciated.

Thanks so much!

Kory

Title: Re: Populate $productarray with custom fields
Post by: ivus on July 20, 2012, 08:18:45 AM
Hi kory27,

Yeah simple. I'm going to assume that you know enough about PHP to be able to figure this out...

On the CATERORY page, place this piece of code within your products loop


 
  foreach ($product->customfields as $customfields) :
  if( $customfields->virtuemart_custom_id == XXX) :
echo $customfields->display;
endif;
  endforeach;
 


On the PRODUCTS DETAILS page, place this piece of code where you want to display you image


 
  foreach ($this->product->customfieldsSorted['normal'] as $customfields) :
  if( $customfields->virtuemart_custom_id == XXX) :
echo $customfields->display;
endif;
  endforeach;
 


You will need to substitute the XXX with the ID of the custom field you're looking for.

I hope this helps.
Title: Re: Populate $productarray with custom fields
Post by: kory27 on July 20, 2012, 17:03:09 PM
Thanks Ivus!

That lead me to this, which worked.

    <?php foreach ($this->product->customfieldsSorted['normal'] as $customfields) :if( $customfields->virtuemart_custom_id == 4) : ?><img src="<?php echo $customfields->display?>"/><?php endif; endforeach; ?>


Hope this helps someone else with a workaround to remotely hosting images or positioning custom fields on a template.

Kory

www.urbanposters.com (http://www.urbanposters.com)
Title: Re: Populate $productarray with custom fields
Post by: kory27 on July 20, 2012, 18:01:16 PM
Oh yeah, for the category page I used the following code.

    <?php foreach ($product->customfields as $customfields) : if( $customfields->virtuemart_custom_id == 3) : ?><img src="<?php echo $customfields->display?>"/><?php endif;endforeach; ?>


Thanks again.

Kory
Title: Re: Populate $productarray with custom fields
Post by: ivus on July 20, 2012, 18:21:55 PM
Hi kory27

I'm glad you managed to work it out, but for anyone else out there who want to extend Vm... the key is to use the following:

echo '<pre>'; print($this); echo '</pre>';

that'll give you every variable on the page you can use.

Good luck.