| @@ -130,9 +130,9 @@ | ||
| 130 | 130 | * |
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | 133 | public static function getBackLinkTransientName(): string { |
| 134 | - return Transients::LABEL_PRINT_BACK_LINK_PREFIX . wp_get_session_token(); | |
| 134 | + return 'packetery_label_print_back_link_' . wp_get_session_token(); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Prepares form and renders template. |
| @@ -294,45 +294,23 @@ | ||
| 294 | 294 | $request = new Request\PacketsLabelsPdf( array_values( $packetIds ), $this->labelPrintParametersService->getLabelFormat(), $offset ); |
| 295 | 295 | $response = $this->soapApiClient->packetsLabelsPdf( $request ); |
| 296 | 296 | |
| 297 | 297 | foreach ( $packetIds as $orderId => $packetId ) { |
| 298 | - $isClaimAssistantLabel = false; | |
| 299 | - $order = $this->orderRepository->getByIdWithValidCarrier( $orderId ); | |
| 300 | - | |
| 301 | - if ( $order === null ) { | |
| 302 | - // TODO Only a temporary solution to prevent a situation where the order is null and we are unable to verify whether it is a printout from the claim assistant form. | |
| 303 | - // TODO Needs to be refactored - ticket PES-2896 | |
| 304 | - $this->logLabelPrintWithoutWcOrder( $orderId, $packetId, $response, $request ); | |
| 305 | - | |
| 306 | - continue; | |
| 307 | - } | |
| 308 | - | |
| 309 | - if ( $order->isPacketClaim( $packetId ) ) { | |
| 310 | - $isClaimAssistantLabel = true; | |
| 311 | - } | |
| 312 | - | |
| 313 | 298 | $record = new Log\Record(); |
| 314 | - $record->action = $isClaimAssistantLabel ? Log\Record::ACTION_CLAIM_LABEL_PRINT : Log\Record::ACTION_LABEL_PRINT; | |
| 299 | + $record->action = Log\Record::ACTION_LABEL_PRINT; | |
| 315 | 300 | $record->orderId = $orderId; |
| 301 | + $order = $this->orderRepository->getByIdWithValidCarrier( $orderId ); | |
| 316 | 302 | |
| 317 | 303 | if ( ! $response->hasFault() ) { |
| 318 | - if ( $isClaimAssistantLabel === false ) { | |
| 304 | + if ( $order !== null ) { | |
| 319 | 305 | $order->setIsLabelPrinted( true ); |
| 320 | 306 | } |
| 321 | 307 | |
| 322 | 308 | $record->status = Log\Record::STATUS_SUCCESS; |
| 323 | - if ( $isClaimAssistantLabel === true ) { | |
| 324 | - $record->title = $this->wpAdapter->__( 'Claim assistant label was printed successfully.', 'packeta' ); | |
| 325 | - } else { | |
| 326 | - $record->title = $this->wpAdapter->__( 'Label was printed successfully.', 'packeta' ); | |
| 327 | - } | |
| 309 | + $record->title = __( 'Label has been printed successfully.', 'packeta' ); | |
| 328 | 310 | } else { |
| 329 | 311 | $record->status = Log\Record::STATUS_ERROR; |
| 330 | - if ( $isClaimAssistantLabel === true ) { | |
| 331 | - $record->title = $this->wpAdapter->__( 'Claim assistant label could not be printed.', 'packeta' ); | |
| 332 | - } else { | |
| 333 | - $record->title = $this->wpAdapter->__( 'Label could not be printed.', 'packeta' ); | |
| 334 | - } | |
| 312 | + $record->title = __( 'Label could not be printed.', 'packeta' ); | |
| 335 | 313 | $record->params = [ |
| 336 | 314 | 'packetId' => $packetId, |
| 337 | 315 | 'isPacketIdInvalid' => $response->hasInvalidPacketId( (string) $packetId ), |
| 338 | 316 | 'request' => [ |
| @@ -345,10 +323,12 @@ | ||
| 345 | 323 | } |
| 346 | 324 | |
| 347 | 325 | $this->logger->add( $record ); |
| 348 | 326 | |
| 349 | - $order->updateApiErrorMessage( $response->getFaultString() ); | |
| 350 | - $this->orderRepository->save( $order ); | |
| 327 | + if ( $order !== null ) { | |
| 328 | + $order->updateApiErrorMessage( $response->getFaultString() ); | |
| 329 | + $this->orderRepository->save( $order ); | |
| 330 | + } | |
| 351 | 331 | } |
| 352 | 332 | |
| 353 | 333 | return $response; |
| 354 | 334 | } |
| @@ -475,36 +455,8 @@ | ||
| 475 | 455 | $this->moduleHelper->createHtmlLink( $trackingUrl, $linkText ) |
| 476 | 456 | ) |
| 477 | 457 | ); |
| 478 | 458 | $wcOrder->save(); |
| 479 | - } | |
| 480 | - | |
| 481 | - /** | |
| 482 | - * Logs label print operation when there is no WooCommerce order. | |
| 483 | - */ | |
| 484 | - private function logLabelPrintWithoutWcOrder( int $orderId, string $packetId, Response\PacketsLabelsPdf $response, Request\PacketsLabelsPdf $request ): void { | |
| 485 | - $record = new Log\Record(); | |
| 486 | - $record->action = Log\Record::ACTION_LABEL_PRINT; | |
| 487 | - $record->orderId = $orderId; | |
| 488 | - | |
| 489 | - if ( ! $response->hasFault() ) { | |
| 490 | - $record->status = Log\Record::STATUS_SUCCESS; | |
| 491 | - $record->title = $this->wpAdapter->__( 'Label was printed successfully.', 'packeta' ); | |
| 492 | - } else { | |
| 493 | - $record->status = Log\Record::STATUS_ERROR; | |
| 494 | - $record->title = $this->wpAdapter->__( 'Label could not be printed.', 'packeta' ); | |
| 495 | - } | |
| 496 | - $record->params = [ | |
| 497 | - 'packetId' => $packetId, | |
| 498 | - 'isPacketIdInvalid' => $response->hasInvalidPacketId( $packetId ), | |
| 499 | - 'request' => [ | |
| 500 | - 'packetIds' => $request->getPacketIds(), | |
| 501 | - 'format' => $request->getFormat(), | |
| 502 | - 'offset' => $request->getOffset(), | |
| 503 | - ], | |
| 504 | - 'errorMessage' => $response->getFaultString(), | |
| 505 | - ]; | |
| 506 | - $this->logger->add( $record ); | |
| 507 | 459 | } |
| 508 | 460 | |
| 509 | 461 | public function flashMessageAndRedirect( string $message, ?int $orderId ): void { |
| 510 | 462 | $this->messageManager->flash_message( $message, MessageManager::TYPE_ERROR ); |