private function commissionBuyer($auction, $bid) { $orderitems = BidsHelperAuction::getOrderItemsForAuction($bid->id, self::getItemName()); if (count($orderitems)) { foreach ($orderitems as $item) { if ($item->status == 'C') { return; } } //Bid was paid for! } $my = JFactory::getUser(); $model = self::getModel(); $price = $model->getItemPrice($auction->cat, 'buyer'); if (!floatval($price->price)) { return; } // no buyer's premium $modelbalance = JTheFactoryPricingHelper::getModel('balance'); $balance = $modelbalance->getUserBalance(); $bp_amount = $price->price * $bid->bid_price / 100; $currency = $auction->currency; $funds_delta = 0; if (BidsHelperPrices::comparePrices(array("price" => $bp_amount, "currency" => $currency), array("price" => $balance->balance, "currency" => $balance->currency)) > 0) { $funds_delta = BidsHelperPrices::convertCurrency($balance->balance, $balance->currency, $currency); if ($funds_delta <= 0) { $funds_delta = 0; } //if he has some funds - get the rest $has_funds = false; } else { $has_funds = true; } $balance_minus = BidsHelperPrices::convertCurrency($bp_amount, $currency, $balance->currency); $modelbalance->decreaseBalance($balance_minus); $modelorder = JTheFactoryPricingHelper::getModel('orders'); $items = array($model->getOderitem($auction, $bid, 'buyer')); if ($funds_delta > 0) { $item = new stdClass(); $item->itemname = JText::_("COM_BIDS_EXISTING_FUNDS"); $item->itemdetails = JText::_("COM_BIDS_EXISTING_FUNDS"); $item->iteminfo = 0; $item->price = -$funds_delta; $item->currency = $currency; $item->quantity = 1; $item->params = ''; $items[] = $item; } $order = $modelorder->createNewOrder($items, $bp_amount - $funds_delta, $currency, $bid->userid, $has_funds ? 'C' : 'P'); if (!$has_funds && $my->id == $bid->userid) { $session = JFactory::getSession(); $session->set('checkout-order', $order->id, self::getContext()); } $date = new JDate(); $comission_table = self::getTable(); $comission_table->userid = $bid->userid; $comission_table->auction_id = $auction->id; $comission_table->bid_id = $bid->id; $comission_table->comission_date = $date->toMySQL(); $comission_table->amount = $bp_amount; $comission_table->currency = $currency; $comission_table->commissionType = 'buyer'; $comission_table->store(); }
function onAfterSaveAuctionSuccess($auction) { if (!$auction->published) { return; } //not published yet $orderitems = BidsHelperAuction::getOrderItemsForAuction($auction->id, self::getItemName()); if (count($orderitems)) { foreach ($orderitems as $item) { if ($item->status == 'C') { return; } } //Auction was paid for! } $model = self::getModel(); $price = $model->getItemPrice($auction->cat); if (!floatval($price->price)) { return; } // Free publishing $modelbalance = JTheFactoryPricingHelper::getModel('balance'); $balance = $modelbalance->getUserBalance(); if (BidsHelperPrices::comparePrices($price, array("price" => $balance->balance, "currency" => $balance->currency)) > 0) { //insufficient funds $auction->published = 0; $a = JTable::getInstance('auction'); $a->bind($auction); $a->store(); $modelorder = JTheFactoryPricingHelper::getModel('orders'); $item = $model->getOderitem($auction); $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'P'); $session = JFactory::getSession(); $session->set('checkout-order', $order->id, self::getContext()); return; } //get funds from account, create confirmed order $balance_minus = BidsHelperPrices::convertCurrency($price->price, $price->currency, $balance->currency); $modelbalance->decreaseBalance($balance_minus); $modelorder = JTheFactoryPricingHelper::getModel('orders'); $item = $model->getOderitem($auction); $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'C'); }
private function generateOrder($bid, $catid, $needsPositiveBalance) { $app = JFactory::getApplication(); $model = self::getModel(); $price = $model->getItemPrice($catid); if (!floatval($price->price)) { return; } // Free publishing $modelbalance = JTheFactoryPricingHelper::getModel('balance'); $balance = $modelbalance->getUserBalance($bid->userid); if ($needsPositiveBalance) { if (BidsHelperPrices::comparePrices($price, array("price" => $balance->balance, "currency" => $balance->currency)) > 0) { $app->enqueueMessage(JText::_('COM_BIDS_NOT_ENOUGH_FUNDS_TO_BID'), 'notice'); $modelorder = JTheFactoryPricingHelper::getModel('orders'); $item = $model->getOderitem($bid); $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'P'); $app->redirect(BidsHelperRoute::getCheckoutRoute($order->id, false)); } } //get funds from account, create confirmed order $balance_minus = BidsHelperPrices::convertCurrency($price->price, $price->currency, $balance->currency); $modelbalance->decreaseBalance($balance_minus, $bid->userid); $modelorder = JTheFactoryPricingHelper::getModel('orders'); $item = $model->getOderitem($bid); $modelorder->createNewOrder($item, $price->price, $price->currency, $bid->userid, 'C'); }
function onBeforeExecuteTask(&$stopexecution) { $app = JFactory::getApplication(); if ($app->isAdmin()) { return; } $task = JRequest::getCmd('task', 'listauctions'); if ($task == 'setfeatured') { $id = JRequest::getInt("id"); $auction = JTable::getInstance('auction'); $app = JFactory::getApplication(); if (!$auction->load($id)) { JError::raiseWarning(550, JText::_("COM_BIDS_ERROR_LOADING_AUCTION_ID") . $id); $app->redirect(BidsHelperRoute::getAuctionDetailRoute($auction)); return; } if (!$auction->isMyAuction()) { JError::raiseWarning(501, JText::_("COM_BIDS_THIS_AUCTION_DOES_NOT_BELONG_TO_YOU")); $app->redirect(BidsHelperRoute::getAuctionDetailRoute($auction)); return; } $model = self::getModel(); $modelorder = JTheFactoryPricingHelper::getModel('orders'); $modelbalance = JTheFactoryPricingHelper::getModel('balance'); $price = $model->getItemPrice(); $balance = $modelbalance->getUserBalance(); $item = $model->getOderitem($auction); if (BidsHelperPrices::comparePrices($price, array("price" => $balance->balance, "currency" => $balance->currency)) > 0) { $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'P'); $app->redirect(BidsHelperRoute::getCheckoutRoute($order->id, false)); return; } //get funds from account, create confirmed order $balance_minus = BidsHelperPrices::convertCurrency($price->price, $price->currency, $balance->currency); $modelbalance->decreaseBalance($balance_minus); $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'C'); $auction->featured = 'featured'; $auction->store(); $app->redirect(BidsHelperRoute::getAuctionDetailRoute($auction)); return; } }
function onBeforeExecuteTask(&$stopexecution) { $app = JFactory::getApplication(); if ($app->isAdmin()) { return; } $task = JRequest::getCmd('task', 'listauctions'); if ($task == 'buy_contact') { $user = JFactory::getUser(); $app = JFactory::getApplication(); $id = JRequest::getInt("id"); $model = self::getModel(); if ($user->id == $id && $model->checkContact($id)) { JError::raiseWarning(501, JText::_("COM_BIDS_CONTACT_IS_ALREADY_PURCHASED")); $app->redirect(BidsHelperRoute::getUserdetailsRoute($id, false)); return; } $modelorder = JTheFactoryPricingHelper::getModel('orders'); $modelbalance = JTheFactoryPricingHelper::getModel('balance'); $price = $model->getItemPrice(); $balance = $modelbalance->getUserBalance(); $item = $model->getOderitem($id); if (BidsHelperPrices::comparePrices($price, array("price" => $balance->balance, "currency" => $balance->currency)) > 0) { $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'P'); $app->redirect(BidsHelperRoute::getCheckoutRoute($order->id, false)); return; } //get funds from account, create confirmed order $balance_minus = BidsHelperPrices::convertCurrency($price->price, $price->currency, $balance->currency); $modelbalance->decreaseBalance($balance_minus); $order = $modelorder->createNewOrder($item, $price->price, $price->currency, null, 'C'); $model->addContact($id, $order->userid); $app->redirect(BidsHelperRoute::getUserdetailsRoute($id)); return; } }