Example #1
0
 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');
 }
 function onBeforeDisplay($task, $smarty)
 {
     if (!is_object($smarty)) {
         return;
     }
     if (!in_array($task, array('viewbids', 'details'))) {
         return;
     }
     $auction = $smarty->get_template_vars('auction');
     $curent_info = $smarty->get_template_vars('payment_items_header');
     if ($auction->close_offer || !$auction->published || !$auction->isMyAuction() || $auction->featured == 'featured') {
         return;
     }
     $orderitems = BidsHelperAuction::getOrderItemsForAuction($auction->id, self::getItemName());
     if (count($orderitems)) {
         $priceinfo = JText::_("COM_BIDS_PAYMENT_FOR_FEATURE_AUCTION_IS_PENDING");
         foreach ($orderitems as $item) {
             if ($item->status == 'C') {
                 return;
             }
         }
         //Auction was payed for!
         $smarty->assign('payment_items_header', $curent_info . $priceinfo);
         return;
     }
     $model = self::getModel();
     $price = $model->getItemPrice($auction->cat);
     if (!floatval($price->price)) {
         return;
     } else {
         $priceinfo = "<a href='" . BidsHelperRoute::getFeaturedRoute($auction->id) . "'>";
         $priceinfo .= JText::_("COM_BIDS_UPGRADE_TO_FEATURED_FOR") . number_format($price->price, 2) . " " . $price->currency;
         $priceinfo .= "</a><br/>";
     }
     $smarty->assign('payment_items_header', $curent_info . $priceinfo);
 }
 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();
 }