/**
  * Update shipping Info
  * It has 2 logic in it. Update your own shipping info, and update already created trade records which has no shipping info.
  * 
  * @param integer $userID
  * @param array $data
  */
 public function updateShippingInfo($userID, $data)
 {
     if (!is_numeric($userID) || $data['shippingAddress'] == '' || $data['shippingCity'] == '' || $data['shippingState'] == '' || $data['shippingZip'] == '' || $data['shippingCountryID'] == '' || !is_numeric($data['shippingCountryID'])) {
         return false;
     }
     //Update my shipping info
     global $db;
     $query = sprintf('UPDATE %s SET ', TABLE_TRADE_USERS);
     $query = $db->prepare($query . 'shippingAddress=%s, shippingCity=%s, shippingState=%s, shippingZip=%s, shippingCountryID=%d WHERE userID=' . $userID, $data['shippingAddress'], $data['shippingCity'], $data['shippingState'], $data['shippingZip'], $data['shippingCountryID']);
     $db->query($query);
     //Update trade table which has no shipping info with this info.
     //It will check trade table, and create records in trade_shipping_info
     $tradeIns = new BuckysTrade();
     $tradeShippingInfoIns = new BuckysTradeShippingInfo();
     //---------------- Update for seller ----------------------//
     $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'seller');
     if (!empty($requiredList) && count($requiredList) > 0) {
         foreach ($requiredList as $tradeData) {
             //Add shipping info
             $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID);
             if (!empty($shippingRecID) && is_numeric($shippingRecID)) {
                 //update trade table
                 $tradeIns->updateTrade($tradeData['tradeID'], array('sellerShippingID' => $shippingRecID));
             }
         }
     }
     //---------------- Update for buyer ----------------------//
     $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'buyer');
     if (!empty($requiredList) && count($requiredList) > 0) {
         foreach ($requiredList as $tradeData) {
             //Add shipping info
             $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID);
             if (!empty($shippingRecID) && is_numeric($shippingRecID)) {
                 //update trade table
                 $tradeIns->updateTrade($tradeData['tradeID'], array('buyerShippingID' => $shippingRecID));
             }
         }
     }
     return true;
 }
 /**
  * Update shipping Info
  * It has 2 logic in it. Update your own shipping info, and update already created trade records which has no shipping info.
  *
  * @param integer $userID
  * @param array   $data
  * @return bool
  */
 public function updateShippingInfo($userID, $data)
 {
     if (!is_numeric($userID) || $data['shippingAddress'] == '' || $data['shippingCity'] == '' || $data['shippingState'] == '' || $data['shippingZip'] == '' || $data['shippingCountryID'] == '' || !is_numeric($data['shippingCountryID'])) {
         return false;
     }
     //Update my shipping info
     global $db;
     $db->updateFromArray(TABLE_TRADE_USERS, $data, ['userID' => $userID]);
     //Update trade table which has no shipping info with this info.
     //It will check trade table, and create records in trade_shipping_info
     $tradeIns = new BuckysTrade();
     $tradeShippingInfoIns = new BuckysTradeShippingInfo();
     //---------------- Update for seller ----------------------//
     $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'seller');
     if (!empty($requiredList) && count($requiredList) > 0) {
         foreach ($requiredList as $tradeData) {
             //Add shipping info
             $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID);
             if (!empty($shippingRecID) && is_numeric($shippingRecID)) {
                 //update trade table
                 $tradeIns->updateTrade($tradeData['tradeID'], ['sellerShippingID' => $shippingRecID]);
             }
         }
     }
     //---------------- Update for buyer ----------------------//
     $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'buyer');
     if (!empty($requiredList) && count($requiredList) > 0) {
         foreach ($requiredList as $tradeData) {
             //Add shipping info
             $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID);
             if (!empty($shippingRecID) && is_numeric($shippingRecID)) {
                 //update trade table
                 $tradeIns->updateTrade($tradeData['tradeID'], ['buyerShippingID' => $shippingRecID]);
             }
         }
     }
     //-------------------- Update Buyer Shipping Info -----------------------//
     $tradeShippingInfoIns->updateTradeShippingInfo($userID, $data);
     return true;
 }