Shopware:如何获取订单对象中产品的自定义字段
Shopware : How to get customFields for products in the Order Object
我目前正在尝试在使用以下代码下订单时在产品中获取自定义字段“emakers_custom_field_warehouse_name”。
这是我的搜索请求:
$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();
这是我在序列化 $orderObject->getLineItems->first()->getProduct() 时得到的:
https://gist.github.com/Youmar0504/8b53632fbc1b43c11769711519a74a17
我已经尝试过但结果是空的:
$orderObject->getLineItems->first()->getProduct()->getCustomFields()
TBH,我不知道还能尝试什么。看起来(如果您在要点中搜索 customField 的名称)它在产品翻译实体中。但是如果我执行 $orderObject->getLineItems->first()->getProduct()->getProductTranslations(),我会收到一条错误消息“Attempted to call an undefined method named “getProductTranslations” of class "Shopware\Core\Content\Product\ProductEntity"
还有什么我可以尝试得到的吗?
发现这与语言有关。刚刚在 criteria 中替换:
'lineItems.product.translations' 通过 'lineItems.product.default' 我现在可以通过以下方式轻松获得 customFields:
$orderObject->getLineItems->first()->getProduct()->getCustomFields()
我目前正在尝试在使用以下代码下订单时在产品中获取自定义字段“emakers_custom_field_warehouse_name”。
这是我的搜索请求:
$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();
这是我在序列化 $orderObject->getLineItems->first()->getProduct() 时得到的: https://gist.github.com/Youmar0504/8b53632fbc1b43c11769711519a74a17
我已经尝试过但结果是空的:
$orderObject->getLineItems->first()->getProduct()->getCustomFields()
TBH,我不知道还能尝试什么。看起来(如果您在要点中搜索 customField 的名称)它在产品翻译实体中。但是如果我执行 $orderObject->getLineItems->first()->getProduct()->getProductTranslations(),我会收到一条错误消息“Attempted to call an undefined method named “getProductTranslations” of class "Shopware\Core\Content\Product\ProductEntity"
还有什么我可以尝试得到的吗?
发现这与语言有关。刚刚在 criteria 中替换: 'lineItems.product.translations' 通过 'lineItems.product.default' 我现在可以通过以下方式轻松获得 customFields:
$orderObject->getLineItems->first()->getProduct()->getCustomFields()