VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: johnknit on May 25, 2022, 08:38:00 AM

Title: customfields not showing in cart
Post by: johnknit on May 25, 2022, 08:38:00 AM
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
Title: Re: customfields not showing in cart
Post by: Jumbo! on May 25, 2022, 09:25:47 AM
Try switching to any other template. It can be a template related issue.
Title: Re: customfields not showing in cart
Post by: johnknit on May 25, 2022, 10:31:49 AM
The cart tempate or the productdetails template ?
Title: Re: customfields not showing in cart
Post by: jenkinhill on May 25, 2022, 11:00:27 AM
Try Protostar or VMBeez3 to rule out all overrides first.
Title: Re: customfields not showing in cart
Post by: johnknit on May 25, 2022, 12:35:39 PM
I disabled our template and activated beez3.
That gives no changes in beez3 happens the same.
Title: Re: customfields not showing in cart
Post by: johnknit on May 30, 2022, 16:51:01 PM
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.
Title: Re: customfields not showing in cart
Post by: GJC Web Design on May 30, 2022, 21:58:03 PM
there is a 4.0.2 http://dev.virtuemart.net/attachments/download/1314/com_virtuemart.4.0.2.10661.zip - maybe fixed?
Title: Re: customfields not showing in cart
Post by: johnknit on June 01, 2022, 15:03:26 PM
Thanks for the file.
I have tested it and the error is still there.
So the error is in /adminsistrator/models/customfields.php
Title: Re: customfields not showing in cart
Post by: Milbo on June 16, 2022, 23:48:07 PM
Thank you for your report, I am going to check it
Title: Re: customfields not showing in cart
Post by: johnknit on June 22, 2022, 13:00:45 PM
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>
Title: Re: customfields not showing in cart
Post by: Alexb65 on January 24, 2023, 12:03:37 PM
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?
Title: Re: customfields not showing in cart
Post by: 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

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                 }

Title: Re: customfields not showing in cart
Post by: Alexb65 on January 30, 2023, 10:51:36 AM
@Milbo could you please check this fix and import it into the source of next release?

Thank you
Title: Re: customfields not showing in cart
Post by: gap on March 13, 2023, 18:55:37 PM
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
Title: Re: customfields not showing in cart
Post by: pinochico on March 13, 2023, 23:22:15 PM
@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?

Title: Re: customfields not showing in cart
Post by: Milbo on March 20, 2023, 12:19:08 PM
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

Title: Re: customfields not showing in cart
Post by: gap on August 06, 2023, 14:11:35 PM
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.
Title: Re: customfields not showing in cart
Post by: Milbo on August 11, 2023, 22:33:16 PM
Please read the news https://virtuemart.net/news/516-virtuemart-4-2-including-new-paypal-checkout :-)