Hello all,
I have a parent product and multiple child products. Some child products have higher prices than the other child products. In the product list view, I have the parent shown only, so users will have to click on the parent and then select child products via custom fields.
In the product list, the parent product (not orderable) currently shows the lowest price of its children which is correct. I want to let my customers know that this price is the lowest price of the children by adding a "From:" tag before this final price, e.g. "From: $300".
If I set a language override to change the "Sales price" to "From:" it would affect even the solo products with no children. Is there a way I can add the "From" to only products that have children?
You'd have to create a custom prices.php sublayout and modify it. How to use sublayouts http://docs.virtuemart.net/tutorials/templating-layouts/199-sublayouts.html
The logic would be to check whether the product has children and add "From" if it does.
What we do is we do not set price in the parent product and the childs show the price of each child in the dropdown.
But I understand your request, would be cool to have a "from" or the parent to show the lowest price from the childs.
Hi,
I have do it simpler,on checking the array product->customfields["addtocart"] position, you can know, if you have cart options and change the label
Quote from: brooklynbase on February 22, 2016, 17:56:46 PM
In the product list, the parent product (not orderable) currently shows the lowest price of its children which is correct. I want to let my customers know that this price is the lowest price of the children by adding a "From:" tag before this final price, e.g. "From: $300".
Hello I forgot to ask you how you make this? I mean you manually write the lowest price in the parent or you have it automatically to show the lowest price of the childs cause that would be great.
Quote from: Studio 42 on March 15, 2016, 09:43:28 AM
Hi,
I have do it simpler,on checking the array product->customfields["addtocart"] position, you can know, if you have cart options and change the label
Sounds interesting, I have not done this in VM3 yet. So far I only check if the product has children and this I use for not showing the stock, because the stock for the parent does not give any real info. If it is a Child I show the correct child stock instead of the parents stock which seems to be the default. Deciding if the product is a parent can of course also be used to display the label From. I will have a go at this. Would be nice to have a good method for these repeating tasks.
If You have a better idea please share.
Jörgen @ Kreativ Fotografi
Hi Jorgen,
I can perhaps add it to my generic child variant plugin, all child are loaded in the same loop, so it's possible to compare the price and modify the main product price and set a value in parent product eg. childPrice.
But in all case you have at end to overide the price display and add label by condition and don't use core jText display in this case.
The code should be something so
replace
echo $currency->createPriceDiv ('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $product->prices);
with
if (isset($product->childPrice)) $label = 'COM_VIRTUEMART_PRODUCT_SALESPRICE';
else $label = 'COM_VIRTUEMART_CHILD_PRODUCT_SALESPRICE';
echo $currency->createPriceDiv ('salesPrice', $label, $product->prices);
Hello Patrick
I get the idea.
But if I don´t use the plugin, it would give the same effekt if I just check if it has children, right? The parents price must of course be set to the lowest child price before this.
regards
Jörgen @ Kreativ Fotografi
Perhaps you can return right price from customfields sublayout, but i think you need perhaps to modify core file for this, i don't have check, because i prefer use my plugin, it's simpler for me because core file do not permit to have conditional layout render.
Quote from: brooklynbase on February 22, 2016, 17:56:46 PM
In the product list, the parent product (not orderable)
<?php if (!$product->orderable){echo'From ';} ?>
Hello Pro
Great idea, thank You. Now I just have to see if the product has a parent id, in that case it is a child product. This makes me take out a unneccesary query from my templates :)
regards
Jörgen @ Kreativ Fotografi
In all case, Pro solution do not solve price from child, but can be a partial solution, but he's code give php error warning in all case.
Quote from: Studio 42 on May 11, 2016, 14:26:50 PM
but he's code give php error warning in all case.
<?php if ($product->orderable !=1){echo 'From ';} ?>
@Jorgen this would be a life saver if you can get this to work.
@Uglystick
I have the skeleton working for this right now. I use it to hide the stock and SKU for a parent item. I could publish my code, but I don´t really have the time to do it this week. PM me if I forget to do it next week.
Jörgen @ Kreativ Fotografi
Has anyone got this working, I have an clothing outlet site about to go live and child products prices vary.
So would love the Parent Product page to have From....
Overide your template file for product prices (if you use standard way, this is in sublayouts)
The simplest way, but i don't know if this work in last releases.
if (!empty($this->product->customsChilds))
echo $currency->createPriceDiv ('salesPrice', 'FROM', $product->prices);
else
echo $currency->createPriceDiv ('salesPrice', 'COM_VIRTUEMART_PRODUCT_SALESPRICE', $product->prices);
Else you have to check all customfield to know if you have child relations (type "C" and type="A") or use a DB query
see > \components\com_virtuemart\sublayouts\customfield.php