I am currently trying to get a custom field ‘emakers_custom_field_warehouse_name‘ in the products when an order is made with the code below.
Here’s my search Request :
$criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('id', $orderId)); $criteria->addAssociations([ 'deliveries.shippingOrderAddress.salutation', 'deliveries.shippingOrderAddress.country', 'orderCustomer.customer.group', 'lineItems.product.translations', ]); $orderObject = $this->orderRepository->search($criteria), Context::createDefaultContext())->first();
Here’s what I get when I serialize $orderObject->getLineItems->first()->getProduct() : https://gist.github.com/Youmar0504/8b53632fbc1b43c11769711519a74a17
What I already tried and gave me empty result :
$orderObject->getLineItems->first()->getProduct()->getCustomFields()
TBH, I don’t know what to try else. It looks like (if you search on the customField’s name in the gist) that it’s in the product Translation Entity. But if I do $orderObject->getLineItems->first()->getProduct()->getProductTranslations(), I receive an error saying “Attempted to call an undefined method named “getProductTranslations” of class “ShopwareCoreContentProductProductEntity“
Anything else I can try to get it?
Advertisement
Answer
Find out that this was language dependant. Just replaced in the criteria : ‘lineItems.product.translations’ by ‘lineItems.product.default’ and I am now easily getting the customFields by doing :
$orderObject->getLineItems->first()->getProduct()->getCustomFields()