Example #1
0
    protected function addOrder($Data, $clientId = 0, $orginalOrderId = NULL)
    {
        $selectedOption = Session::getActiveDispatchmethodOption();
        $globalPrice = 0;
        $globalNetto = 0;
        $price = 0;
        $sql = 'INSERT INTO `order` (
					price, 
					dispatchmethodprice, 
					globalprice, 
					dispatchmethodname, 
					paymentmethodname, 
					orderstatusid,
					dispatchmethodid, 
					paymentmethodid, 
					clientid, 
					globalpricenetto, 
					viewid, 
					pricebeforepromotion, 
					currencyid, 
					currencysymbol, 
					currencyrate,
					rulescartid,
					sessionid,
					customeropinion
				)
				VALUES (
					:price, 
					:dispatchmethodprice, 
					:globalprice, 
					:dispatchmethodname, 
					:paymentmethodname,
					(SELECT idorderstatus FROM orderstatus WHERE `default` = 1), 
					:dispatchmethodid, 
					:paymentmethodid, 
					:clientid, 
					:globalpricenetto, 
					:viewid, 
					:pricebeforepromotion, 
					:currencyid, 
					:currencysymbol, 
					:currencyrate,
					:rulescartid,
					:sessionid,
					:customeropinion
				)';
        $stmt = Db::getInstance()->prepare($sql);
        $stmt->bindValue('dispatchmethodprice', $Data['dispatchmethod']['dispatchmethodcost']);
        $stmt->bindValue('dispatchmethodname', $Data['dispatchmethod']['dispatchmethodname']);
        $stmt->bindValue('dispatchmethodid', $Data['dispatchmethod']['dispatchmethodid']);
        $stmt->bindValue('paymentmethodname', $Data['payment']['paymentmethodname']);
        $stmt->bindValue('paymentmethodid', $Data['payment']['idpaymentmethod']);
        $stmt->bindValue('clientid', $clientId);
        $stmt->bindValue('sessionid', session_id());
        $stmt->bindValue('customeropinion', $Data['customeropinion']);
        $shopCurrency = Session::getActiveShopCurrencyId();
        $clientCurrency = Session::getActiveCurrencyId();
        if ($shopCurrency !== $clientCurrency) {
            $stmt->bindValue('currencyid', $clientCurrency);
            $stmt->bindValue('currencysymbol', Session::getActiveCurrencySymbol());
            $stmt->bindValue('currencyrate', Session::getActiveCurrencyRate());
        } else {
            $stmt->bindValue('currencyid', $shopCurrency);
            $stmt->bindValue('currencysymbol', $this->layer['currencysymbol']);
            $stmt->bindValue('currencyrate', Session::getActiveCurrencyRate());
        }
        if (isset($Data['priceWithDispatchMethodPromo']) && $Data['priceWithDispatchMethodPromo'] > 0) {
            $stmt->bindValue('pricebeforepromotion', $Data['priceWithDispatchMethod']);
            if ($globalPrice == 0) {
                $globalPrice = $Data['priceWithDispatchMethodPromo'];
                $globalNetto = $Data['priceWithDispatchMethodNettoPromo'];
                $price = $Data['globalPricePromo'];
            }
        } else {
            $stmt->bindValue('pricebeforepromotion', 0);
        }
        if ($globalPrice == 0 || $globalNetto == 0) {
            $globalPrice = $Data['priceWithDispatchMethod'];
            $globalNetto = $Data['globalPriceWithoutVat'];
            $price = $Data['globalPrice'];
        }
        if (isset($Data['rulescartid']) && !empty($Data['rulescartid'])) {
            $stmt->bindValue('rulescartid', $Data['rulescartid']);
        } else {
            $stmt->bindValue('rulescartid', NULL);
        }
        $stmt->bindValue('globalprice', $globalPrice);
        $stmt->bindValue('globalpricenetto', $globalNetto);
        $stmt->bindValue('price', $price);
        $stmt->bindValue('viewid', Helper::getViewId());
        try {
            $stmt->execute();
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }
        return Db::getInstance()->lastInsertId();
    }