VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: marvays on December 16, 2019, 15:09:47 PM

Title: "if" product havent children
Post by: marvays on December 16, 2019, 15:09:47 PM
Hi again.
I try change template. I need hide div#productPrice for parent product with with children.

In code i see
if ($this->product->prices['salesPrice'] > 0) {
  echo shopFunctionsF::renderVmSubLayout('snippets',array('product'=>$this->product, 'currency'=>$this->currency, 'showRating'=>$this->showRating));
}


How i can change "if" to "when product have children"?

I try

if ($this->product->children != 0) {
  echo shopFunctionsF::renderVmSubLayout('snippets',array('product'=>$this->product, 'currency'=>$this->currency, 'showRating'=>$this->showRating));
}


but no work.
Title: Re: "if" product havent children
Post by: PRO on December 16, 2019, 19:36:42 PM
function hasChilds($pid){
$productModel = VmModel::getModel('product');
$ids = $productModel->getProductChildIds($pid);
if (!empty($ids)){
return 1;
}
}

if (hasChilds($this->product->virtuemart_product_id)==1){
  echo shopFunctionsF::renderVmSubLayout('snippets',array('product'=>$this->product, 'currency'=>$this->currency, 'showRating'=>$this->showRating));
}


///////////////////////////////

&&& for anyone that wants to check if a product is a child

function hasParent($pid){
$productModel = VmModel::getModel('product');
$id = $productModel->getProductParentId($pid);
if (!empty($id)){
return 1;
}
}
Title: Re: "if" product havent children
Post by: marvays on December 17, 2019, 03:52:23 AM
Thank you very much for your help.
In my case . . . If I want to keep the price with my parents and only show it to their offspring, this works:

function hasChilds($pid){
$productModel = VmModel::getModel('product');
$ids = $productModel->getProductChildIds($pid);
if (!empty($ids)){
return 1;
}
}

if (hasChilds($this->product->virtuemart_product_id)!=1){
  echo shopFunctionsF::renderVmSubLayout('prices',array('product'=>$this->product,'currency'=>$this->currency));
}
Title: Re: "if" product havent children
Post by: pinochico on December 17, 2019, 06:38:15 AM
Our customers want to see the price immediately when the product (== parent) is displayed on the category or detail and not be obliged to select the child to display the price.
As soon as I force them to choose a child, they leave because they don't care.

You are also breaking the details of the product and Google will mark the parent page as faulty and will not include it in the index. Is it really the right way?
Title: Re: "if" product havent children
Post by: marvays on December 17, 2019, 10:34:23 AM
faulty because the site has no selling price? Ideally, I would only index children. The parent is only a signpost.
Title: Re: "if" product havent children
Post by: PRO on December 17, 2019, 14:41:58 PM
I do a price table on 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);

Title: Re: "if" product havent children
Post by: marvays on December 18, 2019, 02:48:56 AM
Nice, this work.
But, where I can change prize. I see "26230.0049 - 27980.0037", and need "26 230,- Kč - 27 980,- Kč"
https://novy.azttrade.eu/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=1538&virtuemart_category_id=23&lang=cs
Title: Re: "if" product havent children
Post by: razor7 on May 19, 2021, 20:20:01 PM
Quote from: PRO on December 16, 2019, 19:36:42 PM
function hasChilds($pid){
$productModel = VmModel::getModel('product');
$ids = $productModel->getProductChildIds($pid);
if (!empty($ids)){
return 1;
}
}

if (hasChilds($this->product->virtuemart_product_id)==1){
  echo shopFunctionsF::renderVmSubLayout('snippets',array('product'=>$this->product, 'currency'=>$this->currency, 'showRating'=>$this->showRating));
}


///////////////////////////////

&&& for anyone that wants to check if a product is a child

function hasParent($pid){
$productModel = VmModel::getModel('product');
$id = $productModel->getProductParentId($pid);
if (!empty($id)){
return 1;
}
}

Cool! that's what I was looking for! thanks!