Back to PhocacartOrder class

Method saveOrderProductDiscounts

public
saveOrderProductDiscounts
(mixed $orderProductId, mixed $productId, mixed $orderId, mixed $k, mixed $fullItems)

Method saveOrderProductDiscounts - Source code

public function saveOrderProductDiscounts($orderProductId, $productId, $orderId, $k, $fullItems)
{
    $db = Factory::getDBO();
    // REWARD DIVIDED INTO PRODUCTS
    if (isset($fullItems[5][$k]['rewardproduct']) && $fullItems[5][$k]['rewardproduct'] == 1) {
        //$row = JTable::getInstance('PhocacartOrderProductDiscounts', 'Table', array());
        $query = ' DELETE FROM #__phocacart_order_product_discounts WHERE order_id = ' . (int) $orderId . ' AND order_product_id = ' . (int) $orderProductId . ' AND product_id = ' . (int) $productId . ' AND type = 5';
        $db->setQuery($query);
        $db->execute();
        $amount = $fullItems[5][$k]['netto'];
        $netto = $fullItems[5][$k]['netto'];
        $brutto = $fullItems[5][$k]['brutto'];
        $tax = $fullItems[5][$k]['tax'];
        $final = $fullItems[5][$k]['final'];
        $quantity = $fullItems[5][$k]['quantity'];
        $catid = $fullItems[5][$k]['catid'];
        $query = ' INSERT INTO #__phocacart_order_product_discounts (order_id, product_id, order_product_id, discount_id, product_id_key, category_id, type, title, amount, netto, brutto, tax, final, quantity, published)' . ' VALUES (' . (int) $orderId . ', ' . (int) $productId . ', ' . (int) $orderProductId . ', ' . 0 . ', ' . $db->quote($k) . ', ' . (int) $catid . ', 5, ' . $db->quote($fullItems[5][$k]['rewardproducttitle']) . ', ' . $amount . ', ' . $netto . ', ' . $brutto . ', ' . $tax . ', ' . $final . ', ' . (int) $quantity . ', 0)';
        $db->setQuery($query);
        $db->execute();
    }
    // DISCOUNT PRODUCTS
    if (isset($fullItems[2][$k]['discountproduct']) && $fullItems[2][$k]['discountproduct'] == 1) {
        //$row = JTable::getInstance('PhocacartOrderProductDiscounts', 'Table', array());
        $query = ' DELETE FROM #__phocacart_order_product_discounts WHERE order_id = ' . (int) $orderId . ' AND order_product_id = ' . (int) $orderProductId . ' AND product_id = ' . (int) $productId . ' AND type = 2';
        $db->setQuery($query);
        $db->execute();
        $amount = $fullItems[2][$k]['netto'];
        $netto = $fullItems[2][$k]['netto'];
        $brutto = $fullItems[2][$k]['brutto'];
        $tax = $fullItems[2][$k]['tax'];
        $final = $fullItems[2][$k]['final'];
        $quantity = $fullItems[2][$k]['quantity'];
        $catid = $fullItems[3][$k]['catid'];
        $query = ' INSERT INTO #__phocacart_order_product_discounts (order_id, product_id, order_product_id, product_id_key, category_id, type, title, amount, netto, brutto, tax, final, quantity, published)' . ' VALUES (' . (int) $orderId . ', ' . (int) $productId . ', ' . (int) $orderProductId . ', ' . $db->quote($k) . ', ' . (int) $catid . ', 2, ' . $db->quote($fullItems[2][$k]['discountproducttitle']) . ', ' . $amount . ', ' . $netto . ', ' . $brutto . ', ' . $tax . ', ' . $final . ', ' . (int) $quantity . ', 0)';
        $db->setQuery($query);
        $db->execute();
    }
    // DISCOUNT CART DIVEDED INTO PRODUCTS
    if (isset($fullItems[3][$k]['discountcart']) && $fullItems[3][$k]['discountcart'] == 1) {
        //$row = JTable::getInstance('PhocacartOrderProductDiscounts', 'Table', array());
        $query = ' DELETE FROM #__phocacart_order_product_discounts WHERE order_id = ' . (int) $orderId . ' AND order_product_id = ' . (int) $orderProductId . ' AND product_id = ' . (int) $productId . ' AND type = 3';
        $db->setQuery($query);
        $db->execute();
        $amount = $fullItems[3][$k]['netto'];
        $netto = $fullItems[3][$k]['netto'];
        $brutto = $fullItems[3][$k]['brutto'];
        $tax = $fullItems[3][$k]['tax'];
        $final = $fullItems[3][$k]['final'];
        $quantity = $fullItems[3][$k]['quantity'];
        $catid = $fullItems[3][$k]['catid'];
        $query = ' INSERT INTO #__phocacart_order_product_discounts (order_id, product_id, order_product_id, discount_id, product_id_key, category_id, type, title, amount, netto, brutto, tax, final, quantity, published)' . ' VALUES (' . (int) $orderId . ', ' . (int) $productId . ', ' . (int) $orderProductId . ', ' . (int) $fullItems[3][$k]['discountcartid'] . ', ' . $db->quote($k) . ', ' . (int) $catid . ', 3, ' . $db->quote($fullItems[3][$k]['discountcarttitle']) . ', ' . $amount . ', ' . $netto . ', ' . $brutto . ', ' . $tax . ', ' . $final . ', ' . (int) $quantity . ', 0)';
        $db->setQuery($query);
        $db->execute();
    }
    // COUPON DIVIDED INTO PRODUCTS
    if (isset($fullItems[4][$k]['couponcart']) && $fullItems[4][$k]['couponcart'] == 1) {
        //$row = JTable::getInstance('PhocacartOrderProductDiscounts', 'Table', array());
        $query = ' DELETE FROM #__phocacart_order_product_discounts WHERE order_id = ' . (int) $orderId . ' AND order_product_id = ' . (int) $orderProductId . ' AND product_id = ' . (int) $productId . ' AND type = 4';
        $db->setQuery($query);
        $db->execute();
        $amount = $fullItems[4][$k]['netto'];
        $netto = $fullItems[4][$k]['netto'];
        $brutto = $fullItems[4][$k]['brutto'];
        $tax = $fullItems[4][$k]['tax'];
        $final = $fullItems[4][$k]['final'];
        $quantity = $fullItems[4][$k]['quantity'];
        $catid = $fullItems[4][$k]['catid'];
        $query = ' INSERT INTO #__phocacart_order_product_discounts (order_id, product_id, order_product_id, discount_id, product_id_key, category_id, type, title, amount, netto, brutto, tax, final, quantity, published)' . ' VALUES (' . (int) $orderId . ', ' . (int) $productId . ', ' . (int) $orderProductId . ', ' . (int) $fullItems[4][$k]['couponcartid'] . ', ' . $db->quote($k) . ', ' . (int) $catid . ', 4, ' . $db->quote($fullItems[4][$k]['couponcarttitle']) . ', ' . $amount . ', ' . $netto . ', ' . $brutto . ', ' . $tax . ', ' . $final . ', ' . (int) $quantity . ', 0)';
        $db->setQuery($query);
        $db->execute();
    }
    return true;
}