Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with importing new Product and Variant in Craft Commerce 5 – "Call to a member function getFieldByHandle() on null" (Fields.php:216) #1525

Closed
thibaultjadoul opened this issue Oct 3, 2024 · 3 comments
Assignees
Labels

Comments

@thibaultjadoul
Copy link

Description

I encountered an issue when importing a new Product and Variant in Craft Commerce. The error occurs during the parseField function when it tries to import values into custom fields.

The error message is as follows:

Error: Call to a member function getFieldByHandle() on null in /var/www/html/vendor/craftcms/feed-me/src/services/Fields.php:216
I have added some logs to investigate the issue and found that the error appears when attempting to import a custom field either at the Product or Variant level.

Logs for importing a custom field at the Product level:

2024-10-03 17:44:39 [queue.ERROR] [application] log element: {"elementQueryResult":null,"eagerLoadInfo":null,"id":39778,"tempId":null,"draftId":1718,"revisionId":null,"isProvisionalDraft":false,"uid":"31661a18-47c8-4779-b800-406253e61e2e","siteSettingsId":112544,"fieldLayoutId":25,"structureId":null,"enabled":true,"archived":false,"siteId":1,"title":null,"slug":"__temp_ngxpzwncqaynxsbgkovatirwwuabfviqjglg","uri":"sans-alcool\/__temp_ngxpzwncqaynxsbgkovatirwwuabfviqjglg","dateCreated":{"date":"2024-10-03 17:44:39.000000","timezone_type":3,"timezone":"Europe\/Luxembourg"},"dateUpdated":{"date":"2024-10-03 17:44:39.000000","timezone_type":3,"timezone":"Europe\/Luxembourg"},"dateLastMerged":null,"dateDeleted":null,"deletedWithOwner":null,"root":null,"lft":null,"rgt":null,"level":null,"searchScore":null,"trashed":false,"awaitingFieldValues":false,"propagating":false,"propagatingFrom":null,"propagateAll":false,"newSiteIds":[],"isNewForSite":false,"resaving":false,"duplicateOf":null,"firstSave":false,"mergingCanonicalChanges":false,"updatingFromDerivative":false,"previewing":false,"forceSave":false,"hardDelete":false,"defaultBasePrice":null,"postDate":{"date":"2024-10-03 17:44:00.000000","timezone_type":3,"timezone":"Europe\/Luxembourg"},"expiryDate":null,"typeId":4,"defaultVariantId":null,"defaultSku":null,"defaultHeight":null,"defaultLength":null,"defaultWidth":null,"defaultWeight":null,"taxCategory":null,"name":null,"storeId":1} {"memory":9708464} 
2024-10-03 17:44:39 [queue.ERROR] [application] log getFieldLayout: {"id":25,"type":"craft\\commerce\\elements\\Product","uid":"58f63570-01df-4478-a2ae-41bb39ed1bba","provider":null,"reservedFieldHandles":null} {"memory":9708904} 

Logs for importing a custom field at the Variant level:

2024-10-03 17:44:39 [queue.ERROR] [application] log element: {"elementQueryResult":null,"eagerLoadInfo":null,"id":null,"tempId":null,"draftId":null,"revisionId":null,"isProvisionalDraft":false,"uid":null,"siteSettingsId":null,"fieldLayoutId":null,"structureId":null,"enabled":true,"archived":false,"siteId":2,"title":null,"slug":null,"uri":null,"dateCreated":null,"dateUpdated":null,"dateLastMerged":null,"dateDeleted":null,"deletedWithOwner":null,"root":null,"lft":null,"rgt":null,"level":null,"searchScore":null,"trashed":false,"awaitingFieldValues":false,"propagating":false,"propagatingFrom":null,"propagateAll":false,"newSiteIds":[],"isNewForSite":false,"resaving":false,"duplicateOf":null,"firstSave":false,"mergingCanonicalChanges":false,"updatingFromDerivative":false,"previewing":false,"forceSave":false,"hardDelete":false,"width":null,"height":null,"length":null,"weight":0,"freeShipping":false,"promotable":true,"availableForPurchase":true,"minQty":null,"maxQty":null,"inventoryItemId":null,"inventoryTracked":true,"isDefault":false,"sortOrder":null,"deletedWithProduct":false,"fieldId":null,"saveOwnership":true,"updateSearchIndexForOwner":false} {"memory":9407552} 
2024-10-03 17:44:39 [queue.ERROR] [application] log getFieldLayout: null {"memory":9407832} 
2024-10-03 17:44:39 [queue.ERROR] [feed-me] {"message":"`Call to a member function getFieldByHandle() on null - Fields.php: 219`.","feed":"PRODUCTS - IMPORT - Non-alcoholic","key":"fwftoaqldwansaohxxqe"} {"memory":9413288} 
2024-10-03 17:44:39 [queue.ERROR] [Error] Error: Call to a member function getFieldByHandle() on null in /var/www/html/vendor/craftcms/feed-me/src/services/Fields.php:219

From the logs, it’s clear that $element->getFieldLayout() is returning null, and the $element object has no fieldLayoutId, id, or draftId.

Steps to Reproduce

Try to import a new Product and Variant with custom fields that do not yet exist in Craft Commerce using FeedMe.
Monitor the logs and observe the error when the import process reaches the parseField function for custom fields.

Expected Behavior

The product and variant should be imported successfully, including their custom fields.

Actual Behavior

The import process fails when trying to assign values to custom fields, resulting in the error:
Call to a member function getFieldByHandle() on null - Fields.php:216.

Versions

Craft CMS: 5.4.6
Craft Commerce: 5.1.3
FeedMe: 6.4.0

@thibaultjadoul
Copy link
Author

I'm experiencing two major issues with Feed Me 6.4.0 when using Craft Commerce 5:

  1. Custom Fields on Variants: There is an issue importing data into custom fields for product variants, which wasn't present in version 6.3.0.
  2. Content Propagation Across Sites: The content isn't being properly propagated across all my sites. This worked fine in version 6.3.0.

Is it possible to release a dev version with only the stock import fix from 6.4.0? This would allow me to bypass the regressions in 6.4.0 while still benefiting from the stock import improvements.

Thanks for your help!

@i-just
Copy link
Contributor

i-just commented Oct 9, 2024

Hi, thanks for reporting! I raised a PR for this.

@angrybrad
Copy link
Member

Feed Me 6.4.1 is out with the Commerce Variant import fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants