Example #1
0
 function saveManufacturer($data)
 {
     $this->onExecuteBefore('saveManufacturer', array(&$data));
     $data['alias'] = KSFunctions::CheckAlias($data['alias'], $data['id']);
     if ($data['alias'] == '') {
         $data['alias'] = KSFunctions::GenAlias($data['title']);
     }
     $data['country'] = isset($data['country']) ? $data['country'] : 0;
     $table = $this->getTable('manufacturers');
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'manufacturer', 'manufacturers');
     $on_close = 'window.parent.ManufacturersModule.refresh();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('saveManufacturer', array(&$return));
     return $return;
 }
Example #2
0
 function saveRegion($data)
 {
     $this->onExecuteBefore('saveRegion', array(&$data));
     $data['alias'] = KSFunctions::CheckAlias($data['alias'], $data['id']);
     $data['alias'] = $data['alias'] == '' ? KSFunctions::GenAlias($data['title']) : $data['alias'];
     $data['country_id'] = isset($data['country_id']) ? $data['country_id'] : 0;
     $table = $this->getTable('regions');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_regions')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'region', 'regions');
     $on_close = 'window.parent.RegionsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('saveRegion', array(&$return));
     return $return;
 }
Example #3
0
 function savePayment($data)
 {
     $this->onExecuteBefore('savePayment', array(&$data));
     $data['params'] = isset($data['params']) && is_array($data['params']) ? json_encode($data['params']) : json_encode(array());
     $data['regions'] = isset($data['regions']) && is_array($data['regions']) ? $data['regions'] : array();
     $data['published'] = isset($data['published']) ? $data['published'] : 0;
     $data['images'] = isset($data['images']) ? $data['images'] : array();
     foreach ($data['regions'] as &$country) {
         $country = array_filter($country, 'KSFunctions::filterArray');
     }
     unset($country);
     $data['regions'] = json_encode($data['regions']);
     $table = $this->getTable('payments');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_payments')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'payment', 'payments');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSavePayment', array($id));
     $on_close = 'window.parent.PaymentsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('savePayment', array(&$return));
     return $return;
 }
Example #4
0
 function SaveDiscount($data)
 {
     $this->onExecuteBefore('SaveDiscount', array(&$data));
     $data['categories'] = is_array($data['categories']) ? json_encode($data['categories']) : json_encode(array());
     $data['manufacturers'] = is_array($data['manufacturers']) ? json_encode($data['manufacturers']) : json_encode(array());
     $data['regions'] = isset($data['regions']) && is_array($data['regions']) ? $data['regions'] : array();
     $data['params'] = is_array($data['params']) ? json_encode($data['params']) : json_encode(array());
     $data['user_actions'] = isset($data['user_actions']) && is_array($data['user_actions']) ? json_encode($data['user_actions']) : json_encode(array());
     $data['user_groups'] = isset($data['user_groups']) && is_array($data['user_groups']) ? json_encode($data['user_groups']) : json_encode(array());
     $data['info_methods'] = isset($data['info_methods']) && is_array($data['info_methods']) ? json_encode($data['info_methods']) : json_encode(array());
     $data['from_date'] = date('Y-m-d', strtotime($data['from_date']));
     $data['to_date'] = date('Y-m-d', strtotime($data['to_date']));
     $data['sum'] = isset($data['sum']) ? $data['sum'] : 0;
     $data['enabled'] = isset($data['enabled']) ? $data['enabled'] : 0;
     $data['images'] = isset($data['images']) ? $data['images'] : array();
     foreach ($data['regions'] as &$country) {
         $country = array_filter($country, 'KSFunctions::filterArray');
     }
     unset($country);
     $data['regions'] = json_encode($data['regions']);
     $table = $this->getTable('discounts');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_discounts')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'discount', 'discounts');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSaveDiscount', array($id));
     $on_close = 'window.parent.DiscountsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('SaveDiscount', array(&$return));
     return $return;
 }
Example #5
0
 function saveUser($data)
 {
     $this->onExecuteBefore('saveUser', array(&$data));
     $data['name'] = '';
     if (!empty($data['last_name'])) {
         $data['name'] .= $data['last_name'] . ' ';
     }
     if (!empty($data['first_name'])) {
         $data['name'] .= $data['first_name'] . ' ';
     }
     if (!empty($data['middle_name'])) {
         $data['name'] .= $data['middle_name'];
     }
     if ($data['social'] == 1) {
         $data['email'] = $data['username'] . '@email.ru';
     }
     $user = JUser::getInstance($data['id']);
     if (!$user->bind($data)) {
         $this->setError($user->getError());
         return false;
     }
     if (!$user->save()) {
         $this->setError($user->getError());
         return false;
     }
     $id = $user->id;
     $query = $this->_db->getQuery(true);
     $query->select('id')->from('#__ksen_users')->where('id=' . (int) $data['id']);
     $this->_db->setQuery($query);
     $count = $this->_db->loadResult();
     if (empty($count)) {
         $query = $this->_db->getQuery(true);
         $query->insert('#__ksen_users')->columns('id')->values(array($id));
         $this->_db->setQuery($query);
         $this->_db->query();
         $data['id'] = $user->id;
     }
     $table = $this->getTable('KMUsers');
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     KSMedia::saveItemMedia($id, $data, 'user', 'users');
     $in = array();
     foreach ($data['addresses'] as $k => $v) {
         $v['user_id'] = $id;
         $table = $this->getTable('useraddresses');
         if ($k > 0) {
             $v['id'] = $k;
         }
         if (!$table->bindCheckStore($v)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
     }
     $query = $this->_db->getQuery(true);
     $query->delete('#__ksen_user_addresses')->where('user_id=' . $id);
     if (count($in)) {
         $query->where('id not in (' . implode(',', $in) . ')');
     }
     $this->_db->setQuery($query);
     $this->_db->query();
     $in = array();
     foreach ($data['fields'] as $k => $v) {
         $value = array('user_id' => $id, 'field_id' => $k, 'value' => $v);
         $table = $this->getTable('userfieldsvalues');
         if (!$table->bindCheckStore($value)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
     }
     $query = $this->_db->getQuery(true);
     $query->delete('#__ksen_user_fields_values')->where('user_id=' . $id);
     if (count($in)) {
         $query->where('id not in (' . implode(',', $in) . ')');
     }
     $this->_db->setQuery($query);
     $this->_db->query();
     $on_close = 'window.parent.UsersList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('saveUser', array(&$return));
     return $return;
 }
Example #6
0
 function SaveShipping($data)
 {
     $this->onExecuteBefore('SaveShipping', array(&$data));
     $data['params'] = isset($data['params']) && is_array($data['params']) ? json_encode($data['params']) : json_encode(array());
     $data['regions'] = isset($data['regions']) && is_array($data['regions']) ? $data['regions'] : array();
     $data['published'] = isset($data['published']) ? $data['published'] : 0;
     $data['user_fields'] = isset($data['user_fields']) ? $data['user_fields'] : array();
     $data['images'] = isset($data['images']) ? $data['images'] : array();
     foreach ($data['regions'] as &$country) {
         $country = array_filter($country, 'KSFunctions::filterArray');
     }
     unset($country);
     $data['regions'] = json_encode($data['regions']);
     $table = $this->getTable('shippings');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_shippings')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'shipping', 'shippings');
     $in = array();
     foreach ($data['user_fields'] as $key => $field) {
         $key = (int) $key;
         if ($key > 0) {
             $field['id'] = $key;
         }
         $field['shipping_id'] = $id;
         $field['required'] = isset($field['required']) ? $field['required'] : 0;
         $table = $this->getTable('ShippingFields');
         if (!$table->bindCheckStore($field)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
         if ($field['type'] == 'select') {
             foreach ($field['values'] as $key => $value) {
                 $key = (int) $key;
                 if ($key > 0) {
                     $value['id'] = $key;
                 }
                 $value['field_id'] = $table->id;
                 $vtable = $this->getTable('ShippingFieldsValues');
                 if (!$vtable->bindCheckStore($value)) {
                     $this->setError($vtable->getError());
                     return false;
                 }
             }
         }
     }
     foreach ($data['address_fields'] as $key => $field) {
         $key = (int) $key;
         if ($key > 0) {
             $field['id'] = $key;
         }
         $field['shipping_id'] = $id;
         $field['required'] = isset($field['required']) ? $field['required'] : 0;
         $table = $this->getTable('ShippingFields');
         if (!$table->bindCheckStore($field)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
         if ($field['type'] == 'select') {
             foreach ($field['values'] as $key => $value) {
                 $key = (int) $key;
                 if ($key > 0) {
                     $value['id'] = $key;
                 }
                 $value['field_id'] = $table->id;
                 $vtable = $this->getTable('ShippingFieldsValues');
                 if (!$vtable->bindCheckStore($value)) {
                     $this->setError($vtable->getError());
                     return false;
                 }
             }
         }
     }
     $query = $this->_db->getQuery(true);
     $query->select('id')->from('#__ksenmart_shipping_fields')->where('shipping_id=' . $id);
     if (count($in)) {
         $query->where('id not in (' . implode(', ', $in) . ')');
     }
     $this->_db->setQuery($query);
     $ids = $this->_db->loadColumn();
     if (count($ids) > 0) {
         $query = $this->_db->getQuery(true);
         $query->delete('#__ksenmart_shipping_fields')->where('id in (' . implode(',', $ids) . ')');
         $this->_db->setQuery($query);
         $this->_db->query();
         $query = $this->_db->getQuery(true);
         $query->delete('#__ksenmart_shipping_fields_values')->where('field_id in (' . implode(',', $ids) . ')');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSaveShipping', array($id));
     $on_close = 'window.parent.ShippingsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('SaveShipping', array(&$return));
     return $return;
 }