News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Children product prices

Started by niosme, December 07, 2022, 13:12:55 PM

Previous topic - Next topic

niosme

After update i show a lot of children products without prices that was not inheriting the price of the parent product in fronshop.
I fixed that by giving an sql query and setted has_prices of all products to 1. Then this fixed the problem.

1.This is getting fixed by saving again the parent product. But when saving a children product the has_prices field turns back to 0 again

2.Yesterday when a product gone out of stock by an order i saw the has_prices value setted to 0 again.
So lets say i have a product with stock 1. The product order so a notify me button instead of add to cart shown app.Doesnt matter which one stockhandling chosen from the backend.
When the product ordered and gone the has_prices value turned again to 0 and the children products dont have prices.

By saving the parent product this fixed the problem again or by giving an sql query.

So in conclusion has prices is setting back to 0 for a reason after saving the children product which inherits the parent price, after ordering and completing an order and after the virtuemart update.
Fullstack Developer and Joomla Expert

Milbo

Did you try with vm4.0.8? because that should be fixed. At least in my current version
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

niosme

I have VirtueMart 4.0.8 10748 with Joomla 3.10.11. Also reinstalled the latest virtuemart package to ovewrite files in case of something gone wrong and problem still exists.
Fullstack Developer and Joomla Expert

Milbo

Yeh but I think I got the fix after vm4.0.8. A user suggested to use not isset, but !empty instead. So please give it a try. https://dev.virtuemart.net/projects/virtuemart/files
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

niosme

Its ok in 4.0.10.10767. Thanks a lot
Fullstack Developer and Joomla Expert

cdbaron88

Hello,
I am migrating from VirtueMart 3.8.8 10472. Joomla 3.10.11

Virtuemart 4.0.10 10767 works fine, but with version 4.0.12 10777 I have exactly the same problem again.

It happens to someone else?

niosme

Yes problem still exists. It is happening again with latest virtuemart version :/
Fullstack Developer and Joomla Expert

Milbo

Thank you. I think the solution is in product model, function getProduct

around line 1313 (woha, 1313 the doubled dammed line, lol). This

$child->selectedPrice!==null and $child->selectedPrice!==false


should be that

$child->selectedPrice!==null and $child->selectedPrice!=false


just one = too much. But  I really wonder. A selected Price can be the first price and has as number 0. So the if should check if there is a price. So 0 is valid.
From https://www.php.net/manual/en/language.operators.comparison.php

$a == $b   Equal   true if $a is equal to $b after type juggling.
$a === $b   Identical   true if $a is equal to $b, and they are of the same type.
$a != $b   Not equal   true if $a is not equal to $b after type juggling.
$a <> $b   Not equal   true if $a is not equal to $b after type juggling.
$a !== $b   Not identical   true if $a is not equal to $b, or they are not of the same type.

"$a !== $b   Not identical   true if $a is not equal to $b, or they are not of the same type." So I thought, that will not react to 0 (0 can be counted as false, but is not of the same type as false)

But the right solution (at least the one that works is "$a != $b   Not equal   true if $a is not equal to $b after type juggling". But with type jugglin false=0 ???

Maybe someone can enlighten me.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

niosme

#8
The question is really what selectedPrice represents. I see in the getProductSingle function in product model that selectedPrice is setted as 0 by default and what actually that stands for?
Maybe you forgot somewhere to set the selectedPrice value to be setted to false and is remaing zero ( looks like this happens inside the getRawProductPrices).

A solution that worked for me is
from line 1311 in product admin model

$withPrice = true;
if(!empty($child->allPrices)){
$withPrice = false;
//vmdebug('Child has price, load parent without price');
}


Also this solution is working because in function getRawProductPrices which you call inside the getProductSingle you set the has_prices ( 0 or 1 ) value taking account of allPrices if empty or not of the current product so this is working also

$withPrice = true;
if(!empty($child->has_prices)){
$withPrice = false;
//vmdebug('Child has price, load parent without price');
}


some code from getRawProductPrices

public function getRawProductPrices(&$product,$quantity,$virtuemart_shoppergroup_ids,$front,$withParent=0, $optimised = true){

$productId = $product->virtuemart_product_id===0? $this->_id:$product->virtuemart_product_id;

if(!$optimised or !isset($product->has_prices) or $product->has_prices){
$product->allPrices = $this->loadProductPrices($productId,$virtuemart_shoppergroup_ids,$front);
if(empty($product->allPrices)){
$product->has_prices = 0;
} else {
$product->has_prices = 1;
}

} else {
//$product->has_prices = 0;
$product->allPrices = false;
$product->selectedPrice = false;
}


By the way the 0 or false value can be checked with is_numeric function which checks if value or a string is a number like integer or float and we can stop there cause is_numeric will not pass the if statement if a null or false variable is presented. Alternative we can check for a boolean with is_bool($child->selectedPrice); But as i show in vmdebug which i printed the selectedPrice always remains 0. Maybe  and idea should be to set another by default variable to the selectedPrice should be setted like false at the start or null by default and the turn it to a valid one or zero.
Fullstack Developer and Joomla Expert