Esempio n. 1
0
 /**
  * Filter products based on current vendor
  *
  * @param unknown $orders
  *
  * @return unknown
  */
 public function filter_products($orders)
 {
     $products = WCV_Vendors::get_vendor_products($this->vendor_id);
     $ids = array();
     foreach ($products as $product) {
         $ids[] = $product->ID;
     }
     foreach ($orders as $key => $order) {
         if (!in_array($order->product_id, $ids)) {
             unset($orders[$key]);
             continue;
         } else {
             if (!empty($order->line_total)) {
                 $orders[$key]->line_total = WCV_Commission::calculate_commission($order->line_total, $order->product_id, $order);
             }
         }
     }
     return $orders;
 }
Esempio n. 2
0
 /**
  *
  *
  * @param unknown $order
  * @param unknown $group (optional)
  *
  * @return unknown
  */
 public static function get_vendor_dues_from_order($order, $group = true)
 {
     global $woocommerce;
     $give_tax = WC_Vendors::$pv_options->get_option('give_tax');
     $give_shipping = WC_Vendors::$pv_options->get_option('give_shipping');
     $receiver = array();
     $shipping_given = 0;
     $tax_given = 0;
     WCV_Shipping::$pps_shipping_costs = array();
     foreach ($order->get_items() as $key => $product) {
         $product_id = !empty($product['variation_id']) ? $product['variation_id'] : $product['product_id'];
         $author = WCV_Vendors::get_vendor_from_product($product_id);
         $give_tax_override = get_user_meta($author, 'wcv_give_vendor_tax', true);
         $give_shipping_override = get_user_meta($author, 'wcv_give_vendor_shipping', true);
         $is_vendor = WCV_Vendors::is_vendor($author);
         $commission = $is_vendor ? WCV_Commission::calculate_commission($product['line_subtotal'], $product_id, $order) : 0;
         $tax = !empty($product['line_tax']) ? (double) $product['line_tax'] : 0;
         // Check if shipping is enabled
         if (get_option('woocommerce_calc_shipping') === 'no') {
             $shipping = 0;
             $shipping_tax = 0;
         } else {
             $shipping_costs = WCV_Shipping::get_shipping_due($order->id, $product, $author);
             $shipping = $shipping_costs['amount'];
             $shipping_tax = $shipping_costs['tax'];
         }
         // Add line item tax and shipping taxes together
         $total_tax = (double) $tax + (double) $shipping_tax;
         // Tax override on a per vendor basis
         if ($give_tax_override) {
             $give_tax = true;
         }
         // Shipping override
         if ($give_shipping_override) {
             $give_shipping = true;
         }
         if ($is_vendor) {
             $shipping_given += $give_shipping ? $shipping : 0;
             $tax_given += $give_tax ? $total_tax : 0;
             $give = 0;
             $give += !empty($receiver[$author]['total']) ? $receiver[$author]['total'] : 0;
             $give += $give_shipping ? $shipping : 0;
             $give += $commission;
             $give += $give_tax ? $total_tax : 0;
             if ($group) {
                 $receiver[$author] = array('vendor_id' => (int) $author, 'commission' => !empty($receiver[$author]['commission']) ? $receiver[$author]['commission'] + $commission : $commission, 'shipping' => $give_shipping ? !empty($receiver[$author]['shipping']) ? $receiver[$author]['shipping'] + $shipping : $shipping : 0, 'tax' => $give_tax ? !empty($receiver[$author]['tax']) ? $receiver[$author]['tax'] + $total_tax : $total_tax : 0, 'qty' => !empty($receiver[$author]['qty']) ? $receiver[$author]['qty'] + $product['qty'] : $product['qty'], 'total' => $give);
             } else {
                 $receiver[$author][$key] = array('vendor_id' => (int) $author, 'product_id' => $product_id, 'commission' => $commission, 'shipping' => $give_shipping ? $shipping : 0, 'tax' => $give_tax ? $total_tax : 0, 'qty' => $product['qty'], 'total' => ($give_shipping ? $shipping : 0) + $commission + ($give_tax ? $total_tax : 0));
             }
         }
         $admin_comm = $product['line_subtotal'] - $commission;
         if ($group) {
             $receiver[1] = array('vendor_id' => 1, 'qty' => !empty($receiver[1]['qty']) ? $receiver[1]['qty'] + $product['qty'] : $product['qty'], 'commission' => !empty($receiver[1]['commission']) ? $receiver[1]['commission'] + $admin_comm : $admin_comm, 'total' => !empty($receiver[1]) ? $receiver[1]['total'] + $admin_comm : $admin_comm);
         } else {
             $receiver[1][$key] = array('vendor_id' => 1, 'product_id' => $product_id, 'commission' => $admin_comm, 'shipping' => 0, 'tax' => 0, 'qty' => $product['qty'], 'total' => $admin_comm);
         }
     }
     // Add remainders on end to admin
     $discount = $order->get_total_discount();
     $shipping = $order->order_shipping - $shipping_given;
     $tax = round($order->order_tax + $order->order_shipping_tax - $tax_given, 2);
     $total = $tax + $shipping - $discount;
     if ($group) {
         $receiver[1]['commission'] = $receiver[1]['commission'] - $discount;
         $receiver[1]['shipping'] = $shipping;
         $receiver[1]['tax'] = $tax;
         $receiver[1]['total'] += $total;
     } else {
         $receiver[1][$key]['commission'] = $receiver[1][$key]['commission'] - $discount;
         $receiver[1][$key]['shipping'] = $order->order_shipping - $shipping_given;
         $receiver[1][$key]['tax'] = $tax;
         $receiver[1][$key]['total'] += $total;
     }
     // Reset the array keys
     // $receivers = array_values( $receiver );
     return $receiver;
 }
Esempio n. 3
0
 /**
  * Split order into vendor orders (when applicable) after checkout
  *
  * @since 
  * @param int $order_id
  * @return void
  */
 public static function create_child_orders($order_id)
 {
     $order = wc_get_order($order_id);
     $items = $order->get_items();
     $vendor_items = array();
     foreach ($items as $item_id => $item) {
         if (isset($item['product_id']) && $item['product_id'] !== 0) {
             // check if product is from vendor
             $product_author = get_post_field('post_author', $item['product_id']);
             if (WCV_Vendors::is_vendor($product_author)) {
                 $vendor_items[$product_author][$item_id] = array('item_id' => $item_id, 'qty' => $item['qty'], 'total' => $item['line_total'], 'subtotal' => $item['line_subtotal'], 'tax' => $item['line_tax'], 'subtotal_tax' => $item['line_subtotal_tax'], 'tax_data' => maybe_unserialize($item['line_tax_data']), 'commission' => WCV_Commission::calculate_commission($item['line_subtotal'], $item['product_id'], $order, $item['qty']));
             }
         }
     }
     foreach ($vendor_items as $vendor_id => $items) {
         if (!empty($items)) {
             $vendor_order = WCV_Vendors::create_vendor_order(array('order_id' => $order_id, 'vendor_id' => $vendor_id, 'line_items' => $items));
         }
     }
 }
 /**
  *
  *
  * @param unknown $items
  * @param unknown $order
  *
  * @return unknown
  */
 function check_items($items, $order)
 {
     foreach ($items as $key => $product) {
         //  If this is a line item
         if ($product['type'] == 'line_item') {
             $author = WCV_Vendors::get_vendor_from_product($product['product_id']);
             if ($this->current_vendor != $author) {
                 unset($items[$key]);
                 continue;
             } else {
                 $commission_due = WCV_Commission::calculate_commission($product['line_subtotal'], $product['product_id'], $order);
                 $items[$key]['line_subtotal'] = $commission_due;
                 $items[$key]['line_total'] = $commission_due;
                 // Don't display tax if give tax is not enabled.
                 // if ( !WC_Vendors::$pv_options->get_option( 'give_tax' ) ) {
                 // 	unset($items[ $key ][ 'line_tax' ]) ;
                 // }
             }
         }
     }
     return $items;
 }
 /**
  *
  *
  * @param unknown $items
  * @param unknown $order
  *
  * @return unknown
  */
 function check_items($items, $order)
 {
     $settings = get_option('woocommerce_vendor_new_order_settings');
     foreach ($items as $key => $product) {
         //  If this is a line item
         if ($product['type'] == 'line_item') {
             $author = WCV_Vendors::get_vendor_from_product($product['product_id']);
             if ($this->current_vendor != $author) {
                 unset($items[$key]);
                 continue;
             } else {
                 // If display commission is ticked show this otherwise show the full price.
                 if ('yes' == $settings['commission_display']) {
                     $commission_due = WCV_Commission::calculate_commission($product['line_subtotal'], $product['product_id'], $order, $product['qty']);
                     $items[$key]['line_subtotal'] = $commission_due;
                     $items[$key]['line_total'] = $commission_due;
                     // Don't display tax if give tax is not enabled.
                     if (!WC_Vendors::$pv_options->get_option('give_tax')) {
                         unset($items[$key]['line_tax']);
                     }
                 }
             }
         }
     }
     return $items;
 }
 /**
  *
  *
  * @param unknown $items
  * @param unknown $order
  *
  * @return unknown
  */
 function check_items($items, $order)
 {
     foreach ($items as $key => $product) {
         //  If this is a line item
         if ($product['type'] == 'line_item') {
             $author = WCV_Vendors::get_vendor_from_product($product['product_id']);
             if ($this->current_vendor != $author) {
                 unset($items[$key]);
                 continue;
             } else {
                 $commission_due = WCV_Commission::calculate_commission($product['line_subtotal'], $product['product_id'], $order);
                 $items[$key]['line_subtotal'] = $commission_due;
                 $items[$key]['line_total'] = $commission_due;
                 unset($items[$key]['line_tax']);
             }
         }
     }
     return $items;
 }