Hallo Shopware Gemeinde, wir haben ein eigenes kleines Plugin im Shop, dass uns einen Export für die Buchhaltung bereitstellt. Wenn nun ein Kunde jedoch gelöscht wurde erscheint in der Konsole folgender Fehler:
Uncaught h {sourceClass: "Ext.JSON", sourceMethod: "decode", msg: "You're trying to decode an invalid JSON String: on line 47↵", message: "You're trying to decode an invalid JSON String: on line 47↵"}message: "You're trying to decode an invalid JSON String: ↵Fatal error: Uncaught Doctrine\ORM\EntityNotFoundException: Entity of type 'Shopware\Models\Customer\Customer' for IDs id(5965) was not found in /XY/vendor/doctrine/orm/lib/Doctrine/ORM/EntityNotFoundException.php:47↵Stack trace:↵#0 /XY/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php(194): Doctrine\ORM\EntityNotFoundException::fromClassNameAndIdentifier('Shopware\\Models...', Array)↵#1 /XY/var/cache/production_201801171346/doctrine/proxies/ __CG__ ShopwareModelsCustomerCustomer.php(692): Doctrine\ORM\Proxy\ProxyFactory->Doctrine\ORM\Proxy\{closure}(Object(Shopware\Proxies\ __CG__ \Shopware\Models\Customer\Customer), 'getBilling', Array)↵#2 /XY/var/cache/production_201801171346/doctrine/proxies/ __CG__ ShopwareModelsCustomerCustomer.php(692): Closure->__invoke(Object(Shopware\Proxies\__CG__\Shopware\Models\Customer\Customer), 'getBilling', Array)↵#3 /XY/engine in /XY/vendor/doctrine/orm/lib/Doctrine/ORM/EntityNotFoundException.php on line 47↵"msg: "You're trying to decode an invalid JSON String: ↵Fatal error: Uncaught Doctrine\ORM\EntityNotFoundException: Entity of type 'Shopware\Models\Customer\Customer' for IDs id(5965) was not found in /XY/vendor/doctrine/orm/lib/Doctrine/ORM/EntityNotFoundException.php:47↵Stack trace:↵#0 /XY/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php(194): Doctrine\ORM\EntityNotFoundException::fromClassNameAndIdentifier('Shopware\\Models...', Array)↵#1 /XY/var/cache/production_201801171346/doctrine/proxies/__CG__ShopwareModelsCustomerCustomer.php(692): Doctrine\ORM\Proxy\ProxyFactory->Doctrine\ORM\Proxy\{closure}(Object(Shopware\Proxies\__CG__\Shopware\Models\Customer\Customer), 'getBilling', Array)↵#2 /XY/var/cache/production_201801171346/doctrine/proxies/__CG__ShopwareModelsCustomerCustomer.php(692): Closure->__invoke(Object(Shopware\Proxies\ __CG__ \Shopware\Models\Customer\Customer), 'getBilling', Array)↵#3 /XY/engine in /XY/vendor/doctrine/orm/lib/Doctrine/ORM/EntityNotFoundException.php on line 47↵"sourceClass: "Ext.JSON"sourceMethod: "decode" __proto__ : Error
raise @ ext-all.js:18
Ext.JSON.me.decode @ ext-all.js:18
success
callback @ ext-all.js:18
onComplete @ ext-all.js:18
onStateChange @ ext-all.js:18
(anonymous) @ ext-all.js:18
Wenn ich das richtig verstehe heisst das, dass er den zugehörigen Kunden nicht findet. Kann man es nicht so programieren, dass er einfach weitermacht und im Zweifel „Error“ in das Feld schreibt?
config = $config;
$this->csvWriter = new CsvWriter();
$this->writeCsvHeader();
}
/**
* Startet den Export Prozess und schreibt alles in die CSV Datei
*/
public function export()
{
$qb = \Shopware()->Models()->getRepository('Shopware\Models\Order\Document\Document')->createQueryBuilder('d');
$query = $qb->where('d.date >= :date')
->setParameter('date', new \DateTime($this->config->sdSinceDate))
->getQuery();
$results = $query->getResult();
if (!$results) {
return false;
}
$this->processOrderDocuments($results);
return true;
}
/**
* @return string
*/
public function getCsvLink()
{
return $this->csvWriter->getCsvLink();
}
/**
* @param array $documents
*/
protected function processOrderDocuments(array $documents)
{
foreach ($documents as $orderDocument) {
/**
* @var Document $orderDocument
*/
$order = $orderDocument->getOrder();
/**
* @var Document $orderDocument
*/
$typeId = $orderDocument->getTypeId();
if ($typeId == 2 || $typeId == 4) {
continue;
}
$csvLine = $this->buildCsvLine($order, $orderDocument);
$this->csvWriter->writeLine($csvLine);
}
}
/**
* schreibt den Header in die CSV-Datei
*/
protected function writeCsvHeader()
{
$header = array(
'Typ',
'Käufer',
'Rechnungs- bzw. Gutschriftsdatum',
'Rechnungs- bzw. Gutschriftsnummer',
'Betrag-Brutto',
'Betrag-Netto',
'Zahlart',
'Bestellnummer',
'Überweisungsdatum',
'Bestell-Land'
);
$this->csvWriter->writeLine($header);
}
/**
* @param Order $order
* @param Document $orderDocument
*
* @return array
*/
protected function buildCsvLine(Order $order, Document $orderDocument)
{
$csvLine = array();
// Typ (Rechnung oder Gutschrift)
$csvLine[] = $orderDocument->getType()->getName();
// Vorname Nachname
$billing = $order->getCustomer()->getBilling();
$csvLine[] = $billing->getFirstName() . ' ' . $billing->getLastName();
// Dokumentendatum
$csvLine[] = $orderDocument->getDate()->format('d.m.Y');
// Dokumentennummer
$csvLine[] = $orderDocument->getDocumentId();
// Betrag Brutto
$brutto = $orderDocument->getAmount();
$csvLine[] = $this->replaceDotWithComma($orderDocument->getAmount());
// Betrag Netto
$netto = $this->getNetto($brutto, $this->getTax($order));
$csvLine[] = $this->replaceDotWithComma($netto);
// Beschreibung
$paymentDescription = '';
try {
$payment = $order->getPayment();
$paymentDescription = $payment->getDescription();
} catch (EntityNotFoundException $e) {
}
$csvLine[] = $paymentDescription;
// Bestellnummer
$csvLine[] = $order->getNumber();
// "Überweisungsdatum"
$csvLine[] = $this->getPaymentDate($order);
// Bestell-Land
$csvLine[] = $order->getBilling()->getCountry()->getName();
return $csvLine;
}
/**
* @param Order $order
*
* @return int
*/
protected function getTax(Order $order)
{
$maxTaxRate = 0;
$details = $order->getDetails();
foreach ($details as $detail) {
/**
* @var Detail $detail
*/
$taxRate = (int)$detail->getTaxRate();
if ($maxTaxRate < $taxRate) {
$maxTaxRate = $taxRate;
}
}
return $maxTaxRate;
}
/**
* @param Order $order
*
* @return string
*/
protected function getPaymentDate(Order $order)
{
$orderHistory = $order->getHistory();
foreach ($orderHistory as $history) {
/**
* @var History $history
*/
if ($history->getPaymentStatus()->getId() == 12) {
return $history->getChangeDate()->format('d.m.Y');
}
}
return '';
}
protected function getNetto($brutto, $tax)
{
return round($brutto / (1 + ($tax * 0.01)), 2);
}
/**
* @param $value
*
* @return string
*/
protected function replaceDotWithComma($value)
{
return str_replace('.', ',', $value);
}
}