Skip to content

Commit

Permalink
Fix: Redução de linhas da função build_product_from_order_item com a …
Browse files Browse the repository at this point in the history
…criação de uma nova função chamada build_product_from_order_item_bill
  • Loading branch information
lucastgama committed Jul 5, 2024
1 parent d669df8 commit 70c4d68
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/utils/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
*
Expand Down

0 comments on commit 70c4d68

Please sign in to comment.