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

customfields not showing in cart

Started by johnknit, May 25, 2022, 08:38:00 AM

Previous topic - Next topic

johnknit

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

Jumbo!

Try switching to any other template. It can be a template related issue.

johnknit

The cart tempate or the productdetails template ?

jenkinhill

Try Protostar or VMBeez3 to rule out all overrides first.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

johnknit

I disabled our template and activated beez3.
That gives no changes in beez3 happens the same.

johnknit

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.

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

johnknit

Thanks for the file.
I have tested it and the error is still there.
So the error is in /adminsistrator/models/customfields.php

Milbo

Thank you for your report, I am going to check it
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

johnknit

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>

Alexb65

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?

Alexb65

#11
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                 }


Alexb65

@Milbo could you please check this fix and import it into the source of next release?

Thank you

gap

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

pinochico

@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?

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products