Esempio n. 1
0
 function addSaveOrderItems($insert_order_id, $cart_itemsdata, $data, $updateOrderstatus)
 {
     $productHelper = new productHelper();
     // GET BILLING AND SHIPPING ADDRESS
     $bill = $data->get('bill', array(), "ARRAY");
     $ship = $data->get('ship', array(), "ARRAY");
     $comquick2cartHelper = new comquick2cartHelper();
     $data->set('order_id', $insert_order_id);
     // row_id= last insert id
     $store_info = array();
     $itemsTaxDetail = $data->get('itemsTaxDetail', array(), 'ARRAY');
     $itemShipMethDetail = $data->get('itemShipMethDetail', array(), 'ARRAY');
     foreach ($cart_itemsdata as $cart_items) {
         $item_id = $cart_items['item_id'];
         $taxdetail = '';
         $shipdetail = '';
         // Get item tax detail
         if (!empty($itemsTaxDetail[$item_id])) {
             // Get current item tax detail
             $taxdetail = $itemsTaxDetail[$item_id];
         }
         // Get item ship detail
         if (!empty($itemShipMethDetail[$item_id])) {
             // Get current item tax detail
             $shipdetail = $itemShipMethDetail[$item_id];
         }
         $items = new stdClass();
         $items->order_id = $insert_order_id;
         $items->item_id = $item_id;
         // Getting store id from item_id
         $items->store_id = $comquick2cartHelper->getSoreID($cart_items['item_id']);
         $items->product_attributes = $cart_items['product_attributes'];
         $items->product_attribute_names = $cart_items['options'];
         $items->order_item_name = $cart_items['title'];
         $items->product_quantity = $cart_items['qty'];
         $items->product_item_price = $cart_items['amt'];
         $items->product_attributes_price = $cart_items['opt_amt'];
         // This field store price without cop, tax,shipp etc
         //~ $originalProdPrice = ($items->product_item_price + $items->product_attributes_price ) * $items->product_quantity;
         //~ $items->original_price = isset($cart_items['original_price']) ? $cart_items['original_price'] : $originalProdPrice;
         $items->original_price = $cart_items['original_price'];
         $items->item_tax = !empty($taxdetail['taxAmount']) ? $taxdetail['taxAmount'] : 0;
         $items->item_tax_detail = !empty($taxdetail) ? json_encode($taxdetail) : '';
         $items->item_shipcharges = !empty($shipdetail['totalShipCost']) ? $shipdetail['totalShipCost'] : 0;
         $items->item_shipDetail = !empty($shipdetail) ? json_encode($shipdetail) : '';
         $items->product_final_price = $cart_items['tamt'] + $items->item_tax + $items->item_shipcharges;
         $items->params = $cart_items['params'];
         $items->cdate = date("Y-m-d H:i:s");
         //$cart_items['cdate'];
         $items->mdate = date("Y-m-d H:i:s");
         //$cart_items['mdate'];
         $items->status = 'P';
         if (!$this->_db->insertObject('#__kart_order_item', $items, 'order_item_id')) {
             echo $this->_db->stderr();
             return 0;
         }
         // Add entry in order_itemattributes
         $query = "Select *\n\t\t\t FROM #__kart_cartitemattributes\n\t\t\t WHERE cart_item_id=" . (int) $cart_items['id'];
         // cart_item_id as id
         $this->_db->setQuery($query);
         $cartresult = $this->_db->loadAssocList();
         if (!empty($cartresult)) {
             foreach ($cartresult as $key => $cart_itemopt) {
                 $items_opt = new stdClass();
                 $items_opt->order_item_id = $items->order_item_id;
                 $items_opt->itemattributeoption_id = $cart_itemopt['itemattributeoption_id'];
                 $items_opt->orderitemattribute_name = $cart_itemopt['cartitemattribute_name'];
                 $attopprice = $this->getAttrOptionPrice($cart_itemopt['itemattributeoption_id']);
                 $items_opt->orderitemattribute_price = $attopprice;
                 $items_opt->orderitemattribute_prefix = $cart_itemopt['cartitemattribute_prefix'];
                 if (!$this->_db->insertObject('#__kart_order_itemattributes', $items_opt, 'orderitemattribute_id')) {
                     echo $this->_db->stderr();
                     return 0;
                 }
             }
         }
         $params = JComponentHelper::getParams('com_quick2cart');
         $socialintegration = $params->get('integrate_with', 'none');
         $streamBuyProd = $params->get('streamBuyProd', 0);
         //$libclass = new activityintegrationstream();
         if ($streamBuyProd && $socialintegration != 'none') {
             // adding msg in stream
             $user = JFactory::getUser();
             $action = 'buyproduct';
             $prodLink = '<a class="" href="' . $comquick2cartHelper->getProductLink($cart_items['item_id']) . '">' . $cart_items['title'] . '</a>';
             $store_info[$items->store_id] = $comquick2cartHelper->getSoreInfo($items->store_id);
             $storeLink = '<a class="" href="' . JUri::root() . substr(JRoute::_('index.php?option=com_quick2cart&view=vendor&layout=store&store_id=' . $items->store_id), strlen(JUri::base(true)) + 1) . '">' . $store_info[$items->store_id]['title'] . '</a>';
             $originalMsg = JText::sprintf('QTC_ACTIVITY_BUY_PROD', $prodLink, $storeLink);
             $title = '{actor} ' . $originalMsg;
             // According to integration create social lib class obj.
             $libclass = $comquick2cartHelper->getQtcSocialLibObj();
             $libclass->pushActivity($user->id, $act_type = '', $act_subtype = '', $originalMsg, $act_link = '', $title = '', $act_access = '');
         }
         if (0) {
             // add to JS stream
             if (JFile::exists(JPATH_SITE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php')) {
                 @$comquick2cartHelper->addJSstream($user->id, $user->id, $title, '', $action, 0);
                 require_once JPATH_SITE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php';
                 $userid = JFactory::getUser()->id;
                 if ($userid) {
                     $userLink = '<a class="" href="' . JUri::root() . substr(CRoute::_('index.php?option=com_community&view=profile&userid=' . $userid), strlen(JUri::base(true)) + 1) . '">' . JFactory::getUser()->name . '</a>';
                 } else {
                     $userLink = $bill['email1'];
                 }
                 //Get connected Users of logged in user
                 $jsuser = CFactory::getUser($userid);
                 $connections_aa = $jsuser->getFriendIds();
                 if (!empty($connections_aa)) {
                     foreach ($connections_aa as $connections) {
                         $notification_subject = JText::sprintf('QTC_NOTIFIY_BUY_PROD_FRN', $userLink, $prodLink);
                         @$comquick2cartHelper->addJSnotify($userid, $connections, $notification_subject, 'notif_system_messaging', '0', '');
                     }
                 }
                 $groupIDs = explode(",", $jsuser->_groups);
                 if (empty($groupIDs)) {
                     $query = "SELECT groupid FROM #__community_groups_members " . "WHERE memberid=" . $userid;
                     $this->_db->setQuery($query);
                     $groupIDs = $this->_db->loadColumn();
                 }
                 if (!empty($groupIDs)) {
                     foreach ($groupIDs as $groupID) {
                         if (!empty($groupID)) {
                             $query = "SELECT name FROM #__community_groups " . " WHERE id=" . $groupID;
                             $this->_db->setQuery($query);
                             $groupName = $this->_db->loadResult();
                             $query = "SELECT memberid " . "FROM #__community_groups_members " . "WHERE groupid=" . $groupID . " AND approved=1 AND memberid<>" . $userid . "";
                             $this->_db->setQuery($query);
                             $group_ids = $this->_db->loadColumn();
                             if (!empty($group_ids)) {
                                 foreach ($group_ids as $group_id) {
                                     $notification_subject = JText::sprintf('QTC_NOTIFIY_BUY_PROD_GRP', $userLink, $groupName, $prodLink);
                                     $comquick2cartHelper->addJSnotify($userid, $group_id, $notification_subject, 'notif_system_messaging', '0', '');
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // end of if (0)
         // REMOVED JS CODE
         /* end add to JS stream*/
     }
     // ENd of cart item for each
     // For JS notification is sent
     if (!empty($storeLink) && JFile::exists(JPATH_SITE . '/components/com_community/libraries/core.php')) {
         require_once JPATH_SITE . '/components/com_community/libraries/core.php';
         $commented_by_userid = JFactory::getUser()->id;
         if ($commented_by_userid) {
             $userLink = '<a class="" href="' . JUri::root() . substr(CRoute::_('index.php?option=com_community&view=profile&userid=' . $commented_by_userid), strlen(JUri::base(true)) + 1) . '">' . JFactory::getUser()->name . '</a>';
         } else {
             $userLink = $bill['email1'];
         }
         foreach ($store_info as $store_id => $storeinfo) {
             $storeLink = '<a class="" href="' . JUri::root() . substr(JRoute::_('index.php?option=com_quick2cart&view=vendor&layout=store&store_id=' . $store_id), strlen(JUri::base(true)) + 1) . '">' . $storeinfo['title'] . '</a>';
             $notification_subject = JText::sprintf('QTC_NOTIFIY_BUY_STORE', $userLink, $storeLink);
             @$comquick2cartHelper->addJSnotify($commented_by_userid, $storeinfo['owner'], $notification_subject, 'notif_system_messaging', '0', '');
         }
     }
 }