public static function getProductsByOrderID($orderID) { if (!$orderID) { return array(); } self::$_msql = SafeMySQL::getInstance(); $sql = "\n\t\t\tSELECT\n\t\t\t\top.`order_product_id`,\n\t\t\t\top.`order_id`,\n\t\t\t\top.`product_id`,\n\t\t\t\top.`flags`,\n\t\t\t\top.`recurring_next`,\n\t\t\t\top.`discount_next`,\n\t\t\t\top.`shipping_id`,\n\t\t\t\top.`next_gateway_id`,\n\t\t\t\tp.`product_price`,\n\t\t\t\tp.`product_sku`,\n\t\t\t\tp.`product_name`\n\t\t\tFROM `orders_products` as op\n\t\t\tJOIN `products` as p on p.`product_id` = op.`product_id`\t\t\n\t\t\tWHERE `order_id`=?i"; $result = self::$_msql->getAll($sql, $orderID); if (!$result) { return array(); } $orderProductsArr = array(); foreach ($result as $item) { $t = new OrderProduct(); //$t->allFIelds = true; $t->fillFromEnterArray($item); $t->IsNewRecord = false; $orderProductsArr[] = $t; unset($t); } return $orderProductsArr; }
public function chargeBackSet($amount, $type = 30, $user_id = 0) { // we need to make sure the chargeback flag is set. if not, set flag and log it if (!$this->isFlag('chargeback')) { $this->addFlags('chargeback'); $this->save(false); $orderProducts = OrderProducts::getProductsByOrderID($this->order_id); foreach ($orderProducts as $orderProduct) { $orderProduct->removeFlags('recurring'); $orderProduct->save(); } OrderLog::createLog($user_id, $this->order_id, 11, 'chargeback'); } if (in_array($type, array(29, 30)) && $amount <= $this->maxAmountChargeback) { $notes = $amount ? $amount : null; OrderLog::createLog($user_id, $this->order_id, $type, $notes, $amount); return $this->maxAmountChargeback; } else { return false; } }
private function upsellProcess() { // is this request still valid? set to one hour. there is a cron that salvages orphaned upsell orders after 1 hour if ($this->intervalCheck) { $this->checkInterval($this->order->updated); } // load previous order upsells, if any $orderUpsells = AFActiveDataProvider::models('OrderUpsell'); $orderUpsells->loadId($this->order->order_id); // is this a switch main product upsell? $replace = false; $upsell = new Upsell(); if (!$upsell->fillFromDbPk($this->post['uid'])) { apiError('order upsell invalid'); } if ($upsell->product_replace && $this->post['act_up'] == 'yes') { $replace = true; // overwrite main order_product record and reset upsell path $this->post['product_id'] = $upsell->product_id; $this->newOrder = false; // $this->upsell_id is built via the function below $this->buildProducts(); $this->order->amount_product = $this->amount_product; if ($upsell->shipping_id) { $shipping = new Shipping(); if ($shipping->fillFromDbPk($upsell->shipping_id)) { $this->order->shipping_id = $shipping->shipping_id; $this->order->amount_shipping = $shipping->amount_initial; } unset($shipping); } if (!$this->order->save()) { fb('order not saved'); continue; } // overwrite step so we can delete all previous steps below $this->post['step'] = 0; } // is this a replace product, or has this step already been recorded? if so, wipe out steps in DB if ($replace || (int) $this->post['step'] <= $orderUpsells->getUpsellStep()) { $orderUpsells->deleteSteps($this->post['step']); } if (!$replace) { $orderUpsells->add($this->order->order_id, $this->post['uid'], $this->post['act_up'], $this->post['step']); if (!$orderUpsells->save()) { apiError('order upsell invalid'); } // is there another upsell based on the asnwer given? $this->upsell_id = $orderUpsells->nextUpsell(); } if (!$this->upsell_id) { // We're all done with upsells, insert upsell products into order products // retrieve existing order_products $orderProducts = new OrderProducts('OrderProduct'); $orderProducts->loadByOrderId($this->order->order_id); foreach ($orderUpsells->orderUpsells as $oa) { if ($oa->answer == 'yes') { $orderProducts->add($oa->product_id, $oa->shipping_id, $this->order->order_id); } // remove from DB $oa->delete(); } if (!$orderProducts->save()) { continue; } // update amounts $this->order->amount_product = $orderProducts->getTotal(); if (!$this->order->save()) { fb('order not saved'); continue; } // process Payment $this->webPayment(); } else { // send user to next upsell page $this->upsellDirect((int) $this->post['step'] + 1); } }
public function createAction() { $model = new Order(); $_POST['status'] = 'new'; $isPayment = AF::get($_POST, 'is_payment'); if (!$isPayment) { $_POST['ps'] = 'pn'; $_POST['payment_method'] = 'cc_debit'; } /*$rtr = ''; foreach($_POST as $k => $v) { $rtr .= " '".$k."' => '".$v."',"; } Message::echoJsonSuccess($rtr);*/ // is this also a new customer creation if (isset($_POST['newCus']) && $_POST['newCus'] == 1) { $cust = new Customer(); $this->performAjaxValidation($cust); //$shipData = (array)json_decode($_POST['shipAddr']); //$shipData['address_type'] = 'shipping'; $this->performAjaxFormFieldsValidation($_POST, explode(',', 'shipping_fname,shipping_lname,shipping_phone,shipping_address1,shipping_city,shipping_state_id,shipping_country_id,shipping_zip')); //Message::echoJsonSuccess('made it2'); if (!$_POST['billingSameAsShipping']) { //$billData = (array)json_decode($_POST['billAddr']); //$billData['address_type'] = 'billing'; $this->performAjaxFormFieldsValidation($_POST, explode(',', 'billing_fname,billing_lname,billing_phone,billing_address1,billing_city,billing_state_id,billing_country_id,billing_zip')); } $orderRules = "campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total"; } else { $_POST['newCus'] = 0; $orderRules = "customer_id,campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total,address_id,billing_address_id"; if (isset($_POST['address_id']) && empty($_POST['billing_address_id'])) { $_POST['billing_address_id'] = $_POST['address_id']; } // before billing validation } // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model, explode(',', $orderRules)); if (isset($_POST['model']) && $_POST['model'] == 'Order') { $isOrderPay = $this->access->actionAccess('order_is_pay') ? (bool) AF::get($_POST, 'is_payment') : false; $_POST['is_payment'] = $isOrderPay ? 1 : 0; // JSON success and error commands handled in the WS functions $ws = new WS(); $ws->crmInit($_POST); $ws->process(); } $orderID = AF::get($this->params, 'order_id', false); $prospectID = AF::get($this->params, 'prospect_id', false); $payments = array(); if ($orderID) { $model->fillFromDbPk($orderID); // if we use clone model then we cannot grab related fields $model->getCopyModel(); $orderProducts = OrderProducts::getProductsArrayByOrder($model->order_id); $payment_methods = ProfileGateways::getMethodsByProfileGateway($model->campaign->profile_id, $model->gateway_id); $cPayments = new Payments('Payment'); $payments = $cPayments->getResultsByCustomerId($model->customer_id, false); } elseif ($prospectID) { $modelProspect = Prospect::model()->findByPk($prospectID); if (!$modelProspect) { throw new AFHttpException(0, 'incorrect_id'); } $model->customer_id = $modelProspect->customer_id; $model->campaign_id = $modelProspect->campaign_id; $model->address_id = $modelProspect->address_id; $orderProducts = array(); $payment_methods = array(); } else { $orderProducts = array(); $payment_methods = array(); } $productModel = new Product(); $products = $productModel->getAvailableByCampaignID($model->campaign_id); $countryModel = new Country(); $languages = $countryModel->getLanguages(); $states = $model->country_id ? State::model()->getStatesByCID($model->country_id) : array(); //$model->country_ids='de,ir'; $countries = $countryModel->getCountries(); $campaigns = Campaign::model()->cache()->findAllInArray(); $shippingModel = new Shipping(); $shipping = $shippingModel->getAvailableByCampaignID($model->campaign_id); $modelGateways = new Gateway(); //$modelGateways->getGateways() $gateways = $orderID ? $modelGateways->getAvailableByCampaignID($model->campaign_id) : array(); $methods = Method::model()->cache()->findAllInArray(); $fields_expyear = array('current_year' => date("Y"), 'last_year' => date("Y") + 12); Assets::js('jquery.form'); Assets::js('jquery.autocomplete'); Assets::js('as24.bind-1.3.5.min'); Assets::js('jquery-ui'); Assets::css('jquery-ui'); $this->addToPageTitle('Create Order'); $this->render('create', array('model' => $model, 'products' => $products, 'languages' => $languages, 'campaigns' => $campaigns, 'states' => $states, 'countries' => $countries, 'fields_expyear' => $fields_expyear, 'shipping' => $shipping, 'gateways' => $gateways, 'orderProducts' => $orderProducts, 'payment_methods' => $payment_methods, 'payments' => $payments, 'methods' => $methods)); }