From 70c4d68195480939941fe5717ac6691f6c5c534e Mon Sep 17 00:00:00 2001 From: Lucas Gama Date: Fri, 5 Jul 2024 12:56:57 -0300 Subject: [PATCH] =?UTF-8?q?Fix:=20Redu=C3=A7=C3=A3o=20de=20linhas=20da=20f?= =?UTF-8?q?un=C3=A7=C3=A3o=20build=5Fproduct=5Ffrom=5Forder=5Fitem=20com?= =?UTF-8?q?=20a=20cria=C3=A7=C3=A3o=20de=20uma=20nova=20fun=C3=A7=C3=A3o?= =?UTF-8?q?=20chamada=20build=5Fproduct=5Ffrom=5Forder=5Fitem=5Fbill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/PaymentProcessor.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/utils/PaymentProcessor.php b/src/utils/PaymentProcessor.php index 0e2be816..6351c411 100644 --- a/src/utils/PaymentProcessor.php +++ b/src/utils/PaymentProcessor.php @@ -664,20 +664,7 @@ protected function apply_remainder($remainder, $full_price, &$new_order_item) protected function build_product_from_order_item($order_type, $order_items) { if ('bill' === $order_type) { - foreach ($order_items as $key => $order_item) { - $product = $order_item->get_product(); - $order_items[$key]['type'] = 'product'; - $product_id = $product->get_id(); - if($this->is_variable($product)){ - $product_id = $order_item['product_id']; - } - $vindi_id = get_post_meta($product_id,'vindi_product_id',true); - if(!$vindi_id){ - $vindi_id = $this->routes->findProductByCode('WC-' . $product_id)['id']; - } - $order_items[$key]['vindi_id'] = $vindi_id; - $order_items[$key]['price'] = (float) $order_items[$key]['subtotal'] / $order_items[$key]['qty']; - } + $order_items = $this->build_product_from_order_item_bill($order_items); return $order_items; } @@ -700,6 +687,25 @@ protected function build_product_from_order_item($order_type, $order_items) return $order_items; } + protected function build_product_from_order_item_bill($order_items) + { + foreach ($order_items as $key => $order_item) { + $product = $order_item->get_product(); + $order_items[$key]['type'] = 'product'; + $product_id = $product->get_id(); + if ($this->is_variable($product)) { + $product_id = $order_item['product_id']; + } + $vindi_id = get_post_meta($product_id, 'vindi_product_id', true); + if (!$vindi_id) { + $vindi_id = $this->routes->findProductByCode('WC-' . $product_id)['id']; + } + $order_items[$key]['vindi_id'] = $vindi_id; + $order_items[$key]['price'] = (float) $order_items[$key]['subtotal'] / $order_items[$key]['qty']; + } + return $order_items; + } + /** * Create the sign-up fee item to be added to the bill. *