Skip to content

Commit

Permalink
Fix: Check for missing order metadata (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethobey authored May 27, 2022
1 parent 18eaac1 commit b460435
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Observer/SaveOrderMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,25 @@ public function __construct(
public function execute(Observer $observer)
{
$encodedMetadata = $this->checkoutSession->getData(self::ORDER_METADATA);
$metadata = json_decode($encodedMetadata, true);

/** @var OrderInterface $order */
$order = $observer->getOrder();
$extensionAttributes = $order->getExtensionAttributes() ?? $this->extensionFactory->create();
if ($encodedMetadata) {
$metadata = json_decode($encodedMetadata, true);

if (isset($metadata[MetadataInterface::TAX_CALCULATION_STATUS])) {
$extensionAttributes->setTjTaxCalculationStatus($metadata[MetadataInterface::TAX_CALCULATION_STATUS]);
}
/** @var OrderInterface $order */
$order = $observer->getOrder();
$extensionAttributes = $order->getExtensionAttributes() ?? $this->extensionFactory->create();

if (isset($metadata[MetadataInterface::TAX_CALCULATION_MESSAGE])) {
$extensionAttributes->setTjTaxCalculationMessage($metadata[MetadataInterface::TAX_CALCULATION_MESSAGE]);
}
if (isset($metadata[MetadataInterface::TAX_CALCULATION_STATUS])) {
$extensionAttributes->setTjTaxCalculationStatus($metadata[MetadataInterface::TAX_CALCULATION_STATUS]);
}

$order->setExtensionAttributes($extensionAttributes);
if (isset($metadata[MetadataInterface::TAX_CALCULATION_MESSAGE])) {
$extensionAttributes->setTjTaxCalculationMessage($metadata[MetadataInterface::TAX_CALCULATION_MESSAGE]);
}

$this->orderRepository->save($order);
$order->setExtensionAttributes($extensionAttributes);

$this->orderRepository->save($order);
}
}
}

0 comments on commit b460435

Please sign in to comment.