Beispiel #1
0
 /** This function save the store detail.
  * USED IN PLUGIN::  ACCORDING TO REGISTERED USER ACCESS LAVEL , NEW  SOTRE IS CREATD FOR THAT USER
  *	@param  object $post post
  *  @param  integer userid.
  *	@return  userid  number
  * */
 function store($post, $userid = '')
 {
     $params = JComponentHelper::getParams('com_quick2cart');
     $email = $post->get('email', '', 'RAW');
     if (!empty($email)) {
         $db = JFactory::getDBO();
         $user = JFactory::getUser();
         $oldData = '';
         // Get old data if exists
         $id = $post->get('id');
         if (!empty($id)) {
             $query = "SELECT `id`, store_avatar, header\n\t\t\t\t FROM #__kart_store\n\t\t\t\t WHERE `id`=" . $id;
             $db->setQuery($query);
             $oldData = $db->loadAssoc($query);
         }
         $oldAvtarPath = !empty($oldData) ? $oldData['store_avatar'] : '';
         $oldHeaderPath = !empty($oldData) ? $oldData['header'] : '';
         $row = new stdClass();
         $row->owner = $user->id;
         if ($userid != '') {
             $row->owner = $userid;
         }
         $row->description = $post->get('description', '', 'RAW');
         $row->company_name = $post->get('companyname', '', 'RAW');
         $row->address = $post->get('address', '', 'RAW');
         $row->phone = $post->get('phone');
         $row->store_email = $post->get('email', '', 'RAW');
         $row->length_id = $post->get('qtc_length_class', '', 'INTEGER');
         $row->weight_id = $post->get('qtc_weight_class', '', 'INTEGER');
         $row->taxprofile_id = $post->get('taxprofile_id', '', 'INTEGER');
         $row->shipprofile_id = $post->get('qtc_shipProfile', '', 'INTEGER');
         // Added by vbmundhe Dont remove as it is require on install script
         $helper_path = JPATH_SITE . '/components/com_quick2cart/helper.php';
         if (!class_exists('comquick2cartHelper')) {
             JLoader::register('comquick2cartHelper', $helper_path);
             JLoader::load('comquick2cartHelper');
         }
         $comquick2cartHelper = new comquick2cartHelper();
         // STORE LOGO IMGE
         $avatar = $post->get('avatar', '', 'RAW');
         if (!empty($avatar)) {
             $avtar_path = $avatar;
         } else {
             $img_dimensions = array();
             $img_dimensions[] = 'storeavatar';
             // upload avtar
             // name of file field
             $file_field = "avatar";
             $avtar_path = $comquick2cartHelper->imageupload($file_field, $img_dimensions, 0);
         }
         if (!empty($avtar_path)) {
             // AVOID  IMAGE OVERWRITE TO NULL WHILE UPDATE
             $row->store_avatar = $avtar_path;
         }
         // STORE STOREHEADER IMGE
         /*if (!empty($post['storeheader']))
         		{
         		$header_path=$post['storeheader'];
         		}
         		else
         		{
         		// upload header img
         		$file_field="storeheader";  // name of file field in from view eg <input type="file" name="avatar"  id="avatar" />
         		$header_path=$comquick2cartHelper->uploadImage($file_field,$oldHeaderPath);
         		}*/
         $header_path = '';
         $row->header = $header_path;
         $extra = $post->get('extra', '', 'RAW');
         if (!empty($extra)) {
             // While update , AVOID DONT MAKE EMPTY
             $row->extra = $extra;
         }
         $row->payment_mode = $post->get('paymentMode');
         if (empty($row->payment_mode)) {
             $row->pay_detail = $post->get('paypalemail', '', 'RAW');
         } else {
             $row->pay_detail = $post->get('otherPayMethod', '', 'RAW');
         }
         $quick2cartModelVendor = new quick2cartModelVendor();
         //$row->live =$post['title'];
         //$row->extra=
         $id = "";
         $title = $post->get('title', '', 'RAW');
         $storeVanityUrl = $post->get('storeVanityUrl', '', 'RAW');
         $id = $post->get('id', '', 'RAW');
         // If already present then update
         if (!empty($oldData)) {
             $row->title = $quick2cartModelVendor->formatttedTitle($title, $id);
             $row->vanityurl = $quick2cartModelVendor->formatttedVanityURL($storeVanityUrl, $title, $id);
             $row->id = $id = $oldData['id'];
             $row->mdate = date("Y-m-d");
             try {
                 $db->updateObject('#__kart_store', $row, 'id');
             } catch (RuntimeException $e) {
                 $this->setError($e->getMessage());
                 return 0;
             }
             $mail_on_store_edit = (int) $params->get('mail_on_store_edit');
             if ($mail_on_store_edit === 1) {
                 // Send store edited email to admin
                 $this->SendMailAdminOnStoreEdit($row);
             }
             $role = 1;
             $quick2cartModelVendor->addRoleEntry($id, $role, $row->owner);
             return $id;
         } else {
             // Insert
             $row->title = $quick2cartModelVendor->formatttedTitle($title);
             $row->vanityurl = $quick2cartModelVendor->formatttedVanityURL($storeVanityUrl, $title);
             $row->cdate = date("Y-m-d");
             $row->mdate = date("Y-m-d");
             $mail_on_store_create = (int) $params->get('mail_on_store_create');
             if ($mail_on_store_create == 1) {
                 $row->live = 0;
             }
             if (!$db->insertObject('#__kart_store', $row, 'id')) {
                 echo $db->stderr();
                 return 0;
             }
             if ($mail_on_store_create === 1) {
                 // Send Approval mail to admin
                 $this->SendMailAdminOnCreateStore($row);
                 $this->SendMailOwnerOnCreateStore($row);
             }
             $id = $db->insertid();
             global $mainframe;
             $mainframe = JFactory::getApplication();
             $socialintegration = $params->get('integrate_with', 'none');
             $streamOnCeateStore = $params->get('streamCeateStore', 1);
             // If (!$mainframe->isAdmin() && $streamOnCeateStore && $socialintegration != 'none')
             if ($socialintegration != 'none') {
                 $user = JFactory::getUser();
                 $libclass = $comquick2cartHelper->getQtcSocialLibObj();
                 // Add in activity.
                 if ($streamOnCeateStore) {
                     $action = 'addstore';
                     $storeLink = '<a class="" href="' . JUri::root() . substr(JRoute::_('index.php?option=com_quick2cart&view=vendor&layout=store&store_id=' . $id), strlen(JUri::base(true)) + 1) . '">' . $title . '</a>';
                     $originalMsg = JText::sprintf('QTC_ACTIVITY_ADD_STORE', $storeLink);
                     $libclass->pushActivity($user->id, $act_type = '', $act_subtype = '', $originalMsg, $act_link = '', $title = '', $act_access = 0);
                 }
                 // Add points
                 $point_system = $params->get('point_system');
                 $options['extension'] = 'com_quick2cart';
                 if ($socialintegration == "EasySocial") {
                     $options['command'] = 'create_store';
                     $libclass->addpoints($user, $options);
                 } elseif ($socialintegration == "JomSocial") {
                     $options['command'] = 'CreateStore.points';
                     $libclass->addpoints($user, $options);
                 }
             }
         }
         $role = 1;
         $uid = $user->id;
         if ($userid != '') {
             $uid = $userid;
         }
         $quick2cartModelVendor = new quick2cartModelVendor();
         $quick2cartModelVendor->addRoleEntry($id, $role, $uid);
         // Add only on creating store insted of edit
         return $id;
     } else {
         return 0;
     }
 }