/** * Public function that creates a single instance */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * Handle drawing referral list tag. * * @param array $tag_params * @param array $children */ public function tag_ReferralList($tag_params, $children) { $manager = AffiliateReferralsManager::getInstance(); $conditions = array(); }
/** * Update transaction data. * * @param integer $type * @param object $payment_method * @param string $delivery_method * @param object $buyer * @param object $address * @return array */ private function updateTransaction($type, $payment_method, $delivery_method, $buyer, $address) { global $db; $result = array(); $transactions_manager = ShopTransactionsManager::getInstance(); $transaction_items_manager = ShopTransactionItemsManager::getInstance(); $transaction_plans_manager = ShopTransactionPlansManager::getInstance(); // generate recipient array for delivery method if (!is_null($address)) { $recipient = array('street' => array($address->street), 'city' => $address->city, 'zip_code' => $address->zip, 'state' => $address->state, 'country' => $address->country); if (isset($address->street2)) { $recipient['street'][] = $address->street2; } } else { $recipient = null; } // update buyer if (!is_null($buyer)) { $result['buyer'] = $buyer->id; } // determine if we need a new session $new_transaction = true; if (isset($_SESSION['transaction']) && isset($_SESSION['transaction']['uid'])) { $uid = $_SESSION['transaction']['uid']; $transaction = $transactions_manager->getSingleItem(array('status'), array('uid' => $uid)); $new_transaction = !(is_object($transaction) && $transaction->status == TransactionStatus::PENDING); } // check if we have existing transaction in our database if ($new_transaction) { // get shopping cart summary $uid = uniqid('', true); $summary = $this->getCartSummary($type, $recipient, $uid); $result['uid'] = $uid; $result['type'] = $type; $result['status'] = TransactionStatus::PENDING; $result['handling'] = $summary['handling']; $result['shipping'] = $summary['shipping']; $result['weight'] = $summary['weight']; $result['payment_method'] = $payment_method->get_name(); $result['delivery_method'] = $delivery_method; $result['remark'] = ''; $result['total'] = $summary['total']; // add address if needed if (!is_null($address)) { $result['address'] = $address->id; } // assign system user if ($_SESSION['logged']) { $result['system_user'] = $_SESSION['uid']; } // create new transaction $transactions_manager->insertData($result); $result['id'] = $transactions_manager->getInsertedID(); // store transaction data to session $_SESSION['transaction'] = $result; } else { $uid = $_SESSION['transaction']['uid']; $summary = $this->getCartSummary($type, $recipient, $uid); // there's already an existing transaction $result = $_SESSION['transaction']; $result['handling'] = $summary['handling']; $result['shipping'] = $summary['shipping']; $result['total'] = $summary['total']; $data = array('handling' => $summary['handling'], 'shipping' => $summary['shipping'], 'total' => $summary['total']); if (!is_null($address)) { $data['address'] = $address->id; } // update existing transaction $transactions_manager->updateData($data, array('uid' => $uid)); // update session storage with newest data $_SESSION['transaction'] = $result; } // remove items associated with transaction $transaction_items_manager->deleteData(array('transaction' => $result['id'])); // remove plans associated with transaction $transaction_plans_manager->deleteData(array('transaction' => $result['id'])); // store items if (count($summary['items_for_checkout']) > 0) { foreach ($summary['items_for_checkout'] as $uid => $item) { $transaction_items_manager->insertData(array('transaction' => $result['id'], 'item' => $item['id'], 'price' => $item['price'], 'tax' => $item['tax'], 'amount' => $item['count'], 'description' => $item['description'])); } } // create plan entry if (isset($_SESSION['recurring_plan'])) { $plan_name = $_SESSION['recurring_plan']; $plan_list = $payment_method->get_recurring_plans(); $plan = isset($plan_list[$plan_name]) ? $plan_list[$plan_name] : null; if (!is_null($plan)) { $transaction_plans_manager->insertData(array('transaction' => $result['id'], 'plan_name' => $plan_name, 'trial' => $plan['trial'], 'trial_count' => $plan['trial_count'], 'interval' => $plan['interval'], 'interval_count' => $plan['interval_count'], 'start_time' => $db->format_timestamp($plan['start_time']), 'end_time' => $db->format_timestamp($plan['end_time']))); } } // if affiliate system is active, update referral if (isset($_SESSION['referral_id']) && class_exists('affiliates')) { $referral_id = $_SESSION['referral_id']; $referrals_manager = AffiliateReferralsManager::getInstance(); $referrals_manager->updateData(array('transaction' => $result['id']), array('id' => $referral_id)); } return $result; }