Author Topic: "if" product havent children  (Read 1162 times)

marvays

  • Jr. Member
  • **
  • Posts: 307
    • richta.cz
  • Skype Name: marvays
"if" product havent children
« 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
Code: [Select]
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
Code: [Select]
if ($this->product->children != 0) {
  echo shopFunctionsF::renderVmSubLayout('snippets',array('product'=>$this->product, 'currency'=>$this->currency, 'showRating'=>$this->showRating));
}

but no work.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10404
  • VirtueMart Version: 3+
Re: "if" product havent children
« Reply #1 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;
}
}
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

marvays

  • Jr. Member
  • **
  • Posts: 307
    • richta.cz
  • Skype Name: marvays
Re: "if" product havent children
« Reply #2 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));
}

pinochico

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 384
    • MiniJoomla
  • VirtueMart Version: 3
Re: "if" product havent children
« Reply #3 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?
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

marvays

  • Jr. Member
  • **
  • Posts: 307
    • richta.cz
  • Skype Name: marvays
Re: "if" product havent children
« Reply #4 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.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10404
  • VirtueMart Version: 3+
Re: "if" product havent children
« Reply #5 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);

J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

marvays

  • Jr. Member
  • **
  • Posts: 307
    • richta.cz
  • Skype Name: marvays
Re: "if" product havent children
« Reply #6 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