function getCreditCardSettings($visible_only = true)
 {
     //
     global $application;
     $tables = $this->getTables();
     $columns = $tables['credit_card_settings']['columns'];
     $query = new DB_Select();
     $query->addSelectField($columns["id"], "id");
     $query->addSelectField($columns["name"], "name");
     $query->addSelectField($columns["tag"], "tag");
     $query->addSelectField($columns["sort_order"], "sort_order");
     $query->addSelectField($columns["visible"], "visible");
     if ($visible_only === true) {
         $query->WhereValue($columns["visible"], DB_EQ, DB_TRUE);
     }
     $query->SelectOrder($columns['sort_order']);
     $result = $application->db->getDB_Result($query);
     $res = array();
     foreach ($result as $credit_card_info) {
         $res[$credit_card_info["tag"]] = array("id" => $credit_card_info["id"], "sort_order" => $credit_card_info["sort_order"], "name" => (string) $credit_card_info["name"], "tag" => (string) $credit_card_info["tag"], "visible" => (string) $credit_card_info["visible"]);
     }
     return $res;
 }
Ejemplo n.º 2
0
 function getPersonInfoCustomAttributeList($variant_id)
 {
     global $application;
     $tables = $this->getTables();
     $s = $tables['person_info_variants_to_attributes']['columns'];
     $a = $tables['person_attributes']['columns'];
     $query = new DB_Select();
     $query->addSelectField($a['tag'], 'tag');
     $query->addSelectField($s['name'], 'name');
     $query->WhereValue($s['variant_id'], DB_EQ, $variant_id);
     $query->WhereAND();
     $query->WhereField($a['id'], DB_EQ, $s['attribute_id']);
     $query->WhereAND();
     $query->WhereValue($a['is_custom'], DB_EQ, 1);
     $query->SelectOrder($s['sort']);
     $result = $application->db->getDB_Result($query);
     return $result;
 }
 function _addInputType($type_name, $type_values = array(), $it_id = '')
 {
     global $application;
     $result = array();
     // magic numbers: 9 is the maximal pre-defined input type
     if ($it_id > 0 && $it_id <= 9) {
         return;
     }
     // removing empty values
     if (!is_array($type_values)) {
         $type_values = array($type_values);
     }
     foreach ($type_values as $k => $v) {
         if (!trim($v)) {
             unset($type_values[$k]);
         }
     }
     $tables = modApiFunc('Catalog', 'getTables');
     $it = $tables['input_types']['columns'];
     $itv = $tables['input_type_values']['columns'];
     $i = new DB_Replace('input_types');
     if ($it_id) {
         $i->addReplaceValue($it_id, $it['ut_id']);
     }
     $i->addReplaceValue($type_name, $it['name']);
     $result['new_input_type'] = $application->db->getDB_Result($i);
     if ($it_id) {
         $result['insert_type_id'] = $it_id;
     } else {
         $result['insert_type_id'] = $application->db->DB_Insert_Id();
     }
     //adding values for new type
     $id = $result['insert_type_id'];
     if (is_array($type_values) && !empty($type_values)) {
         $saved_values = array();
         if ($it_id) {
             $query = new DB_Select();
             $query->addSelectField($itv['id'], 'id');
             $query->WhereValue($itv['it_id'], DB_EQ, $id);
             $query->SelectOrder($itv['id'], 'ASC');
             $saved_values = $application->db->getDB_Result($query);
             if (!$saved_values) {
                 $saved_values = array();
             } else {
                 foreach ($saved_values as $k => $v) {
                     $saved_values[$k] = $v['id'];
                 }
             }
         }
         $index = 1;
         foreach ($type_values as $i => $value) {
             $old_id = array_shift($saved_values);
             if ($old_id) {
                 $upd = new DB_Update('input_type_values');
                 $upd->addMultiLangUpdateValue($itv['value'], $value, $itv['id'], $old_id, 'Catalog');
                 $upd->WhereValue($itv['id'], DB_EQ, $old_id);
                 $application->db->getDB_Result($upd);
             } else {
                 $ins = new DB_Insert('input_type_values');
                 $ins->addInsertValue($id, $itv['it_id']);
                 $ins->addMultiLangInsertValue($value, $itv['value'], $itv['id'], 'Catalog');
                 $application->db->getDB_Result($ins);
             }
             $result['new_input_values'][] = $value;
         }
         if (!empty($saved_values)) {
             $d1 = new DB_Delete("input_type_values");
             $d1->deleteMultiLangField($itv['value'], $itv['id'], 'Catalog');
             $d1->WhereValue($itv['id'], DB_IN, '(\'' . implode('\', \'', $saved_values) . '\')');
             $application->db->getDB_Result($d1);
         }
     } elseif ($it_id) {
         $d1 = new DB_Delete("input_type_values");
         $d1->deleteMultiLangField($itv['value'], $itv['id'], 'Catalog');
         $d1->WhereValue($itv['it_id'], DB_EQ, $it_id);
         $application->db->getDB_Result($d1);
     }
     return $result;
 }
 function getTopicEmails($topic_id, $search_email = null)
 {
     global $application;
     $tables = $this->getTables();
     $etable = 'subscription_email';
     $ecolumns =& $tables[$etable]['columns'];
     $atable = 'email_address';
     $acolumns =& $tables[$atable]['columns'];
     $query = new DB_Select($atable);
     $query->addSelectField($acolumns['email_id']);
     $query->addSelectField($acolumns['customer_id']);
     $query->addSelectField($acolumns['email']);
     $query->addSelectField($acolumns['lng']);
     $query->addInnerJoin($etable, $ecolumns['email_id'], DB_EQ, $acolumns['email_id']);
     $query->WhereValue($ecolumns['topic_id'], DB_EQ, $topic_id);
     if (!empty($search_email)) {
         $query->WhereAND();
         $query->WhereValue($acolumns['email'], DB_LIKE, '%' . $search_email . '%');
     }
     $query->SelectOrder($acolumns['email'], 'ASC');
     $query = modApiFunc('paginator', 'setQuery', $query);
     $res = $application->db->getDB_Result($query);
     return $res;
 }
 function getPersonInfoGroupAttrs($group_id, $attr_vis = PERSON_INFO_GROUP_ATTR_ALL)
 {
     global $application;
     $tables = $this->getTables();
     $pia_table = $tables['ca_person_info_attrs']['columns'];
     $atg_table = $tables['ca_attrs_to_groups']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('ca_person_info_attrs');
     $query->addSelectTable('ca_attrs_to_groups');
     $query->addSelectField($pia_table['attr_id'], 'attr_id');
     $query->addSelectField($pia_table['attr_name'], 'attr_name');
     $query->addSelectField($pia_table['lang_code'], 'lang_code');
     $query->setMultiLangAlias('_ml_name', 'ca_attrs_to_groups', $atg_table['visible_name'], $atg_table['ag_id'], 'Customer_Account');
     $query->addSelectField($query->getMultiLangAlias('_ml_name'), 'visible_name');
     $query->addSelectField($atg_table['is_visible'], 'is_visible');
     $query->addSelectField($atg_table['is_required'], 'is_required');
     $query->Where($atg_table['group_id'], DB_EQ, $group_id);
     $query->WhereAND();
     $query->Where($pia_table['attr_id'], DB_EQ, $atg_table['attr_id']);
     if ($attr_vis == PERSON_INFO_GROUP_ATTR_VISIBLE) {
         $query->WhereAND();
         $query->WhereValue($atg_table['is_visible'], DB_EQ, 'Y');
     } elseif ($attr_vis == PERSON_INFO_GROUP_ATTR_HIDDEN) {
         $query->WhereAND();
         $query->WhereValue($atg_table['is_visible'], DB_EQ, 'N');
     }
     $query->SelectOrder($atg_table['sort_order']);
     $res = $application->db->getDB_Result($query);
     $group_name = $this->getPersonInfoGroupNameByID($group_id);
     if ($group_name == 'Customer') {
         $attrs = $res;
         return $attrs;
     }
     foreach ($res as $k => $attr_info) {
         if ($attr_vis == PERSON_INFO_GROUP_ATTR_ALL) {
             $attrs[] = $attr_info;
         }
         if ($attr_vis == PERSON_INFO_GROUP_ATTR_VISIBLE) {
             if ($this->__isCOAttrVisible($this->detectCOPITypeID($group_name), $this->detectCOAttrID($attr_info['attr_name']))) {
                 $attrs[] = $attr_info;
             }
         }
         if ($attr_vis == PERSON_INFO_GROUP_ATTR_HIDDEN) {
             if ($this->__isCOAttrHidden($this->detectCOPITypeID($group_name), $this->detectCOAttrID($attr_info['attr_name']))) {
                 $attrs[] = $attr_info;
             }
         }
     }
     return $attrs;
 }
 function getCFldValues()
 {
     global $application;
     $values = "";
     if ($this->mode == "add") {
         $values = "";
         if (isset($this->field_data['postdata']['customFieldValues'])) {
             $values = $this->field_data['postdata']['customFieldValues'];
         }
     } else {
         $itid = $this->field_data[0]['input_type_id'];
         $tables = modAPIFunc("Catalog", "getTables");
         $t_input_type_values = $tables['input_type_values']['columns'];
         $query = new DB_Select();
         $query->setMultiLangAlias('_ml_value', 'input_type_values', $t_input_type_values['value'], $t_input_type_values['id'], 'Catalog');
         $query->addSelectField($query->getMultiLangAlias('_ml_value'), 'value');
         $query->WhereValue($t_input_type_values['it_id'], DB_EQ, $itid);
         $query->SelectOrder($t_input_type_values['id'], 'ASC');
         $result = $application->db->getDB_Result($query);
         foreach ($result as $r) {
             $values .= modApiFunc('Catalog', 'getInputTypeActualValue', $r['value']) . "\n";
         }
     }
     return "<textarea class=\"form-control\"" . $this->HtmlForm->genInputTextAreaField(20, 'customFieldValues', 5) . " id='customFieldValues' disabled=disabled>" . $values . "</textarea>";
 }
Ejemplo n.º 7
0
 function sendMessagesPortion3($num)
 {
     global $application;
     loadCoreFile('ascHtmlMimeMail.php');
     $mailer = new ascHtmlMimeMail();
     $tables = $this->getTables();
     $table = 'newsletter_temp';
     $columns =& $tables[$table]['columns'];
     $query = new DB_Select($table);
     $query->addSelectField($columns['recipient_value']);
     $query->addSelectField($columns['key_unsubscribe']);
     $query->addSelectField($columns['lng']);
     $query->WhereValue($columns['recipient_num'], DB_EQ, $num);
     $query->SelectOrder($columns['recipient_id'], 'ASC');
     $query->SelectLimit(0, PORTION_MAX_MESSAGES_NUM);
     $res = $application->db->getDB_Result($query);
     $addr_num = count($res);
     $start_time = $this->microtime_float();
     $sent_count = 0;
     // getting the default language
     $default_language = modApiFunc('MultiLang', 'getDefaultLanguage');
     // saving the current language
     $current_language = modApiFunc('MultiLang', 'getLanguage');
     // storing the current letter_id
     $letter_id = $this->_currentMessage['letter_id'];
     while ($this->microtime_float() - $start_time < PORTION_MAX_EXPORT_TIME && $sent_count < $addr_num) {
         //
         //
         //
         // setting the language
         if (!$res[$sent_count]['lng']) {
             $res[$sent_count]['lng'] = $default_language;
         }
         modApiFunc('MultiLang', 'setLanguage', $res[$sent_count]['lng']);
         // reading the newsletter for the language
         $this->_currentMessage = $this->getMessageInfo($letter_id);
         $from = $this->_currentMessage['letter_from_name'] . ' <' . $this->_currentMessage['letter_from_email'] . '>';
         $mailer->setFrom($from);
         $mailer->setSubject($this->_currentMessage['letter_subject']);
         $html_tmpl = "<html><head><title>{$this->_currentMessage['letter_subject']}</title></head><body>{$this->_currentMessage['letter_html']}</body></html>";
         $html_log = str_replace('%KEY_UNSUBSCRIBE%', $res[$sent_count]['key_unsubscribe'], $this->_currentMessage['letter_html']);
         $mailer->setHtml(str_replace('%KEY_UNSUBSCRIBE%', $res[$sent_count]['key_unsubscribe'], $html_tmpl));
         $result = $mailer->send(array($res[$sent_count]['recipient_value']));
         $mailer->resetMessageBuilt();
         $this->addNewsletterToTimeline($res[$sent_count]['recipient_value'], $this->_currentMessage['letter_subject'], $html_log, $result);
         $sent_count++;
         // :
         /*debug*/
         //usleep(200000);
     }
     // restoring the current language
     modApiFunc('MultiLang', 'setLanguage', $current_language);
     if ($sent_count) {
         $this->_sentCountTotal += $sent_count;
         $this->removeEmails($num, $sent_count);
     }
     if ($this->_sentCountTotal < $this->_totalRecipients) {
         $sending_status = 'PROCESSING';
     } else {
         $sending_status = 'COMPLETED';
         $this->_sentCountTotal = $this->_totalRecipients;
         $this->updateMessage($this->_currentMessage['letter_id'], array('letter_sent_date' => date('Y-m-d G:i:s')));
     }
     return array('errors' => '', 'warnings' => '', 'sent_total' => $this->_sentCountTotal, 'sending_status' => $sending_status);
 }
 /**
  * Reencrypts temporary data on the server. The step of replacing RSA keys.
  * It selects encrypted data by chunks from the database. It reencrypts it and
  * saves back to the temporary table. If all data are reencrypted, returns
  * b_finished =true in the returned array, false otherwise.
  *
  * @param string $rsa_private_key_cryptrsa_format old RSA private key, which
  * was used to encrypt data, stored in the DB
  * @param string $new_rsa_public_key_asc_format new RSA public key, which is
  * used to encrypt data, decrypted by the old RSA private key.
  */
 function ReplaceRSAKeyPairStep2ReencryptTmpData($rsa_private_key_cryptrsa_format, $new_rsa_public_key_asc_format)
 {
     global $application;
     $new_rsa_public_key_cryptrsa_format = modApiFunc("Crypto", "convert_rsa_public_key_from_asc_into_cryptrsa_format", $new_rsa_public_key_asc_format);
     /**
      * Read out from the temporary table 500 records at a time (empirical
      * value).
      *
      * Reencrypt by chunks, that have the same Blowfish key, it is about
      * 10 database records. The decryption of one blowfish key (RSA), if no
      * mathematical libraries exist, can take 10 sec.
      * Check the timeout after each chunk - 2 sec.
      * If no records are left and the timeout is over, exit.
      *
      * Write what has been reencrypted to the database.
      */
     $tmp_table_name = "order_person_data" . $this->getTmpTableSuffix();
     // TableInfo only, but not data. Refer to the table using AVACTIS.
     $opd_tmp_info = clone_db_table_info("Checkout", "order_person_data", $tmp_table_name);
     $opd_tmp = $opd_tmp_info['columns'];
     # get Person Info data. Total record number.
     $query = new DB_Select();
     $query->addSelectField($query->fCount('*'), 'count');
     $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1");
     $result = $application->db->getDB_Result($query);
     $n_total = $result[0]['count'];
     # get Person Info data.
     $query = new DB_Select();
     $query->addSelectField($opd_tmp['id'], 'id');
     $query->addSelectField($opd_tmp['value'], 'value');
     $query->addSelectField($opd_tmp['encrypted_secret_key'], 'encrypted_secret_key');
     $query->addSelectField($opd_tmp['rsa_public_key_asc_format'], 'rsa_public_key_asc_format');
     $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1");
     $query->WhereAnd();
     $query->Where($opd_tmp['id'], DB_GTE, $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId);
     $query->SelectOrder($opd_tmp['id']);
     $query->SelectLimit(0, 500);
     $_person_data = $application->db->getDB_Result($query);
     if (sizeof($_person_data) == 0) {
         //No unreencrypted data is left. The reencryption is completed.
         return array("error_msg" => "", "b_finished" => true, "progress_position" => 1.0);
     } else {
         $i = 0;
         // a number of record from order_person_data
         $start_time = time();
         while (time() - $start_time < 2) {
             //Process one block with the same blowfish key.
             $rsa_encrypted_blowfish_key = $_person_data[$i]['encrypted_secret_key'];
             /*
             If the loaded Private key doesn't match the Public key storing in the database  -
             output an error message. Don't rewrite anything in the database.
             */
             $old_rsa_public_key_asc_format = $_person_data[$i]['rsa_public_key_asc_format'];
             $old_rsa_public_key_cryptrsa_format = modApiFunc("Crypto", "convert_rsa_public_key_from_asc_into_cryptrsa_format", $old_rsa_public_key_asc_format);
             if (modApiFunc("Crypto", "rsa_do_public_key_match_private_key", $old_rsa_public_key_cryptrsa_format, $rsa_private_key_cryptrsa_format) === true) {
                 //BEGIN decrypt blowfish key.
                 $rsa_obj = new Crypt_RSA();
                 $blowfish_key = $rsa_obj->decrypt($rsa_encrypted_blowfish_key, $rsa_private_key_cryptrsa_format);
                 $new_blowfish_key = modApiFunc("Crypto", "blowfish_gen_blowfish_key");
                 $new_encrypted_blowfish_key = $rsa_obj->encrypt($new_blowfish_key, $new_rsa_public_key_cryptrsa_format);
                 //END decrypt blowfish key.
                 //Bulk INSERT will increase the rate greatly!
                 for (; $i < sizeof($_person_data) && $_person_data[$i]['encrypted_secret_key'] == $rsa_encrypted_blowfish_key; $i++) {
                     $decrypted_value = modApiFunc("Crypto", "blowfish_decrypt", base64_decode($_person_data[$i]['value']), $blowfish_key);
                     //Store decrypted data:
                     $query = new DB_Update($tmp_table_name);
                     $query->addUpdateValue($opd_tmp['value'], base64_encode(modApiFunc("Crypto", "blowfish_encrypt", $decrypted_value, $new_blowfish_key)));
                     $query->addUpdateValue($opd_tmp['encrypted_secret_key'], $new_encrypted_blowfish_key);
                     $query->addUpdateValue($opd_tmp['rsa_public_key_asc_format'], $new_rsa_public_key_asc_format);
                     $query->WhereValue($opd_tmp['id'], DB_EQ, $_person_data[$i]['id']);
                     $application->db->getDB_Result($query);
                     $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId = $_person_data[$i]['id'] + 1;
                     $this->saveState();
                     //Don't lose reencrypted data and save correct number
                     //of the last processed record. Otherwise the timeout can occur during the
                     //SQL query and data in the session will be incorrect.
                 }
                 if ($i >= sizeof($_person_data)) {
                     break;
                 }
             } else {
                 //Report an error: keys don't match.
                 $MessageResources =& $application->getInstance('MessageResources');
                 $msg = $MessageResources->getMessage('CRYPTO_RSA_PUBLIC_PRIVATE_KEYS_MISMATCH_DECRYPT_ERROR');
                 return array("error_msg" => $msg, "b_finished" => false, "progress_position" => 0.0);
             }
         }
         # get Person Info data. Total record count.
         $query = new DB_Select();
         $query->addSelectField($query->fCount('*'), 'count');
         $query->Where($opd_tmp['b_encrypted'], DB_EQ, "1");
         $query->WhereAnd();
         $query->Where($opd_tmp['id'], DB_LT, $this->ReplaceRSAKeyPairStep2ReencryptTmpDataOrderPersonDataId);
         $result = $application->db->getDB_Result($query);
         $n_done = $result[0]['count'];
         return array("error_msg" => "", "b_finished" => false, "progress_position" => 1.0 * $n_done / $n_total);
     }
 }
 /**
  * Reelects the default value for the option of the type 'SS'
  *
  * @param int $option_id - option ID
  * @param int $value_id - ID of the value, dominating in the reelection
  * (if it is null, no dominating value exists)
  *
  * @return true it was successfully reelected, false otherwise
  */
 function __chooseAndSetDefaultValueForOption($option_id, $value_id = 0)
 {
     global $application;
     $tables = $this->getTables();
     $values = $tables['po_options_values']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('po_options_values');
     $query->addSelectField($values['value_id'], 'value_id');
     $query->addSelectField($values['is_default'], 'is_default');
     $query->WhereValue($values['option_id'], DB_EQ, $option_id);
     $query->SelectOrder($values['sort_order'], 'ASC');
     $res = $application->db->getDB_Result($query);
     if (!is_array($res)) {
         return false;
     }
     if (!empty($res)) {
         $default_ids = array();
         foreach ($res as $k => $v) {
             if ($v['is_default'] == 'Y') {
                 $default_ids[] = $v['value_id'];
             }
         }
         if (empty($default_ids)) {
             $new_default_id = $value_id > 0 ? $value_id : $res[0]['value_id'];
             $query = new DB_Update('po_options_values');
             $query->addUpdateValue($values['is_default'], 'Y');
             $query->WhereValue($values['value_id'], DB_EQ, $new_default_id);
             $application->db->PrepareSQL($query);
             return $application->db->DB_Exec();
         } elseif (count($default_ids) == 1) {
             if ($value_id > 0) {
                 $query = new DB_Update('po_options_values');
                 $query->addUpdateValue($values['is_default'], 'N');
                 $query->WhereValue($values['value_id'], DB_EQ, $default_ids[0]);
                 $application->db->PrepareSQL($query);
                 if ($application->db->DB_Exec()) {
                     $query = new DB_Update('po_options_values');
                     $query->addUpdateValue($values['is_default'], 'Y');
                     $query->WhereValue($values['value_id'], DB_EQ, $value_id);
                     $application->db->PrepareSQL($query);
                     return $application->db->DB_Exec();
                 } else {
                     return false;
                 }
             }
             return true;
         } else {
             $query = new DB_Update('po_options_values');
             $query->addUpdateValue($values['is_default'], 'N');
             $query->WhereValue($values['option_id'], DB_EQ, $option_id);
             $application->db->PrepareSQL($query);
             if ($application->db->DB_Exec()) {
                 $new_default_id = $value_id > 0 ? $value_id : $default_ids[0];
                 $query = new DB_Update('po_options_values');
                 $query->addUpdateValue($values['is_default'], 'Y');
                 $query->WhereValue($values['value_id'], DB_EQ, $new_default_id);
                 $application->db->PrepareSQL($query);
                 return $application->db->DB_Exec();
             } else {
                 return false;
             }
         }
     }
     return true;
 }
 function getFilesListForProduct($product_id)
 {
     global $application;
     $tables = $this->getTables();
     $file_table = $tables['pf_files']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('pf_files');
     $query->addSelectField('*');
     $query->WhereValue($file_table['product_id'], DB_EQ, $product_id);
     $query->SelectOrder($file_table['file_id'], 'ASC');
     return $application->db->getDB_Result($query);
 }
Ejemplo n.º 11
0
 /**
  * Deletes old records in the news table.
  * After that <= NEWS_MAX_COUNT records remain.
  */
 function deleteOldNews()
 {
     global $application;
     $tables = $this->getTables();
     $columns = $tables['news']['columns'];
     # select the latest date piece of news among the remain ones in the table...
     $query = new DB_Select('news');
     $query->addSelectField($columns['date'], 'NewsDate');
     $query->SelectOrder($columns['date'], 'DESC');
     $query->SelectLimit($this->settings[NEWS_MAX_COUNT] - 1, 1);
     $result = $application->db->getDB_Result($query);
     if ($result == NULL) {
         return;
     }
     # ...delete all the latest news @ check this line
     $query = new DB_Delete('news');
     $query->WhereValue($columns['date'], DB_LT, $result[0]['NewsDate']);
     $query->WhereAND();
     $query->WhereValue($columns['type'], DB_EQ, 'avactis');
     $application->db->getDB_Result($query);
 }
Ejemplo n.º 12
0
 function __searchOrders()
 {
     global $application;
     $tables = modApiStaticFunc('Checkout', 'getTables');
     $orders_table = $tables['orders']['columns'];
     $query = new DB_Select();
     $query->addSelectTable('orders');
     $query->addSelectField($orders_table['id'], 'order_id');
     $query->WhereValue($orders_table['person_id'], DB_EQ, $this->base_info['ID']);
     if ($this->orders_filter['type'] == 'id') {
         $query->WhereAND();
         $query->WhereValue($orders_table['id'], DB_EQ, $this->orders_filter['order_id']);
     }
     $query->SelectGroup($orders_table['id']);
     $query->SelectOrder($orders_table['id'], 'DESC');
     $oids_wo_filter = array();
     $res = $application->db->getDB_Result($query);
     for ($i = 0; $i < count($res); $i++) {
         $oids_wo_filter[] = $res[$i]['order_id'];
     }
     if ($this->orders_filter['type'] != 'custom' and ($this->orders_filter['order_status'] == ORDER_STATUS_ALL or empty($oids_wo_filter))) {
         $this->__setOrdersIDs($oids_wo_filter);
         return;
     }
     $query = new DB_Select();
     $query->addSelectTable('orders');
     $query->addSelectField($orders_table['id'], 'order_id');
     if ($this->orders_filter['type'] == 'quick') {
         $query->WhereValue($orders_table['status_id'], DB_EQ, $this->orders_filter['order_status']);
     }
     if ($this->orders_filter['type'] == 'custom') {
         $from_date = implode("-", array($this->orders_filter['year_from'], $this->orders_filter['month_from'], $this->orders_filter['day_from'])) . ' 00:00:00';
         $to_date = implode("-", array($this->orders_filter['year_to'], $this->orders_filter['month_to'], $this->orders_filter['day_to'])) . ' 23:59:59';
         $query->WhereValue($orders_table['date'], DB_GTE, $from_date);
         $query->WhereAND();
         $query->WhereValue($orders_table['date'], DB_LTE, $to_date);
         if ($this->orders_filter['order_status'] != ORDER_STATUS_ALL) {
             $query->WhereAND();
             $query->WhereValue($orders_table['status_id'], DB_EQ, $this->orders_filter['order_status']);
         }
         if ($this->orders_filter['order_payment_status'] != ORDER_PAYMENT_STATUS_ALL) {
             $query->WhereAND();
             $query->WhereValue($orders_table['payment_status_id'], DB_EQ, $this->orders_filter['order_payment_status']);
         }
     }
     $query->WhereAND();
     $query->Where($orders_table['id'], DB_IN, "('" . implode("','", $oids_wo_filter) . "')");
     $oids_with_filter = array();
     $res = $application->db->getDB_Result($query);
     for ($i = 0; $i < count($res); $i++) {
         $oids_with_filter[] = $res[$i]['order_id'];
     }
     $this->__setOrdersIDs($oids_with_filter);
 }
Ejemplo n.º 13
0
 /**
  * @param int $category_id - ID
  * @param array $period = ('begin' => timestamp, 'end' => timestamp) -
  *
  * @param int $limit -                   (
  *                          ,    STAT_NO_LIMIT)
  * @param int $what_category = STAT_CATEGORY_THIS_ONLY ||
  * STAT_CATEGORY_RECURSIVE -
  *
  * @param int $what_products = STAT_PRODUCTS_ALL ||
  * STAT_PRODUCTS_EXISTS_ONLY -                                 ,
  *
  */
 function getProductsSellingStat($category_id, $period, $limit = STAT_NO_LIMIT, $what_category = STAT_CATEGORY_THIS_ONLY, $what_products = STAT_PRODUCTS_EXISTS_ONLY)
 {
     global $application;
     $tables = $this->getTables();
     $ps_table = $tables['stat_products_sold']['columns'];
     $categories_ids = array();
     if ($what_category == STAT_CATEGORY_RECURSIVE) {
         $categories = modApiFunc('Catalog', 'getSubcategoriesFullListWithParent', $category_id, false, false);
         foreach ($categories as $cat_info) {
             $categories_ids[] = $cat_info['id'];
         }
     } else {
         $categories_ids[] = $category_id;
     }
     $query = new DB_Select();
     $query->addSelectField($ps_table['product_id'], 'product_id');
     $query->addSelectField($query->fSum($ps_table['quantity']), 'sum_quantity');
     $query->addSelectTable('stat_products_sold');
     $query->WhereValue($ps_table['categories_ids'], DB_REGEXP, '[[.vertical-line.]]' . implode('|', $categories_ids) . '[[.vertical-line.]]');
     $query->WhereAND();
     $query->Where($ps_table['time'], DB_GTE, $period['begin']);
     $query->WhereAND();
     $query->Where($ps_table['time'], DB_LTE, $period['end']);
     if ($what_products == STAT_PRODUCTS_EXISTS_ONLY) {
         $catalog_tables = modApiStaticFunc('Catalog', 'getTables');
         $query->addSelectTable('products');
         $query->WhereAND();
         $query->WhereField($ps_table['product_id'], DB_EQ, $catalog_tables['products']['columns']['id']);
     }
     $query->SelectGroup('product_id');
     $query->SelectOrder('sum_quantity', 'DESC');
     if ($limit != STAT_NO_LIMIT) {
         $query->SelectLimit(0, $limit);
     }
     return $application->db->getDB_Result($query);
 }