114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Retrieve standard bundles from order
|
|
*
|
|
* @param int|WC_Order $order
|
|
*
|
|
* @return array
|
|
*/
|
|
function wiaas_get_order_standard_bundle_items($order) {
|
|
|
|
if (is_numeric($order)) {
|
|
|
|
$order = wc_get_order($order);
|
|
}
|
|
|
|
$items = $order->get_items();
|
|
|
|
$standard_bundle_items = array();
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if (isset($item['wiaas_standard_package'])) {
|
|
|
|
$standard_bundle_items[] = $item;
|
|
}
|
|
}
|
|
|
|
return $standard_bundle_items;
|
|
}
|
|
|
|
/**
|
|
* Retrieve order summary data for procurement order for suppliers
|
|
*
|
|
* @param int $order_id
|
|
*
|
|
* @return array
|
|
*/
|
|
function wiaas_get_order_procurement_info($order_id) {
|
|
|
|
$order = wc_get_order($order_id);
|
|
|
|
$order_items = $order->get_items();
|
|
|
|
$order_suppliers_info = $order->get_meta('_wiaas_suppliers');
|
|
|
|
$data = array();
|
|
|
|
foreach ($order_items as $order_item_id => $order_item) {
|
|
|
|
$category = $order_item['_wiaas_category'];
|
|
$supplier_organization_id = $order_item['wiaas_supplier_organization_id'];
|
|
$supplier_info = $order_suppliers_info[$supplier_organization_id];
|
|
|
|
if (empty($category)) {
|
|
|
|
continue;
|
|
}
|
|
|
|
$data[$category] ?: array();
|
|
|
|
// get price and quantity
|
|
$single_product_item_cost = floatval($order_item['wiaas_product_price']);
|
|
|
|
$quantity = absint($order_item['quantity']);
|
|
$total_price = $quantity * $single_product_item_cost;
|
|
|
|
$data[$category][] = array(
|
|
'Name' => $order_item->get_name(),
|
|
'Category' => ucfirst(strtolower($category)),
|
|
'Manufacturer Product No' => $order_item['wiaas_manufacturer_product_no'],
|
|
'Supplier Product No' => $order_item['wiaas_supplier_product_no'],
|
|
'Units' => $quantity,
|
|
'Price' => $total_price,
|
|
'Supplier Company' => $supplier_info['name'],
|
|
'Supplier VAT' => $supplier_info['vat_code'],
|
|
'Supplier Phone' => $supplier_info['phone'],
|
|
'Supplier Email' => $supplier_info['email'],
|
|
);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Retrieve delivery supplier organizations for order which does not include installation providers
|
|
*
|
|
* @param int $order_id
|
|
*
|
|
* @return array
|
|
*/
|
|
function wiaas_get_order_delivery_suppliers($order_id) {
|
|
|
|
$order = wc_get_order($order_id);
|
|
|
|
$supplier_organizations = $order->get_meta('_wiaas_suppliers', true);
|
|
|
|
$delivery_supplier_organizations = array();
|
|
|
|
$order_items = $order->get_items();
|
|
|
|
foreach ($order_items as $order_item_id => $order_item) {
|
|
|
|
$supplier_organization_id = $order_item['wiaas_supplier_organization_id'];
|
|
|
|
if (! empty($supplier_organization_id) && $order_item['wiaas_category'] !== 'installation' &&
|
|
empty($delivery_supplier_organizations[$supplier_organization_id])) {
|
|
|
|
$delivery_supplier_organizations[$supplier_organization_id] = $supplier_organizations[$supplier_organization_id];
|
|
}
|
|
}
|
|
|
|
return $delivery_supplier_organizations;
|
|
} |