| @@ -17,14 +17,11 @@ | ||
| 17 | 17 | use Packetery\Core\Entity\PickupPoint; |
| 18 | 18 | use Packetery\Module\Carrier; |
| 19 | 19 | use Packetery\Module\Carrier\PacketaPickupPointsConfig; |
| 20 | 20 | use Packetery\Module\CustomsDeclaration; |
| 21 | -use Packetery\Module\Exception\DeleteErrorException; | |
| 22 | 21 | use Packetery\Module\Exception\InvalidCarrierException; |
| 23 | -use Packetery\Module\Framework\WcAdapter; | |
| 24 | 22 | use Packetery\Module\ModuleHelper; |
| 25 | 23 | use Packetery\Module\Shipping\ShippingProvider; |
| 26 | -use Packetery\Module\WcLogger; | |
| 27 | 24 | use Packetery\Module\WpdbAdapter; |
| 28 | 25 | use WC_Order; |
| 29 | 26 | use WP_Post; |
| 30 | 27 | |
| @@ -77,13 +74,8 @@ | ||
| 77 | 74 | */ |
| 78 | 75 | private $customsDeclarationRepository; |
| 79 | 76 | |
| 80 | 77 | /** |
| 81 | - * @var WcAdapter | |
| 82 | - */ | |
| 83 | - private $wcAdapter; | |
| 84 | - | |
| 85 | - /** | |
| 86 | 78 | * Repository constructor. |
| 87 | 79 | * |
| 88 | 80 | * @param WpdbAdapter $wpdbAdapter WpdbAdapter. |
| 89 | 81 | * @param Builder $orderFactory Order factory. |
| @@ -97,10 +89,9 @@ | ||
| 97 | 89 | Builder $orderFactory, |
| 98 | 90 | CoreHelper $coreHelper, |
| 99 | 91 | PacketaPickupPointsConfig $pickupPointsConfig, |
| 100 | 92 | Carrier\EntityRepository $carrierRepository, |
| 101 | - CustomsDeclaration\Repository $customsDeclarationRepository, | |
| 102 | - WcAdapter $wcAdapter | |
| 93 | + CustomsDeclaration\Repository $customsDeclarationRepository | |
| 103 | 94 | ) { |
| 104 | 95 | $this->wpdbAdapter = $wpdbAdapter; |
| 105 | 96 | $this->builder = $orderFactory; |
| 106 | 97 | $this->coreHelper = $coreHelper; |
| @@ -106,9 +97,8 @@ | ||
| 106 | 97 | $this->coreHelper = $coreHelper; |
| 107 | 98 | $this->pickupPointsConfig = $pickupPointsConfig; |
| 108 | 99 | $this->carrierRepository = $carrierRepository; |
| 109 | 100 | $this->customsDeclarationRepository = $customsDeclarationRepository; |
| 110 | - $this->wcAdapter = $wcAdapter; | |
| 111 | 101 | } |
| 112 | 102 | |
| 113 | 103 | /** |
| 114 | 104 | * Applies custom order status filter. |
| @@ -206,12 +196,10 @@ | ||
| 206 | 196 | `is_exported` tinyint(1) NOT NULL, |
| 207 | 197 | `packet_id` varchar(15) NULL, |
| 208 | 198 | `packet_claim_id` varchar(15) NULL, |
| 209 | 199 | `packet_claim_password` varchar(10) NULL, |
| 210 | - `consign_password` varchar(10) NULL, | |
| 211 | 200 | `is_label_printed` tinyint(1) NOT NULL, |
| 212 | 201 | `point_id` varchar(50) NULL, |
| 213 | - `point_place` varchar(100) NULL, | |
| 214 | 202 | `point_name` varchar(150) NULL, |
| 215 | 203 | `point_url` varchar(255) NULL, |
| 216 | 204 | `point_street` varchar(120) NULL, |
| 217 | 205 | `point_zip` varchar(10) NULL, |
| @@ -376,9 +364,8 @@ | ||
| 376 | 364 | 'is_exported' => (int) $order->isExported(), |
| 377 | 365 | 'packet_id' => $order->getPacketId(), |
| 378 | 366 | 'packet_claim_id' => $order->getPacketClaimId(), |
| 379 | 367 | 'packet_claim_password' => $order->getPacketClaimPassword(), |
| 380 | - 'consign_password' => $order->getConsignPassword(), | |
| 381 | 368 | 'packet_status' => $order->getPacketStatus(), |
| 382 | 369 | 'stored_until' => $this->coreHelper->getStringFromDateTime( $order->getStoredUntil(), CoreHelper::DATEPICKER_FORMAT ), |
| 383 | 370 | 'is_label_printed' => (int) $order->isLabelPrinted(), |
| 384 | 371 | 'carrier_number' => $order->getCarrierNumber(), |
| @@ -384,9 +371,8 @@ | ||
| 384 | 371 | 'carrier_number' => $order->getCarrierNumber(), |
| 385 | 372 | 'weight' => $order->getWeight(), |
| 386 | 373 | 'car_delivery_id' => $order->getCarDeliveryId(), |
| 387 | 374 | 'point_id' => $point->getId(), |
| 388 | - 'point_place' => $point->getPlace(), | |
| 389 | 375 | 'point_name' => $point->getName(), |
| 390 | 376 | 'point_url' => $point->getUrl(), |
| 391 | 377 | 'point_street' => $point->getStreet(), |
| 392 | 378 | 'point_zip' => $point->getZip(), |
| @@ -411,12 +397,12 @@ | ||
| 411 | 397 | * Saves order. |
| 412 | 398 | * |
| 413 | 399 | * @param Order $order Order. |
| 414 | 400 | * |
| 415 | - * @return int|false The number of rows updated, or false on error. | |
| 401 | + * @return void | |
| 416 | 402 | */ |
| 417 | - public function save( Order $order ) { | |
| 418 | - return $this->saveData( $this->orderToDbArray( $order ) ); | |
| 403 | + public function save( Order $order ): void { | |
| 404 | + $this->saveData( $this->orderToDbArray( $order ) ); | |
| 419 | 405 | } |
| 420 | 406 | |
| 421 | 407 | /** |
| 422 | 408 | * Saves order data. |
| @@ -422,14 +408,13 @@ | ||
| 422 | 408 | * Saves order data. |
| 423 | 409 | * |
| 424 | 410 | * @param array<string, int|string|null|DateTimeImmutable> $orderData Order data. |
| 425 | 411 | * |
| 426 | - * @return int|false The number of rows updated, or false on error. | |
| 412 | + * @return void | |
| 427 | 413 | */ |
| 428 | - public function saveData( array $orderData ) { | |
| 414 | + public function saveData( array $orderData ): void { | |
| 429 | 415 | $this->onBeforeDataInsertion( $orderData ); |
| 430 | - | |
| 431 | - return $this->wpdbAdapter->insertReplaceHelper( $this->wpdbAdapter->packeteryOrder, $orderData, null, 'REPLACE' ); | |
| 416 | + $this->wpdbAdapter->insertReplaceHelper( $this->wpdbAdapter->packeteryOrder, $orderData, null, 'REPLACE' ); | |
| 432 | 417 | } |
| 433 | 418 | |
| 434 | 419 | /** |
| 435 | 420 | * Calls logic before order data replace/insert. |
| @@ -450,9 +435,9 @@ | ||
| 450 | 435 | if ( ( $pointId !== null && $pointId !== '' ) || ! $isLoggingActive || ! $this->pickupPointsConfig->isInternalPickupPointCarrier( $carrierId ) ) { |
| 451 | 436 | return; |
| 452 | 437 | } |
| 453 | 438 | |
| 454 | - $wcLogger = $this->wcAdapter->getLogger(); | |
| 439 | + $wcLogger = wc_get_logger(); | |
| 455 | 440 | $dataToLog = [ |
| 456 | 441 | 'order' => $orderData, |
| 457 | 442 | 'trace' => array_map( |
| 458 | 443 | static function ( array $item ): array { |
| @@ -695,42 +680,24 @@ | ||
| 695 | 680 | * Deletes order data including customs declaration and its items from custom tables. |
| 696 | 681 | * |
| 697 | 682 | * @param int $orderId Order id. |
| 698 | 683 | * |
| 699 | - * @return bool true on success, false in case of db failure. | |
| 684 | + * @return void | |
| 700 | 685 | */ |
| 701 | - public function delete( int $orderId ): bool { | |
| 702 | - try { | |
| 703 | - $this->customsDeclarationRepository->delete( (string) $orderId ); | |
| 704 | - $this->wpdbAdapter->delete( $this->wpdbAdapter->packeteryOrder, [ 'id' => $orderId ], '%d' ); | |
| 705 | - | |
| 706 | - return true; | |
| 707 | - } catch ( DeleteErrorException $e ) { | |
| 708 | - return false; | |
| 709 | - } | |
| 686 | + public function delete( int $orderId ): void { | |
| 687 | + $this->customsDeclarationRepository->delete( (string) $orderId ); | |
| 688 | + $this->wpdbAdapter->delete( $this->wpdbAdapter->packeteryOrder, [ 'id' => $orderId ], '%d' ); | |
| 710 | 689 | } |
| 711 | 690 | |
| 712 | 691 | /** |
| 713 | 692 | * Fires after post deletion. |
| 714 | 693 | * |
| 715 | - * @param int|mixed $postId Post id. | |
| 716 | - * @param WP_Post|mixed $post Post object. | |
| 694 | + * @param int $postId Post id. | |
| 695 | + * @param WP_Post $post Post object. | |
| 717 | 696 | * |
| 718 | 697 | * @return void |
| 719 | 698 | */ |
| 720 | - public function deletedPostHook( $postId, $post ): void { | |
| 721 | - if ( ! is_int( $postId ) ) { | |
| 722 | - WcLogger::logArgumentTypeError( __METHOD__, 'postId', 'int', $postId ); | |
| 723 | - | |
| 724 | - return; | |
| 725 | - } | |
| 726 | - | |
| 727 | - if ( ! $post instanceof WP_Post ) { | |
| 728 | - WcLogger::logArgumentTypeError( __METHOD__, 'post', WP_Post::class, $post ); | |
| 729 | - | |
| 730 | - return; | |
| 731 | - } | |
| 732 | - | |
| 699 | + public function deletedPostHook( int $postId, WP_Post $post ): void { | |
| 733 | 700 | // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps |
| 734 | 701 | if ( $post->post_type === 'shop_order' ) { |
| 735 | 702 | $this->delete( $postId ); |
| 736 | 703 | } |