After updating to the latest version the customfields of the first products are showing but after continue shopping and ordering a second (different version of the same product (child) the customfields of that second product are not showed in the cart.
What is happening?
Joomla! 3.10.6 Stable
VirtueMart 4.0.0 10645
Try switching to any other template. It can be a template related issue.
The cart tempate or the productdetails template ?
Try Protostar or VMBeez3 to rule out all overrides first.
I disabled our template and activated beez3.
That gives no changes in beez3 happens the same.
Hello
I think the problem is in ?administrator/com_virtuemart/models/customfield.php
After i replaced it with a previus version the customfields are showed in the cart.
Please check the file for a bug.
there is a 4.0.2 http://dev.virtuemart.net/attachments/download/1314/com_virtuemart.4.0.2.10661.zip - maybe fixed?
Thanks for the file.
I have tested it and the error is still there.
So the error is in /adminsistrator/models/customfields.php
Thank you for your report, I am going to check it
I found this issue in the log.
Perhaps the reasen for the error ?
2022-06-22 09:58:30 ERROR vmError: vmTable Error, $obj->{$xParams} is not a string <pre>#0 vmError() called at [/home/jojoknit/domains/dasle.nl/public_html/administrator/components/com_virtuemart/helpers/vmtable.php:606]
</pre>
VM 4.0.12 I have the same behaviour
Custom fields in cart are displayed only on the first product
Al subsequent products have no custom fields shown.
I have no error in the logs
The template calls:
$this->customfieldsModel->CustomsFieldCartDisplay ($prow);
to render custom fields
Looking at the model file it says:
static public function CustomsFieldCartDisplay ($product) {
return self::displayProductCustomfieldSelected ($product, '<div class="vm-customfield-cart">', 'plgVmOnViewCart');
}
So does it loop in multiple instances of products?
Hi everyone
I spent some time fixing this issue abd have discovered that the problem arises since the multiple ids searching for custom fields values in models/customfields.php
The fix is easy
Original code around line 110-117 in administrator/components/com/virtuemart/models/customfields.php in function
function getCustomEmbeddedProductCustomFields($productIds, $virtuemart_custom_id = 0, $cartattribute = -1, $forcefront = FALSE){
...
We have to prevent clearing the value of the parent product to be searched:
foreach($productIds as $k=>$productId){
106 $hkey = (int)$productId.'_'.$virtuemart_custom_id;//.'_'.$cartattribute;
107 if (array_key_exists ($hkey, $_customFieldByProductId)) {
108
109 //Must be cloned!
110 foreach($_customFieldByProductId[$hkey] as $ccust){
111 if(!empty($ccust)){
112 $productCustomsCached[] = clone($ccust);
113 }
114
115 }
116 unset($productIds[$k]);
117 }
118 }
commenting out the "unset" fixes the problem, so the fixed code is as follows:
foreach($productIds as $k=>$productId){
106 $hkey = (int)$productId.'_'.$virtuemart_custom_id;//.'_'.$cartattribute;
107 if (array_key_exists ($hkey, $_customFieldByProductId)) {
108
109 //Must be cloned!
110 foreach($_customFieldByProductId[$hkey] as $ccust){
111 if(!empty($ccust)){
112 $productCustomsCached[] = clone($ccust);
113 }
114
115 }
116 // unset($productIds[$k]);
117 }
118 }
@Milbo could you please check this fix and import it into the source of next release?
Thank you
Thanks for sharing!
:)
Quote from: Alexb65 on January 30, 2023, 10:31:57 AM
Hi everyone
I spent some time fixing this issue abd have discovered that the problem arises since the multiple ids searching for custom fields values in models/customfields.php
The fix is easy
@Alexb65
Hi our developper delete all from this and function too :)
QuoteVáclav: It's great to lighten the loading, but then if it doesn't load customfields at all, the modification sucks
/*
foreach($productIds as $k=>$productId){
$hkey = (int)$productId.'_'.$virtuemart_custom_id;//.'_'.$cartattribute;
if (array_key_exists ($hkey, $_customFieldByProductId)) {
//Must be cloned!
foreach($_customFieldByProductId[$hkey] as $ccust){
if(!empty($ccust)){
$productCustomsCached[] = clone($ccust);
}
}
unset($productIds[$k]);
}
}
*/
I don't think what is better
@Max?
Your developer just removed the whole cache. To remove the unset function was the right grib. But it is also missing another case. The fixed files are here
https://dev.virtuemart.net/projects/virtuemart/repository/revisions/10801/diff/trunk/virtuemart/administrator/components/com_virtuemart/models/customfields.php
Hi Milbo,
J! 3.10.11 / VM 4.0.12 10777
By removing the unset function I got multiplications of customfields by each child product with the same parent, both in category and in product-details view.
(https://i.ibb.co/3cq5gpX/Screenshot230806.png)
How to fix this?
BTW dev.virtuemart.net is unreachable by me since yesterday.
Please read the news https://virtuemart.net/news/516-virtuemart-4-2-including-new-paypal-checkout :-)