예제 #1
0
파일: html.php 프로젝트: sahartak/megamedia
/**
 * Calculates the data needed for the offer boxes
 *
 * @param array $request the request from the POST or the SESSIOn
 * @param array $locations list with locations with the units being delivered
 * @return array values to be used later on
 */
function html_offer_box($request, $locations)
{
    // Calculating prices
    $headers = product_feature_all(true);
    $rows = array();
    $product_prices = array();
    $variants = isset($request['VARIANT']) ? array_unique($request['VARIANT']) : array();
    $copies = array();
    $estimated_delivery = array();
    $estimated_production = array();
    $runs = array();
    // Getting the prices for each variant
    foreach ($variants as $index => $_product) {
        $product_prices[$_product] = product_get_all_prices($_product, $_SESSION['user']['PARTY_ID'], true);
        $copies[$_product] = product_assoc_get($_product, PRODUCT_ASSOC_PAIR, true);
    }
    // Getting the price of the pair products in this case the
    // copies it will be most probably be always the same case
    // where the copies are the procuts
    foreach ($copies as $_main_product => &$_pair_product) {
        $_pair_product[$_pair_product[0]['PRODUCT_ID']] = product_get_all_prices($_pair_product[0]['PRODUCT_ID'], $_SESSION['user']['PARTY_ID'], true);
    }
    $delivery = 0.0;
    $units = 0;
    if (!empty($request['MOTIVES'])) {
        foreach ($request['MOTIVES'] as $index => $_motive) {
            if ($_motive) {
                $new_row = array();
                foreach ($headers as $_header) {
                    $new_row[$_header] = $_motive * product_price_by_header($request['VARIANT'][$index], $product_prices[$request['VARIANT'][$index]]['FEATURES'], $_header);
                    $copy_price = product_price_by_header($copies[$request['VARIANT'][$index]][0]['PRODUCT_ID'], $copies[$request['VARIANT'][$index]][$copies[$request['VARIANT'][$index]][0]['PRODUCT_ID']]['FEATURES'], $_header);
                    $new_row[$_header] += $request['RUNS'][$index] * $copy_price;
                    $units += $request['RUNS'][$index];
                }
                // The mixed index prices is the lowest price of all production lines
                // so the customer can have some super nice and low price but first we
                // remove all prices that are 0-s
                foreach ($new_row as $_new_row_header => $_new_row) {
                    if (!$_new_row) {
                        unset($new_row[$_new_row_header]);
                    }
                }
                $new_row['MIXED'] = min($new_row);
                $rows[$index] = $new_row;
            }
        }
    }
    foreach ($locations as $_units) {
        $delivery += shipment_cost_estimate($_units);
    }
    // Adding the MIXED header to all calculations
    array_push($headers, 'MIXED');
    return array($headers, $rows, $variants, $copies, $delivery);
}
예제 #2
0
    }
}
// If the POST is emoty or there is no category then we resent
// the visitor back to the respective page because they came
// to this page following bad URL
if (empty($_POST) || $empty) {
    if (isset($_GET['PRODUCT_CATEGORY_ID']) && !empty($_GET['PRODUCT_CATEGORY_ID'])) {
        $url = sprintf('/orders/order?%s', http_build_query(array('PRODUCT_CATEGORY_ID' => $_GET['PRODUCT_CATEGORY_ID'], 'ERROR' => 'Please fill in the fields')));
    } else {
        $url = '/dashboard/dashboard';
    }
    header('location: ' . $url);
    exit;
}
$product = products_get_by_type($_GET['PRODUCT_CATEGORY_ID'], PRODUCT_VISUAL);
$assocs = product_assoc_get($product['PRODUCT_ID'], PRODUCT_ASSOC_VARIANT);
foreach ($_POST['RUNS'] as $_index => $_run) {
    if ($_run && !$_POST['MOTIVES'][$_index]) {
        $errors[] = 'There are runs whithout motives attached to them';
        break;
    }
}
if (!empty($assocs)) {
    foreach ($_POST['MOTIVES'] as $_index => $_motive) {
        if ($_motive && $_POST['RUNS'][$_index]) {
            if (!isset($_POST['VARIANT'][$_index])) {
                $errors[] = 'Please select variant type';
                break;
            }
        }
    }