VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: TurnTex on January 06, 2016, 01:07:23 AM

Title: Different descriptions for same product depending on what catagory is viewed?
Post by: TurnTex on January 06, 2016, 01:07:23 AM
First, to get the software specifics out there.  I am running J! 3.4.8 and VM 3.0.13 using Virtueplanet Merchant Template.  My php version is 5.6.16.

I building a new website for myself to replace an aging J1.5.26 VM1.1.9 site.  On the new site, I have a product that is applicable to 2 different categories so I have them both assigned in the product categories section.  The problem is even though it is the same product and sku, it is used differently for category A than for category B.  Is it possible to have a description displayed depending on what category the customer is viewing?  In other words, if the customer is viewing category A and clicks on this product, I would like the description to be applicable for using it with other products in Category A.  If they view the product through Category B, I want a different description that is applicable to Category B products.  I really do not want to have 2 different products/skus for the same product because it will make inventory management difficult.

Does anyone have any suggestions to do this?  Thank you in advance for any help you can provide.  I am not a coder so I can't custom code something and was hoping there might be an option I am not thinking of "out of the box".
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: GJC Web Design on January 06, 2016, 01:53:07 AM
Even if u use another field for prod desc 2 or a custom field you still have to switch which one to use depending on the cat -
and for that IMHO you need to have some code in the template .. detect the catid.. show the correct desc
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: TurnTex on January 06, 2016, 02:32:44 AM
Unfortunately that is over my head, GJC.  Maybe I should contact the template creator to see if he can help me with it?
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: TurnTex on January 06, 2016, 02:33:11 AM
BTW, THANK YOU for your reply, GJC!
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: GJC Web Design on January 06, 2016, 10:29:12 AM
Once u sort how you will fill-in two descriptions in the admin (custom field or use another field like Internal note) you just need the logic in the template to switch them according to the cat id
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: Studio 42 on January 06, 2016, 16:25:06 PM
Another solution, is to use 2 layout file for product desc, and associate the layout for the product.
See in categorie edition form : Default Product Details Page
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: PRO on January 06, 2016, 23:35:11 PM

I just did a little with this,

I created a customfield "textarea"
Named it   cat92   (92 for the category id)
Then in my product template
added this

   <?php   
          if (!empty($this->product->customfieldsSorted[cat92]))   {
          $jinput = JFactory::getApplication()->input;
        $ccat = $jinput->getInt('virtuemart_category_id', '0');
   foreach ($this->product->customfieldsSorted[cat92] as $field) {
   $ccheck  = str_replace( 'cat', '', $field->custom_title);
   if ($ccheck==$ccat)   {
   $this->product->product_desc=$field->customfield_value;}
   }
       } ?>

This will display the "textarea" field when the product is in category id 92.

of course this could easily be scale able with a little more logic, technically the code would only work on 1 category per custom field.
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: Studio 42 on January 07, 2016, 00:43:57 AM
WHy changing the code when you have native code to do this ?
Read my answer.
Copy the dafault layout and remove product desc or any field you need to remove.
And Add in this copy of default to render customfield with position YOURPOSITION
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'YOURPOSITION'));
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: TurnTex on January 07, 2016, 01:55:08 AM
Thank you all for the replies.  Unfortunately, I am not a coder and know just enough about PHP to make changes when I am told what to change or add and where.  If anyone is willing to give me a little more in depth details on how to implement this, it would be greatly appreciated.  If not, I completely understand!

One thing that I wonder about...I am using Virtueplanet Merchant template.  The template creates a tab for the description as well as other custom fields that are set a certain way.  How would either of the options mentioned be affected by that?  Here is a screen shot of what I mean.  If anyone wants to see the site www.pensandbeyond.com.  This is still in development and not publicized yet.  It is on a shared hosting account I use for development.  Once I am done with it, I will move it back to my VPS to replace the old site.

Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: GJC Web Design on January 07, 2016, 02:18:40 AM
you would need to make the changes within the desc tab area...
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: PRO on January 07, 2016, 13:40:41 PM
Quote from: TurnTex on January 07, 2016, 01:55:08 AM
The template creates a tab for the description as well as other custom fields that are set a certain way.  How would either of the options mentioned be affected by that? 


the code I posted above actually CHANGES the product description
so, no layout changes are made.
It simply switches the product description for the customfield text
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: GJC Web Design on January 07, 2016, 14:00:39 PM
Quoteyou would need to make the changes within the desc tab area...

of course dependent on what solution you go for
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: TurnTex on January 13, 2016, 07:02:17 AM
Folks, than you so much for your help!  I was able to get it implemented and it is fully functional!  I have to give a huge Thank You to Jumbo with Virtueplanet on this.  I am using his Merchant template and he is one of the absolute best template providers I have worked with.  He is willing to help out and did some custom coding for me to implement this.  After posting here, I decided to post on his support forum like I have many times asking if this could be done.  He said it was not possible so I directed him to this thread to get some of your ideas.  He went to work and implemented it for me as I do not have the technical abilities to do this.  All if this was done without him asking for a penny!  (of course I sent him some money anway!).

So, thank you all for the ideas and inspiration to help me get this done and for providing some ideas for Jumbo to work with!  I sincerely appreciate it!
Title: Re: Different descriptions for same product depending on what catagory is viewed?
Post by: GJC Web Design on January 13, 2016, 12:55:00 PM
Nice to hear and see feedback about users experiences with templaters and coders .. should be encouraged..   :)