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;
     }
 }
 /**
  * Save the product basic option.
  *
  * @param   object  $curr_post  Post objec.
  *
  * @since   2.2
  * @return   null
  */
 function storecurrency($curr_post)
 {
     $itemname = $curr_post->get('item_name', '', 'STRING');
     $store_id = $curr_post->get('store_id', '', 'STRING');
     $pid = $curr_post->get('pid', '', 'STRING');
     //@TODO check - ^sanjivani
     if (empty($pid)) {
         // For native product manager
         $pid = $curr_post->get('item_id', '', 'STRING');
     }
     //@TODO check - ^sanjivani
     $client = $curr_post->get('client', '', 'STRING');
     $sku = $curr_post->get('sku', '', 'RAW');
     $res = '';
     $message = '';
     $comquick2cartHelper = new comquick2cartHelper();
     $db = JFactory::getDbo();
     $params = JComponentHelper::getParams('com_quick2cart');
     $kart_curr_param = $params->get('addcurrency');
     // used to store in kart_item table
     $kart_curr_param_array = explode(',', $kart_curr_param);
     $kart_item_curr = $kart_curr_param_array[0];
     $quick2cartModelAttributes = new quick2cartModelAttributes();
     //@TODO check - ^sanjivani
     //$item_id = $quick2cartModelAttributes->getitemid($pid, $client, $sku);
     $item_id = $quick2cartModelAttributes->getitemid($pid, $client);
     $img_dimensions = array();
     $img_dimensions[] = 'small';
     $img_dimensions[] = 'medium';
     $img_dimensions[] = 'large';
     $image_path = array();
     // STORING ALL IMAGES images upladed (on new or edit)
     foreach ($_FILES as $key => $imgfile) {
         if (!empty($imgfile['name'])) {
             $image_path[] = $comquick2cartHelper->imageupload($key, $img_dimensions);
             //$imgfile['name']);
         }
     }
     $qtc_prodImgs = $curr_post->get('qtc_prodImg', array(), 'ARRAY');
     // ON EDIT
     if (!empty($qtc_prodImgs)) {
         foreach ($image_path as $newImg) {
             $qtc_prodImgs[] = $newImg;
         }
         //$image_path = $curr_post->get('qtc_prodImg', array(), 'ARRAY'); //$curr_post['qtc_prodImg'];
         $image_path = array_filter($qtc_prodImgs, "trim");
     }
     if (!empty($image_path)) {
         $image_path = json_encode($image_path);
     } else {
         $image_path = '';
     }
     //@TODO save images and store in DB
     $images = "";
     //GETTING ATTRIBUTE DETAILS,multi currency and discount details
     $att_detail = $curr_post->get('att_detail', array(), 'ARRAY');
     $multi_cur = $curr_post->get('multi_cur', array(), 'ARRAY');
     $multi_dis_cur = $curr_post->get('multi_dis_cur', array(), 'ARRAY');
     if (!$item_id) {
         $state = $curr_post->get('state');
         if (empty($state)) {
             $state = 0;
         }
         // Call the trigger to add extra field in product page.
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin("system");
         $result = $dispatcher->trigger("beforeSavingProductBasicDetail", array($curr_post, 'insert'));
         // Save new product
         $item_id = $this->storeInKartItem('insert', $image_path, $multi_cur[$kart_item_curr], $curr_post);
     } else {
         $state = $curr_post->get('state');
         // dont set default value as 1 (require for unpublish)
         if (isset($state)) {
             $state = $state;
         }
         $productHelper = $comquick2cartHelper->loadqtcClass(JPATH_SITE . DS . "components" . DS . "com_quick2cart" . DS . "helpers" . DS . "product.php", "productHelper");
         $productHelper->deleteNotReqProdImages($item_id, $image_path);
         // Call the trigger to add extra field in product page.
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin("system");
         $result = $dispatcher->trigger("beforeSavingProductBasicDetail", array($curr_post, 'update'));
         $item_id = $this->storeInKartItem('update', $image_path, $multi_cur[$kart_item_curr], $curr_post);
     }
     $message = $item_id;
     $query = "SELECT * FROM #__kart_base_currency  WHERE item_id = " . (int) $item_id;
     $db->setQuery($query);
     $res = $db->loadAssocList();
     //if there is a entry in kart_base_currency table
     if ($res) {
         foreach ($multi_cur as $cur_name => $cur_value) {
             $db = JFactory::getDBO();
             $flag = 0;
             foreach ($res as $k => $v) {
                 if ($cur_name == $v['currency']) {
                     $flag = 1;
                     // take currency value frm post and match whith Db currency
                     break;
                 }
             }
             if ($flag == 1) {
                 $dis_curr = !empty($multi_dis_cur[$cur_name]) ? (double) $multi_dis_cur[$cur_name] : 'NULL';
                 //if (isset( $curr_post['multi_dis_cur'][$cur_name]) && $curr_post['multi_dis_cur'][$cur_name] != '' ){
                 $dis_curr = " , discount_price=" . $dis_curr;
                 //}
                 $query = "UPDATE #__kart_base_currency SET price=" . (double) $cur_value . " " . $dis_curr . " WHERE `item_id`=" . (int) $item_id . " AND `currency`='" . $cur_name . "'";
                 $db->setQuery($query);
                 $update = $db->execute();
                 /*if ($update)
                 		print"UPDATE";
                 		else
                 		print"NOT UPDATE";*/
             } else {
                 $items = new stdClass();
                 $items->item_id = $item_id;
                 $items->currency = $cur_name;
                 // eg INR,usd
                 $items->price = $cur_value;
                 //if (isset( $curr_post['multi_dis_cur'][$cur_name]) && $curr_post['multi_dis_cur'][$cur_name] != '' ){
                 $items->discount_price = !empty($multi_dis_cur[$cur_name]) ? (double) $multi_dis_cur[$cur_name] : 'NULL';
                 //}
                 if (!$db->insertObject('#__kart_base_currency', $items)) {
                     $messagetype = 'notice';
                     $message = JText::_('QTC_PARAMS_SAVE_FAIL') . " - " . $db->stderr();
                 }
             }
         }
     } else {
         //insert query
         foreach ($multi_cur as $cur_name => $cur_value) {
             $items = new stdClass();
             $items->item_id = $item_id;
             $items->currency = $cur_name;
             // eg INR,usd
             $items->price = $cur_value;
             // currencey value
             if (isset($multi_dis_cur[$cur_name]) && $multi_dis_cur[$cur_name] != '') {
                 $items->discount_price = $multi_dis_cur[$cur_name];
             }
             if (!$db->insertObject('#__kart_base_currency', $items)) {
                 $messagetype = 'notice';
                 $message = JText::_('QTC_PARAMS_SAVE_FAIL') . " - " . $db->stderr();
             }
         }
     }
     return $message;
 }