public static function saveOrder($cart, $user, $payGty, $payGtyDetail, $deliveryGty, $deliveryDetail, $status, $guest_buying = '0') { $db = JFactory::getDBO(); $cartItem = array_pop($cart->getAll()); $__data = new stdClass(); $__data->total_buyer_paid = $cart->getTotalPrice(); $__data->point_used_to_pay = $cart->getPoint(); $__data->status = $status; $__data->session_id = JFactory::getSession()->getId(); $__data->buyer_id = $user['id']; $__data->buyer_detail = json_encode($user); $__data->referral_id = $cart->getReferralId(); $__data->pay_gty_id = $payGty->id; $__data->delivery_gty_id = $deliveryGty->id; $__data->delivery_detail = json_encode($deliveryDetail); $__data->created_at = DatetimeWrapper::getDatetimeOfNow(); $__data->updated_at = DatetimeWrapper::getDatetimeOfNow(); $__data->paid_amount = number_format($cartItem->getCount() * $cartItem->item->price * $cartItem->item->prepay_percent / 100, 2); $db->insertObject('#__enmasse_order', $__data, 'id'); if ($db->getErrorNum()) { echo $db->stderr(); return false; } else { return $__data; } }
function getDealListByLocationId($locationId) { $mainframe = JFactory::getApplication('site'); $db = JFactory::getDBO(); $query = "SELECT *\n\t\t\t\tFROM `#__enmasse_deal`\n\t\t\t\tWHERE \n\t\t\t\tstatus NOT LIKE 'Pending' AND\n\t\t \t\tpublished = '1' AND\n\t\t\t\t\t\tstart_at <='" . DatetimeWrapper::getDatetimeOfNow() . "' \n\t\t \t\tAND end_at >= '" . DatetimeWrapper::getDatetimeOfNow() . "' \n\t\t \t\tAND id\n\t\t\t\tIN (\t\t\t\t\n\t\t\t\t\tSELECT deal_id\n\t\t\t\t\tFROM `#__enmasse_deal_location`\n\t\t\t\t\tWHERE location_id = " . $locationId . "\n\t\t\t\t) ORDER BY created_at DESC"; $db->setQuery($query); $rows = $db->loadAssocList(); return $rows; }
function getListDeal() { $mainframe = JFactory::getApplication('site'); // deal $db = JFactory::getDBO(); $query = "\tSELECT \n\t\t\t\t\t\t* \n\t\t\t\t\tFROM \n\t\t\t\t\t\t#__enmasse_deal \n\t\t\t\t\tWHERE\n\t\t\t\t\t status NOT LIKE 'Pending' AND\n\t\t \t\tpublished = '1' AND\n\t\t\t\t\t\tstart_at <='" . DatetimeWrapper::getDatetimeOfNow() . "' \n\t\t \t\tAND end_at >= '" . DatetimeWrapper::getDatetimeOfNow() . "' "; $db->setQuery($query); $rows = $db->loadObjectList(); return $rows; }
function getTodayDeal() { $mainframe = JFactory::getApplication('site'); // deal $db = JFactory::getDBO(); $query = "\tSELECT\n\t\t\t\t\t\t\t* \n\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t#__enmasse_deal \n\t\t\t\t\t\tWHERE\n\t\t \t\tpublished = '1' AND \n\t\t \t\tend_at > '" . DatetimeWrapper::getDatetimeOfNow() . "'\n\t\t \tORDER BY\n\t\t \t\tposition Asc\n\t\t \tLIMIT\n\t\t \t\t1\n\t\t "; $db->setQuery($query); $deal = $db->loadObject(); return $deal; }
function updatePayDetail($id, $payDetail) { $db = JFactory::getDBO(); $query = "UPDATE #__enmasse_order SET pay_detail ='" . $payDetail . "', updated_at = '" . DatetimeWrapper::getDatetimeOfNow() . "' where id =" . $id; $db->setQuery($query); $db->query(); if ($this->_db->getErrorNum()) { JError::raiseError(500, $this->_db->stderr()); return false; } return true; }
function updateStatus($id, $value) { $db = JFactory::getDBO(); $query = 'UPDATE #__enmasse_order_item SET status ="' . $value . '", updated_at = "' . DatetimeWrapper::getDatetimeOfNow() . '" where id =' . $id; $db->setQuery($query); $db->query(); if ($this->_db->getErrorNum()) { JError::raiseError(500, $this->_db->stderr()); return false; } return true; }
public function save($data) { $nUser = $data['user_id']; $arOrderId = $data['orders']; $dtNow = DatetimeWrapper::getDatetimeOfNow(); $sInsert = "({$nUser} , '{$dtNow}', '{$dtNow}' ," . implode("),({$nUser} , '{$dtNow}', '{$dtNow}' ,", $arOrderId) . ")"; $db = JFactory::getDbo(); $query = "INSERT IGNORE INTO #__enmasse_order_deliverer (user_id, created_at, updated_at, order_id) VALUES " . $sInsert; $db->setQuery($query); $db->query(); if ($db->getErrorNum()) { $this->setError($db->getErrorMsg()); return false; } else { return true; } }
public function updateOrder() { $orderId = JRequest::getVar('id', 0, 'post', 'int'); $sComment = JRequest::getVar('description'); $sDlvStatus = JRequest::getVar('delivery_status', 'undelivered'); $oOrderTbl = JTable::getInstance('order', 'Table'); $oOrderTbl->load($orderId); $oOrderTbl->description = $sComment; $oOrderTbl->updated_at = DatetimeWrapper::getDatetimeOfNow(); if ($sDlvStatus == "delivered") { $oOrderTbl->status = EnmasseHelper::$ORDER_STATUS_LIST['Holding_By_Deliverer']; } $oOrderTbl->store(); JModel::getInstance('orderDeliverer', 'enmasseModel')->updateStatus($orderId, $sDlvStatus); $msg = JText::_('ORDER_DELIVERER_UPDATE_SUCCESS_MSG'); $link = JRoute::_("index.php?option=com_enmasse&controller=deliverer&task=show"); JFactory::getApplication()->redirect($link, $msg); }
function submit_review() { $nDealId = JRequest::getVar('nDealId'); $nRating = JRequest::getVar('nRating'); $sReviewBody = JRequest::getVar('sReviewBody'); // Be sure this is a valid deal id if ($nDealId > 0) { // Check for a valid rating number and review content // User has to select his/her rating (the number is from 1 to 5) // and has enter his/her review if ($nRating <= 0 || $nRating > 5) { $sMessage = JText::_('PLEASE_RATE'); $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false); } elseif ($sReviewBody == '') { $sMessage = JText::_('PLEASE_ENTER_REVIEW'); $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false); } else { if (EnmasseHelper::checkSpammer(JFactory::getUser()->get('id'))) { // If this user is a spammer, lie to him/her that the review is submitted but actually we store nothing $sMessage = JText::_('REVIEW_SUBMITTED_SUCCESSFULLY'); $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false); } else { $aComment = array(); $aComment['deal_id'] = $nDealId; $aComment['user_id'] = JFactory::getUser()->get('id'); $aComment['comment'] = $sReviewBody; $aComment['rating'] = $nRating; $aComment['created_at'] = DatetimeWrapper::getDatetimeOfNow(); $aComment['status'] = 0; $oRow = JModel::getInstance('comment', 'enmasseModel')->store($aComment); if ($oRow->success) { $sMessage = JText::_('REVIEW_SUBMITTED_SUCCESSFULLY'); } else { $sMessage = JText::_('SAVE_REVIEW_FAILED'); } $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&controller=deal&task=comment&id=' . $nDealId, false); } } } else { $sMessage = JText::_('SAVE_REVIEW_FAILED'); $sRedirectUrl = JRoute::_('index.php?option=com_enmasse&view=dealtoday', false); } $this->setRedirect($sRedirectUrl, $sMessage); }
function store($data) { $row = $this->getTable(); if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if ($row->id <= 0) { $row->created_at = DatetimeWrapper::getDatetimeOfNow(); } $row->updated_at = DatetimeWrapper::getDatetimeOfNow(); if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }
public function save($data) { $nUser = $data['user_id']; $arOrderId = $data['orders']; $dtNow = DatetimeWrapper::getDatetimeOfNow(); $sInsert = "({$nUser} , '{$dtNow}', '{$dtNow}' ," . implode("),({$nUser} , '{$dtNow}', '{$dtNow}' ,", $arOrderId) . ")"; $db = JFactory::getDbo(); //Delete the order that already assigned for other deliverer $query = "DELETE FROM #__enmasse_order_deliverer WHERE user_id != {$nUser} AND order_id IN (" . implode(',', $arOrderId) . ")"; $db->setQuery($query); $db->query(); //insert $query = "INSERT IGNORE INTO #__enmasse_order_deliverer (user_id, created_at, updated_at, order_id) VALUES " . $sInsert; $db->setQuery($query); $db->query(); if ($db->getErrorNum()) { $this->setError($db->getErrorMsg()); return false; } else { return true; } }
?> </div> </div> <div class="deal_cont_bottom"> </div> </div> <!--Time Count Down Script--> <script language="JavaScript"> TargetDate = "<?php echo date('Y/m/d H:i:s', strtotime($deal->end_at)); ?> "; CurrentDate = "<?php echo date('Y/m/d H:i:s', strtotime(DatetimeWrapper::getDatetimeOfNow())); ?> "; CountActive = true; CountStepper = -1; LeadingZero = true; function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return s ; } function CountBack(secs) { if (secs < 0) {
/** * * Create bill with PDF format, return file location. * @param integer $nOrderId order id that need to print bill. * @param string $dest whether save to the file or echo direct to web browser (for preview). * @return string name of created file with absolute path. */ public static function createPDF($nOrderId, $dest = 'F') { $oOrder = JModel::getInstance('order', 'enmasseModel')->getById($nOrderId); if (empty($oOrder)) { return null; } $buyer = json_decode($oOrder->buyer_detail); $arOrderItem = JModel::getInstance('orderItem', 'enmasseModel')->listByOrderId($nOrderId); $sOderDetail = '<table border="1"><tr valign="middle"><th align="center" style="width:30px;">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_NO") . '</th><th style="width:60px;">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_QUANTITY") . '</th><th style="width:50px;">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_DEAL_ID") . '</th><th align="center" style="width:320px; ">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_DEAL_DESC") . '</th><th style="width:50px;">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_UNIT_PRICE") . '</th><th style="width:50px;">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_TAX") . '</th><th style="width:80px;">' . JText::_("BILL_TEMPLATE_ORDER_DETAIL_TOTAL") . '</th></tr>'; $oPayGty = JModel::getInstance('payGty', 'enmasseModel')->getById($oOrder->pay_gty_id); if (empty($oPayGty)) { $oPayGty = new JObject(); $oPayGty->name = ""; } $count = 1; foreach ($arOrderItem as $oItem) { $sOderDetail .= '<tr valign="middle"><td >' . $count++ . '</td><td >' . $oItem->qty . '</td><td >' . $oItem->pdt_id . '</td><td style="width:300px;text-align: left">' . $oItem->description . '</td><td >' . $oItem->unit_price . '</td><td >' . '</td><td >' . $oItem->total_price . '</td></tr>'; } $sOderDetail .= '<tr><td colspan="7" style="text-align:right" >Total Amount: ' . $oOrder->total_buyer_paid . '</td></tr></table>'; $db = JFactory::getDbo(); $query = "SELECT *\n\t\t\t\t\t\tFROM #__enmasse_bill_template\n\t\t\t\t\t\tWHERE slug_name = " . $db->quote(self::$BUYER_RECEIPT_TMPL_NAME); $db->setQuery($query); $oBillTmpl = $db->loadObject(); $sTmpl = $oBillTmpl->content; $arParam = array(); $arParam['[BUYER_NAME]'] = $buyer->name; $arParam['[BUYER_EMAIL]'] = $buyer->email; $arParam['[BILL_NUMBER]'] = EnmasseHelper::displayOrderDisplayId($oOrder->id); $arParam['[BILL_DATE]'] = DatetimeWrapper::getDatetimeOfNow(); $arParam['[PAYMENT_METHOD]'] = $oPayGty->name; $arParam['[BILL_DETAIL]'] = $sOderDetail; $arParam['[BILL_DESCRIPTION]'] = $oOrder->description; //ADD style for table $sTmpl = '<style>p{margin: 8px 0px }table {border-collapse:collapse;} td, th{text-align: center} th{height: 40px}</style>' . $sTmpl; $arSearch = array_keys($arParam); $sTmpl = str_replace($arSearch, $arParam, $sTmpl); //----------------------------- //process for image tag because there have the difference source path between //html2pdf and richtext editor(using for edit bill template),image tag //was wrong source path and it cause html2pdf error $sPattern = '/(<img\\s+src=")(.*)(")/i'; if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { $sReplace = '$1' . JPATH_SITE . DS . '\\$2$3'; } else { $sReplace = '$1' . JPATH_SITE . DS . '$2$3'; } $sTmpl = preg_replace($sPattern, $sReplace, $sTmpl); require_once dirname(__FILE__) . '/html2pdf/html2pdf.class.php'; try { $sOutFileName = "bill_preview.pdf"; if ($dest == 'F') { $sOutFileName = JPATH_ADMINISTRATOR . DS . "components" . DS . "com_enmasse" . DS . "bills" . DS . EnmasseHelper::displayOrderDisplayId($oOrder->id) . ".pdf"; if (file_exists($sOutFileName)) { unlink($sOutFileName); } } $html2pdf = new HTML2PDF('P', 'A4', 'en'); $html2pdf->setDefaultFont('Arial'); $html2pdf->writeHTML($sTmpl); $html2pdf->Output($sOutFileName, $dest); } catch (HTML2PDF_exception $e) { return; } return $sOutFileName; }
function getCouponFreeByPdtID($id) { $db = JFactory::getDBO(); $query = 'SELECT * FROM #__enmasse_invty WHERE pdt_id = ' . $id . ' AND status= "Free" AND deallocated_at < ' . strtotime(DatetimeWrapper::getDatetimeOfNow()); $db->setQuery($query); return $db->loadObjectList(); }
function storeGtyConfig($id, $attribute_config) { $obj->id = $id; $obj->attribute_config = json_encode($attribute_config); $row =& JTable::getInstance('payGty', 'Table'); if (!$row->bind($obj)) { $this->setError($this->_db->getErrorMsg()); return false; } $row->updated_at = DatetimeWrapper::getDatetimeOfNow(); if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; }
function save() { $data = JRequest::get('post'); $data['name'] = trim($data['name']); $data['slug_name'] = EnmasseHelper::seoUrl($data['name']); $data['description'] = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $data['highlight'] = JRequest::getVar('highlight', '', 'post', 'string', JREQUEST_ALLOWRAW); $data['terms'] = JRequest::getVar('terms', '', 'post', 'string', JREQUEST_ALLOWRAW); if ($data['slug_name'] == '_' || $data['slug_name'] == '') { $now = str_replace(":", " ", DatetimeWrapper::getDatetimeOfNow()); $data['slug_name'] = EnmasseHelper::seoUrl($now); } $model = JModel::getInstance('deal', 'enmasseModel'); //--------------------------------------------------------------- // if edit deal if ($data['id'] > 0) { //---get deal data $deal = JModel::getInstance('deal', 'enmasseModel')->getById($data['id']); // get sold coupon qty for deal $soldCouponList = JModel::getInstance('invty', 'enmasseModel')->getSoldCouponByPdtId($deal->id); //if from unlimited to limited if ($deal->max_coupon_qty < 0) { if ($data['max_coupon_qty'] > 0) { if ($data['max_coupon_qty'] <= count($soldCouponList)) { $msg = JText::_('MSG_CURRENT_SOLD_GRATER_THAN_MODIFIED_COUPON'); JFactory::getApplication()->redirect('index.php?option=com_enmasse&controller=deal&task=edit&cid=' . $data['id'], $msg); } else { $numOfAddCoupon = $data['max_coupon_qty'] - count($soldCouponList); } } } else { //---------------- if change from limited to unlimited if ($data['max_coupon_qty'] < 0) { $unlimit = true; } else { if ($data['max_coupon_qty'] < $deal->max_coupon_qty) { //---------------------- if new coupon qty <= the sold coupon qty if ($data['max_coupon_qty'] <= count($soldCouponList)) { $msg = JText::_('MSG_CURRENT_SOLD_GRATER_THAN_MODIFIED_COUPON'); JFactory::getApplication()->redirect('index.php?option=com_enmasse&controller=deal&task=edit&cid=' . $data['id'], $msg); } else { $numOfRemoveCoupon = $deal->max_coupon_qty - $data['max_coupon_qty']; } } else { if ($data['max_coupon_qty'] > $deal->max_coupon_qty) { $numOfAddCoupon = $data['max_coupon_qty'] - $deal->max_coupon_qty; } } } } } //------------------------ //gemerate integration class $integrateFileName = EnmasseHelper::getSubscriptionClassFromSetting() . '.class.php'; $integrationClass = EnmasseHelper::getSubscriptionClassFromSetting(); require_once JPATH_SITE . DS . "components" . DS . "com_enmasse" . DS . "helpers" . DS . "subscription" . DS . $integrationClass . DS . $integrateFileName; $integrationObject = new $integrationClass(); // store data $row = $model->store($data); if ($row->success) { if ($data['id'] == 0) { $integrationObject->integration($row, 'newDeal'); } //-------------------------------------- // store location and category JModel::getInstance('dealCategory', 'enmasseModel')->store($row->id, $data['pdt_cat_id']); JModel::getInstance('dealLocation', 'enmasseModel')->store($row->id, $data['location_id']); // if is new deal and limited the coupon then create coupon in invty if ($data['id'] == 0 && $row->max_coupon_qty > 0) { for ($i = 0; $i < $row->max_coupon_qty; $i++) { $name = $i + 1; JModel::getInstance('invty', 'enmasseModel')->generateCouponFreeStatus($row->id, $name, 'Free'); } } else { if ($data['id'] != 0) { if (!empty($numOfRemoveCoupon)) { $freeCouponList = JModel::getInstance('invty', 'enmasseModel')->getCouponFreeByPdtID($data['id']); // removed the coupons from invty for ($i = 0; $i < $numOfRemoveCoupon; $i++) { JModel::getInstance('invty', 'enmasseModel')->removeById($freeCouponList[$i]->id); } } else { if (!empty($numOfAddCoupon)) { // add more coupon to invty for ($i = 0; $i < $numOfAddCoupon; $i++) { $name = $i + 1; JModel::getInstance('invty', 'enmasseModel')->generateCouponFreeStatus($data['id'], $name, 'Free'); } } else { if ($unlimit) { //remove all free coupon JModel::getInstance('invty', 'enmasseModel')->removeCouponByPdtIdAndStatus($data['id'], 'Free'); } } } } } $msg = JText::_('SAVE_SUCCESS_MSG'); $this->setRedirect('index.php?option=com_enmasse&controller=' . JRequest::getVar('controller'), $msg); } else { $msg = JText::_('SAVE_ERROR_MSG') . ": " . $model->getError(); if ($data['id'] == null) { $this->setRedirect('index.php?option=com_enmasse&controller=' . JRequest::getVar('controller') . '&task=add', $msg, 'error'); } else { $this->setRedirect('index.php?option=com_enmasse&controller=' . JRequest::getVar('controller') . '&task=edit&cid[0]=' . $data['id'], $msg, 'error'); } } }
function store($data) { $row = $this->getTable(); $data['name'] = trim($data['name']); if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if ($row->id <= 0) { $row->created_at = DatetimeWrapper::getDatetimeOfNow(); } $row->updated_at = DatetimeWrapper::getDatetimeOfNow(); if (!$row->check()) { $this->setError($row->getError(0)); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } //set group for the merchant person $jUserId = EnmasseHelper::getUserByName($data['user_name'])->id; $nGroup = JModel::getInstance('setting', 'EnmasseModel')->getSetting(1)->merchant_group; $user = new JUser($jUserId); $user->groups = array_merge($user->groups, array($nGroup)); $user->save(); return true; }
/** * * Store merchant data into the DB * @param array $data * @return boolean true on success */ public function store($data) { $oRow = JTable::getInstance('merchant', 'Table'); if (!$oRow->bind($data)) { $this->setError($oRow->getError()); return false; } if (empty($oRow->id)) { $oRow->created_at = DatetimeWrapper::getDatetimeOfNow(); } $oRow->updated_at = DatetimeWrapper::getDatetimeOfNow(); if (!$oRow->check()) { $this->setError($oRow->getError()); return false; } if (!$oRow->store()) { $this->setError($oRow->getError()); return false; } //set group for the merchant person $jUserId = EnmasseHelper::getUserByName($data['user_name'])->id; $nGroup = JModel::getInstance('setting', 'EnmasseModel')->getSetting(1)->merchant_group; $user = new JUser($jUserId); $user->groups = array_merge($user->groups, array($nGroup)); $user->save(); return true; }
function generateCouponFreeStatus($pdtId, $couponName, $status) { $db = JFactory::getDBO(); $created_at = DatetimeWrapper::getDatetimeOfNow(); $query = "INSERT INTO #__enmasse_invty (name, pdt_id, status,created_at) VALUES ('" . $couponName . "','" . $pdtId . "','" . $status . "','" . $created_at . "')"; $db->setQuery($query); $db->query(); if ($this->_db->getErrorNum()) { JError::raiseError(500, $this->_db->stderr()); return false; } return true; }
function submitCheckOut() { $activeGuestBuying = EnmasseHelper::isGuestBuyingEnable(); $bBuy4friend = JRequest::getVar('buy4friend', 0); $sEmailPt = "/^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})\$/"; //save user input data into the session if (JRequest::getMethod() == "POST") { $arData = JRequest::get('post'); JFactory::getApplication()->setUserState("com_enmasse.checkout.data", $arData); } //check the permission for checkout action if (JFactory::getUser()->get('guest') && !$activeGuestBuying) { $msg = JText::_("MERCHANT_PLEASE_LOGIN_BEFORE"); $redirectUrl = base64_encode("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}"); $link = JRoute::_("index.php?option=com_users&view=login&return=" . $redirectUrl, false); JFactory::getApplication()->redirect($link, $msg, 'error'); } //validate the cart $cart = unserialize(JFactory::getSession()->get('cart')); CartHelper::checkCart($cart); foreach ($cart->getAll() as $cartItem) { $item = $cartItem->getItem(); } //get enmasse setting $setting = JModel::getInstance('setting', 'enmasseModel')->getSetting(); // check max cart Item $this->checkMaxCartItem($cart); //validate Buyer information $buyerName = JRequest::getVar('name'); $buyerEmail = JRequest::getVar('email'); if (empty($buyerName) || empty($buyerEmail)) { $msg = JText::_("SHOP_CARD_CHECKOUT_BUYER_INFORMATION_REQUIRED_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } elseif (!preg_match($sEmailPt, $buyerEmail)) { $msg = JText::_("SHOP_CARD_CHECKOUT_BUYER_EMAIL_INVALID_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } //----- If the deal permit partial payment, it mean the coupon was delivery by directly, so we need to validate address and phone number of receiver if ($item->prepay_percent < 100) { $receiverAddress = JRequest::getVar('receiver_address'); $receiverPhone = JRequest::getVar('receiver_phone'); if (empty($receiverPhone) || empty($receiverAddress)) { $msg = JText::_("SHOP_CARD_CHECKOUT_RECEIVER_INFORMATION_REQUIRED_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } else { if (!preg_match('/^[0-9 \\.,\\-\\(\\)\\+]*$/', $receiverPhone)) { $msg = JText::_("SHOP_CARD_CHECKOUT_RECEIVER_PHONE_INVALID"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } } } if ($bBuy4friend) { $receiverName = JRequest::getVar('receiver_name'); $receiverEmail = JRequest::getVar('receiver_email'); $receiverMsg = JRequest::getVar('receiver_msg'); if (empty($receiverName) || empty($receiverEmail)) { $msg = JText::_("SHOP_CARD_CHECKOUT_RECEIVER_INFORMATION_REQUIRED_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } elseif (!preg_match($sEmailPt, $receiverEmail)) { $msg = JText::_("SHOP_CARD_CHECKOUT_RECEIVER_EMAIL_INVALID_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } } //------------------------------------------------------ // to check it this deal is free for customer if ($cart->getTotalPrice() > 0) { //deal is not free $payGtyId = JRequest::getVar('payGtyId'); if ($payGtyId == null) { $msg = JText::_("SELECT_PAYMENT_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } if ($setting->article_id != 0 && JRequest::getVar('terms') == false) { $msg = JText::_("AGREE_TERM_CONDITION_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg, 'error'); } $payGty = JModel::getInstance('payGty', 'enmasseModel')->getById($payGtyId); // checking gateway configuration if (CartHelper::checkGty($payGty) == false) { $msg = JText::_("PAYMENT_INCOMPLETE_MSG"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=checkout&buy4friend={$bBuy4friend}", false); JFactory::getApplication()->redirect($link, $msg); } // save gty info into session JFactory::getSession()->set('payGty', serialize($payGty)); JFactory::getSession()->set('attribute_config', json_encode($payGty->attribute_config)); //--------If admin set the prepay_percent of the deal to 0.00, set the order status to 'Paid' (with paid_amount is 0.00) if ($item->prepay_percent == 0.0) { $status = EnmasseHelper::$ORDER_STATUS_LIST['Paid']; $couponStatus = EnmasseHelper::$INVTY_STATUS_LIST['Hold']; } else { //------------------------------------ // generate name of payment gateway file and class $payGtyFile = 'PayGty' . ucfirst($payGty->class_name) . '.class.php'; $className = 'PayGty' . ucfirst($payGty->class_name); //--------------------------------------------------- // get payment gateway object require_once JPATH_SITE . DS . "components" . DS . "com_enmasse" . DS . "helpers" . DS . "payGty" . DS . $payGty->class_name . DS . $payGtyFile; $paymentClassObj = new $className(); $paymentReturnStatusObj = $paymentClassObj->returnStatus(); $status = $paymentReturnStatusObj->order; $couponStatus = $paymentReturnStatusObj->coupon; } } else { //deal is free $payGty = "Free"; $status = 'Unpaid'; $couponStatus = 'Pending'; //save the payGty as free JFactory::getSession()->set('payGty', 'Free'); } //---------------------------------------- //determine information of coupon receiver if ($bBuy4friend) { $deliveryDetail = array('name' => $receiverName, 'email' => $receiverEmail, 'msg' => $receiverMsg, 'address' => $receiverAddress, 'phone' => $receiverPhone); } else { $deliveryDetail = array('name' => $buyerName, 'email' => $buyerEmail, 'msg' => '', 'address' => $receiverAddress, 'phone' => $receiverPhone); } //-------------------------- //generate order $dvrGty = $item->prepay_percent < 100 ? 2 : 1; $deliveryGty = JModel::getInstance('deliveryGty', 'enmasseModel')->getById($dvrGty); $user = array(); $user['id'] = JFactory::getUser()->get('id', 0); $user['name'] = $buyerName; $user['email'] = $buyerEmail; $order = CartHelper::saveOrder($cart, $user, $payGty, null, $deliveryGty, $deliveryDetail, $status); $session =& JFactory::getSession(); $session->set('newOrderId', $order->id); $orderItemList = CartHelper::saveOrderItem($cart, $order, $status); //----------------------------- // if this deal is set limited the coupon to sold out, go to invty and allocate coupons for this order // if not create coupons for that order if ($item->max_coupon_qty > 0) { $now = DatetimeWrapper::getDatetimeOfNow(); $nunOfSecondtoAdd = EnmasseHelper::getMinuteReleaseInvtyFromSetting($payGty) * 60; $intvy = CartHelper::allocatedInvty($orderItemList, DatetimeWrapper::mkFutureDatetimeSecFromNow($now, $nunOfSecondtoAdd), $couponStatus); } else { JModel::getInstance('invty', 'enmasseModel')->generateForOrderItem($orderItemList[0]->pdt_id, $orderItemList[0]->id, $orderItemList[0]->qty, $couponStatus); } //------------------------ //generate integration class $isPointSystemEnabled = EnmasseHelper::isPointSystemEnabled(); if ($isPointSystemEnabled) { $integrationClass = EnmasseHelper::getPointSystemClassFromSetting(); $integrateFileName = $integrationClass . '.class.php'; require_once JPATH_SITE . DS . "components" . DS . "com_enmasse" . DS . "helpers" . DS . "pointsystem" . DS . $integrationClass . DS . $integrateFileName; $user = JFactory::getUser(); $user_id = $user->get('id'); $point = $cart->getPoint(); if ($point > 0) { $integrationObject = new $integrationClass(); $integrationObject->integration($user_id, 'paybypoint', $point); } } //validating is ok, flush user data JFactory::getApplication()->setUserState("com_enmasse.checkout.data", null); // -------------------------------- // if deal is free then directly do the notify if ($cart->getTotalPrice() > 0) { //deal is not free, check if buyer must prepay a specific amount if ($item->prepay_percent > 0) { $link = JRoute::_("index.php?option=com_enmasse&controller=payment&task=gateway&orderId=" . $order->id, false); } else { //do notify for the order that not to prepay EnmasseHelper::doNotify($order->id); $link = JRoute::_("index.php?option=com_enmasse&controller=deal&task=listing"); $msg = JText::_("PARTIAL_PAYMENT_NO_PREPAY_CHECKOUT_MSG"); JFactory::getApplication()->redirect($link, $msg); } } else { //deal is free $link = JRoute::_("index.php?option=com_enmasse&controller=payment&task=doNotify&orderId={$order->id}", false); } JFactory::getApplication()->redirect($link); }
public function store($data) { $row = $this->getTable(); $data['name'] = trim($data['name']); if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if ($row->id <= 0) { $row->created_at = DatetimeWrapper::getDatetimeOfNow(); } $row->updated_at = DatetimeWrapper::getDatetimeOfNow(); if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $row->success = false; $this->setError($this->_db->getErrorMsg()); } else { $row->oldname = $data['oldname']; $row->success = true; } return $row; }
function getDealByMerchantId($merchantId) { $db = JFactory::getDBO(); $query = "\tSELECT \n\t\t\t\t\t\t* \n\t\t\t\t\tFROM \n\t\t\t\t\t\t#__enmasse_deal \n\t\t where merchant_id = {$merchantId}\n\t\t AND status != 'Voided' AND end_at <= '" . DatetimeWrapper::getDatetimeOfNow() . "'"; $db->setQuery($query); $deals = $db->loadObjectList('id'); if ($this->_db->getErrorNum()) { JError::raiseError(500, $this->_db->stderr()); return false; } return $deals; }