Change the Custom Fields for Child products

Support desk for Villa Belluci Joomla Hotel Template
GK User
Tue Feb 07, 2017 5:25 pm
Image

Hello all.

I have a site at ta-panda.gr and it lists ALL prices in a Without tax form. Now that works on every page except the drop down menu of children products. That one seems to be created seperately and always displays the full (with tax) price. Another issue is that the site is configured to show 3 decimal points and the dropdown displays only two.

screenshot.jpg


So I want to find in which php the drop down menu for selectind the children products is created and change the prices there to make it consistent with the rest of the site. Does anyone know? I tried to look it up using the default product details php but I found nothing.

Thankl you.
User avatar
Senior Boarder

teitbite
Mon Feb 13, 2017 9:23 am
Hi

This question should be asked to Virtuemart support, I'm not an expert of that component, but my guess is that the code building custom fields is in /administrator/components/com_virtuemart/models/customfields.php
User avatar
Moderator

GK User
Mon Feb 13, 2017 10:03 am
Well I have already an open topic in virtuemart forums asking that particular thing in a relevant question thread.
However I haven't got a reply on that one yet. So your reply seems very helpful
The path you refer to only renders the backend custom fields though. However it was very useful to me... I poked around and found out that the php that renders the customfields in the frontend is located at
Code: Select all
/components/com_virtuemart/sublayouts/customfield.php

Carefull there is also a customfields.php that actually hides or displays a custom field.

I will create an override and see how it goes.
Thanks
User avatar
Senior Boarder

GK User
Mon Feb 13, 2017 10:04 am
Well I have already an open topic in virtuemart forums asking that particular thing in a relevant question thread.
However I haven't got a reply on that one yet. So your reply seems very helpful
The path you refer to only renders the backend custom fields though. However it was very useful to me... I poked around and found out that the php that renders the customfields in the frontend is located at
Code: Select all
/components/com_virtuemart/sublayouts/customfield.php

Carefull there is also a customfields.php that actually hides or displays a custom field.

I will create an override and see how it goes.
Thanks
User avatar
Senior Boarder

GK User
Mon Feb 13, 2017 5:51 pm
Ok as I said your help was valuable. It actually set me on the right track.

So the file that should be edited is indeed the one I mentioned in my previous post
Code: Select all
/components/com_virtuemart/sublayouts/customfield.php

Best way to go is to create a template override so you could copy the original file to
Code: Select all
/templates/[your template]/html/com_virtuemart/sublayouts/customfield.php


Then you may go to the line 310 (give or take a few lines depending on the virtuemart version you use) and look for the if clause that is:
Code: Select all
if($customfield->wPrice){

There is the generation of the customfield's price inside the parenthesis. I changed the whole if clause and added a bunch of things:
Code: Select all
if($customfield->wPrice){
                        //$product = $productModel->getProductSingle((int)$child['virtuemart_product_id'],false);
                        $productPrices = $calculator->getProductPrices ($productChild);
                                if($product->prices['discountedPriceWithoutTax'] != $productPrices['discountedPriceWithoutTax']){
                                    $priceStr =  ' (' . $currency->priceDisplay ($productPrices['discountedPriceWithoutTax']) . ')';//Normally here it's salesPrice (including VAT) but we need the price without VAT. However if there is a discount we should display that price. Instead of priceWithoutTax which would not work properly displaying the price without VAT, for discounted products I used discountedPriceWithoutTax which is equal to priceWithoutTax when there is no discount applied.
                                }
                                else{
                                    $priceStr = ''; //I made this if clause so that if the child product price is different from the parent product, only then I will see a price in a parenthesis in the dropdpown. Just a bit of impressive code work on my part.
                                }
                        
                     }

I've included all my original comments to make the code clearer.
So what I did was to add a second if clause to check whether the child product has a different price that the one that is being displayed. Only when there is a price difference should the dropdown display prices in parentheses.
I also used the DiscountedPriceWithoutVAT global variable, to make the comparisons and price display cause I needed to show wholesale prices. However you may use any price that is convenient to you.

Also this way you get the discounted prices displayed on products on sale.

Hope that was helpful.
User avatar
Senior Boarder

teitbite
Sun Feb 19, 2017 8:06 pm
Hi

That's a great explanation. Thank You for searing that. I'm sure someone will benefit from it.
User avatar
Moderator


cron
Remember me
Register New Account
If you are old Gavick user, click HERE for steps to retrieve your account.