Esempio n. 1
0
 public function swapCart($user)
 {
     Zend_Registry::get('logger')->entering();
     Zend_Registry::get('logger')->debug('Instantiate transaction');
     $transactionId = $this->create();
     Zend_Registry::get('logger')->debug('Find items to buy');
     $lineItemTable = new LineItem();
     $items = $lineItemTable->findItems($user->id);
     $lineItems = $user->findLineItem();
     Zend_Registry::get('logger')->debug('Calculate charges & fees');
     $totalCharges = 0;
     $totalFees = 0;
     /*
             foreach ($items as $item)
             {
                 $totalCharges += $item->points + Item::shippingCharge($item->weight);
                 $totalFees += self::TRANSACTION_CHARGE;
             }
     */
     foreach ($lineItems as $lineItem) {
         $item = $lineItem->findParentItem();
         $totalCharges += $item->points;
         if (1 == $lineItem->shipping) {
             $totalCharges += Item::shippingCharge($item->weight);
         }
         $totalFees += self::TRANSACTION_CHARGE;
     }
     Zend_Registry::get('logger')->debug('Calculate swapbucks to buy');
     $swapbucksToBuy = $totalCharges - $user->balance;
     if ($swapbucksToBuy < 0) {
         $swapbucksToBuy = 0;
     }
     Zend_Registry::get('logger')->debug('Find the swaplady user');
     $users = new User();
     $swaplady = $users->fetchRow('username = "******"');
     Zend_Registry::get('logger')->debug('Transfer charges & fees from paypal');
     $totalPaypalTransfer = $totalCharges + $totalFees;
     PaypalEntry::transfer($transactionId, $user, $swaplady, $totalPaypalTransfer);
     Zend_Registry::get('logger')->debug('Transfer bought swapbucks');
     SwapbuckEntry::transfer($transactionId, $swaplady, $user, $swapbucksToBuy);
     Zend_Registry::get('logger')->debug('Transfer items');
     foreach ($items as $item) {
         $this->swapItem($transactionId, $user, $item);
     }
     Zend_Registry::get('logger')->exiting();
 }