public static function createRecurringOrder($item) { if (!$item['product_next_id']) { return; } //Current order $newOrderModel = new Order(); $newOrderModel->fillFromArray($item); //Next product $productModel = new Product(); $productModel->fillFromDbPk($item['product_next_id']); //Current shipping $shippingModel = new Shipping(); $shippingModel->fillFromDbPk($item['shipping_id']); //Update order $newOrderModel->updated = 'NOW():sql'; $newOrderModel->created = 'NOW():sql'; unset($newOrderModel->order_id); $newOrderModel->status = 'pending'; $newOrderModel->amount_product = $item['discount_next'] ? round($productModel->product_price - $productModel->product_price * $item['discount_next'] / 100, 2) : $productModel->product_price; $newOrderModel->amount_shipping = $productModel->shippable ? $shippingModel->amount_subscription : 0.0; $newOrderModel->amount_refunded = 0.0; $newOrderModel->payment_total = 0.0; $newOrderModel->pixel_fired = 0; $newOrderModel->discount_next = 0; $newOrderModel->click_id = ''; $newOrderModel->rocket = 0; $newOrderModel->product_id = $item['product_next_id']; $newOrderModel->rma_code = 'NULL:sql'; $newOrderModel->recurring = 0; //(!$productModel->subscription_days || $item['recurring'] === '-1') ? 'NULL:sql' : 0; $newOrderModel->billing_cycle++; $newOrderModel->recurring_next = !$productModel->subscription_days || $item['recurring'] === '-1' ? 'NULL:sql' : date('Y-m-d', time() + 86400 * $item['subscription_days']); $newOrderModel->setRecuringShipWith($item['ship_with']); /* if($item['ship_with']) { $newOrderModel->setRecuringShipWith(); } else $newOrderModel->ship_with = 'NULL:sql'; */ //Save new order $newOrderModel->flags = isset($item['flags']) && $item['flags'] ? $item['flags'] : 'NULL:sql'; $newOrderModel->tracking_number = 'NULL:sql'; $newOrderModel->save(false); $paymentID = $item['status'] == 'upsell' ? $item['ship_with'] : $item['order_id']; //Current Payment $paymentModelName = 'Order' . ucfirst($newOrderModel->payment_type); $paymentModel = new $paymentModelName(); $paymentModel->fillFromDbPk($paymentID); //Update Paument if ($newOrderModel->payment_type == 'pn') { $paymentModel->pn_status = 'new'; $paymentModel->approval_code = ''; //$paymentModel->card_number = ''; $paymentModel->response_cc_cvv = ''; $paymentModel->filename = ''; $paymentModel->request_id = ''; $paymentModel->tracking_number = ''; } elseif ($newOrderModel->payment_type == 'og') { //??? } elseif ($newOrderModel->payment_type == 'gc') { $paymentModel->gc_updated = 'NOW():sql'; $paymentModel->gc_status = ''; $paymentModel->gc_refunded = 0.0; $paymentModel->gc_ref = ''; $paymentModel->gc_mac = ''; } $paymentModel->order_id = $newOrderModel->order_id; $paymentModel->setIsNewRecord(true); //Save new Payment $paymentModel->save(false); //Update current Order $currentOrdermodel = new Order(); $currentOrdermodel->setIsNewRecord(false); $currentOrdermodel->order_id = $item['order_id']; $currentOrdermodel->recurring = $newOrderModel->order_id; $currentOrdermodel->recurring_next = 'NULL:sql'; $currentOrdermodel->save(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); } }
function deleteAction() { $id = AF::get($_POST, 'id', 0); $modelsID = explode(',', $id); $errors = FALSE; foreach ($modelsID as $id) { $model = new Shipping(); $model->model_uset_id = $this->user->user_id; if ($model->fillFromDbPk($id)) { $model->delete($id); } else { $errors = TRUE; } if ($model->getErrors()) { $errors = TRUE; } unset($model); } if (isset($_POST['ajax'])) { AF::setJsonHeaders('json'); if ($errors) { Message::echoJsonError(__('shipping_not_deleted')); } else { $countE = AF::get($_POST, 'countE', 100000); if (count($modelsID) >= $countE) { $link = AF::link(array('shipping' => 'view')); Message::echoJsonRedirect($link); } else { Message::echoJsonSuccess(__('shipping_deleted')); } } } $this->redirect(); }
public function loadFullPackage($pid) { //$this->package_id = $pid; $this->loadPackage($pid); // use first order_id to grab relationship info. key($this->orders) The only orders that exists in the // package will have the same details otherwise there will be separate packages reset($this->orders); $this->main_order_id = key($this->orders); $this->shippingAddress = new FullAddress(); $this->shippingAddress->allFIelds = true; $this->shippingAddress->fillFromDbPk($this->orders[$this->main_order_id]->address_id); $this->billingAddress = new FullAddress(); $this->billingAddress->allFIelds = true; $this->billingAddress->fillFromDbPk($this->orders[$this->main_order_id]->billing_address_id); $this->click = new Click(); $this->click->allFIelds = true; $this->click->fillFromDbPk($this->orders[$this->main_order_id]->click_id); $this->products = array(); $this->shipping = array(); $combo = false; if (count($this->orders) > 1) { $combo = true; } foreach ($this->orders as $o) { foreach ($o->getOrderProducts() as $op) { $this->products[$op['product_id']] = new Product(); // set combo sku if applicable if ($combo && $op['product_shipping_sku']) { $op['product_sku'] = $op['product_shipping_sku']; } $this->products[$op['product_id']]->fillFromArray($op); /*$this->products[$op['product_id']]->product_price = $o->amount_product; $this->productPrice += $o->amount_product; $this->shippingPrice += $o->amount_shipping;*/ $this->productPrice += $op['product_price']; $ship = new Shipping(); $ship->fillFromDbPk($op['shipping_id']); $this->shippingPrice += $ship->amount_initial; $this->productWeight += $op['product_weight']; $this->shipping[] = new FullShipping(); $this->shipping[count($this->shipping) - 1]->fillFromDbPk($op['shipping_id']); } } $this->gateway = new Gateway(); $this->gateway->fillFromDbPk($this->orders[$this->main_order_id]->gateway_id); $this->campaign = new Campaign(); $this->campaign->fillFromDbPk($this->orders[$this->main_order_id]->campaign_id); $this->payment = new Payment(); $this->payment->fillFromDbPk($this->orders[$this->main_order_id]->payment_id); if ($this->shipping) { foreach ($this->shipping as $shippingModel) { $this->totalShipping += $shippingModel->amount_initial; } } $this->shipMethodName = $this->shipping[0]->shipping_name; $this->shipGroupName = $this->fulfillment->alias; $this->shipGroupCode = $this->shipping[0]->shipcat_code; $this->total_non_tax = $this->productPrice + $this->shippingPrice; $this->total = $this->productPrice + $this->shippingPrice; }