PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.19
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.19
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / API / V2 / Writers / Customer_Writer.php

Customer_Writer.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.19, at includes/API/V2/Writers/Customer_Writer.php

58 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Customer collection writer.
4 *
5 * @package WCPOS\WooCommercePOS\API\V2\Writers
6 */
7
8 // phpcs:disable Squiz.Commenting, Generic.Commenting -- Lifecycle docblocks are intentionally concise.
9
10 namespace WCPOS\WooCommercePOS\API\V2\Writers;
11
12 use WCPOS\WooCommercePOS\Services\Tax_Id_Writer;
13 use WCPOS\WooCommercePOS\Sync\Order_Write_Payload;
14
15 /** Adapts customer tax IDs and walk-in billing emails around wc/v3. */
16 class Customer_Writer extends Null_Writer {
17 /** Prepare a customer create. */
18 public function prepare_create( array $meta, array $payload, callable $validate_tax_ids ) {
19 $error = $validate_tax_ids( $payload );
20 return is_wp_error( $error ) ? $error : parent::prepare_create( $meta, $this->prepare_payload( $payload ), $validate_tax_ids );
21 }
22
23 /** Prepare a customer update. */
24 public function prepare_update( array $meta, int $id, array $payload, callable $validate_tax_ids ) {
25 $error = $validate_tax_ids( $payload );
26 return is_wp_error( $error ) ? $error : parent::prepare_update( $meta, $id, $this->prepare_payload( $payload ), $validate_tax_ids );
27 }
28
29 /** Persist customer tax IDs after create. */
30 public function after_create( int $id, array $payload ): void {
31 $this->write_tax_ids( $id, $payload );
32 }
33
34 /** Persist customer tax IDs after recovery. */
35 public function after_recovery( int $id, array $payload ): void {
36 $this->write_tax_ids( $id, $payload );
37 }
38
39 /** Persist customer tax IDs after update. */
40 public function after_update( int $id, array $payload, array $current, array $response_data, array $context ): void {
41 $this->write_tax_ids( $id, $payload );
42 }
43
44 /** The one tax-ID write every lifecycle phase shares; identity itself never carries tax ids. */
45 private function write_tax_ids( int $id, array $payload ): void {
46 if ( $id <= 0 || ! is_array( $payload['tax_ids'] ?? null ) ) {
47 return;
48 }
49 ( new Tax_Id_Writer() )->write_for_user( $id, $payload['tax_ids'] );
50 }
51
52 /** Remove customer-only fields from the wc/v3 forward. */
53 private function prepare_payload( array $payload ): array {
54 unset( $payload['tax_ids'] );
55 return ( new Order_Write_Payload() )->without_empty_billing_email( $payload );
56 }
57 }
58