function getOrderList() { global $application; $tables = modApiFunc('Checkout', 'getTables'); $o = $tables['orders']['columns']; $request =& $application->getInstance('Request'); $order_id_list = $request->getValueByKey('order_id'); $export_all = $request->getValueByKey('export_all'); // id- $query = new DB_Select(); $query->addSelectField($o['id'], 'id'); if ($export_all == null || $export_all == 'false') { $query->WhereField($o['id'], DB_IN, ' (' . implode(',', $order_id_list) . ') '); } $result = $application->db->getDB_Result($query); $plain_list = array(); foreach ($result as $item) { $plain_list[] = $item['id']; } return $plain_list; }
/** * This function calculates hash from checkout form fields array. * @author Andrei V. Zhuravlev * */ function updateCheckoutFormHash() { global $application; $tables = $this->getTables(); $pa = $tables['person_attributes']['columns']; $piva = $tables['person_info_variants_to_attributes']['columns']; $s = new DB_Select(); $s->addSelectTable('person_attributes'); $s->addSelectTable('person_info_variants_to_attributes'); $s->WhereField($piva['attribute_id'], DB_EQ, $pa['id']); $checkout_data = $application->db->getDB_Result($s); //query fields $hash = md5(serialize($checkout_data)); /*$tables = Configuration::getTables(); $ss = $tables['store_settings']['columns']; $u = new DB_Update('store_settings'); $u->addUpdateValue('variable_value',$hash); $u->WhereValue('variable_name', DB_EQ, SYSCONFIG_CHECKOUT_FORM_HASH); $application->db->getDB_Result($u);*/ $cache = CCacheFactory::getCache('hash'); $cache->write(SYSCONFIG_CHECKOUT_FORM_HASH, $hash); return $hash; }
/** * * * @author Alexandr Girin * @param * @return */ function DeleteOrders($ordersId) { modApiFunc('EventsManager', 'throwEvent', 'OrdersWillBeDeleted', $ordersId); global $application; $tables = $this->getTables(); $on = $tables['order_notes']['columns']; $opd = $tables['order_person_data']['columns']; $opr = $tables['order_prices']['columns']; $otx = $tables['order_taxes']['columns']; $otdo = $tables['order_tax_display_options']['columns']; $op = $tables['order_product']['columns']; $opca = $tables['order_product_custom_attributes']['columns']; $opta = $tables['order_product_to_attributes']['columns']; $opot = $tables['order_product_options']['columns']; $o = $tables['orders']['columns']; $DB_IN_string = "('" . implode("', '", $ordersId) . "')"; $query = new DB_Select(); $query->addSelectField($op['id'], 'id'); $query->WhereField($op['order_id'], DB_IN, $DB_IN_string); $order_products_id = $application->db->getDB_Result($query); foreach ($order_products_id as $key => $order_product_id) { $order_products_id[$key] = $order_product_id['id']; } $query = new DB_Delete('order_notes'); $query->WhereField($on['order_id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); $query = new DB_Delete('order_person_data'); $query->WhereField($opd['order_id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); $query = new DB_Delete('order_prices'); $query->WhereField($opr['order_id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); $query = new DB_Delete('order_taxes'); $query->WhereField($otx['order_id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); $query = new DB_Delete('order_tax_display_options'); $query->WhereField($otdo['order_id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); $query = new DB_Delete('order_product'); $query->WhereField($op['order_id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); $query = new DB_Delete('order_product_custom_attributes'); $query->WhereField($opca['product_id'], DB_IN, "('" . implode("', '", $order_products_id) . "')"); $application->db->getDB_Result($query); $query = new DB_Delete('order_product_to_attributes'); $query->WhereField($opta['product_id'], DB_IN, "('" . implode("', '", $order_products_id) . "')"); $application->db->getDB_Result($query); $query = new DB_Select(); $query->addSelectField($opot['option_value'], 'option_value'); $query->WhereValue($opot['is_file'], DB_EQ, 'Y'); $query->WhereAND(); $query->Where($opot['order_product_id'], DB_IN, "('" . implode("', '", $order_products_id) . "')"); $__res = $application->db->getDB_Result($query); if (count($__res) > 0) { foreach ($__res as $oinfo) { if ($oinfo['option_value'] != '') { modApiFunc('Shell', 'removeDirectory', dirname($oinfo['option_value'])); } } } $query = new DB_Delete('order_product_options'); $query->WhereField($opot['order_product_id'], DB_IN, "('" . implode("', '", $order_products_id) . "')"); $application->db->getDB_Result($query); modApiFunc("PromoCodes", "DeleteOrders", $ordersId); modApiFunc("TaxExempts", "DeleteOrders", $ordersId); modApiFunc('GiftCertificateApi', 'DeleteOrders', $ordersId); $query = new DB_Delete('orders'); $query->WhereField($o['id'], DB_IN, $DB_IN_string); $application->db->getDB_Result($query); }
/** * * * @return array - . */ function getPromoCodesListFull($b_active_only = true, $cost_type_id = NULL, $b_between_start_date_and_date_only = true, $b_times_to_use_greater_than_times_used = true, $promo_code_id = NULL, $use_paginator = false) { global $application; /// $tables = call_user_func(array($__CLASS__, "getTables"); $tables = $this->getTables(); $tr = $tables['promo_codes_coupons_table']['columns']; $result_array = array(); $query = new DB_Select(); $query->addSelectField($tr["id"], "id"); $query->addSelectField($tr["min_subtotal"], "min_subtotal"); $query->addSelectField($tr["promo_code"], "promo_code"); $query->addSelectField($tr["campaign_name"], "campaign_name"); $query->addSelectField($tr["b_ignore_other_discounts"], "b_ignore_other_discounts"); $query->addSelectField($tr["status"], "status"); $query->addSelectField($tr["discount_cost"], "discount_cost"); $query->addSelectField($tr["discount_cost_type_id"], "discount_cost_type_id"); $query->addSelectField($tr["start_date"], "start_date"); $query->addSelectField($tr["end_date"], "end_date"); $query->addSelectField($tr["times_to_use"], "times_to_use"); $query->addSelectField($tr["times_used"], "times_used"); $query->addSelectField($tr["categories_affected"], "cats"); $query->addSelectField($tr["products_affected"], "prods"); $query->addSelectField($tr["free_shipping"], "free_shipping"); $query->addSelectField($tr["free_handling"], "free_handling"); $query->addSelectField($tr["strict_cart"], "strict_cart"); $query->WhereValue('', '', '1'); if ($cost_type_id !== NULL) { $query->WhereAnd(); $query->WhereValue($tr["discount_cost_type_id"], DB_EQ, $cost_type_id); } if ($b_active_only === true) { $query->WhereAND(); $query->WhereValue($tr["status"], DB_EQ, 1); } if ($b_times_to_use_greater_than_times_used === true) { $query->WhereAND(); $query->WhereField($tr["times_to_use"], DB_GT, $tr["times_used"]); } if ($promo_code_id !== NULL) { $query->WhereAND(); $query->WhereValue($tr["id"], DB_EQ, $promo_code_id); } if ($use_paginator == true) { $query = modApiFunc('paginator', 'setQuery', $query); } $query->SelectOrder($tr['id']); $result_rows = $application->db->getDB_Result($query); foreach ($result_rows as $row) { if ($b_between_start_date_and_date_only === true) { // , , . // . . // , 0 0 0 start_date // 0 0 0 (end_date + 1 ) . if ($this->is_coupon_not_expired(strtotime($row['start_date']), strtotime($row['end_date'])) === true) { $result_array[] = $row; } else { // , . } } else { $result_array[] = $row; } } return $result_array; }
/** * Gets a list of available info block tags by all actions. * *@param array $actionsList - a list of all actions * *@return array - a list of tags associated with actions */ function getAvailableTagsList($actionsList) { global $application; $tables = $this->getTables(); $i2a = $tables['infotags_to_action']['columns']; $ni = $tables['notification_infotags']['columns']; $b2a = $tables['blocktags_to_action']['columns']; $nb = $tables['notification_blocktags']['columns']; $i2b = $tables['infotags_to_blocktag']['columns']; $tagsList = array(); foreach ($actionsList as $actionInfo) { $tagsList[$actionInfo['Id']] = array(); $query = new DB_Select(); $query->addSelectField($ni['id'], 'Id'); $query->addSelectField($ni['name'], 'InfoTag'); $query->WhereField($ni['id'], DB_EQ, $i2a["ni_id"]); $query->WhereAnd(); $query->WhereValue($i2a['na_id'], DB_EQ, $actionInfo['Id']); $result = $application->db->getDB_Result($query); $InfoTags = array(); foreach ($result as $InfoTag) { $InfoTags[$InfoTag['Id']] = $InfoTag['InfoTag']; } $tagsList[$actionInfo['Id']]['InfoTags'] = $InfoTags; $query = new DB_Select(); $query->addSelectField($nb['id'], 'Id'); $query->addSelectField($nb['name'], 'BlockTag'); $query->WhereField($nb['id'], DB_EQ, $b2a["nb_id"]); $query->WhereAnd(); $query->WhereValue($b2a['na_id'], DB_EQ, $actionInfo['Id']); $result = $application->db->getDB_Result($query); $tagsList[$actionInfo['Id']]['BlockTags'] = array(); foreach ($result as $BlockTag) { $query = new DB_Select(); $query->addSelectField($ni['id'], 'Id'); $query->addSelectField($ni['name'], 'InfoTag'); $query->WhereField($ni['id'], DB_EQ, $i2b["ni_id"]); $query->WhereAnd(); $query->WhereValue($i2b['nb_id'], DB_EQ, $BlockTag['Id']); $_result = $application->db->getDB_Result($query); $InfoTags = array(); foreach ($_result as $InfoTag) { $InfoTags[$InfoTag['Id']] = $InfoTag['InfoTag']; } $tagsList[$actionInfo['Id']]['BlockTags'][$BlockTag['Id']] = array("BlockTag" => $BlockTag['BlockTag'], "BlockInfoTags" => $InfoTags); } } return $tagsList; }
/** * Gets modifiers of default combination from the entity. * * @param string $parent_entity - entity name * @param int $entity_id - ID of the entity * @return array( * 'price' => sum of price modificators and values included in the combination * ,'weight' => sum of weight modificators and values included in the combination * ,'shipping_cost' => sum of shipping cost modificators and values included in the combination * ,'handling_cost' => sum of handling cost modificators and values included in the combination * ) */ function getModifiersOfDefaultCombination($parent_entity, $entity_id) { $modifiers = $this->__getInnerVar("_MODIFIERS"); if (!empty($modifiers)) { global $application; $tables = $this->getTables(); $options_table = $tables['po_options']['columns']; $values_table = $tables['po_options_values']['columns']; $query = new DB_Select(); $query->addSelectTable('po_options'); $query->addSelectTable('po_options_values'); foreach ($modifiers as $mod) { $query->addSelectField($query->fSum($values_table[$mod . '_modifier']), $mod); } $query->WhereValue($values_table['is_default'], DB_EQ, 'Y'); $query->WhereAND(); $query->WhereValue($options_table['parent_entity'], DB_EQ, $parent_entity); $query->WhereAND(); $query->WhereValue($options_table['entity_id'], DB_EQ, $entity_id); $query->WhereAND(); $query->WhereField($values_table['option_id'], DB_EQ, $options_table['option_id']); return array_shift(array_values($application->db->getDB_Result($query))); } else { return array(); } }
/** * A constructor. */ function NotificationContent($condition = array()) { global $application; $this->notificationId = $condition['notification_id']; $this->orderId = isset($condition['order_id']) ? $condition['order_id'] : NULL; $this->actionId = $condition['action_id']; $this->gift_cert = isset($condition['gc_obj']) ? $condition['gc_obj'] : NULL; $this->MessageResources =& $application->getInstance('MessageResources', "notifications-messages", "AZ"); $this->customerAccount = null; $this->haveToSend = $this->getNotificationInfo($this->notificationId); if (!$this->haveToSend) { return; } if (isset($condition['status'])) { if ($condition['status'] == 'order') { $orderNewStatus = modApiFunc("Checkout", "getOrderStatusList", $condition['statuses']['new_status']); $orderNewStatus = $orderNewStatus[$condition['statuses']['new_status']]['id']; $tables = Notifications::getTables(); $naov = $tables['notification_action_option_values']['columns']; $ov2n = $tables['option_values_to_notification']['columns']; $query = new DB_Select(); $query->addSelectField($ov2n['value'], 'value'); $query->WhereValue($naov['nao_id'], DB_EQ, 1); $query->WhereAnd(); $query->WhereValue($ov2n['n_id'], DB_EQ, $this->notificationId); $query->WhereAnd(); $query->WhereField($ov2n['naov_id'], DB_EQ, $naov['id']); $query->WhereAnd(); $query->WhereValue($naov['key'], DB_EQ, $orderNewStatus); $result = $application->db->getDB_Result($query); if (isset($result[0]['value']) && $result[0]['value'] == 'true') { $this->haveToSend = true; $orderOldStatus = modApiFunc("Checkout", "getOrderStatusList", $condition['statuses']['old_status']); $this->OrderOldStatus = $orderOldStatus[$condition['statuses']['old_status']]['name']; } else { $this->haveToSend = false; } } if ($condition['status'] == 'payment') { $orderNewPaymentStatus = modApiFunc("Checkout", "getOrderPaymentStatusList", $condition['statuses']['new_status']); $orderNewPaymentStatus = $orderNewPaymentStatus[$condition['statuses']['new_status']]['id']; $tables = Notifications::getTables(); $naov = $tables['notification_action_option_values']['columns']; $ov2n = $tables['option_values_to_notification']['columns']; $query = new DB_Select(); $query->addSelectField($ov2n['value'], 'value'); $query->WhereValue($naov['nao_id'], DB_EQ, 2); $query->WhereAnd(); $query->WhereValue($ov2n['n_id'], DB_EQ, $this->notificationId); $query->WhereAnd(); $query->WhereField($ov2n['naov_id'], DB_EQ, $naov['id']); $query->WhereAnd(); $query->WhereValue($naov['key'], DB_EQ, $orderNewPaymentStatus); $result = $application->db->getDB_Result($query); if (isset($result[0]['value']) && $result[0]['value'] == 'true') { $this->haveToSend = true; $orderOldStatus = modApiFunc("Checkout", "getOrderPaymentStatusList", $condition['statuses']['old_status']); $this->OrderOldPaymentStatus = $orderOldStatus[$condition['statuses']['old_status']]['name']; } else { $this->haveToSend = false; } } } if ($this->actionId == 4) { /* : . , , , , $this->haveToSend false, . , . . , , , , . prepareEmailTextAndSubject. : QuantityInStock LowStockLevel. : - - , : - ( ) - ( ) : - ProductLowLevelInStock , . */ $this->haveToSend = false; $orderInfo = modApiFunc("Checkout", "getOrderInfo", $this->orderId, modApiFunc("Localization", "whichCurrencyToDisplayOrderIn", $this->orderId)); foreach ($orderInfo['Products'] as $productInfo) { //check if the attributes of the product QuantityInStock and LowStockLevel is visible if (!modApiFunc("Catalog", "isProductAttributeVisible", $productInfo['storeProductID'], 3) or !modApiFunc("Catalog", "isProductAttributeVisible", $productInfo['storeProductID'], 6)) { // , continue; } $_productInfo = new CProductInfo($productInfo['storeProductID']); if ($_productInfo->whichStockControlMethod() == PRODUCT_OPTIONS_INVENTORY_TRACKING) { $productQuantityInStock = modApiFunc('Product_Options', 'getQuantityInStockByInventoryTable', 'product', $productInfo['storeProductID']); } else { $productQuantityInStock = $_productInfo->getProductTagValue('QuantityInStock', PRODUCTINFO_NOT_LOCALIZED_DATA); } $productLowLevelInStock = $_productInfo->getProductTagValue('LowStockLevel', PRODUCTINFO_NOT_LOCALIZED_DATA); // // if (is_numeric($productLowLevelInStock) and is_numeric($productQuantityInStock)) { if ($productQuantityInStock <= $productLowLevelInStock) { $this->haveToSend = true; $this->_LowLevelProducts[] = $productInfo['storeProductID']; } } } } if ($this->actionId == 5) { $this->haveToSend = false; // downloadable products, $this->haveToSend = true; // id - $this->orderId if (count(modApiFunc('Product_Files', 'getHotlinksListForOrder', $this->orderId)) > 0) { $this->haveToSend = true; } } if ($this->actionId == 6) { $this->haveToSend = true; $this->customerRegData = $condition['reg_data']; $this->customerAccount = $this->customerRegData['account']; } if ($this->actionId >= 7 and $this->actionId <= 13) { $this->haveToSend = true; $this->customerAccount = $condition['account_name']; } if ($this->actionId == 14) { $this->haveToSend = true; $this->inventory_info = $condition['inventory_info']; } if ($this->actionId == 15) { $this->haveToSend = true; $this->review_data = modApiFunc('Customer_Reviews', 'searchCustomerReviews', array('cr_id' => $condition['cr_id'])); if (!$this->review_data) { $this->haveToSend = false; } else { $this->review_data = $this->review_data[0]; } } if ($this->actionId == 16) { $this->haveToSend = false; if (count(modApiFunc('GiftCertificateApi', 'getGiftCertificatesForOrderId', $this->orderId)) > 0) { // receive a list of GCs purchased in specified order_id $this->haveToSend = true; } } if ($this->actionId == 17) { $this->haveToSend = true; //check conditions //$this->haveToSend = false; } if ($this->actionId == 18) { $this->haveToSend = true; //check conditions //$this->haveToSend = false; } }
/** * @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); }