【发布时间】:2023-02-01 13:37:51
【问题描述】:
我正在尝试获取 Shopware 6.4.18.1 中的所有 OrderLineItems,它们是某个制造商的产品并且:
- 已支付(如果使用预付款)
- 或者:
- 已部分支付
- 正在付款
- 付款打开
以下代码:
<?php
declare(strict_types=1);
namespace MyBundle\App\Query\OrderLineItem;
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\PrePayment;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\AndFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NorFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\OrFilter;
class OrderLineItemQuery
{
public const PAID_STATE = 'paid';
public const PAID_PARTIALLY_STATE = 'paid_partially';
public const IN_PROGRESS_STATE = 'in_progress';
public const OPEN_STATE = 'open';
protected EntityRepository $orderLineItemRepository;
public function __construct(
EntityRepository $orderLineItemRepository
) {
$this->orderLineItemRepository = $orderLineItemRepository;
}
public function getOrderLineItemsByManufacturer(string $manufacturerId): EntityCollection
{
$criteria = new Criteria();
// default associations needed for following procedures
$criteria->addAssociations([
'order.deliveries.shippingOrderAddress.country',
'order.deliveries.shippingOrderAddress.salutation',
'order.orderCustomer.customer.salutation',
'order.salesChannel',
'order.transactions.stateMachineState',
'order.transactions.paymentMethod',
'product.manufacturer',
]);
$criteria->addFilter(
// only take manufacturer products
new EqualsFilter('product.manufacturer.id', $manufacturerId),
// exclude unpaid prepayment orders
new OrFilter([
new EqualsFilter('order.transactions.stateMachineState.technicalName', self::PAID_STATE),
// removing the filters inside here fixes the problem
new AndFilter([
new NorFilter([
new EqualsFilter('order.transactions.paymentMethod.handlerIdentifier', PrePayment::class),
]),
new OrFilter([
new EqualsFilter('order.transactions.stateMachineState.technicalName', self::PAID_PARTIALLY_STATE),
new EqualsFilter('order.transactions.stateMachineState.technicalName', self::IN_PROGRESS_STATE),
new EqualsFilter('order.transactions.stateMachineState.technicalName', self::OPEN_STATE),
]),
]),
])
);
return $this->orderLineItemRepository->search($criteria, Context::createDefaultContext())->getEntities();
}
}
但它只返回错误:
在 Exception.php 第 18 行中:
SQLSTATE [42S22]:未找到列:1054“字段列表”中的未知列“order_line_item.order.order_line_item_version_id”删除
AndFilter内的所有内容似乎可以消除错误,但我需要从选择预付款作为付款方式但尚未付款的订单中排除 OrderLineItems。我应该如何更改查询以使其工作?
【问题讨论】: