Ejemplo n.º 1
0
/**
 * Hook for modify shippings groups
 *
 * @param array $cart Cart array
 * @param array $allow
 * @param array $product_groups Products groups from cart
 */
function fn_suppliers_order_notification(&$order_info, &$order_statuses, &$force_notification)
{
    $status_params = $order_statuses[$order_info['status']]['params'];
    $notify_supplier = isset($force_notification['S']) ? $force_notification['S'] : (!empty($status_params['notify_supplier']) && $status_params['notify_supplier'] == 'Y' ? true : false);
    if ($notify_supplier == true) {
        $suppliers = array();
        if (!empty($order_info['product_groups'])) {
            foreach ($order_info['product_groups'] as $key_group => $group) {
                foreach ($group['products'] as $cart_id => $product) {
                    $supplier_id = fn_get_product_supplier_id($product['product_id']);
                    if (!empty($supplier_id) && empty($suppliers[$supplier_id])) {
                        $rate = 0;
                        foreach ($group['chosen_shippings'] as $shipping) {
                            $rate += $shipping['rate'];
                        }
                        $suppliers[$supplier_id] = array('name' => fn_get_supplier_name($supplier_id), 'company_id' => $group['company_id'], 'cost' => $rate, 'shippings' => $group['chosen_shippings']);
                    }
                    if (!empty($supplier_id)) {
                        $suppliers[$supplier_id]['products'][$cart_id] = $product;
                    }
                }
            }
        }
        foreach ($suppliers as $supplier_id => $supplier) {
            $lang = fn_get_company_language($supplier['company_id']);
            $order = $order_info;
            $order['products'] = $supplier['products'];
            $supplier['data'] = fn_get_supplier_data($supplier_id);
            if (!empty($supplier['shippings'])) {
                if (!empty($supplier['data']['shippings'])) {
                    $shippings = array();
                    foreach ($supplier['shippings'] as $shipping) {
                        if (!isset($shippings[$shipping['group_name']])) {
                            $shippings[$shipping['group_name']] = $shipping;
                        }
                    }
                    foreach ($shippings as $key => $shipping) {
                        if ($key != $supplier['name']) {
                            unset($shippings[$key]);
                            if ($supplier['cost'] > $shipping['rate']) {
                                $supplier['cost'] -= $shipping['rate'];
                            } else {
                                $supplier['cost'] = 0;
                            }
                        }
                    }
                    $supplier['shippings'] = array_values($shippings);
                } else {
                    $supplier['shippings'] = array();
                }
            }
            Mailer::sendMail(array('to' => $supplier['data']['email'], 'from' => 'company_orders_department', 'reply_to' => 'company_orders_department', 'data' => array('order_info' => $order, 'status_inventory' => $status_params['inventory'], 'supplier_id' => $supplier_id, 'supplier' => $supplier, 'order_status' => fn_get_status_data($order_info['status'], STATUSES_ORDER, $order_info['order_id'], $lang), 'profile_fields' => fn_get_profile_fields('I', '', $lang)), 'tpl' => 'addons/suppliers/notification.tpl'), 'A', $lang);
        }
    }
}
Ejemplo n.º 2
0
/**
 * Processes export field
 *
 * @param int $supplier_id
 * @return string Supplier name
 */
function fn_exim_get_supplier($product_id)
{
    $supplier_id = fn_get_product_supplier_id($product_id);
    return fn_get_supplier_name($supplier_id);
}