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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / DataStores / Orders / OrdersTableRefundDataStore.php
woocommerce / src / Internal / DataStores / Orders Last commit date
CustomOrdersTableController.php 3 years ago DataSynchronizer.php 3 years ago OrdersTableDataStore.php 3 years ago OrdersTableDataStoreMeta.php 3 years ago OrdersTableFieldQuery.php 3 years ago OrdersTableMetaQuery.php 3 years ago OrdersTableQuery.php 3 years ago OrdersTableRefundDataStore.php 3 years ago OrdersTableSearchQuery.php 3 years ago
OrdersTableRefundDataStore.php
195 lines
1 <?php
2 /**
3 * Order refund data store. Refunds are based on orders (essentially negative orders) but there is slight difference in how we save them.
4 * For example, order save hooks etc can't be fired when saving refund, so we need to do it a separate datastore.
5 */
6
7 namespace Automattic\WooCommerce\Internal\DataStores\Orders;
8
9 /**
10 * Class OrdersTableRefundDataStore.
11 */
12 class OrdersTableRefundDataStore extends OrdersTableDataStore {
13
14 /**
15 * We do not have and use all the getters and setters from OrderTableDataStore, so we only select the props we actually need.
16 *
17 * @var \string[][]
18 */
19 protected $operational_data_column_mapping = array(
20 'id' => array( 'type' => 'int' ),
21 'order_id' => array( 'type' => 'int' ),
22 'woocommerce_version' => array(
23 'type' => 'string',
24 'name' => 'version',
25 ),
26 'prices_include_tax' => array(
27 'type' => 'bool',
28 'name' => 'prices_include_tax',
29 ),
30 'coupon_usages_are_counted' => array(
31 'type' => 'bool',
32 'name' => 'recorded_coupon_usage_counts',
33 ),
34 'shipping_tax_amount' => array(
35 'type' => 'decimal',
36 'name' => 'shipping_tax',
37 ),
38 'shipping_total_amount' => array(
39 'type' => 'decimal',
40 'name' => 'shipping_total',
41 ),
42 'discount_tax_amount' => array(
43 'type' => 'decimal',
44 'name' => 'discount_tax',
45 ),
46 'discount_total_amount' => array(
47 'type' => 'decimal',
48 'name' => 'discount_total',
49 ),
50 );
51
52 /**
53 * Delete a refund order from database.
54 *
55 * @param \WC_Order $refund Refund object to delete.
56 * @param array $args Array of args to pass to the delete method.
57 *
58 * @return void
59 */
60 public function delete( &$refund, $args = array() ) {
61 $refund_id = $refund->get_id();
62 if ( ! $refund_id ) {
63 return;
64 }
65
66 $this->delete_order_data_from_custom_order_tables( $refund_id );
67 $refund->set_id( 0 );
68
69 // If this datastore method is called while the posts table is authoritative, refrain from deleting post data.
70 if ( ! is_a( $refund->get_data_store(), self::class ) ) {
71 return;
72 }
73
74 // Delete the associated post, which in turn deletes order items, etc. through {@see WC_Post_Data}.
75 // Once we stop creating posts for orders, we should do the cleanup here instead.
76 wp_delete_post( $refund_id );
77 }
78
79 /**
80 * Read a refund object from custom tables.
81 *
82 * @param \WC_Abstract_Order $refund Refund object.
83 *
84 * @return void
85 */
86 public function read( &$refund ) {
87 parent::read( $refund );
88 $this->set_refund_props( $refund );
89 }
90
91 /**
92 * Read multiple refund objects from custom tables.
93 *
94 * @param \WC_Order $refunds Refund objects.
95 */
96 public function read_multiple( &$refunds ) {
97 parent::read_multiple( $refunds );
98 foreach ( $refunds as $refund ) {
99 $this->set_refund_props( $refund );
100 }
101 }
102
103 /**
104 * Helper method to set refund props.
105 *
106 * @param \WC_Order $refund Refund object.
107 */
108 private function set_refund_props( $refund ) {
109 $refund->set_props(
110 array(
111 'amount' => $refund->get_meta( '_refund_amount', true ),
112 'refunded_by' => $refund->get_meta( '_refunded_by', true ),
113 'refunded_payment' => wc_string_to_bool( $refund->get_meta( '_refunded_payment', true ) ),
114 'reason' => $refund->get_meta( '_refund_reason', true ),
115 )
116 );
117 }
118
119 /**
120 * Method to create a refund in the database.
121 *
122 * @param \WC_Abstract_Order $refund Refund object.
123 */
124 public function create( &$refund ) {
125 $refund->set_status( 'completed' ); // Refund are always marked completed.
126 $this->persist_save( $refund );
127 }
128
129 /**
130 * Update refund in database.
131 *
132 * @param \WC_Order $refund Refund object.
133 */
134 public function update( &$refund ) {
135 $this->persist_updates( $refund );
136 }
137
138 /**
139 * Helper method that updates post meta based on an refund object.
140 * Mostly used for backwards compatibility purposes in this datastore.
141 *
142 * @param \WC_Order $refund Refund object.
143 */
144 public function update_order_meta( &$refund ) {
145 parent::update_order_meta( $refund );
146
147 // Update additional props.
148 $updated_props = array();
149 $meta_key_to_props = array(
150 '_refund_amount' => 'amount',
151 '_refunded_by' => 'refunded_by',
152 '_refunded_payment' => 'refunded_payment',
153 '_refund_reason' => 'reason',
154 );
155
156 $props_to_update = $this->get_props_to_update( $refund, $meta_key_to_props );
157 foreach ( $props_to_update as $meta_key => $prop ) {
158 $value = $refund->{"get_$prop"}( 'edit' );
159 $refund->update_meta_data( $meta_key, $value );
160 $updated_props[] = $prop;
161 }
162
163 /**
164 * Fires after updating meta for a order refund.
165 *
166 * @since 2.7.0
167 */
168 do_action( 'woocommerce_order_refund_object_updated_props', $refund, $updated_props );
169 }
170
171 /**
172 * Get a title for the new post type.
173 *
174 * @return string
175 */
176 protected function get_post_title() {
177 return sprintf(
178 /* translators: %s: Order date */
179 __( 'Refund &ndash; %s', 'woocommerce' ),
180 ( new \DateTime( 'now' ) )->format( _x( 'M d, Y @ h:i A', 'Order date parsed by DateTime::format', 'woocommerce' ) ) // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.UnorderedPlaceholdersText
181 );
182 }
183
184
185 /**
186 * Returns data store object to use backfilling.
187 *
188 * @return \WC_Order_Refund_Data_Store_CPT
189 */
190 protected function get_post_data_store_for_backfill() {
191 return new \WC_Order_Refund_Data_Store_CPT();
192 }
193
194 }
195