← All changes
|
src/Packetery/Module/Api/Internal/OrderController.php
+5
-27
trunk
→
2.1
View file →
| @@ -14,9 +14,8 @@ | ||
| 14 | 14 | use Packetery\Core\Validator; |
| 15 | 15 | use Packetery\Module\Exception\InvalidCarrierException; |
| 16 | 16 | use Packetery\Module\Forms\FormData\OrderFormData; |
| 17 | 17 | use Packetery\Module\Forms\StoredUntilFormFactory; |
| 18 | -use Packetery\Module\Framework\WpAdapter; | |
| 19 | 18 | use Packetery\Module\Options\OptionsProvider; |
| 20 | 19 | use Packetery\Module\Order; |
| 21 | 20 | use Packetery\Module\Order\Form; |
| 22 | 21 | use Packetery\Module\Order\GridExtender; |
| @@ -99,13 +98,8 @@ | ||
| 99 | 98 | */ |
| 100 | 99 | private $optionsProvider; |
| 101 | 100 | |
| 102 | 101 | /** |
| 103 | - * @var WpAdapter | |
| 104 | - */ | |
| 105 | - private $wpAdapter; | |
| 106 | - | |
| 107 | - /** | |
| 108 | 102 | * Controller constructor. |
| 109 | 103 | * |
| 110 | 104 | * @param OrderRouter $router Router. |
| 111 | 105 | * @param Repository $orderRepository Order repository. |
| @@ -125,10 +119,9 @@ | ||
| 125 | 119 | CoreHelper $coreHelper, |
| 126 | 120 | Form $orderForm, |
| 127 | 121 | StoredUntilFormFactory $storedUntilFormFactory, |
| 128 | 122 | PacketSetStoredUntil $packetSetStoredUntil, |
| 129 | - OptionsProvider $optionsProvider, | |
| 130 | - WpAdapter $wpAdapter | |
| 123 | + OptionsProvider $optionsProvider | |
| 131 | 124 | ) { |
| 132 | 125 | $this->orderForm = $orderForm; |
| 133 | 126 | $this->orderRepository = $orderRepository; |
| 134 | 127 | $this->gridExtender = $gridExtender; |
| @@ -137,9 +130,8 @@ | ||
| 137 | 130 | $this->router = $router; |
| 138 | 131 | $this->storedUntilFormFactory = $storedUntilFormFactory; |
| 139 | 132 | $this->packetSetStoredUntil = $packetSetStoredUntil; |
| 140 | 133 | $this->optionsProvider = $optionsProvider; |
| 141 | - $this->wpAdapter = $wpAdapter; | |
| 142 | 134 | } |
| 143 | 135 | |
| 144 | 136 | /** |
| 145 | 137 | * Register the routes of the controller. |
| @@ -241,16 +233,10 @@ | ||
| 241 | 233 | } |
| 242 | 234 | $order->setSize( $size ); |
| 243 | 235 | $order->setDeliverOn( $this->coreHelper->getDateTimeFromString( $packeteryDeliverOn ) ); |
| 244 | 236 | |
| 245 | - $invalidFields = $this->orderForm->getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ); | |
| 246 | - $invalidFieldsMessage = $this->orderForm->getInvalidFieldsMessageFromValidationResult( $invalidFields, $order ); | |
| 237 | + $this->orderRepository->save( $order ); | |
| 247 | 238 | |
| 248 | - $updatedRowCount = $this->orderRepository->save( $order ); | |
| 249 | - if ( $updatedRowCount === false ) { | |
| 250 | - return new WP_Error( 'order_not_updated', (string) $this->wpAdapter->__( 'An error occurred while saving the order. More details in WC log.', 'packeta' ), 400 ); | |
| 251 | - } | |
| 252 | - | |
| 253 | 239 | $data['message'] = __( 'Success', 'packeta' ); |
| 254 | 240 | $data['data'] = [ |
| 255 | 241 | 'fragments' => [ |
| 256 | 242 | sprintf( '[data-packetery-order-id="%d"][data-packetery-order-grid-cell-weight]', $orderId ) => $this->gridExtender->getWeightCellContent( $order ), |
| @@ -266,10 +252,9 @@ | ||
| 266 | 252 | Form::FIELD_VALUE => $order->getFinalValue(), |
| 267 | 253 | Form::FIELD_CALCULATED_VALUE => $order->getCalculatedValue(), |
| 268 | 254 | Form::FIELD_DELIVER_ON => $this->coreHelper->getStringFromDateTime( $order->getDeliverOn(), CoreHelper::DATEPICKER_FORMAT ), |
| 269 | 255 | 'orderIsSubmittable' => $this->orderValidator->isValid( $order ), |
| 270 | - 'orderWarningFields' => $invalidFields, | |
| 271 | - 'invalidFieldsMessage' => $invalidFieldsMessage, | |
| 256 | + 'orderWarningFields' => Form::getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ), | |
| 272 | 257 | 'hasOrderManualWeight' => $order->hasManualWeight(), |
| 273 | 258 | 'hasOrderManualCod' => $order->hasManualCod(), |
| 274 | 259 | 'hasOrderManualValue' => $order->hasManualValue(), |
| 275 | 260 | ]; |
| @@ -316,22 +301,15 @@ | ||
| 316 | 301 | } |
| 317 | 302 | |
| 318 | 303 | $order->setStoredUntil( $this->coreHelper->getDateTimeFromString( $storedUntil ) ); |
| 319 | 304 | |
| 320 | - $updatedRowCount = $this->orderRepository->save( $order ); | |
| 321 | - if ( $updatedRowCount === false ) { | |
| 322 | - return new WP_Error( 'order_not_updated', (string) $this->wpAdapter->__( 'Date set in the Packeta system, but an error occurred while saving the order. More details in WC log.', 'packeta' ), 400 ); | |
| 323 | - } | |
| 305 | + $this->orderRepository->save( $order ); | |
| 324 | 306 | |
| 325 | - $invalidFields = $this->orderForm->getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ); | |
| 326 | - $invalidFieldsMessage = $this->orderForm->getInvalidFieldsMessageFromValidationResult( $invalidFields, $order ); | |
| 327 | - | |
| 328 | 307 | $data['message'] = __( 'Success', 'packeta' ); |
| 329 | 308 | $data['data'] = [ |
| 330 | 309 | 'packeteryStoredUntil' => $order->getStoredUntil(), |
| 331 | 310 | 'orderIsSubmittable' => $this->orderValidator->isValid( $order ), |
| 332 | - 'orderWarningFields' => $invalidFields, | |
| 333 | - 'invalidFieldsMessage' => $invalidFieldsMessage, | |
| 311 | + 'orderWarningFields' => Form::getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ), | |
| 334 | 312 | ]; |
| 335 | 313 | |
| 336 | 314 | return new WP_REST_Response( $data, 200 ); |
| 337 | 315 | } |