Hello,
I have parent products with child products. Parent products have only descriptions (without prices), but child products have own prices. Now is shown only button "Ask for price" in product detail page and price is shown only when customer select child product. But I need show the lowest price form child products in parent products or their prices range (price from - to). Is it possible? Thank you
On 1 of my sites I use this code to display a price range for parent.
function price_table($pid){
$productModel = VmModel::getModel('product');
$ids = $productModel->getProductChildIds($pid);
$prods = $productModel->getProducts($ids);
$customfieldsModel = VmModel::getModel ('Customfields');
$prods->customfields = $customfieldsModel->getCustomEmbeddedProductCustomFields ($product->allIds,0,-1, true);
$html='';
if (!empty($prods)){
$prices=Array();
foreach ($prods as $p){
$prices[]=$p->prices['salesPrice'];
}
if (count($prices>1)){
$html.='<p class="redtext bold">Price from $'.min($prices).' - $'.max($prices).'</p>';
$html.='<p class="greentext">Choose Options to See Price</p>';
}
}
echo $html;
}
echo price_table($this->product->virtuemart_product_id);
echo shopFunctionsF::renderVmSubLayout('prices',array('product'=>$this->product,'currency'=>$this->currency));
You can see the display here.
https://www.glowgizmo.com/bars/fb-size
Thank you very much :)
Hello,
I have issue with this code. when I copy this code to prices.php in my template, everything is OK in product. But in category view (there I have more then one product without price of parent products), scprit is stopped and page is not loaded correctly.
In attachments I send screens of correct view in product detail and problem in category view, where is more than one product where parent products don't have price. If is only one product without parent product price in category view, everithing is ok.
My code is:
function price_table($pid){
$productModel = VmModel::getModel('product');
$ids = $productModel->getProductChildIds($pid);
$prods = $productModel->getProducts($ids);
$customfieldsModel = VmModel::getModel ('Customfields');
$prods->customfields = $customfieldsModel->getCustomEmbeddedProductCustomFields ($product->allIds,0,-1, true);
$html='';
if (!empty($prods)){
$prices=Array();
foreach ($prods as $p){
$prices[]=$p->prices['salesPrice'];
}
if (count($prices>1)){
$mincena = min($prices);
$maxcena = max($prices);
$mincena = number_format($mincena, 2, ',', ' ');;
$maxcena = number_format($maxcena, 2, ',', ' ');;
if (min($prices) == max($prices) || ($mincena == "0,00") ) {
$html.='<div class="PricesalesPrice vm-display vm-price-value" data-mh="vm-product-price">
<div class="product-price">
<div class="vm-basic-prices clearfix"><div class="PricesalesPrice vm-display vm-price-value"><span class="vm-price-desc">Predajná cena</span><span class="PricesalesPrice">'.$maxcena.' €</span></div></div></div> </div>';
}
else {
$html.='<div class="PricesalesPrice vm-display vm-price-value" data-mh="vm-product-price">
<div class="product-price">
<div class="vm-basic-prices clearfix"><div class="PricesalesPrice vm-display vm-price-value"><span class="vm-price-desc">Predajná cena</span><span class="PricesalesPrice">od '.$mincena.' €</br> do '.$maxcena.' €</span></div></div></div> </div>';
}
}
}
echo $html;
}
echo price_table($product->virtuemart_product_id);
Certainly, it's because you redeclare function price_table
This is not possible in PHP.
Enable PHP debug so you see why you have an error
Thank you, I copied function() to router.php and now, it is OK.
Why do you think, then file router.php is the right place?
Where is right place for declarate function()?
For product details do it at the top of
default.php
or make a functions.php file in the same folder, and do
include("functions.php");
Then, you will also need to add the function for category view
top of products.php
FOR category view.
You need to add it to top of products.php
ofcourse if you setup your own library, you could use the function anywhere throughout Joomla
There is also a possibility to do that without code changes. Settings for the parent product would be:
1. Delete the Base price
2. In the Custom Fields tab uncheck 'Display parent as option' and 'Parent orderable'.
3. In the VM Configuration > Pricing tab > Price Configuration uncheck 'Show call for price, when the price is empty'.
4. Save the product settings.
Quote from: PRO on February 03, 2020, 15:52:41 PM
For product details do it at the top of
default.php
or make a functions.php file in the same folder, and do
include("functions.php");
Then, you will also need to add the function for category view
top of products.php
FOR category view.
You need to add it to top of products.php
ofcourse if you setup your own library, you could use the function anywhere throughout Joomla
Hello, but if I want use include(), I need copy this function to lot of files (everywhere where is price of product displayed). Is it possible paste include() only in one php file for use at all VM web? Thank you
Quote from: jarlu on February 04, 2020, 19:29:13 PM
Hello, but if I want use include(), I need copy this function to lot of files (everywhere where is price of product displayed). Is it possible paste include() only in one php file for use at all VM web? Thank you
No,
thats why I use a library.
----
The best way is to use a system plugin.
Then you add all function needed in the class
Eg
static class plgsystemcustom {
static function price_table($pid){
//mycode
}
static function otherFc(){
//mycode
}
}
Then you use plgsystemcustom::price_table();
or plgsystemcustom::otherFc();
Do you have some manual for making very simple system plugin? Because I don't' have any experience.
some more information here
http://forum.virtuemart.net/index.php?topic=141917.0
https://docs.joomla.org/Using_own_library_in_your_extensions
See for eg JOOMLAROOT/plugins/system/log/
the xml is the declaration of the plugin
you have a naming convention for this exemple class PlgSystemLog because it's a "system" plugin in folder "log"
You don't need system plugin, it is only one of possibility, only one way, which uses different programmers.
You need to put the custom function on right place, that is the right way.
(A lot of system plugins only slow down the website).