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

Populate $productarray with custom fields

Started by kory27, July 19, 2012, 18:06:30 PM

Previous topic - Next topic

kory27

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

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


ivus

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.

kory27

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

kory27

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

ivus

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.