| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Class BulkActions | |
| 4 | + * | |
| 5 | + * @package Packetery\Order | |
| 6 | + */ | |
| 2 | 7 | |
| 3 | 8 | declare( strict_types=1 ); |
| 4 | 9 | |
| 5 | 10 | namespace Packetery\Module\Order; |
| @@ -4,12 +9,15 @@ | ||
| 4 | 9 | |
| 5 | 10 | namespace Packetery\Module\Order; |
| 6 | 11 | |
| 7 | 12 | use Packetery\Latte\Engine; |
| 8 | -use Packetery\Module\WcLogger; | |
| 9 | 13 | use Packetery\Nette\Http\Request; |
| 10 | -use WC_Order; | |
| 11 | 14 | |
| 15 | +/** | |
| 16 | + * Class BulkActions | |
| 17 | + * | |
| 18 | + * @package Packetery\Order | |
| 19 | + */ | |
| 12 | 20 | class BulkActions { |
| 13 | 21 | const ACTION_SUBMIT_TO_API = 'submit_to_api'; |
| 14 | 22 | |
| 15 | 23 | /** |
| @@ -62,19 +70,13 @@ | ||
| 62 | 70 | |
| 63 | 71 | /** |
| 64 | 72 | * Adds custom actions to dropdown in admin order list. |
| 65 | 73 | * |
| 66 | - * @param array<string, string>|mixed $actions Array of action. | |
| 74 | + * @param array<string, string> $actions Array of action. | |
| 67 | 75 | * |
| 68 | - * @return array<string, string>|mixed | |
| 76 | + * @return array<string, string> | |
| 69 | 77 | */ |
| 70 | - public function addActions( $actions ) { | |
| 71 | - if ( ! is_array( $actions ) ) { | |
| 72 | - WcLogger::logArgumentTypeError( __METHOD__, 'actions', 'array', $actions ); | |
| 73 | - | |
| 74 | - return $actions; | |
| 75 | - } | |
| 76 | - | |
| 78 | + public function addActions( array $actions ): array { | |
| 77 | 79 | $actions[ self::ACTION_SUBMIT_TO_API ] = __( 'Packeta export', 'packeta' ); |
| 78 | 80 | $actions[ LabelPrint::ACTION_PACKETA_LABELS ] = __( 'Packeta download labels', 'packeta' ); |
| 79 | 81 | $actions[ LabelPrint::ACTION_CARRIER_LABELS ] = __( 'Packeta download carrier labels', 'packeta' ); |
| 80 | 82 | $actions[ CollectionPrint::ACTION_PRINT_ORDER_COLLECTION ] = __( 'Packeta AWB (delivery note)', 'packeta' ); |
| @@ -84,33 +86,15 @@ | ||
| 84 | 86 | |
| 85 | 87 | /** |
| 86 | 88 | * Executes the action for selected orders and returns url to redirect to. |
| 87 | 89 | * |
| 88 | - * @param string|mixed $redirectTo Url. | |
| 89 | - * @param string|mixed $action Action id. | |
| 90 | - * @param int[]|mixed $postIds Order ids. | |
| 90 | + * @param string $redirectTo Url. | |
| 91 | + * @param string $action Action id. | |
| 92 | + * @param int[] $postIds Order ids. | |
| 91 | 93 | * |
| 92 | - * @return string|mixed | |
| 94 | + * @return string | |
| 93 | 95 | */ |
| 94 | - public function handleActions( $redirectTo, $action, $postIds ) { | |
| 95 | - if ( ! is_string( $redirectTo ) ) { | |
| 96 | - WcLogger::logArgumentTypeError( __METHOD__, 'redirectTo', 'string', $redirectTo ); | |
| 97 | - | |
| 98 | - return $redirectTo; | |
| 99 | - } | |
| 100 | - | |
| 101 | - if ( ! is_string( $action ) ) { | |
| 102 | - WcLogger::logArgumentTypeError( __METHOD__, 'action', 'string', $action ); | |
| 103 | - | |
| 104 | - return $redirectTo; | |
| 105 | - } | |
| 106 | - | |
| 107 | - if ( ! is_array( $postIds ) ) { | |
| 108 | - WcLogger::logArgumentTypeError( __METHOD__, 'postIds', 'array', $postIds ); | |
| 109 | - | |
| 110 | - return $redirectTo; | |
| 111 | - } | |
| 112 | - | |
| 96 | + public function handleActions( string $redirectTo, string $action, array $postIds ): string { | |
| 113 | 97 | if ( $action === CollectionPrint::ACTION_PRINT_ORDER_COLLECTION ) { |
| 114 | 98 | set_transient( CollectionPrint::getOrderIdsTransientName(), $postIds ); |
| 115 | 99 | |
| 116 | 100 | return add_query_arg( |
| @@ -136,28 +120,17 @@ | ||
| 136 | 120 | |
| 137 | 121 | if ( $action === self::ACTION_SUBMIT_TO_API ) { |
| 138 | 122 | $finalSubmissionResult = new PacketSubmissionResult(); |
| 139 | 123 | foreach ( $postIds as $postId ) { |
| 140 | - if ( ! is_numeric( $postId ) ) { | |
| 141 | - WcLogger::logArgumentTypeError( __METHOD__, 'postId', 'is_numeric', $postId ); | |
| 142 | - | |
| 143 | - continue; | |
| 124 | + $wcOrder = $this->orderRepository->getWcOrderById( $postId ); | |
| 125 | + if ( $wcOrder !== null ) { | |
| 126 | + $submissionResult = $this->packetSubmitter->submitPacket( | |
| 127 | + $wcOrder, | |
| 128 | + null, | |
| 129 | + true | |
| 130 | + ); | |
| 131 | + $finalSubmissionResult->merge( $submissionResult ); | |
| 144 | 132 | } |
| 145 | - | |
| 146 | - $wcOrder = $this->orderRepository->getWcOrderById( (int) $postId ); | |
| 147 | - | |
| 148 | - if ( ! $wcOrder instanceof WC_Order ) { | |
| 149 | - WcLogger::logArgumentTypeError( __METHOD__, 'wcOrder', 'WC_Order', $wcOrder ); | |
| 150 | - | |
| 151 | - continue; | |
| 152 | - } | |
| 153 | - | |
| 154 | - $submissionResult = $this->packetSubmitter->submitPacket( | |
| 155 | - $wcOrder, | |
| 156 | - null, | |
| 157 | - true | |
| 158 | - ); | |
| 159 | - $finalSubmissionResult->merge( $submissionResult ); | |
| 160 | 133 | } |
| 161 | 134 | |
| 162 | 135 | $queryArgs = $finalSubmissionResult->getCounter(); |
| 163 | 136 | $queryArgs[ self::ACTION_SUBMIT_TO_API ] = true; |