Code Duplication    Length = 65-65 lines in 2 locations

includes/api/class-wc-rest-order-refunds-controller.php 1 location

@@ 136-200 (lines=65) @@
133
		);
134
135
		// Add line items.
136
		foreach ( $refund->get_items() as $item_id => $item ) {
137
			$product      = $refund->get_product_from_item( $item );
138
			$product_id   = 0;
139
			$variation_id = 0;
140
			$product_sku  = null;
141
142
			// Check if the product exists.
143
			if ( is_object( $product ) ) {
144
				$product_id   = $product->id;
145
				$variation_id = $product->variation_id;
146
				$product_sku  = $product->get_sku();
147
			}
148
149
			$meta = new WC_Order_Item_Meta( $item, $product );
150
151
			$item_meta = array();
152
153
			$hideprefix = 'true' === $request['all_item_meta'] ? null : '_';
154
155
			foreach ( $meta->get_formatted( $hideprefix ) as $meta_key => $formatted_meta ) {
156
				$item_meta[] = array(
157
					'key'   => $formatted_meta['key'],
158
					'label' => $formatted_meta['label'],
159
					'value' => $formatted_meta['value'],
160
				);
161
			}
162
163
			$line_item = array(
164
				'id'           => $item_id,
165
				'name'         => $item['name'],
166
				'sku'          => $product_sku,
167
				'product_id'   => (int) $product_id,
168
				'variation_id' => (int) $variation_id,
169
				'quantity'     => wc_stock_amount( $item['qty'] ),
170
				'tax_class'    => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '',
171
				'price'        => wc_format_decimal( $refund->get_item_total( $item, false, false ), $dp ),
172
				'subtotal'     => wc_format_decimal( $refund->get_line_subtotal( $item, false, false ), $dp ),
173
				'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ),
174
				'total'        => wc_format_decimal( $refund->get_line_total( $item, false, false ), $dp ),
175
				'total_tax'    => wc_format_decimal( $item['line_tax'], $dp ),
176
				'taxes'        => array(),
177
				'meta'         => $item_meta,
178
			);
179
180
			$item_line_taxes = maybe_unserialize( $item['line_tax_data'] );
181
			if ( isset( $item_line_taxes['total'] ) ) {
182
				$line_tax = array();
183
184
				foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) {
185
					$line_tax[ $tax_rate_id ] = array(
186
						'id'       => $tax_rate_id,
187
						'total'    => $tax,
188
						'subtotal' => '',
189
					);
190
				}
191
192
				foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) {
193
					$line_tax[ $tax_rate_id ]['subtotal'] = $tax;
194
				}
195
196
				$line_item['taxes'] = array_values( $line_tax );
197
			}
198
199
			$data['line_items'][] = $line_item;
200
		}
201
202
		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
203
		$data    = $this->add_additional_fields_to_object( $data, $request );

includes/api/class-wc-rest-orders-controller.php 1 location

@@ 159-223 (lines=65) @@
156
		$data['shipping'] = $order->get_address( 'shipping' );
157
158
		// Add line items.
159
		foreach ( $order->get_items() as $item_id => $item ) {
160
			$product      = $order->get_product_from_item( $item );
161
			$product_id   = 0;
162
			$variation_id = 0;
163
			$product_sku  = null;
164
165
			// Check if the product exists.
166
			if ( is_object( $product ) ) {
167
				$product_id   = $product->id;
168
				$variation_id = $product->variation_id;
169
				$product_sku  = $product->get_sku();
170
			}
171
172
			$meta = new WC_Order_Item_Meta( $item, $product );
173
174
			$item_meta = array();
175
176
			$hideprefix = 'true' === $request['all_item_meta'] ? null : '_';
177
178
			foreach ( $meta->get_formatted( $hideprefix ) as $meta_key => $formatted_meta ) {
179
				$item_meta[] = array(
180
					'key'   => $formatted_meta['key'],
181
					'label' => $formatted_meta['label'],
182
					'value' => $formatted_meta['value'],
183
				);
184
			}
185
186
			$line_item = array(
187
				'id'           => $item_id,
188
				'name'         => $item['name'],
189
				'sku'          => $product_sku,
190
				'product_id'   => (int) $product_id,
191
				'variation_id' => (int) $variation_id,
192
				'quantity'     => wc_stock_amount( $item['qty'] ),
193
				'tax_class'    => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '',
194
				'price'        => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ),
195
				'subtotal'     => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ),
196
				'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ),
197
				'total'        => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ),
198
				'total_tax'    => wc_format_decimal( $item['line_tax'], $dp ),
199
				'taxes'        => array(),
200
				'meta'         => $item_meta,
201
			);
202
203
			$item_line_taxes = maybe_unserialize( $item['line_tax_data'] );
204
			if ( isset( $item_line_taxes['total'] ) ) {
205
				$line_tax = array();
206
207
				foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) {
208
					$line_tax[ $tax_rate_id ] = array(
209
						'id'       => $tax_rate_id,
210
						'total'    => $tax,
211
						'subtotal' => '',
212
					);
213
				}
214
215
				foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) {
216
					$line_tax[ $tax_rate_id ]['subtotal'] = $tax;
217
				}
218
219
				$line_item['taxes'] = array_values( $line_tax );
220
			}
221
222
			$data['line_items'][] = $line_item;
223
		}
224
225
		// Add taxes.
226
		foreach ( $order->get_items( 'tax' ) as $key => $tax ) {