Php Shopware:通过其ID获取文档编号

Php Shopware:通过其ID获取文档编号,php,symfony,shopware,Php,Symfony,Shopware,我需要通过其ID获取documentRepository中的documentNumber。 我正在执行一个“简单”的DAL请求来完成此操作,但由于某些原因,转储输出会给出空字段 这是我的订阅服务器,包含DAL请求: <?php declare(strict_types=1); namespace HmDocumentGeneratorPlugin\Subscriber; use Shopware\Core\Framework\DataAbstractionLayer\EntityRe

我需要通过其ID获取documentRepository中的documentNumber。 我正在执行一个“简单”的DAL请求来完成此操作,但由于某些原因,转储输出会给出空字段

这是我的订阅服务器,包含DAL请求:

<?php

declare(strict_types=1);

namespace HmDocumentGeneratorPlugin\Subscriber;

use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use HmDocumentGeneratorPlugin\Service\HmDocumentService;
use HmDocumentGeneratorPlugin\Service\HmOrderService;
use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
use HmDocumentGeneratorPlugin\Event\InvoiceGeneratedEvent;
use Shopware\Core\Checkout\Order\OrderEntity;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Shopware\Core\Checkout\DocumentEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Emakers\TransmissionPlugin\TransmissionPlugin;
use Emakers\TransmissionPlugin\Services\ExactDataService;

class OrderSubscriber implements EventSubscriberInterface
{

    /**
     * @ContainerInterface $container
     */
    private $container;

    /**
     * @var HmOrderService
     */
    private $service;

    /**
     * @var HmDocumentService
     */
    private $docService;

    /**
     * @var EntityRepositoryInterface
     */
    private $transmissionLogRepository;

    /**
     * @var EntityRepositoryInterface
     */
    private $transmissionRepository;

    /**
     * @var EntityRepositoryInterface
     */
    private $documentRepository;

    /**
     * @var EntityRepositoryInterface
     */
    private $orderRepository;

    public function __construct(ContainerInterface $container, HmOrderService $service, HmDocumentService $docService, EntityRepositoryInterface $transmissionLogRepository, EntityRepositoryInterface $transmissionRepository, EntityRepositoryInterface $documentRepository, EntityRepositoryInterface $orderRepository)
    {
        $this->container = $container;
        $this->service = $service;
        $this->docService = $docService;
        $this->transmissionLogRepository = $transmissionLogRepository;
        $this->transmissionRepository = $transmissionRepository;
        $this->documentRepository = $documentRepository;
        $this->orderRepository = $orderRepository;
    }

    public static function getSubscribedEvents(): array
    {
        return [
            CheckoutOrderPlacedEvent::class => 'onOrderPlaced',
        ];
    }

    public function onOrderPlaced(CheckoutOrderPlacedEvent $event): void
    {
        $order = $event->getOrder();

        if ($order instanceof OrderEntity) {
            $this->service->generateDocuments($order); //document correctly generated (I checked in the db)
            $document = $this->docService->getInvoice($order); //To get the documentId
            $documentObject = $this->documentRepository->search(new Criteria([ $document['id'] ]), \Shopware\Core\Framework\Context::createDefaultContext() );
            var_dump($documentObject);
            die('please man');
        }
   }
}

我还尝试直接转储getInvoice()函数的结果,方法如下:

$document=$this->docService->getInvoice($order);
$contentD=$document['content'];
var_dump($content);
回声(“
”); if(strpos($content,'Invoice')!==false){ 回声“找到单词!”; }否则{ 回声“找不到单词!”; } 死亡(‘mem’);
这是$content d的输出,其中我看到“发票”一词,但strpos返回“找不到词”:

字符串(2759)“%PDF-1.3 1 0 obj>endobj 2 0 obj>endobj 3 0 obj>>/MediaBox[0.000 0.000 595.280 841.890]>>endobj 4 0 obj[/PDF/Text]endobj 5 0 obj>endobj 6 0 obj>endobj 7 0 obj>stream x�}v�R�6��+����<代码>AR7�%+�K�8I�bfhs�"9*���䔃�,�1.���U��[��)\�v u�+�'�x  B�a4��n��我��N��B�?)%(�(+�L���3.��s��W��Y�EN�B��5.oەm�ڶ起来��ţ,�¿=?{8��+�����N@���l�?��ń�C�d��� ���s��N�6.�g] ^W���[S!5v�pL���s���Y�����{j{��=F��nK[U��3.�ƻ=q������T��T�exB��CҠ����#֑���C،m�eNMb�G��)5.���_��_�-太太�]�(�不�A.��;[N] K�P�T��B��KE�9'.��s��M�8.�C�运输署� w�4Rq�#&"B�AnH$~Ӕ��hwh��dMzi;w���~�ޓ�o�}��^<代码>�U��bZ 5iĸ$~�D��第三季度�M� endobj 9 0 obj>endobj 10 0 obj>endobj 11 0 obj>endobj 12 0 obj>endobj 13 0 obj>endobj外部参照0 14 000000 65535 f 000000000 9 00000 n 00000000 74 00000 n 00000000 120 00000 n 0000000 35000000 n 0000000 3790 00000 n 0000000 5740 0000000 n 0000000 18740 000000 1981 00000 n 000000 2093 00000 n 000000 2153 00000 n 000000 n 2213 000000 n 000000 2270 00000 n拖车>开始外部参照2327%%EOF“* 找不到单词!mem

我是否忘记了services.xml中的use语句或其他内容,或者使用了错误的存储库?我100%确定文档的ID是正确的,我还尝试在数据库(表“document”)中手动获取ID,并获得了相同的行为


我发现了错误,以错误的方式获取存储库。 以下是获得它的正确方法:

/* @var EntityRepositoryInterface $docRepository */ 
$docRepository = $this->container->get('document.repository');
最后,我是这样得到发票号码的:

$document = $this->docService->getInvoice($order);

/* @var EntityRepositoryInterface $docRepository */
$docRepository = $this->container->get('document.repository');
$documentObject = $docRepository->search(new Criteria([ $document['id'] ]), $event->getContext());
$documentNumber = $documentObject->first()->getConfig()['custom']['invoiceNumber'];
/* @var EntityRepositoryInterface $docRepository */ 
$docRepository = $this->container->get('document.repository');
$document = $this->docService->getInvoice($order);

/* @var EntityRepositoryInterface $docRepository */
$docRepository = $this->container->get('document.repository');
$documentObject = $docRepository->search(new Criteria([ $document['id'] ]), $event->getContext());
$documentNumber = $documentObject->first()->getConfig()['custom']['invoiceNumber'];