Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DELETE FROM mysql.proc WHERE mysql.proc.db='ecc_dev_maint';
- USE 'ecc_dev_maint';
- -- MySQL dump 10.13 Distrib 5.5.15, for Win64 (x86)
- --
- -- Host: localhost Database: ecc_dev
- -- ------------------------------------------------------
- -- Server version 5.5.15-log
- /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
- /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
- /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
- /*!40101 SET NAMES utf8 */;
- /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
- /*!40103 SET TIME_ZONE='+00:00' */;
- /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
- /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
- /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
- /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
- --
- -- Dumping routines for database 'ecc_dev'
- --
- /*!50003 DROP FUNCTION IF EXISTS `MG_CALC_EPP_FREQUENCY` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 FUNCTION `MG_CALC_EPP_FREQUENCY`(inp_frequency_unit TINYINT(1),inp_frequency TINYINT(3),inp_partner_id INT(10),inp_transaction_description VARCHAR(255),inp_customer_id INT(10),inp_dt_now DATETIME) RETURNS tinyint(1)
- DETERMINISTIC
- BEGIN
- IF inp_frequency_unit = 1 THEN
- SELECT COUNT(1) INTO @cnt_trans
- FROM partners_earn_transactions p
- WHERE p.partner_id = inp_partner_id
- AND p.description = inp_transaction_description
- AND p.TYPE = 20 AND customer_id = inp_customer_id
- AND p.TIME >= DATE_SUB(inp_dt_now,INTERVAL 24 HOUR) ;
- END IF ;
- IF inp_frequency_unit = 2 THEN
- SELECT COUNT(1) INTO @cnt_trans
- FROM partners_earn_transactions p
- WHERE p.partner_id = inp_partner_id
- AND p.description = inp_transaction_description
- AND p.TYPE = 20 AND customer_id = inp_customer_id
- AND p.TIME >= DATE_SUB(inp_dt_now,INTERVAL 1 WEEK ) ;
- END IF ;
- IF inp_frequency_unit = 3 THEN
- SELECT COUNT(1) INTO @cnt_trans
- FROM partners_earn_transactions p
- WHERE p.partner_id = inp_partner_id
- AND p.description = inp_transaction_description
- AND p.TYPE = 20 AND customer_id = inp_customer_id
- AND p.TIME >= DATE_SUB(inp_dt_now,INTERVAL 1 MONTH ) ;
- END IF ;
- IF inp_frequency_unit = 4 THEN
- SELECT COUNT(1) INTO @cnt_trans
- FROM partners_earn_transactions p
- WHERE p.partner_id = inp_partner_id
- AND p.description = inp_transaction_description
- AND p.TYPE = 20 AND customer_id = inp_customer_id
- ;
- END IF ;
- IF inp_frequency > @cnt_trans THEN
- SELECT 1 INTO @ret;
- ELSE
- SELECT 0 INTO @ret;
- END IF;
- RETURN @ret;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP FUNCTION IF EXISTS `MG_GET_ZIP_START_WITH_ZIP` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`magento`@`%`*/ /*!50003 FUNCTION `MG_GET_ZIP_START_WITH_ZIP`(inp_product_id INT(10),inp_zip VARCHAR(255) ) RETURNS tinyint(1)
- DETERMINISTIC
- BEGIN
- -- UX-2997
- -- function takes parameters product_id and zip code and returns 1 if attribute 'start_with' for this product has value that like input Zip else return 0
- -- yfedorchuk 2011-08-26
- SELECT `value` INTO @zip_str
- FROM catalog_product_entity_varchar WHERE entity_id = inp_product_id AND attribute_id = (
- SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'starts_with')
- ;
- SET @ret =0;
- IF TRIM(@zip_str) <>0 THEN
- SET @cnt = LENGTH(@zip_str)-LENGTH(REPLACE(@zip_str, ',',''));
- SET @i=0;
- w1:WHILE @i <= @cnt DO
- IF INSTR(@zip_str,',') >0 THEN
- SET @str_z = SUBSTRING(@zip_str,1,INSTR(@zip_str,',')-1);
- ELSE
- SET @str_z = @zip_str;
- END IF;
- IF TRIM(@str_z)<>'' AND inp_zip LIKE CONCAT(@str_z,'%') THEN
- SET @ret =1;
- LEAVE w1;
- END IF;
- SET @zip_str = SUBSTRING(@zip_str,INSTR(@zip_str,',')+1,LENGTH(@zip_str));
- SET @i =@i+1;
- END WHILE ;
- END IF;
- RETURN @ret;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP FUNCTION IF EXISTS `MG_NY_TIME_TO_UTC` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 FUNCTION `MG_NY_TIME_TO_UTC`(inp_dt DATETIME ) RETURNS datetime
- DETERMINISTIC
- BEGIN
- SELECT DATE_FORMAT(inp_dt,'%Y-03-01'),DATE_FORMAT(inp_dt,'%Y-03-31') INTO @dstart,@dend;
- lbl_start:WHILE @dstart <= @dend
- DO
- SELECT DATE_ADD(@dstart, INTERVAL 1 DAY) INTO @dstart;
- SELECT CASE
- WHEN
- WEEK(@dstart,5) - WEEK(DATE(DATE_FORMAT(@dstart, '%Y-03-01')) ,5)+1 = 2
- AND DAYOFWEEK(@dstart ) = 1
- THEN 1
- ELSE 0 END INTO @dst;
- IF @dst = 1 THEN
- SET @start_date = DATE_FORMAT(@dstart,'%Y-03-%d 01:59:59');
- leave lbl_start;
- END IF;
- END WHILE;
- SELECT DATE_FORMAT(inp_dt,'%Y-11-01'),DATE_FORMAT(inp_dt,'%Y-11-30') INTO @dstart,@dend;
- lbl_end:WHILE @dstart <= @dend
- DO
- SELECT DATE_ADD(@dstart, INTERVAL 1 DAY) INTO @dstart;
- SELECT CASE
- WHEN
- WEEK(@dstart,5) - WEEK(DATE(DATE_FORMAT(@dstart, '%Y-11-01')) ,5)+1 = 1
- AND DAYOFWEEK(@dstart ) = 1
- THEN 2
- ELSE 0 END INTO @dst;
- IF @dst = 2 THEN
- SET @end_date = DATE_FORMAT(@dstart,'%Y-%m-%d 01:59:59');
- LEAVE lbl_end;
- END IF;
- END WHILE;
- SELECT CASE
- WHEN inp_dt <= @start_date OR inp_dt >= @end_date
- THEN CONVERT_TZ(inp_dt,'-05:00','+00:00')
- WHEN inp_dt >= @start_date AND inp_dt <= @end_date
- THEN CONVERT_TZ(inp_dt,'-04:00','+00:00')
- END INTO @ret;
- RETURN @ret;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP FUNCTION IF EXISTS `MG_NY_TIME_TO_UTC_NEW` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 FUNCTION `MG_NY_TIME_TO_UTC_NEW`(i_datetime DATETIME ) RETURNS datetime
- BEGIN
- DECLARE i_month INT(11) DEFAULT EXTRACT(MONTH FROM i_datetime);
- DECLARE i_day INT(11) DEFAULT EXTRACT(DAY FROM i_datetime);
- DECLARE summer_date DATETIME DEFAULT DATE_FORMAT(i_datetime, '%Y-03-08 01:59:59');
- DECLARE winter_date DATETIME DEFAULT DATE_FORMAT(i_datetime, '%Y-11-01 01:59:59');
- DECLARE use_summer_time TINYINT DEFAULT (i_month BETWEEN 4 AND 10 OR (i_month = 3 AND i_day > 14));
- IF (i_month = 3 AND i_day BETWEEN 8 AND 14) THEN
- IF (DAYOFWEEK(summer_date) <> 1) THEN
- SET summer_date = DATE_ADD(summer_date, INTERVAL (8 - DAYOFWEEK(summer_date)) DAY);
- END IF;
- SET use_summer_time = i_datetime > summer_date;
- ELSEIF (i_month = 11 AND i_day BETWEEN 1 AND 7) THEN
- IF (DAYOFWEEK(winter_date) <> 1) THEN
- SET winter_date = DATE_ADD(winter_date, INTERVAL (8 - DAYOFWEEK(winter_date)) DAY);
- END IF;
- SET use_summer_time = i_datetime <= winter_date;
- END IF;
- IF use_summer_time THEN
- RETURN CONVERT_TZ(i_datetime, '-04:00', '+00:00');
- ELSE
- RETURN CONVERT_TZ(i_datetime, '-05:00', '+00:00');
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP FUNCTION IF EXISTS `updateCustomerBalanceByAccountNumber` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`magento`@`%`*/ /*!50003 FUNCTION `updateCustomerBalanceByAccountNumber`(accountNumber varchar(255), delta FLOAT, updatedAt DATETIME, reason INT, descriptionText varchar(255), transaktionsOldId INT ) RETURNS int(11)
- BEGIN
- DECLARE resultCode INT DEFAULT 0;
- CALL MG_CUSTOMER_ADD_TRANSACTION(accountNumber, delta, updatedAt, reason, descriptionText, transaktionsOldId, @result_code);
- SELECT @result_code INTO resultCode;
- RETURN resultCode;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_ALLOCATE_TRANSACTION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_ALLOCATE_TRANSACTION`(
- IN i_g_partner_id INT(10),
- IN i_account_number VARCHAR(255),
- IN i_partner_member_account_number VARCHAR(255),
- IN i_units DECIMAL(12,4),
- IN i_external_comment VARCHAR(255),
- IN i_partner_transaction_id VARCHAR(50),
- IN i_environmental_impact VARCHAR(255),
- IN i_internal_comment VARCHAR(255),
- IN i_created_at DATETIME,
- OUT o_tr_id INT(11),
- OUT o_reason VARCHAR(255)
- )
- L_RETURN:
- BEGIN
- DECLARE c_earn_api_channel_id INT(11) DEFAULT 320;
- DECLARE v_customer_id INT(10);
- DECLARE v_partner_id INT(10);
- DECLARE v_balance_id INT(10);
- DECLARE v_balance_amount DECIMAL(12,4);
- DECLARE v_partner_bal_amount DECIMAL(12,4);
- DECLARE v_partner_name VARCHAR(255);
- DECLARE v_tr_desc VARCHAR(255);
- IF (i_units <= 0) THEN
- SELECT 0, 'The amount of points must be greater than zero' INTO o_tr_id, o_reason;
- LEAVE L_RETURN;
- END IF;
- SELECT p.id, p.name
- INTO v_partner_id, v_partner_name
- FROM partners_earn per
- INNER JOIN partners_entity p
- ON per.partner_id = p.id
- WHERE per.g_partner_id = i_g_partner_id;
- IF i_partner_transaction_id IS NOT NULL AND
- EXISTS
- (SELECT 1
- FROM partners_earn_transactions pet
- WHERE pet.partner_id = v_partner_id
- AND pet.external_partner_transaction_id = i_partner_transaction_id
- )
- THEN
- SELECT 0, 'The partner_transaction_id already exists for partner' INTO o_tr_id, o_reason;
- LEAVE L_RETURN;
- END IF;
- IF NOT EXISTS
- (SELECT 1
- FROM customer_entity ce
- WHERE ce.account_number = i_account_number
- AND ce.is_active = 1
- )
- THEN
- SELECT 0, 'Account not found' INTO o_tr_id, o_reason;
- LEAVE L_RETURN;
- END IF;
- IF NOT EXISTS
- (SELECT 1
- FROM partners_entity p
- INNER JOIN partners_earn pe
- ON p.id = pe.partner_id AND pe.g_partner_id = i_g_partner_id
- INNER JOIN partner_subscription ps
- ON pe.partner_id = ps.partner_id
- AND ps.start_date IS NOT NULL
- AND ps.end_date IS NULL
- INNER JOIN customer_entity ce
- ON ps.customer_id = ce.entity_id
- AND ce.account_number = i_account_number
- WHERE
- CASE
- WHEN i_partner_member_account_number IS NOT NULL
- THEN ps.member_account_number = i_partner_member_account_number
- ELSE 1=1
- END
- )
- THEN
- SELECT 0, 'The customer is not subscribed with this partner' INTO o_tr_id, o_reason;
- LEAVE L_RETURN;
- END IF;
- IF EXISTS
- (SELECT 1
- FROM partners_earn pe
- WHERE pe.g_partner_id = i_g_partner_id
- AND
- CASE
- WHEN pe.has_strict_zero = 0 OR pe.points - i_units > 0 THEN 1=1
- ELSE 1=0
- END
- )
- THEN
- SELECT ce.entity_id
- INTO v_customer_id
- FROM customer_entity ce
- WHERE ce.account_number = i_account_number
- AND ce.is_active = 1;
- IF EXISTS
- (SELECT 1
- FROM enterprise_customerbalance ecb
- WHERE ecb.customer_id = v_customer_id)
- THEN
- SELECT ecb.balance_id, ecb.amount
- INTO v_balance_id, v_balance_amount
- FROM enterprise_customerbalance ecb
- WHERE ecb.customer_id = v_customer_id;
- ELSE
- SET v_balance_amount = 0;
- INSERT INTO enterprise_customerbalance (customer_id, website_id, amount)
- VALUES (v_customer_id, 1, v_balance_amount);
- SET v_balance_id = LAST_INSERT_ID();
- END IF;
- SET o_tr_id = 0;
- SET v_tr_desc = CONCAT(v_partner_name, ': ', i_external_comment);
- START TRANSACTION;
- BEGIN
- DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
- INSERT INTO enterprise_customerbalance_history(balance_id, updated_at, `action`, balance_amount, balance_delta, additional_info, reason_id, description)
- VALUES (v_balance_id, now(), 1, v_balance_amount + i_units, i_units, i_environmental_impact, 21, v_tr_desc);
- SET o_tr_id = LAST_INSERT_ID();
- INSERT INTO enterprise_customerbalance_history_channel_map(history_id, channel_id) VALUES (o_tr_id, c_earn_api_channel_id);
- UPDATE enterprise_customerbalance ecb
- SET ecb.amount = ecb.amount + i_units
- WHERE ecb.balance_id = v_balance_id;
- SELECT pe.points
- INTO v_partner_bal_amount
- FROM partners_earn pe
- WHERE pe.partner_id = v_partner_id;
- INSERT INTO partners_earn_transactions (partner_id, `type`, `time`, points, balance_amount, customer_id, external_partner_transaction_id, customer_balance_history_id, description)
- VALUES (v_partner_id, 20, now(), i_units, v_partner_bal_amount - i_units, v_customer_id, i_partner_transaction_id, o_tr_id, i_external_comment);
- UPDATE partners_earn pe
- SET pe.points = pe.points - i_units
- WHERE pe.partner_id = v_partner_id;
- INSERT INTO enterprise_customerbalance_history_ext_partner(history_id, partner_id)
- VALUES (o_tr_id, v_partner_id);
- END;
- COMMIT;
- ELSE
- SELECT 0, 'Partner balance amount is not sufficient to create transaction' INTO o_tr_id, o_reason;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_CHECK_ACCOUNT_BY_EMAIL` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_CHECK_ACCOUNT_BY_EMAIL`(
- IN i_email VARCHAR(255),
- IN i_only_active TINYINT(1),
- OUT o_success TINYINT(1))
- BEGIN
- SET o_success = EXISTS (
- SELECT 1
- FROM customer_entity ce
- WHERE ce.email = i_email
- AND
- CASE
- WHEN i_only_active
- THEN ce.is_active = 1
- ELSE 1=1
- END
- );
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_CHECK_ACCOUNT_BY_NUMBER` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_CHECK_ACCOUNT_BY_NUMBER`(
- IN i_account_number VARCHAR(255),
- IN i_only_active TINYINT(1),
- OUT o_success TINYINT(1))
- BEGIN
- SET o_success = EXISTS (
- SELECT 1
- FROM customer_entity ce
- WHERE ce.account_number = i_account_number
- AND
- CASE
- WHEN i_only_active
- THEN ce.is_active = 1
- ELSE 1=1
- END
- );
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_CHECK_SUBSCRIPTION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_CHECK_SUBSCRIPTION`(
- IN i_g_partner_id INT(10),
- IN i_account_number VARCHAR(255),
- OUT o_success TINYINT(1))
- BEGIN
- SET o_success = EXISTS (SELECT 1
- FROM partners_entity p
- INNER JOIN partners_earn pe
- ON p.id = pe.partner_id AND pe.g_partner_id = i_g_partner_id
- INNER JOIN partner_subscription ps
- ON pe.partner_id = ps.partner_id
- AND ps.start_date IS NOT NULL
- AND ps.end_date IS NULL
- INNER JOIN customer_entity ce
- ON ps.customer_id = ce.entity_id
- AND ce.account_number = i_account_number
- );
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_CREATE_ACCOUNT` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_CREATE_ACCOUNT`(
- IN i_first_name VARCHAR(255),
- IN i_last_name VARCHAR(255),
- IN i_email VARCHAR(255),
- IN i_postal_code VARCHAR(255),
- IN i_agreed_to_tos TINYINT(1),
- IN i_partner_member_account_number VARCHAR(255),
- IN i_account_number VARCHAR(255),
- IN i_status TINYINT(1),
- IN i_gender TINYINT(1),
- IN i_is_parent TINYINT(1),
- IN i_is_home_owner TINYINT(1),
- IN i_date_of_birth DATE,
- IN i_g_partner_id INT(10),
- OUT o_customer_id INT(11),
- OUT o_reason VARCHAR(255))
- BEGIN
- DECLARE c_earn_api_channel_id INT(11) DEFAULT 320;
- DECLARE v_new_entity_id INT(10) DEFAULT 0;
- DECLARE v_new_addr_entity_id INT(10);
- DECLARE v_ivalue VARCHAR(255);
- DECLARE v_str VARCHAR(1000);
- DECLARE v_ins_rows INT(10);
- DECLARE v_email_already_exist TINYINT(1);
- CALL EARN_CHECK_ACCOUNT_BY_EMAIL(i_email, 0, v_email_already_exist);
- IF (v_email_already_exist) THEN
- SET o_reason = 'email has already been taken';
- SET o_customer_id = 0;
- ELSE
- IF EXISTS
- (SELECT 1
- FROM partners_earn pe
- INNER JOIN earns_customers_partners ecp
- ON pe.partner_id = ecp.partner_id
- WHERE pe.g_partner_id = i_g_partner_id
- AND ecp.partner_member_account_number = i_partner_member_account_number
- )
- THEN
- SET o_reason = 'partner member account number is already used';
- SET o_customer_id = 0;
- ELSE
- START TRANSACTION;
- INSERT INTO `customer_entity`
- (`entity_type_id`,
- `website_id`,
- `group_id`,
- `email`,
- `store_id`,
- `created_at`,
- `updated_at`,
- `is_active`,
- `account_number`)
- SELECT
- 1 AS entity_type_id,
- 1 AS website_id,
- 1 AS group_id,
- i_email AS email,
- 1 AS store_id,
- NOW(),
- NOW(),
- i_status AS is_active,
- i_account_number;
- SET v_new_entity_id = LAST_INSERT_ID();
- SELECT ROW_COUNT() INTO v_ins_rows;
- IF v_ins_rows > 0 THEN
- SET v_str = '';
- SET @entity_type_id = 1;
- SET @attribute_code = '';
- SET @attribute_id = 0;
- SET @backend_type = '';
- WHILE
- EXISTS (
- SELECT attribute_id
- FROM eav_attribute
- WHERE attribute_id > @attribute_id
- AND entity_type_id = @entity_type_id
- AND
- CASE
- WHEN (ISNULL(i_gender) AND ISNULL(i_date_of_birth))
- THEN attribute_code IN ('firstname', 'lastname')
- WHEN (ISNULL(i_gender) AND ISNULL(i_date_of_birth) = 0)
- THEN attribute_code IN ('firstname', 'lastname', 'dob')
- WHEN (ISNULL(i_gender) = 0 AND ISNULL(i_date_of_birth))
- THEN attribute_code IN ('firstname', 'lastname', 'gender')
- ELSE
- attribute_code IN ('firstname', 'lastname', 'dob', 'gender')
- END
- ORDER BY attribute_code ASC
- )
- DO
- SELECT attribute_code, attribute_id, backend_type
- INTO @attribute_code, @attribute_id, @backend_type
- FROM eav_attribute
- WHERE attribute_id > @attribute_id
- AND entity_type_id = @entity_type_id
- AND
- CASE
- WHEN (ISNULL(i_gender) AND ISNULL(i_date_of_birth))
- THEN attribute_code IN ('firstname', 'lastname')
- WHEN (ISNULL(i_gender) AND ISNULL(i_date_of_birth) = 0 )
- THEN attribute_code IN ('firstname', 'lastname', 'dob')
- WHEN (ISNULL(i_gender) = 0 AND ISNULL(i_date_of_birth))
- THEN attribute_code IN ('firstname', 'lastname', 'gender')
- ELSE attribute_code IN ('firstname', 'lastname', 'dob', 'gender')
- END
- ORDER BY attribute_id ASC
- LIMIT 1;
- SET v_ivalue =
- CASE
- WHEN @attribute_code = 'firstname' THEN CONCAT('''', i_first_name, '''')
- WHEN @attribute_code = 'lastname' THEN CONCAT('''', i_last_name, '''')
- WHEN @attribute_code = 'dob' THEN CONCAT('date(''', i_date_of_birth, ''')')
- WHEN @attribute_code = 'gender' THEN i_gender
- END;
- SET @qwr = concat(
- 'INSERT INTO customer_entity_',
- @backend_type,
- '(entity_type_id, attribute_id, entity_id, value)
- SELECT ',
- @entity_type_id,
- ', ',
- @attribute_id,
- ', ',
- v_new_entity_id,
- ', '
- ,v_ivalue,
- ';'
- );
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- SET v_str = CONCAT(v_str, '|', v_ivalue);
- END WHILE;
- IF ISNULL(i_gender) = 0 THEN
- INSERT INTO customer_personal(customer_id, customer_gender, customer_age_range)
- VALUES (v_new_entity_id, i_gender, COALESCE(i_date_of_birth, NOW()));
- END IF;
- SET @entity_type_id = 2;
- INSERT INTO customer_address_entity (entity_type_id, attribute_set_id, parent_id, created_at, updated_at, is_active)
- VALUES (@entity_type_id, 0, v_new_entity_id, NOW(), NOW(), i_status);
- SET v_new_addr_entity_id = LAST_INSERT_ID();
- INSERT INTO customer_address_entity_varchar (entity_type_id, attribute_id, entity_id, value)
- VALUES (@entity_type_id, 29, v_new_addr_entity_id, i_postal_code);
- INSERT INTO customer_entity_int(entity_type_id, attribute_id, entity_id, value)
- VALUES (1, 13, v_new_entity_id, v_new_addr_entity_id), (1, 14, v_new_entity_id, v_new_addr_entity_id);
- INSERT INTO customer_entity_int(attribute_id, value, entity_type_id, entity_id)
- SELECT ea.attribute_id, c_earn_api_channel_id, ea.entity_type_id, v_new_entity_id
- FROM eav_attribute ea
- WHERE ea.attribute_code = 'channel_id';
- END IF;
- SELECT v_new_entity_id, '' INTO o_customer_id, o_reason;
- COMMIT;
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_CREATE_SESSION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_CREATE_SESSION`(
- ipartner_id int(10),
- i_accountNumber varchar(255),
- i_email varchar(255),
- i_landingUrl varchar(255),
- out o_accountNumber varchar(255),
- out o_securityToken varchar(32),
- out o_reason varchar(255))
- BEGIN
- DECLARE accountNumber VARCHAR(255) DEFAULT '';
- DECLARE success TINYINT(1);
- IF i_accountNumber IS NULL
- THEN
- IF i_email IS NULL
- THEN
- SET accountNumber = '';
- ELSE
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET accountNumber = '';
- SELECT account_number
- FROM customer_entity
- WHERE email = i_email
- INTO accountNumber;
- END;
- END IF;
- ELSE
- IF NOT EXISTS (SELECT 1 FROM customer_entity WHERE account_number = i_accountNumber)
- THEN
- SET o_reason = 'Account not found';
- ELSE
- SET accountNumber = i_accountNumber;
- END IF;
- END IF;
- IF accountNumber <> ''
- THEN
- call EARN_CHECK_SUBSCRIPTION(ipartner_id, accountNumber, success);
- IF success
- THEN
- BEGIN
- DECLARE securityToken VARCHAR(255);
- SET securityToken = REPLACE(UUID(), '-', '');
- INSERT INTO direct_login(account_no, login_guid, expiration_datetime, url)
- VALUES(accountNumber, securityToken, ADDDATE(NOW(), INTERVAL 30 MINUTE), i_landingUrl);
- SELECT accountNumber, securityToken INTO o_accountNumber, o_securityToken;
- END;
- ELSE
- SET o_reason = 'Account is not subscribed to partner';
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_CREATE_SUBSCRIPTION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_CREATE_SUBSCRIPTION`(IN i_g_partner_id INT(10),
- IN i_account_number VARCHAR(255),
- IN i_email VARCHAR(255),
- IN i_partner_member_account_number VARCHAR(255),
- OUT o_subs_id INT(11),
- OUT o_reason VARCHAR(255))
- BEGIN
- DECLARE c_earn_other_product_type_id VARCHAR(32) DEFAULT 'earn_other';
- DECLARE v_customer_id INT(10);
- DECLARE v_partner_id INT(10);
- DECLARE v_product_id INT(10);
- DECLARE v_customer_earn_id INT(10);
- DECLARE v_result TINYINT(1);
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_customer_id = -1;
- IF (i_account_number IS NOT NULL) THEN
- SELECT ce.entity_id
- INTO v_customer_id
- FROM customer_entity ce
- WHERE ce.account_number = i_account_number
- AND ce.is_active = 1;
- ELSEIF (i_email IS NOT NULL) THEN
- SELECT ce.entity_id
- INTO v_customer_id
- FROM customer_entity ce
- WHERE ce.email = i_email
- AND ce.is_active = 1;
- ELSE
- SET v_customer_id = -1;
- SELECT 0, 'Please pass account_number or email' INTO o_subs_id, o_reason;
- END IF;
- END;
- IF (v_customer_id = -1) THEN
- SELECT 0, 'Customer does not exist' INTO o_subs_id, o_reason;
- ELSE
- SELECT pe.id
- INTO v_partner_id
- FROM partners_entity pe
- INNER JOIN partners_earn per
- ON pe.id = per.partner_id
- WHERE per.g_partner_id = i_g_partner_id;
- IF ISNULL(v_partner_id) THEN
- SELECT 0, 'Partner does not exists' INTO o_subs_id, o_reason;
- ELSE
- IF EXISTS
- (SELECT 1
- FROM partner_subscription ps
- WHERE ps.partner_id = v_partner_id
- AND ps.member_account_number = i_partner_member_account_number
- AND ps.customer_id <> v_customer_id
- )
- THEN
- SELECT 0, 'Partner member account number is already used' INTO o_subs_id, o_reason;
- ELSE
- CALL EARN_CHECK_SUBSCRIPTION(i_g_partner_id, i_account_number, v_result);
- IF (v_result) THEN
- SELECT 0, 'Customer alredy subscribed to partner' INTO o_subs_id, o_reason;
- ELSE
- START TRANSACTION;
- BEGIN
- DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
- INSERT INTO partner_subscription(partner_id, member_account_number, customer_id, start_date, end_date)
- VALUES(v_partner_id, i_partner_member_account_number, v_customer_id, NOW(), NULL);
- SET o_subs_id = LAST_INSERT_ID();
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_product_id = -1;
- SELECT cpe.entity_id
- INTO v_product_id
- FROM catalog_product_entity cpe
- WHERE cpe.partner_id = v_partner_id
- AND cpe.type_id = c_earn_other_product_type_id
- LIMIT 1;
- END;
- IF (v_product_id <> -1) THEN
- INSERT INTO earns_customers (customer_id, product_id, start_date)
- VALUES (v_customer_id, v_product_id, NOW());
- SET v_customer_earn_id = LAST_INSERT_ID();
- INSERT INTO earns_customers_partners (earns_customers_id, partner_id, partner_member_account_number)
- VALUES (v_customer_earn_id, v_partner_id, i_partner_member_account_number);
- END IF;
- END;
- COMMIT;
- END IF;
- END IF;
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GENERATE_CONFIRMATION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GENERATE_CONFIRMATION`(IN iaccount_number varchar(255),
- IN i_key varchar(255),
- OUT o_key varchar(255))
- BEGIN
- declare icustomer_id int(10);
- declare id_confirmation int(10);
- SET o_key = '';
- SELECT uf_ret_attribute_id(1,'confirmation') into id_confirmation;
- IF EXISTS (SELECT 1 FROM customer_entity WHERE account_number = iaccount_number)
- THEN
- SELECT entity_id INTO icustomer_id
- FROM customer_entity ce WHERE account_number = iaccount_number;
- IF not Exists (SELECT 1 FROM customer_entity_varchar
- WHERE entity_id = icustomer_id
- AND attribute_id = id_confirmation)
- THEN
- INSERT INTO customer_entity_varchar (entity_type_id,attribute_id,entity_id,`value`)
- SELECT 1, id_confirmation ,icustomer_id ,concat(icustomer_id, i_key);
- SELECT concat(icustomer_id, i_key) INTO o_key;
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_ACCOUNT_BY_EMAIL` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_ACCOUNT_BY_EMAIL`(i_email VARCHAR(255))
- BEGIN
- DECLARE delim CHAR(1) DEFAULT '\n';
- SELECT
- ce.account_number AS 'account_number',
- cev_firstname.value AS 'first_name',
- cev_lastname.value AS 'last_name',
- cev_hash_password.value AS 'hash_password',
- ce.email AS 'email',
- ce.is_active AS 'status',
- ecb.amount AS 'point_balance',
- cp.customer_gender AS 'gender',
- cp.customer_age_range AS 'date_of_birth',
- SUBSTRING_INDEX(caet_street.value, delim, 1) AS 'street1',
- SUBSTRING_INDEX(SUBSTRING(caet_street.value, LENGTH(SUBSTRING_INDEX(caet_street.value, delim, 1)) + LENGTH(delim) + 1), delim, 1) AS 'street2',
- SUBSTRING_INDEX(SUBSTRING(caet_street.value, LENGTH(SUBSTRING_INDEX(caet_street.value, delim, 2)) + LENGTH(delim) + 1), delim, 1) AS 'street3',
- caev_city.value AS 'city',
- caev_region.value AS 'state_county',
- caev_postcode.value AS 'postal_code',
- caev_country.value AS 'country',
- eu.start_date AS 'start_date'
- FROM customer_entity ce
- LEFT JOIN enterprise_customerbalance ecb
- ON ce.entity_id = ecb.customer_id
- LEFT JOIN customer_entity_varchar cev_firstname
- ON ce.entity_id = cev_firstname.entity_id AND cev_firstname.attribute_id = 5
- LEFT JOIN customer_entity_varchar cev_lastname
- ON ce.entity_id = cev_lastname.entity_id AND cev_lastname.attribute_id = 7
- LEFT JOIN customer_entity_varchar cev_hash_password
- ON ce.entity_id = cev_hash_password.entity_id AND cev_hash_password.attribute_id = 12
- LEFT JOIN customer_personal cp
- ON cp.customer_id = ce.entity_id
- LEFT JOIN customer_address_entity cae
- ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_text caet_street
- ON cae.entity_id = caet_street.entity_id AND caet_street.attribute_id = 24
- LEFT JOIN customer_address_entity_varchar caev_city
- ON cae.entity_id = caev_city.entity_id AND caev_city.attribute_id = 25
- LEFT JOIN customer_address_entity_varchar caev_region
- ON cae.entity_id = caev_region.entity_id AND caev_region.attribute_id = 27
- LEFT JOIN customer_address_entity_varchar caev_postcode
- ON cae.entity_id = caev_postcode.entity_id AND caev_postcode.attribute_id = 29
- LEFT JOIN customer_address_entity_varchar caev_country
- ON cae.entity_id = caev_country.entity_id AND caev_country.attribute_id = 26
- LEFT JOIN earns_users eu
- ON ce.entity_id = eu.user_id
- WHERE ce.email = i_email AND ce.is_active = 1;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_ACCOUNT_BY_NUMBER` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_ACCOUNT_BY_NUMBER`(i_account_number VARCHAR(255))
- BEGIN
- DECLARE delim CHAR(1) DEFAULT '\n';
- SELECT
- ce.account_number AS 'account_number',
- cev_firstname.value AS 'first_name',
- cev_lastname.value AS 'last_name',
- cev_hash_password.value AS 'hash_password',
- ce.email AS 'email',
- ce.is_active AS 'status',
- ecb.amount AS 'point_balance',
- cp.customer_gender AS 'gender',
- cp.customer_age_range AS 'date_of_birth',
- SUBSTRING_INDEX(caet_street.value, delim, 1) AS 'street1',
- SUBSTRING_INDEX(SUBSTRING(caet_street.value, LENGTH(SUBSTRING_INDEX(caet_street.value, delim, 1)) + LENGTH(delim) + 1), delim, 1) AS 'street2',
- SUBSTRING_INDEX(SUBSTRING(caet_street.value, LENGTH(SUBSTRING_INDEX(caet_street.value, delim, 2)) + LENGTH(delim) + 1), delim, 1) AS 'street3',
- caev_city.value AS 'city',
- caev_region.value AS 'state_county',
- caev_postcode.value AS 'postal_code',
- caev_country.value AS 'country',
- eu.start_date AS 'start_date'
- FROM customer_entity ce
- LEFT JOIN enterprise_customerbalance ecb
- ON ce.entity_id = ecb.customer_id
- LEFT JOIN customer_entity_varchar cev_firstname
- ON ce.entity_id = cev_firstname.entity_id AND cev_firstname.attribute_id = 5
- LEFT JOIN customer_entity_varchar cev_lastname
- ON ce.entity_id = cev_lastname.entity_id AND cev_lastname.attribute_id = 7
- LEFT JOIN customer_entity_varchar cev_hash_password
- ON ce.entity_id = cev_hash_password.entity_id AND cev_hash_password.attribute_id = 12
- LEFT JOIN customer_personal cp
- ON cp.customer_id = ce.entity_id
- LEFT JOIN customer_address_entity cae
- ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_text caet_street
- ON cae.entity_id = caet_street.entity_id AND caet_street.attribute_id = 24
- LEFT JOIN customer_address_entity_varchar caev_city
- ON cae.entity_id = caev_city.entity_id AND caev_city.attribute_id = 25
- LEFT JOIN customer_address_entity_varchar caev_region
- ON cae.entity_id = caev_region.entity_id AND caev_region.attribute_id = 27
- LEFT JOIN customer_address_entity_varchar caev_postcode
- ON cae.entity_id = caev_postcode.entity_id AND caev_postcode.attribute_id = 29
- LEFT JOIN customer_address_entity_varchar caev_country
- ON cae.entity_id = caev_country.entity_id AND caev_country.attribute_id = 26
- LEFT JOIN earns_users eu
- ON ce.entity_id = eu.user_id
- WHERE ce.account_number = i_account_number AND ce.is_active = 1;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_PARTNER_BY_G_ID` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_PARTNER_BY_G_ID`(i_g_partner_id int(11))
- BEGIN
- SELECT
- p.id AS 'id',
- p.name AS 'name',
- p.country AS 'country',
- pe.type AS 'type',
- pe.g_partner_id AS 'g_partner_id',
- pe.g_partner_secret_key AS 'g_partner_secret_key',
- COALESCE(pe.allow_autolink, 0) AS 'allow_autolink'
- FROM partners_entity p
- INNER JOIN partners_earn pe ON p.id = pe.partner_id
- WHERE pe.g_partner_id = i_g_partner_id;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_PARTNER_SECRET_KEY_BY_ID` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_PARTNER_SECRET_KEY_BY_ID`(gpartnerId int(11), out partnerSecretKey varchar(255))
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET partnerSecretKey = '';
- SELECT g_partner_secret_key
- FROM partners_earn
- WHERE g_partner_id = gpartnerId
- INTO partnerSecretKey;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_PARTNER_TYPE_BY_ID` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_PARTNER_TYPE_BY_ID`(gpartnerId int(11), out partnerType int)
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET partnerType = -1;
- SELECT type
- FROM partners_earn
- WHERE g_partner_id = gpartnerId
- INTO partnerType;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_PASSWORD_HASH_BY_EMAIL` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_PASSWORD_HASH_BY_EMAIL`(iemail varchar(255), out passwordHash varchar(255))
- BEGIN
- DECLARE passAttrId int(11) DEFAULT 12;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET passwordHash = '';
- SELECT cev_hash_password.value
- FROM customer_entity ce
- INNER JOIN customer_entity_varchar cev_hash_password
- ON ce.entity_id = cev_hash_password.entity_id AND cev_hash_password.attribute_id = passAttrId
- WHERE ce.email = iemail
- INTO passwordHash;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_PASSWORD_HASH_BY_NUMBER` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_PASSWORD_HASH_BY_NUMBER`(accNumber varchar(255), out passwordHash varchar(255))
- BEGIN
- DECLARE passAttrId int(11) DEFAULT 12;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET passwordHash = '';
- SELECT cev_hash_password.value
- FROM customer_entity ce
- INNER JOIN customer_entity_varchar cev_hash_password
- ON ce.entity_id = cev_hash_password.entity_id AND cev_hash_password.attribute_id = passAttrId
- WHERE ce.account_number = accNumber
- INTO passwordHash;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_TRANSACTION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_TRANSACTION`(
- IN i_g_partner_id INT(10),
- IN i_partner_transaction_id VARCHAR(50),
- OUT o_success TINYINT(1),
- OUT o_reason VARCHAR(255))
- BEGIN
- SELECT
- ce.account_number AS 'account_number',
- ecbh.balance_delta AS 'units',
- ps.member_account_number AS 'partner_member_account_number',
- pet.external_partner_transaction_id AS 'partner_transaction_id',
- ecbh.updated_at AS 'date_time',
- ecbh.description AS 'external_comment'
- FROM partners_entity p
- INNER JOIN partners_earn pe
- ON p.id = pe.partner_id
- AND pe.g_partner_id = i_g_partner_id
- INNER JOIN partners_earn_transactions pet
- ON pe.partner_id = pet.partner_id
- AND pet.external_partner_transaction_id = i_partner_transaction_id
- INNER JOIN enterprise_customerbalance_history ecbh
- ON pet.customer_balance_history_id = ecbh.history_id
- INNER JOIN partner_subscription ps
- ON ps.partner_id = pe.partner_id
- AND ps.customer_id = pet.customer_id
- INNER JOIN customer_entity ce
- ON pet.customer_id = ce.entity_id
- AND ce.is_active = 1
- LIMIT 1;
- IF NOT EXISTS
- (SELECT 1
- FROM partners_earn_transactions pet
- WHERE pet.external_partner_transaction_id = i_partner_transaction_id)
- THEN
- SELECT 0, 'Transaction doesn''t exist' INTO o_success, o_reason;
- ELSEIF NOT EXISTS
- (SELECT 1
- FROM partners_entity p
- INNER JOIN partners_earn pe
- ON p.id = pe.partner_id
- INNER JOIN partners_earn_transactions pet
- ON pe.partner_id = pet.partner_id
- WHERE pet.external_partner_transaction_id = i_partner_transaction_id
- AND pe.g_partner_id = i_g_partner_id)
- THEN
- SELECT 0, 'Transaction doesn''t belong to partner' INTO o_success, o_reason;
- ELSEIF NOT EXISTS
- (SELECT 1
- FROM partners_earn_transactions pet
- INNER JOIN customer_entity ce
- ON pet.customer_id = ce.entity_id
- WHERE pet.external_partner_transaction_id = i_partner_transaction_id
- AND ce.is_active = 1)
- THEN
- SELECT 0, 'Account not found' INTO o_success, o_reason;
- ELSE
- SELECT 1, '' INTO o_success, o_reason;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EARN_GET_TRANSACTIONS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `EARN_GET_TRANSACTIONS`(
- IN i_g_partner_id INT(10),
- IN i_partner_member_account_number VARCHAR(255),
- IN i_from_date DATETIME,
- IN i_to_date DATETIME,
- OUT o_success TINYINT(1),
- OUT o_reason VARCHAR(255))
- BEGIN
- SELECT DISTINCT
- ce.account_number AS 'account_number',
- ecbh.balance_delta AS 'units',
- ps.member_account_number AS 'partner_member_account_number',
- pet.external_partner_transaction_id AS 'partner_transaction_id',
- ecbh.updated_at AS 'date_time',
- ecbh.description AS 'external_comment'
- FROM partners_entity p
- INNER JOIN partners_earn pe
- ON p.id = pe.partner_id
- AND pe.g_partner_id = i_g_partner_id
- INNER JOIN partner_subscription ps
- ON pe.partner_id = ps.partner_id
- AND ps.member_account_number = i_partner_member_account_number
- INNER JOIN customer_entity ce
- ON ps.customer_id = ce.entity_id
- AND ce.is_active = 1
- INNER JOIN partners_earn_transactions pet
- ON ps.partner_id = pet.partner_id
- AND ps.customer_id = pet.customer_id
- INNER JOIN enterprise_customerbalance_history ecbh
- ON pet.customer_balance_history_id = ecbh.history_id
- INNER JOIN enterprise_customerbalance_reasons ecbr
- ON ecbh.reason_id = ecbr.id
- WHERE ecbr.reason_code IN ('Point Allocation', 'Points_Code_Deposit')
- AND ecbh.updated_at BETWEEN i_from_date AND i_to_date
- ORDER BY date_time DESC
- LIMIT 100;
- IF NOT EXISTS
- (SELECT 1
- FROM partner_subscription ps
- WHERE ps.member_account_number = i_partner_member_account_number)
- THEN
- SELECT 0, 'partner member account number does not exist' INTO o_success, o_reason;
- ELSEIF NOT EXISTS
- (SELECT 1
- FROM partners_earn pe
- INNER JOIN partner_subscription ps
- ON pe.partner_id = ps.partner_id
- WHERE pe.g_partner_id = i_g_partner_id
- AND ps.member_account_number = i_partner_member_account_number)
- THEN
- SELECT 0, 'partner member account number doesn''t belong to partner' INTO o_success, o_reason;
- ELSEIF NOT EXISTS
- (SELECT 1
- FROM partners_earn pe
- INNER JOIN partner_subscription ps
- ON pe.partner_id = ps.partner_id
- INNER JOIN customer_entity ce
- ON ps.customer_id = ce.entity_id
- WHERE pe.g_partner_id = i_g_partner_id
- AND ps.member_account_number = i_partner_member_account_number
- AND ce.is_active = 1)
- THEN
- SELECT 0, 'Account not found' INTO o_success, o_reason;
- ELSE
- SELECT 1, '' INTO o_success, o_reason;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `EPP_CREATE_TRANSACTION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `EPP_CREATE_TRANSACTION`(IN inp_hash VARCHAR(255) ,IN inp_customer_id INT(10),IN inp_channel_id INT(10), OUT success TINYINT(1),OUT id_partner_trans INT(10) )
- BEGIN
- DECLARE v_balance_id INT(10);
- DECLARE v_balance_amount DECIMAL(12,4);
- DECLARE v_points_amount DECIMAL(12,4);
- DECLARE v_partner_bal_amount DECIMAL(12,4);
- DECLARE v_partner_id INT(10);
- DECLARE v_transaction_description VARCHAR(255);
- DECLARE v_frequency TINYINT(3);
- DECLARE v_frequency_unit TINYINT(3);
- DECLARE dt_now DATETIME;
- DECLARE v_allow TINYINT(1);
- DECLARE v_start_transaction TINYINT(1);
- DECLARE customer_tr_id INT(10);
- START TRANSACTION;
- BEGIN
- DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
- SELECT partner_id,transaction_description,frequency,frequency_unit,points_amount
- INTO v_partner_id,v_transaction_description,v_frequency,v_frequency_unit,v_points_amount
- FROM earn_plugin_hashes WHERE HASH = inp_hash;
- SET v_start_transaction = 0 ;
- SET customer_tr_id = 0 ;
- SET id_partner_trans = 0;
- SET success =0 ;
- SELECT UTC_TIMESTAMP() INTO dt_now;
- IF EXISTS (SELECT 1 FROM partners_earn_transactions p
- WHERE p.partner_id = v_partner_id
- AND p.description = v_transaction_description
- AND p.TYPE = 20
- AND customer_id = inp_customer_id )
- THEN
- IF v_frequency_unit IS NULL THEN
- SELECT 1 INTO v_start_transaction;
- ELSE
- SELECT `MG_CALC_EPP_FREQUENCY`(v_frequency_unit,v_frequency,v_partner_id,v_transaction_description,inp_customer_id,dt_now) INTO v_allow;
- IF v_allow = 1 THEN
- SELECT 1 INTO v_start_transaction;
- ELSE
- SELECT 0 INTO v_start_transaction;
- END IF;
- END IF;
- ELSE
- SELECT 1 INTO v_start_transaction;
- END IF ;
- IF v_start_transaction =1 THEN
- IF EXISTS
- (SELECT 1
- FROM enterprise_customerbalance ecb
- WHERE ecb.customer_id = inp_customer_id)
- THEN
- SELECT ecb.balance_id, ecb.amount
- INTO v_balance_id, v_balance_amount
- FROM enterprise_customerbalance ecb
- WHERE ecb.customer_id = inp_customer_id;
- ELSE
- SET v_balance_amount = 0;
- INSERT INTO enterprise_customerbalance (customer_id, website_id, amount)
- VALUES (v_customer_id, 1, v_balance_amount);
- SET v_balance_id = LAST_INSERT_ID();
- END IF;
- INSERT INTO enterprise_customerbalance_history(balance_id, updated_at, `action`, balance_amount, balance_delta, additional_info, reason_id, description)
- VALUES (v_balance_id, dt_now, 1, v_balance_amount + v_points_amount, v_points_amount, NULL, 21, v_transaction_description);
- SET customer_tr_id = LAST_INSERT_ID();
- INSERT INTO enterprise_customerbalance_history_channel_map(history_id, channel_id) VALUES (customer_tr_id, inp_channel_id);
- UPDATE enterprise_customerbalance ecb
- SET ecb.amount = ecb.amount + v_points_amount
- WHERE ecb.balance_id = v_balance_id;
- SELECT pe.points
- INTO v_partner_bal_amount
- FROM partners_earn pe
- WHERE pe.partner_id = v_partner_id;
- INSERT INTO partners_earn_transactions (partner_id, `type`, `time`, points, balance_amount, customer_id, rep_id, customer_balance_history_id, description)
- VALUES (v_partner_id, 20,dt_now, v_points_amount, v_partner_bal_amount - v_points_amount, inp_customer_id,'Used by Customer via Earn Plugin' ,customer_tr_id, v_transaction_description);
- SET id_partner_trans = LAST_INSERT_ID();
- UPDATE partners_earn pe
- SET pe.points = pe.points - v_points_amount
- WHERE pe.partner_id = v_partner_id;
- SET success =1 ;
- ELSE
- SET success = 0;
- END IF;
- COMMIT;
- END;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `IVR_MAGENTO_CREATE_IRECYCLE_REPORTING` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `IVR_MAGENTO_CREATE_IRECYCLE_REPORTING`(IN acc_num VARCHAR(255), IN points DECIMAL(12,4), OUT result TINYINT, OUT reason VARCHAR(255))
- BEGIN
- DECLARE tr_id INT(11);
- DECLARE cust_id INT(11);
- DECLARE str_id INT(5);
- DECLARE subs_id INT(11);
- DECLARE bal_id INT(11);
- DECLARE wbs_id INT(5);
- DECLARE res_id INT(11);
- DECLARE ivr_channel_id INT(11) DEFAULT 310;
- DECLARE bal_amount DECIMAL(12,4);
- DECLARE datetime_now DATETIME DEFAULT now();
- DECLARE bal_reason VARCHAR(255) DEFAULT 'curbside_irecycle_report_bonus';
- DECLARE bal_desc VARCHAR(255) DEFAULT 'Telling us you recycled';
- DECLARE bal_info VARCHAR(255) DEFAULT 'Telling us you recycled';
- DECLARE action_updated INT(5) DEFAULT 1;
- DECLARE action_created INT(5) DEFAULT 2;
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET subs_id = -1;
- SELECT ce.entity_id, ce.store_id, cs.subscription_id
- FROM customer_entity ce
- INNER JOIN curbside_subscription cs ON ce.entity_id = cs.customer_id
- WHERE ce.account_number = acc_num AND cs.end_date IS NULL
- LIMIT 1
- INTO cust_id, str_id, subs_id;
- END;
- IF subs_id <> -1 THEN
- IF NOT EXISTS (SELECT 1
- FROM curbside_reports
- WHERE subscription_id = subs_id AND YEARWEEK(reported_at, 3) = YEARWEEK(datetime_now, 3))
- THEN
- INSERT INTO curbside_reports(subscription_id, reported_at) VALUES(subs_id, datetime_now);
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET bal_id = -1;
- SELECT balance_id, amount
- FROM enterprise_customerbalance
- WHERE customer_id = cust_id
- INTO bal_id, bal_amount;
- END;
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET res_id = null;
- SELECT id
- FROM enterprise_customerbalance_reasons
- WHERE reason_code = bal_reason
- INTO res_id;
- END;
- IF bal_id = -1 THEN
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET wbs_id = null;
- SELECT website_id
- FROM core_store
- WHERE store_id = str_id
- INTO wbs_id;
- END;
- INSERT INTO enterprise_customerbalance(customer_id, website_id, amount)
- VALUES (cust_id , wbs_id, 0);
- SET bal_id = LAST_INSERT_ID();
- END IF;
- INSERT INTO enterprise_customerbalance_history
- (balance_id, updated_at, `action`, balance_amount, balance_delta, additional_info, reason_id, description)
- VALUES (bal_id, datetime_now, action_created, bal_amount + points, points, bal_info, res_id, bal_desc);
- SET tr_id = LAST_INSERT_ID();
- INSERT INTO enterprise_customerbalance_history_channel_map(history_id, channel_id) VALUES (tr_id, ivr_channel_id);
- UPDATE enterprise_customerbalance
- SET amount = amount + points
- WHERE balance_id = bal_id;
- SELECT 1, 'Week is successfully reported' INTO result, reason;
- ELSE
- SELECT 0, 'Week already reported' INTO result, reason;
- END IF;
- ELSE
- SELECT 0, 'Subscription not found' INTO result, reason;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MCR_CREATE_ERROR` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MCR_CREATE_ERROR`(i_cust_id INT(11), i_error_id VARCHAR(255), i_message VARCHAR(255), i_description VARCHAR(255))
- BEGIN
- INSERT INTO mcr_errors(cust_id, error_id, message, description)
- VALUES (i_cust_id, i_error_id, i_message, i_description);
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MCR_GET_UNCONFIRMED_MEMBERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MCR_GET_UNCONFIRMED_MEMBERS`()
- BEGIN
- DECLARE remind_period INT(11) DEFAULT 3;
- DECLARE remind_period_days_before DATETIME DEFAULT DATE_SUB(NOW(), INTERVAL remind_period DAY);
- DECLARE start_datetime_criteria DATETIME DEFAULT DATE_FORMAT(remind_period_days_before, '%Y-%m-%d 00:00:00');
- DECLARE end_datetime_criteria DATETIME DEFAULT DATE_FORMAT(remind_period_days_before, '%Y-%m-%d 23:59:59');
- SELECT
- ce.entity_id AS 'id',
- ce.store_id AS 'store_id',
- ce.email AS 'email',
- cev_fn.value AS 'first_name',
- cev_ln.value AS 'last_name',
- cev_cnf.value AS 'confirm_key'
- FROM customer_entity ce
- INNER JOIN customer_entity_varchar cev_fn ON ce.entity_id = cev_fn.entity_id AND cev_fn.attribute_id = 5
- INNER JOIN customer_entity_varchar cev_ln ON ce.entity_id = cev_ln.entity_id AND cev_ln.attribute_id = 7
- INNER JOIN customer_entity_varchar cev_cnf ON ce.entity_id = cev_cnf.entity_id AND cev_cnf.attribute_id = 16
- WHERE
- ce.created_at BETWEEN start_datetime_criteria AND end_datetime_criteria
- AND TRIM(ce.email) <> ''
- ;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_ACTIVITIES_FOR_EARN` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_ACTIVITIES_FOR_EARN`(IN inp_product_id INT(10))
- BEGIN
- DROP TABLE IF EXISTS temp_earn_activities ;
- CREATE TEMPORARY TABLE temp_earn_activities (
- `id` INT(10),
- `type_activity` TINYINT(1),
- `customer_id` INT(10),
- `firstname` VARCHAR(255),
- `lastname` VARCHAR(255),
- `action` VARCHAR(255),
- `for_order` DATETIME
- ) ;
- SELECT pe.NAME INTO @partnerName
- FROM catalog_product_entity cpe
- INNER JOIN partners_entity pe ON cpe.partner_id = pe.id
- WHERE cpe.entity_id = inp_product_id;
- INSERT INTO temp_earn_activities
- (id,type_activity,customer_id,`action`,for_order)
- SELECT
- MAX(ca.id)
- ,0
- ,ca.customer_id
- ,CONCAT('earned with ',@partnerName)
- ,MAX(ca.updated_at)
- FROM customers_activities ca
- WHERE ca.product_id = inp_product_id
- GROUP BY ca.customer_id
- ORDER BY ca.id DESC LIMIT 5 ;
- INSERT INTO temp_earn_activities
- (id,type_activity,customer_id,`action`,for_order)
- SELECT
- MAX(f.id)
- ,1
- ,f.customer_id
- ,'saved this earn opportunity to favorites'
- ,MAX(f.created_at)
- FROM favorite_products_for_users f
- WHERE f.product_id = inp_product_id
- AND favorite.is_private = 0
- GROUP BY f.customer_id
- ORDER BY f.id DESC LIMIT 5;
- DROP TABLE IF EXISTS temp_max_date;
- CREATE TEMPORARY TABLE temp_max_date
- AS
- SELECT customer_id,MAX(for_order) AS max_dt
- FROM temp_earn_activities
- GROUP BY customer_id;
- UPDATE temp_earn_activities t
- INNER JOIN
- customer_entity_varchar fname
- ON fname.entity_id =t.customer_id AND fname.attribute_id =5
- INNER JOIN
- customer_entity_varchar lname
- ON lname.entity_id =t.customer_id AND lname.attribute_id =7
- SET t.firstname = fname.VALUE , t.lastname = lname.VALUE
- ;
- SELECT
- tea.`id`
- ,tea.`type_activity`
- ,tea.`customer_id`
- ,tea.`firstname`
- ,tea.`lastname`
- ,tea.`action`
- ,tea.`for_order`
- FROM temp_earn_activities tea
- INNER JOIN temp_max_date tmd
- ON tea.customer_id = tmd.customer_id AND tea.for_order = tmd.max_dt
- GROUP BY `customer_id`
- ORDER BY for_order DESC
- LIMIT 5;
- DROP TABLE IF EXISTS temp_earn_activities ;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_ACTIVITIES_FOR_REWARD` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_ACTIVITIES_FOR_REWARD`(IN inp_product_id INT(10))
- BEGIN
- DROP TABLE IF EXISTS temp_orders_activities ;
- CREATE TEMPORARY TABLE temp_reward_activities (
- `id` INT(10),
- `type_activity` TINYINT(1),
- `customer_id` INT(10),
- `firstname` VARCHAR(255),
- `lastname` VARCHAR(255),
- `action` VARCHAR(255),
- `for_order` DATETIME
- ) ;
- INSERT INTO temp_reward_activities
- SELECT
- MAX(sfo.entity_id)
- ,0
- ,sfo.customer_id
- ,sfo.customer_firstname
- ,sfo.customer_lastname
- ,'ordered this reward'
- ,MAX(sfoi.created_at)
- FROM sales_flat_order_item sfoi
- INNER JOIN sales_flat_order sfo
- ON sfoi.order_id = sfo.entity_id
- WHERE sfoi.product_id = inp_product_id
- AND sfo.visible_activity = 1
- GROUP BY sfo.customer_id
- ORDER BY sfo.entity_id DESC LIMIT 5 ;
- INSERT INTO temp_reward_activities
- (id,type_activity,customer_id,`action`,for_order)
- SELECT
- MAX(f.id)
- ,1
- ,f.customer_id
- ,'saved this reward to favorites'
- ,MAX(f.created_at)
- FROM favorite_products_for_users f
- WHERE f.product_id = inp_product_id
- AND favorite.is_private = 0
- GROUP BY f.customer_id
- ORDER BY f.id DESC LIMIT 5;
- DROP TABLE IF EXISTS temp_max_date;
- CREATE TEMPORARY TABLE temp_max_date
- AS
- SELECT customer_id,MAX(for_order) AS max_dt
- FROM temp_reward_activities
- GROUP BY customer_id;
- UPDATE temp_reward_activities t
- INNER JOIN
- customer_entity_varchar fname
- ON fname.entity_id =t.id AND fname.attribute_id =5
- INNER JOIN
- customer_entity_varchar lname
- ON lname.entity_id =t.id AND lname.attribute_id =7
- SET t.firstname = fname.VALUE , t.lastname = lname.VALUE
- WHERE t.type_activity = 1 ;
- SELECT
- tra.`id`
- ,tra.`type_activity`
- ,tra.`customer_id`
- ,tra.`firstname`
- ,tra.`lastname`
- ,tra.`action`
- ,tra.`for_order`
- FROM temp_reward_activities tra INNER JOIN temp_max_date tmd
- ON tra.customer_id = tmd.customer_id AND tra.for_order = tmd.max_dt
- ORDER BY for_order DESC LIMIT 5;
- DROP TABLE IF EXISTS temp_reward_activities ;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_CREATE_CUST_ERROR` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MG_CREATE_CUST_ERROR`(i_cust_id INT(11), i_error_id VARCHAR(255), i_message VARCHAR(255), i_description VARCHAR(255))
- BEGIN
- INSERT INTO mg_errors(cust_id, error_id, message, description)
- VALUES (i_cust_id, i_error_id, i_message, i_description);
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_CUSTOMER_ADD_TRANSACTION` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MG_CUSTOMER_ADD_TRANSACTION`(
- IN accountNumber VARCHAR(255),
- IN delta DECIMAL(12,2),
- IN updatedAt DATETIME,
- IN reason INT(10),
- IN descriptionText VARCHAR(255),
- IN itransaktions_old_id INT(11),
- OUT result_code TINYINT(1)
- )
- L_return:
- BEGIN
- DECLARE balanceId INT DEFAULT 0;
- DECLARE customerId INT DEFAULT 0;
- DECLARE oldBalance DECIMAL(12,2);
- DECLARE newBalance DECIMAL(12,2);
- DECLARE balanceAction INT DEFAULT 1;
- DECLARE ret TINYINT(1) DEFAULT 0;
- DECLARE sql_error TINYINT(1) DEFAULT 1;
- DECLARE partner_bal_amount DECIMAL(12,4);
- DECLARE tr_id INT(11);
- IF (accountNumber IS NULL
- OR delta IS NULL
- OR updatedAt IS NULL
- OR reason IS NULL
- OR descriptionText IS NULL
- OR itransaktions_old_id IS NULL
- OR accountNumber = ''
- OR reason = 0
- OR descriptionText = ''
- OR itransaktions_old_id = 0) THEN
- SET result_code = 4;
- LEAVE L_return;
- END IF;
- SELECT entity_id INTO customerId
- FROM customer_entity AS cust_c
- WHERE account_number = accountNumber;
- IF customerId = 0 THEN
- SET result_code = 2;
- LEAVE L_return;
- END IF;
- IF EXISTS(SELECT * FROM enterprise_customerbalance_history WHERE transaktions_old_id = itransaktions_old_id) THEN
- SET result_code = 3;
- LEAVE L_return;
- END IF;
- SELECT balance_id, amount INTO balanceId, oldBalance
- FROM enterprise_customerbalance
- WHERE `customer_id` = customerId;
- SELECT MG_NY_TIME_TO_UTC(updatedAt) INTO updatedAt;
- START TRANSACTION;
- BEGIN
- DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
- SET sql_error = 1;
- IF balanceId = 0 THEN
- SET balanceAction = 2;
- SET oldBalance = 0;
- INSERT INTO enterprise_customerbalance(customer_id, website_id, amount) VALUES (customerId, 1, 0);
- SELECT LAST_INSERT_ID() INTO balanceId;
- END IF;
- SET newBalance = oldBalance + delta;
- UPDATE `enterprise_customerbalance` SET `amount` = newBalance WHERE `customer_id` = customerId;
- INSERT INTO enterprise_customerbalance_history
- (balance_id,balance_amount, balance_delta, ACTION, updated_at, reason_id, description, additional_info, is_customer_notified, transaktions_old_id)
- VALUES
- (balanceId, newBalance, delta, balanceAction, updatedAt, reason, descriptionText, 'ongoing migration', 1, itransaktions_old_id);
- SET tr_id = LAST_INSERT_ID();
- IF reason BETWEEN 25 AND 39 THEN
- INSERT INTO partners_earn_transactions
- (partner_id, `type`, `time`, points, customer_id, customer_balance_history_id, description)
- VALUES (3162, 20, updatedAt, delta, customerId, tr_id, descriptionText);
- END IF;
- SET sql_error = 0;
- END;
- COMMIT;
- IF sql_error = 1 THEN
- SET result_code = 1;
- ELSE
- SET result_code = 0;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_CUSTOMER_SEARCH` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_CUSTOMER_SEARCH`(
- IN ifirstname_ VARCHAR(255)
- ,IN ilastname_ VARCHAR(255)
- ,IN iemail_ VARCHAR(255)
- ,IN iaccount_number_ VARCHAR(255)
- ,IN iphone_ VARCHAR(255)
- ,IN istreet_ VARCHAR(255)
- ,IN izip_ VARCHAR(255)
- ,IN iregion_ VARCHAR(255)
- ,IN icountryid_ VARCHAR(255)
- ,IN sinceFrom_ DATETIME
- ,IN sinceTo_ DATETIME
- ,IN skipNum_ INT(10)
- ,IN getNum_ INT(10)
- )
- BEGIN
- DECLARE cFirst TINYINT(1) DEFAULT 0;
- DECLARE cSecond TINYINT(1) DEFAULT 0;
- DECLARE cThird TINYINT(1) DEFAULT 0;
- DECLARE cFourth TINYINT(1) DEFAULT 0;
- DECLARE ifirstname VARCHAR(255);
- DECLARE ilastname VARCHAR(255) ;
- DECLARE iemail VARCHAR(255);
- DECLARE iaccount_number VARCHAR(255);
- DECLARE iphone VARCHAR(255);
- DECLARE istreet VARCHAR(255);
- DECLARE izip VARCHAR(255);
- DECLARE iregion VARCHAR(255);
- DECLARE icountryid VARCHAR(255);
- DECLARE sinceFrom DATETIME;
- DECLARE sinceTo DATETIME;
- DECLARE skipNum INT(10);
- DECLARE getNum INT(10);
- IF ifirstname_ = '' THEN SET ifirstname = NULL; ELSE SET ifirstname = ifirstname_; END IF;
- IF ilastname_ = '' THEN SET ilastname = NULL; ELSE SET ilastname =ilastname_; END IF;
- IF iemail_ = '' THEN SET iemail = NULL; ELSE SET iemail = iemail_; END IF;
- IF iaccount_number_ = '' THEN SET iaccount_number = NULL; ELSE SET iaccount_number = iaccount_number_; END IF;
- IF iphone_ = '' THEN SET iphone = NULL; ELSE SET iphone = iphone_; END IF;
- IF istreet_ = '' THEN SET istreet = NULL; ELSE SET istreet = istreet_; END IF;
- IF izip_ = '' THEN SET izip = NULL; ELSE SET izip = izip_; END IF;
- IF iregion_ = '' THEN SET iregion = NULL; ELSE SET iregion = iregion_; END IF;
- IF icountryid_ = '' THEN SET icountryid = NULL; ELSE SET icountryid = icountryid_; END IF;
- IF sinceFrom_ = '0000-00-00 00:00:00' OR sinceFrom_ = '' THEN SET sinceFrom = NULL; ELSE SET sinceFrom = sinceFrom_; END IF;
- IF sinceTo_ = '0000-00-00 00:00:00' OR sinceTo_ = '' THEN SET sinceTo = NULL; ELSE SET sinceTo = sinceTo_; END IF;
- IF skipNum_ = '' OR skipNum_ IS NULL THEN SET skipNum = 0; ELSE SET skipNum = skipNum_; END IF;
- IF getNum_ = '' OR getNum_ IS NULL THEN SET getNum = 100; ELSE SET getNum = getNum_; END IF;
- IF ifirstname IS NOT NULL OR ilastname IS NOT NULL
- THEN SET cFirst = 1;
- END IF;
- IF iphone IS NOT NULL OR izip IS NOT NULL OR iregion IS NOT NULL OR icountryid IS NOT NULL
- THEN SET cSecond = 1;
- END IF;
- IF istreet IS NOT NULL
- THEN SET cThird = 1;
- END IF;
- IF sinceFrom IS NOT NULL OR sinceTo OR iemail IS NOT NULL OR iaccount_number IS NOT NULL
- THEN SET cFourth =1 ;
- END IF;
- DROP TEMPORARY TABLE IF EXISTS t_search_customers;
- SET @sql_INS = '
- create temporary table t_search_customers as
- SELECT ce.entity_id AS customer_id
- FROM customer_entity ce ';
- SET @sql_INS =CONCAT(@sql_INS
- ,CASE WHEN ifirstname IS NOT NULL THEN
- ' INNER JOIN customer_entity_varchar cev_firstname
- ON ce.entity_id = cev_firstname.entity_id AND cev_firstname.attribute_id = 5 '
- ELSE '' END
- ,CASE WHEN ilastname IS NOT NULL THEN
- ' INNER JOIN customer_entity_varchar cev_lastname
- ON ce.entity_id = cev_lastname.entity_id AND cev_lastname.attribute_id = 7 '
- ELSE '' END
- , CASE WHEN cSecond =1 OR cThird =1 THEN
- ' INNER join customer_address_entity ae ON ce.entity_id = ae.parent_id '
- ELSE '' END
- ,CASE WHEN iphone IS NOT NULL THEN
- ' INNER JOIN customer_mobile aev_phone ON ce.entity_id = aev_phone.customer_id '
- ELSE '' END
- ,CASE WHEN izip IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_varchar aev_zip ON ae.entity_id = aev_zip.entity_id AND aev_zip.attribute_id = 29 '
- ELSE '' END
- ,CASE WHEN iregion IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_varchar aev_region ON ae.entity_id = aev_region.entity_id AND aev_region.attribute_id = 27 '
- ELSE '' END
- ,CASE WHEN icountryid IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_varchar aev_countryid ON ae.entity_id = aev_countryid.entity_id AND aev_countryid.attribute_id = 26 '
- ELSE '' END
- ,CASE WHEN istreet IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_text aet_street ON ae.entity_id = aet_street.entity_id AND aet_street.attribute_id = 24 '
- ELSE '' END
- ,CASE WHEN cThird =1 THEN
- ' INNER JOIN customer_address_entity_text aet ON ae.entity_id = aet.entity_id '
- ELSE '' END
- ,' WHERE 1=1 '
- , CASE WHEN iemail IS NOT NULL
- THEN CONCAT(" AND (ce.email LIKE '",iemail,"%' ) ")
- ELSE '' END
- , CASE WHEN iaccount_number IS NOT NULL
- THEN CONCAT(" AND (ce.account_number LIKE '",iaccount_number,"%' )")
- ELSE '' END
- , CASE WHEN sinceFrom IS NOT NULL
- THEN CONCAT(" AND (ce.created_at >= date('",sinceFrom,"') )")
- ELSE '' END
- , CASE WHEN sinceTo IS NOT NULL
- THEN CONCAT(" AND (ce.created_at <= date('",sinceTo,"') )")
- ELSE '' END
- ,CASE WHEN ifirstname IS NOT NULL
- THEN CONCAT(" AND ( cev_firstname.`value` LIKE '",ifirstname,"%') ")
- ELSE '' END
- ,CASE WHEN ilastname IS NOT NULL
- THEN CONCAT(" AND ( cev_lastname.`value` LIKE '",ilastname,"%') ")
- ELSE '' END
- ,CASE WHEN iphone IS NOT NULL
- THEN CONCAT(" AND (aev_phone.`phone_number` LIKE '",iphone,"%') ")
- ELSE '' END
- ,CASE WHEN izip IS NOT NULL
- THEN CONCAT(" AND (aev_zip.`value` LIKE '",izip,"%') ")
- ELSE '' END
- ,CASE WHEN iregion IS NOT NULL
- THEN CONCAT(" AND (aev_region.`value` LIKE '",iregion,"%') ")
- ELSE '' END
- ,CASE WHEN icountryid IS NOT NULL
- THEN CONCAT(" AND (aev_countryid.`value` LIKE '",icountryid,"%') ")
- ELSE '' END
- ,CASE WHEN istreet IS NOT NULL
- THEN CONCAT(" AND (aet_street.`value` LIKE '",istreet,"%') ")
- ELSE '' END
- ,' LIMIT '
- ,skipNum
- ,','
- ,getNum
- ,';');
- PREPARE stmt FROM @sql_INS;
- EXECUTE stmt;
- SET @sql_INS ='
- SELECT
- a.entity_id AS customer_id
- , a.email
- , a.account_number
- , firstname.VALUE AS `first_name`
- , lastname.VALUE AS `last_name`
- , adr.phone AS `phone`
- , adr.street AS street
- , adr.zip AS zip
- , adr.region
- , adr.countryid
- FROM t_search_customers t
- INNER JOIN customer_entity a ON t.customer_id = a.entity_id
- left JOIN customer_entity_varchar AS firstname
- ON a.entity_id=firstname.entity_id AND firstname.attribute_id=5
- left JOIN customer_entity_varchar AS lastname
- ON a.entity_id=lastname.entity_id AND lastname.attribute_id=7
- inner join MG_V_customer_addresses adr on a.entity_id = adr.customer_id;
- ';
- PREPARE stmt FROM @sql_INS;
- EXECUTE stmt;
- DROP TABLE IF EXISTS t_search_customers;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_CUSTOMER_SEARCH_COUNT` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_CUSTOMER_SEARCH_COUNT`(
- IN ifirstname_ VARCHAR(255)
- ,IN ilastname_ VARCHAR(255)
- ,IN iemail_ VARCHAR(255)
- ,IN iaccount_number_ VARCHAR(255)
- ,IN iphone_ VARCHAR(255)
- ,IN istreet_ VARCHAR(255)
- ,IN izip_ VARCHAR(255)
- ,IN iregion_ VARCHAR(255)
- ,IN icountryid_ VARCHAR(255)
- ,IN sinceFrom_ DATETIME
- ,IN sinceTo_ DATETIME
- )
- BEGIN
- DECLARE cFirst TINYINT(1) DEFAULT 0;
- DECLARE cSecond TINYINT(1) DEFAULT 0;
- DECLARE cThird TINYINT(1) DEFAULT 0;
- DECLARE cFourth TINYINT(1) DEFAULT 0;
- DECLARE ifirstname VARCHAR(255);
- DECLARE ilastname VARCHAR(255) ;
- DECLARE iemail VARCHAR(255);
- DECLARE iaccount_number VARCHAR(255);
- DECLARE iphone VARCHAR(255);
- DECLARE istreet VARCHAR(255);
- DECLARE izip VARCHAR(255);
- DECLARE iregion VARCHAR(255);
- DECLARE icountryid VARCHAR(255);
- DECLARE sinceFrom DATETIME;
- DECLARE sinceTo DATETIME;
- IF ifirstname_ = '' THEN SET ifirstname = NULL; ELSE SET ifirstname = ifirstname_; END IF;
- IF ilastname_ = '' THEN SET ilastname = NULL; ELSE SET ilastname =ilastname_; END IF;
- IF iemail_ = '' THEN SET iemail = NULL; ELSE SET iemail = iemail_; END IF;
- IF iaccount_number_ = '' THEN SET iaccount_number = NULL; ELSE SET iaccount_number = iaccount_number_; END IF;
- IF iphone_ = '' THEN SET iphone = NULL; ELSE SET iphone = iphone_; END IF;
- IF istreet_ = '' THEN SET istreet = NULL; ELSE SET istreet = istreet_; END IF;
- IF izip_ = '' THEN SET izip = NULL; ELSE SET izip = izip_; END IF;
- IF iregion_ = '' THEN SET iregion = NULL; ELSE SET iregion = iregion_; END IF;
- IF icountryid_ = '' THEN SET icountryid = NULL; ELSE SET icountryid = icountryid_; END IF;
- IF sinceFrom_ = '0000-00-00 00:00:00' OR sinceFrom_ = '' THEN SET sinceFrom = NULL; ELSE SET sinceFrom = sinceFrom_; END IF;
- IF sinceTo_ = '0000-00-00 00:00:00' OR sinceTo_ = '' THEN SET sinceTo = NULL; ELSE SET sinceTo = sinceTo_; END IF;
- IF ifirstname IS NOT NULL OR ilastname IS NOT NULL
- THEN SET cFirst = 1;
- END IF;
- IF iphone IS NOT NULL OR izip IS NOT NULL OR iregion IS NOT NULL OR icountryid IS NOT NULL
- THEN SET cSecond = 1;
- END IF;
- IF istreet IS NOT NULL
- THEN SET cThird = 1;
- END IF;
- IF sinceFrom IS NOT NULL OR sinceTo OR iemail IS NOT NULL OR iaccount_number IS NOT NULL
- THEN SET cFourth =1 ;
- END IF;
- SET @sql_INS = '
- SELECT count(ce.entity_id) AS customer_count
- FROM customer_entity ce ';
- SET @sql_INS =CONCAT(@sql_INS
- ,CASE WHEN ifirstname IS NOT NULL THEN
- ' INNER JOIN customer_entity_varchar cev_firstname
- ON ce.entity_id = cev_firstname.entity_id AND cev_firstname.attribute_id = 5 '
- ELSE '' END
- ,CASE WHEN ilastname IS NOT NULL THEN
- ' INNER JOIN customer_entity_varchar cev_lastname
- ON ce.entity_id = cev_lastname.entity_id AND cev_lastname.attribute_id = 7 '
- ELSE '' END
- , CASE WHEN cSecond =1 OR cThird =1 THEN
- ' INNER join customer_address_entity ae ON ce.entity_id = ae.parent_id '
- ELSE '' END
- ,CASE WHEN iphone IS NOT NULL THEN
- ' INNER JOIN customer_mobile aev_phone ON ce.entity_id = aev_phone.customer_id '
- ELSE '' END
- ,CASE WHEN izip IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_varchar aev_zip ON ae.entity_id = aev_zip.entity_id AND aev_zip.attribute_id = 29 '
- ELSE '' END
- ,CASE WHEN iregion IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_varchar aev_region ON ae.entity_id = aev_region.entity_id AND aev_region.attribute_id = 27 '
- ELSE '' END
- ,CASE WHEN icountryid IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_varchar aev_countryid ON ae.entity_id = aev_countryid.entity_id AND aev_countryid.attribute_id = 26 '
- ELSE '' END
- ,CASE WHEN istreet IS NOT NULL THEN
- ' INNER JOIN customer_address_entity_text aet_street ON ae.entity_id = aet_street.entity_id AND aet_street.attribute_id = 24 '
- ELSE '' END
- ,CASE WHEN cThird =1 THEN
- ' INNER JOIN customer_address_entity_text aet ON ae.entity_id = aet.entity_id '
- ELSE '' END
- ,' WHERE 1=1 '
- , CASE WHEN iemail IS NOT NULL
- THEN CONCAT(" AND (ce.email LIKE '",iemail,"%' ) ")
- ELSE '' END
- , CASE WHEN iaccount_number IS NOT NULL
- THEN CONCAT(" AND (ce.account_number LIKE '",iaccount_number,"%' )")
- ELSE '' END
- , CASE WHEN sinceFrom IS NOT NULL
- THEN CONCAT(" AND (ce.created_at >= date('",sinceFrom,"') )")
- ELSE '' END
- , CASE WHEN sinceTo IS NOT NULL
- THEN CONCAT(" AND (ce.created_at <= date('",sinceTo,"') )")
- ELSE '' END
- ,CASE WHEN ifirstname IS NOT NULL
- THEN CONCAT(" AND ( cev_firstname.`value` LIKE '",ifirstname,"%') ")
- ELSE '' END
- ,CASE WHEN ilastname IS NOT NULL
- THEN CONCAT(" AND ( cev_lastname.`value` LIKE '",ilastname,"%') ")
- ELSE '' END
- ,CASE WHEN iphone IS NOT NULL
- THEN CONCAT(" AND (aev_phone.`phone_number` LIKE '",iphone,"%') ")
- ELSE '' END
- ,CASE WHEN izip IS NOT NULL
- THEN CONCAT(" AND (aev_zip.`value` LIKE '",izip,"%') ")
- ELSE '' END
- ,CASE WHEN iregion IS NOT NULL
- THEN CONCAT(" AND (aev_region.`value` LIKE '",iregion,"%') ")
- ELSE '' END
- ,CASE WHEN icountryid IS NOT NULL
- THEN CONCAT(" AND (aev_countryid.`value` LIKE '",icountryid,"%') ")
- ELSE '' END
- ,CASE WHEN istreet IS NOT NULL
- THEN CONCAT(" AND (aet_street.`value` LIKE '",istreet,"%') ")
- ELSE '' END
- ,';');
- PREPARE stmt FROM @sql_INS;
- EXECUTE stmt;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_GET_ACTIVITIES_BY_ZIP` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_GET_ACTIVITIES_BY_ZIP`(IN inp_zip VARCHAR(255),IN inp_store_id SMALLINT(5))
- BEGIN
- DECLARE inp_dist INT(10);
- DECLARE count_returned TINYINT(3);
- DECLARE time_range INT(10);
- SET inp_dist = 30 ;
- SET count_returned =30;
- SET time_range = 14400 ; -- 4H
- -- SET time_range = 28800 ; -- 8H
- SELECT TIME(NOW()) INTO @now_time ;
- SELECT 0 INTO @count_all_rows;
- DROP TABLE IF EXISTS temp_zip_distance;
- CREATE TEMPORARY TABLE temp_zip_distance (
- `id` INT(10),
- `store_id` SMALLINT(5) UNSIGNED DEFAULT NULL,
- `type_id` TINYINT(2) DEFAULT NULL,
- `customer_id` INT(10) UNSIGNED NOT NULL,
- product_id INT(10),
- `longitude` FLOAT,
- `latitude` FLOAT,
- `content` TEXT DEFAULT NULL,
- `updated_at` DATETIME NOT NULL,
- time_dff INT(10)
- ) ;
- IF TRIM(IFNULL(inp_zip,0)) <> '' THEN
- INSERT INTO temp_zip_distance
- SELECT SQL_CALC_FOUND_ROWS
- k.id
- ,k.store_id
- ,CASE
- WHEN k.type_id =1 THEN 1
- WHEN k.type_id =2 THEN 2
- WHEN k.type_id =3 THEN 3
- WHEN k.type_id =4 THEN 4
- WHEN k.type_id =5 THEN 5
- END AS type_id
- ,k.customer_id
- ,k.product_id
- ,k.longitude
- ,k.latitude
- ,k.content
- ,k.updated_at
- ,k.time_dff
- FROM
- (SELECT ra.id,ra.store_id,ra.type_id,ra.customer_id,ra.content,ra.product_id,ra.updated_at, tl.zip ,ra.longitude AS longitude , ra.latitude AS latitude,TIME_TO_SEC(TIMEDIFF( @now_time ,TIME(ra.updated_at)) ) AS time_dff
- , ((( ACOS(SIN(((tl.latitude *PI())/180)) * SIN((ra.`latitude`*PI()/180))
- + COS(((tl.latitude * PI())/180)) * COS((ra.`latitude`*PI()/180)) * COS((((tl.longitude-ra.`longitude`)*PI())/180))))*180/PI())*60*1.1515
- ) AS distance
- FROM `customers_activities` ra INNER JOIN (SELECT zip,longitude ,latitude FROM zip_geo WHERE zip = inp_zip) tl
- ) k
- WHERE distance <= inp_dist
- AND ABS(time_dff) <= time_range
- ORDER BY id DESC ;
- SELECT FOUND_ROWS() INTO @count_all_rows;
- END IF;
- IF @count_all_rows = 0 THEN
- INSERT INTO temp_zip_distance
- SELECT SQL_CALC_FOUND_ROWS
- k.id
- ,k.store_id
- ,CASE
- WHEN k.type_id =1 THEN 1
- WHEN k.type_id =2 THEN 2
- WHEN k.type_id =3 THEN 3
- WHEN k.type_id =4 THEN 4
- WHEN k.type_id =5 THEN 5
- END AS type_id
- ,k.customer_id
- ,k.product_id
- ,k.longitude
- ,k.latitude
- ,k.content
- ,k.updated_at
- ,TIME_TO_SEC(TIMEDIFF( @now_time ,TIME(k.updated_at)) ) time_dff
- FROM `customers_activities` k
- WHERE
- k.store_id = inp_store_id
- AND ABS(TIME_TO_SEC(TIMEDIFF( @now_time ,TIME(k.updated_at)) )) <= time_range
- ORDER BY id DESC ;
- SELECT FOUND_ROWS() INTO @count_all_rows;
- END IF;
- DROP TABLE IF EXISTS temp_30_customers_activities ;
- CREATE TEMPORARY TABLE temp_30_customers_activities (
- `id` INT(10),
- `store_id` SMALLINT(5) UNSIGNED DEFAULT NULL,
- `type_id` TINYINT(2) DEFAULT NULL,
- `customer_id` INT(10) UNSIGNED NOT NULL,
- `longitude` FLOAT,
- `latitude` FLOAT,
- `content` TEXT DEFAULT NULL,
- `updated_at` DATETIME NOT NULL,
- `cnt_in_result` INT(10),
- time_dff INT(10)
- ) ;
- IF @count_all_rows >0 THEN
- DROP TABLE IF EXISTS temp_type_count;
- CREATE TEMPORARY TABLE temp_type_count
- AS
- SELECT type_id
- ,COUNT(1) cnt
- ,CASE WHEN ROUND(( COUNT(1)/@count_all_rows )*count_returned) >=1 THEN ROUND(( COUNT(1)/@count_all_rows )*count_returned)
- WHEN ROUND(( COUNT(1)/@count_all_rows )*count_returned) >0 THEN 1
- ELSE 0 END
- AS w
- FROM temp_zip_distance
- GROUP BY type_id;
- SET @i =1 ;
- WHILE @i <=4 DO
- SET @sql_ = CONCAT('SELECT round(w) into @cnt_a FROM temp_type_count WHERE type_id =',@i);
- PREPARE stmt FROM @sql_;
- EXECUTE stmt;
- DEALLOCATE PREPARE stmt;
- SET @cnt_limit = @cnt_a;
- IF @cnt_limit IS NOT NULL THEN
- SET @sql_ =
- CONCAT('insert into temp_30_customers_activities
- SELECT `id`,`store_id`,`type_id`,`customer_id`,`longitude`,`latitude`,`content`,`updated_at`,',@cnt_a,',time_dff
- FROM temp_zip_distance
- WHERE type_id = ',@i,' ORDER BY id desc limit ',@cnt_a
- );
- PREPARE stmt FROM @sql_;
- EXECUTE stmt;
- DEALLOCATE PREPARE stmt;
- END IF;
- SET @i = @i +1 ;
- END WHILE;
- END IF;
- SELECT
- id,
- type_id,
- content
- FROM temp_30_customers_activities
- ORDER BY cnt_in_result DESC ,type_id LIMIT 30;
- DROP TABLE IF EXISTS temp_result_customers_activities ;
- DROP TABLE IF EXISTS temp_zip_distance;
- DROP TABLE IF EXISTS temp_type_count;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_GET_MONTH_TRANSACTIONS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MG_GET_MONTH_TRANSACTIONS`(IN `custId` int(11))
- BEGIN
- DECLARE datetime_criteria DATETIME DEFAULT DATE_SUB(NOW(), INTERVAL 1 MONTH);
- DECLARE month_criteria INT DEFAULT MONTH(datetime_criteria);
- DECLARE year_criteria INT DEFAULT YEAR(datetime_criteria);
- DROP TEMPORARY TABLE IF EXISTS gconomy_month_transactions;
- CREATE TEMPORARY TABLE gconomy_month_transactions
- SELECT
- cbh.balance_id,
- cbh.reason_id,
- cbh.balance_delta,
- CASE cbh.reason_id
- WHEN 25 THEN 'Points from Purchases'
- WHEN 26 THEN 'Bonus Points from Reward Partners'
- WHEN 27 THEN 'Bonus Points from Promotions'
- WHEN 28 THEN 'First Purchase bonus'
- WHEN 29 THEN 'Adjustments'
- ELSE 'Bonus Points'
- END AS 'reason'
- FROM enterprise_customerbalance_history cbh
- WHERE
- cbh.reason_id BETWEEN 25 AND 39
- AND year_criteria = YEAR(cbh.updated_at)
- AND month_criteria = MONTH(cbh.updated_at);
- ALTER TABLE gconomy_month_transactions ADD INDEX ix_balance_id(balance_id);
- SELECT
- ce.entity_id AS 'cust_id',
- ce.store_id AS 'store_id',
- ce.email AS 'email',
- cev_fn.value AS 'first_name',
- gmt.reason AS 'reason',
- sum(gmt.balance_delta) AS 'points',
- max(gmt.reason_id) AS 'order_id'
- FROM customer_entity ce
- INNER JOIN enterprise_customerbalance cb ON ce.entity_id = cb.customer_id
- INNER JOIN gconomy_month_transactions gmt ON cb.balance_id = gmt.balance_id
- LEFT OUTER JOIN customer_entity_varchar cev_fn ON cev_fn.entity_id = ce.entity_id AND cev_fn.attribute_id = 5
- LEFT OUTER JOIN customer_entity_varchar cev_confirm ON cev_confirm.entity_id = ce.entity_id AND cev_confirm.attribute_id = 16
- WHERE
- CASE
- WHEN custId IS NOT null
- THEN ce.entity_id > custId
- ELSE 1=1
- END
- AND cev_confirm.value_id IS NULL
- AND TRIM(ce.email) <> ''
- GROUP BY ce.entity_id, gmt.reason
- ORDER BY ce.entity_id, order_id;
- DROP TEMPORARY TABLE gconomy_month_transactions;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_GET_PRODUCT_MOST_USED` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`magento`@`%`*/ /*!50003 PROCEDURE `MG_GET_PRODUCT_MOST_USED`()
- BEGIN
- DROP TABLE if exists catalog_product_entity_most_used;
- CREATE TABLE catalog_product_entity_most_used(
- product_id INT ,
- orders INT,
- PRIMARY KEY (product_id)
- );
- INSERT INTO catalog_product_entity_most_used (product_id, orders)
- SELECT `sfoi`.`product_id`,
- COUNT(order_id) AS `orders`
- FROM `sales_flat_order_item` AS `sfoi`
- WHERE `sfoi`.`product_id` IS NOT NULL
- AND (DATEDIFF(CURDATE(), sfoi.`created_at`) < 7)
- GROUP BY `product_id`;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_GET_ZIP_MOST_USED` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`magento`@`%`*/ /*!50003 PROCEDURE `MG_GET_ZIP_MOST_USED`()
- BEGIN
- SELECT date( date_sub( date(now()), interval 90 DAY)),date(now()) INTO @start_date,@end_date;
- DROP TABLE if exists temp_login_id ;
- CREATE TEMPORARY table temp_login_id
- as
- SELECT distinct customer_id FROM log_customer lc
- WHERE date(lc.login_at) BETWEEN @start_date AND @end_date ;
- DROP TABLE if exists zip_most_used;
- CREATE TABLE zip_most_used
- as
- SELECT zip_code.value,count(ce.entity_id) as cnt_customers
- FROM customer_entity ce
- INNER JOIN customer_address_entity cae ON cae.parent_id = ce.entity_id
- INNER JOIN customer_address_entity_varchar zip_code
- ON zip_code.entity_id =cae.entity_id AND zip_code.attribute_id = 29
- INNER JOIN temp_login_id lc ON lc.customer_id = ce.entity_id
- WHERE trim(zip_code.value)<>''
- GROUP BY zip_code.value
- ORDER by cnt_customers desc limit 5000;
- drop table if exists temp_login_id ;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_catalog_product` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_catalog_product`()
- BEGIN
- declare newValue int(10);
- set @entity_type_id = 4;
- truncate table curbside_subscription;
- truncate table curbside_addresses;
- truncate table earns_customers_partners;
- truncate table earns_customers;
- truncate table online_products_line_items;
- truncate table online_products_codes;
- truncate table online_products_deliveries;
- truncate table pah_coupons_printing_offers;
- truncate table pah_coupons_printings;
- truncate table pah_coupons_ci_analytics;
- truncate table pah_coupons_history;
- truncate table pah_coupons;
- truncate table pah_coupons_offers;
- truncate table sales_flat_order_item;
- truncate table sales_flat_order;
- TRUNCATE TABLE catalog_product_entity_media_gallery;
- TRUNCATE TABLE partners_local_rewards_stores;
- delete from catalog_product_entity;
- set newValue = 1;
- select ifnull((max(entity_id) + 1), 1) into newValue from catalog_product_entity;
- set @qwr = concat('ALTER TABLE catalog_product_entity auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- ALTER TABLE catalog_product_entity_datetime auto_increment =1;
- ALTER TABLE catalog_product_entity_decimal auto_increment =1;
- ALTER TABLE catalog_product_entity_int auto_increment =1;
- ALTER TABLE catalog_product_entity_text auto_increment =1;
- ALTER TABLE catalog_product_entity_varchar auto_increment =1;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'catalog_product_entity'
- and column_name = 'partner_id') then
- alter table catalog_product_entity add column (partner_id int(10) unsigned null);
- end if;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'catalog_product_entity'
- and column_name = 'barcode_url') then
- alter table catalog_product_entity add column (barcode_url varchar(255) null);
- end if;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'catalog_product_entity'
- and column_name = 'has_barcode') then
- alter table catalog_product_entity add column (has_barcode tinyint(1) null);
- end if;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'catalog_product_entity'
- and column_name = 'reward_old_id') then
- alter table catalog_product_entity add column (reward_old_id int(11) null);
- end if;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'catalog_product_entity'
- and column_name = 'is_uk') then
- alter table catalog_product_entity add column (is_uk tinyint(1) null default 0);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'catalog_product_entity'
- and index_name = 'IDX_catalog_product_entity_reward_old_id') then
- alter table catalog_product_entity add
- KEY `IDX_catalog_product_entity_reward_old_id` (`reward_old_id`);
- end if;
- insert into catalog_product_entity
- (
- entity_type_id,
- attribute_set_id,
- type_id,
- sku,
- has_options,
- required_options,
- created_at,
- updated_at,
- partner_id,
- reward_old_id,
- is_uk
- )
- select @entity_type_id as 'entity_type_id',
- (select attribute_set_id from eav_attribute_set where attribute_set_name collate utf8_general_ci = et.attribute_set collate utf8_general_ci and entity_type_id = @entity_type_id) as 'attribute_set_id',
- et.type as 'type_id',
- et.sku as 'sku',
- 0 as 'has_options',
- 0 as 'required_options',
- now() as 'created_at',
- now() as 'updated_at',
- l.new_id,
- et.reward_id,
- et.store_id
- from tload_reward_export et
- left join catalog_product_entity ce on et.reward_id = ce.reward_old_id
- left join tload_partners_entity_map_id l on et.partner_id = l.old_id
- and case when et.reward_id > 9999990 then l.source_table in (2,6,7)
- else l.source_table in (1,3,8) end
- where ce.entity_id is null;
- set @attribute_name = '';
- WHILE EXISTS (select column_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_reward_export'
- and column_name > @attribute_name
- and column_name not in ('attribute_set', 'partner_id', 'type', 'is_in_stock', 'low_stock_date', 'manage_stock', 'stock_id', 'stock_status_changed_automatically', 'use_config_manage_stock', 'use_config_max_sale_qty', 'use_config_min_sale_qty', 'use_config_notify_stock_qty', 'store_id')) DO
- select column_name into @attribute_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_reward_export'
- and column_name > @attribute_name
- and column_name not in ('attribute_set', 'partner_id', 'type', 'is_in_stock', 'low_stock_date', 'manage_stock', 'stock_id', 'stock_status_changed_automatically', 'use_config_manage_stock', 'use_config_max_sale_qty', 'use_config_min_sale_qty', 'use_config_notify_stock_qty', 'store_id')
- order by column_name asc
- limit 1;
- set @attribute_id = 0;
- set @backend_type = '';
- select attribute_id, backend_type into @attribute_id, @backend_type from eav_attribute
- where entity_type_id = @entity_type_id
- and attribute_code = @attribute_name;
- if (@backend_type = 'datetime') then
- set @qwr = concat('insert into catalog_product_entity_datetime
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select @entity_type_id,
- ', @attribute_id,',
- 0,
- e.entity_id,
- tl.',@attribute_name,'
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'decimal') then
- set @qwr = concat('insert into catalog_product_entity_decimal
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select @entity_type_id,
- ', @attribute_id,',
- 0,
- e.entity_id,
- tl.',@attribute_name,'
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'int') then
- set @qwr = concat('insert into catalog_product_entity_int
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select @entity_type_id,
- ', @attribute_id,',
- 0,
- e.entity_id,
- tl.',@attribute_name,'
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'text') then
- set @qwr = concat('insert into catalog_product_entity_text
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select @entity_type_id,
- ', @attribute_id,',
- 0,
- e.entity_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'varchar') then
- set @qwr = concat('insert into catalog_product_entity_varchar
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select @entity_type_id,
- ', @attribute_id,',
- 0,
- e.entity_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@attribute_name = 'website_id') then
- INSERT INTO `catalog_product_website` (`product_id`, `website_id`)
- select e.entity_id, tl.website_id
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- left join catalog_product_website w on e.entity_id = w.product_id
- and tl.website_id = w.website_id
- where w.product_id is null;
- end if;
- if (@attribute_name = 'qty') then
- DELETE c
- FROM `catalog_product_entity_tier_price` as c
- inner join catalog_product_entity e on c.entity_id = e.entity_id
- inner join tload_reward_export tl on tl.reward_id = e.reward_old_id;
- INSERT INTO `cataloginventory_stock_item` (`product_id`, `stock_id`, `qty`, `use_config_min_sale_qty`, `use_config_max_sale_qty`, `is_in_stock`, `use_config_notify_stock_qty`, `manage_stock`, `use_config_manage_stock`, `stock_status_changed_automatically`)
- select e.entity_id, tl.stock_id, tl.qty, tl.use_config_min_sale_qty, tl.use_config_max_sale_qty, tl.is_in_stock, tl.use_config_notify_stock_qty, tl.manage_stock, tl.use_config_manage_stock, tl.stock_status_changed_automatically
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE
- `qty`=VALUES(`qty`),
- `use_config_min_sale_qty`=VALUES(`use_config_min_sale_qty`),
- `use_config_max_sale_qty`=VALUES(`use_config_max_sale_qty`),
- `is_in_stock`=VALUES(`is_in_stock`),
- `use_config_notify_stock_qty`=VALUES(`use_config_notify_stock_qty`),
- `manage_stock`=VALUES(`manage_stock`),
- `use_config_manage_stock`=VALUES(`use_config_manage_stock`),
- `stock_status_changed_automatically`=VALUES(`stock_status_changed_automatically`);
- INSERT INTO `cataloginventory_stock_status` (`product_id`, `website_id`, `stock_id`, `qty`, `stock_status`)
- select e.entity_id, tl.website_id, tl.stock_id, tl.qty, 1
- from tload_reward_export tl
- inner join catalog_product_entity e on tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE `qty`=VALUES(`qty`), `stock_status`=VALUES(`stock_status`);
- end if;
- END WHILE;
- INSERT INTO partners_local_rewards_stores (product_id,store_id)
- SELECT cpe.entity_id,pra.id FROM partners_reward_address pra
- INNER JOIN catalog_product_entity cpe on pra.partner_id = cpe.partner_id;
- INSERT INTO catalog_product_entity_media_gallery (attribute_id, entity_id, VALUE)
- SELECT 77, e.entity_id, tl.image
- FROM tload_reward_export tl
- INNER JOIN catalog_product_entity e ON tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE `value`=VALUES(`value`);
- INSERT INTO catalog_product_entity_media_gallery (attribute_id, entity_id, VALUE)
- SELECT 77, e.entity_id, tl.small_image
- FROM tload_reward_export tl
- INNER JOIN catalog_product_entity e ON tl.reward_id = e.reward_old_id
- ON DUPLICATE KEY UPDATE `value`=VALUES(`value`);
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_catalog_product_category` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_catalog_product_category`()
- BEGIN
- declare newValue int(10);
- set @delete_count = 0;
- select count(*) into @delete_count from catalog_category_entity
- where path = 'new';
- delete from catalog_category_entity
- where path = 'new';
- set @entity_type_id = 3;
- set @attribute_id_name = 33;
- select attribute_set_id into @attribute_set_id from eav_attribute_set where attribute_set_name = 'Default' and entity_type_id = @entity_type_id;
- set @children_count = 0;
- select count(*) into @children_count from tload_reward_category_export;
- set @entity_id = 0;
- select entity_id into @entity_id from `catalog_category_entity_varchar`
- where attribute_id = @attribute_id_name
- and value = 'Rewards';
- select path, `level` into @path, @level_ from `catalog_category_entity`
- where entity_id = @entity_id;
- select (count(*) + @delete_count) into @delete_count from `catalog_category_entity` e
- inner join `catalog_category_entity_varchar` ev on e.entity_id = ev.entity_id
- where ev.attribute_id = @attribute_id_name
- and e.path like concat(@path, '%')
- and e.entity_id not in (@entity_id, 204, 206, 213, 214, 215, 216)
- and value not like '\_%';
- delete e from `catalog_category_entity` e
- inner join `catalog_category_entity_varchar` ev on e.entity_id = ev.entity_id
- where ev.attribute_id = @attribute_id_name
- and e.path like concat(@path, '%')
- and e.entity_id not in (@entity_id, 204, 206, 213, 214, 215, 216)
- and value not like '\_%';
- while (@entity_id <> 0) do
- select parent_id into @parent_id from `catalog_category_entity`
- where entity_id = @entity_id;
- UPDATE `catalog_category_entity` SET `children_count` = `children_count` - @delete_count + @children_count
- WHERE entity_id = @entity_id;
- set @entity_id = @parent_id;
- end while;
- set @parent_id = 0;
- select entity_id into @parent_id from `catalog_category_entity_varchar`
- where attribute_id = @attribute_id_name
- and value = 'Rewards';
- set newValue = 1;
- select ifnull((max(entity_id) + 1), 1) into newValue from catalog_category_entity;
- set @qwr = concat('ALTER TABLE catalog_category_entity auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- set @qwr = concat('ALTER TABLE catalog_category_entity_datetime auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- set @qwr = concat('ALTER TABLE catalog_category_entity_decimal auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- set @qwr = concat('ALTER TABLE catalog_category_entity_int auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- set @qwr = concat('ALTER TABLE catalog_category_entity_text auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- set @qwr = concat('ALTER TABLE catalog_category_entity_varchar auto_increment = ', newValue, ';');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- INSERT INTO `catalog_category_entity` (`path`, `attribute_set_id`, `entity_type_id`, `created_at`, `updated_at`, `position`, `level`, `parent_id`)
- select concat('new'), @attribute_set_id, @entity_type_id, now(), now(), external_id, (@level_ + 1), @parent_id
- from tload_reward_category_export
- order by external_id asc;
- set @attribute_name = '';
- WHILE EXISTS (select column_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_reward_category_export'
- and column_name > @attribute_name
- and column_name not in ('attribute_set', 'partner_id', 'type', 'is_in_stock', 'low_stock_date', 'manage_stock', 'stock_id', 'stock_status_changed_automatically', 'use_config_manage_stock', 'use_config_max_sale_qty', 'use_config_min_sale_qty', 'use_config_notify_stock_qty')) DO
- select column_name into @attribute_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_reward_category_export'
- and column_name > @attribute_name
- and column_name not in ('attribute_set', 'partner_id', 'type', 'is_in_stock', 'low_stock_date', 'manage_stock', 'stock_id', 'stock_status_changed_automatically', 'use_config_manage_stock', 'use_config_max_sale_qty', 'use_config_min_sale_qty', 'use_config_notify_stock_qty')
- order by column_name asc
- limit 1;
- set @attribute_id = 0;
- set @backend_type = '';
- select attribute_id, backend_type into @attribute_id, @backend_type from eav_attribute
- where entity_type_id = @entity_type_id
- and attribute_code = @attribute_name;
- if (@backend_type = 'datetime') then
- set @qwr = concat('insert into catalog_category_entity_datetime
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- 0,
- e.entity_id,
- tl.',@attribute_name,'
- from tload_reward_category_export tl
- inner join catalog_category_entity e on tl.external_id = e.position and e.path = ''new''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'decimal') then
- set @qwr = concat('insert into catalog_category_entity_decimal
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- 0,
- e.entity_id,
- tl.',@attribute_name,'
- from tload_reward_category_export tl
- inner join catalog_category_entity e on tl.external_id = e.position and e.path = ''new''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'int') then
- set @qwr = concat('insert into catalog_category_entity_int
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- 0,
- e.entity_id,
- tl.',@attribute_name,'
- from tload_reward_category_export tl
- inner join catalog_category_entity e on tl.external_id = e.position and e.path = ''new''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'text') then
- set @qwr = concat('insert into catalog_category_entity_text
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- 0,
- e.entity_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_reward_category_export tl
- inner join catalog_category_entity e on tl.external_id = e.position and e.path = ''new''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'varchar') then
- set @qwr = concat('insert into catalog_category_entity_varchar
- (entity_type_id,
- attribute_id,
- store_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- 0,
- e.entity_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_reward_category_export tl
- inner join catalog_category_entity e on tl.external_id = e.position and e.path = ''new''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- END WHILE;
- INSERT INTO `catalog_category_product` (`category_id`,`product_id`,`position`)
- select e.entity_id, pe.entity_id, 0
- from catalog_category_entity e
- inner join tload_reward_category_link_export cl on e.position = cl.category_id_new
- inner join catalog_product_entity pe on cl.reward_id = pe.reward_old_id
- where
- e.path = 'new'
- and cl.category_id_new <> 17;
- UPDATE `catalog_category_entity` SET `path` = concat(@path, '/', entity_id) WHERE path = 'new';
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_curbside_subscr` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_curbside_subscr`()
- BEGIN
- truncate table curbside_subscription ;
- truncate table curbside_addresses ;
- if not exists (select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
- WHERE table_schema = DATABASE()
- and table_name = 'curbside_subscription'
- and constraint_name = 'FK_CURBSIDE_SUBSCR_EARN_ID') then
- alter table curbside_subscription add CONSTRAINT FK_CURBSIDE_SUBSCR_EARN_ID FOREIGN KEY(earn_id)
- REFERENCES `earns_customers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
- end if;
- if not exists (select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
- WHERE table_schema = DATABASE()
- and table_name = 'curbside_subscription'
- and constraint_name = 'FK_CURBSIDE_SUBSCR_CUSTOMER_ID') then
- alter table curbside_subscription add CONSTRAINT FK_CURBSIDE_SUBSCR_CUSTOMER_ID FOREIGN KEY(customer_id)
- REFERENCES `customer_entity` (`entity_id`) ON DELETE SET NULL ON UPDATE CASCADE;
- end if;
- if not exists (select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
- WHERE table_schema = DATABASE()
- and table_name = 'curbside_addresses'
- and constraint_name = 'FK_CURBSIDE_ADDR_CUSTOMER_ID') then
- alter table curbside_addresses add CONSTRAINT FK_CURBSIDE_ADDR_CUSTOMER_ID FOREIGN KEY(customer_id)
- REFERENCES `customer_entity` (`entity_id`) ON DELETE SET NULL ON UPDATE CASCADE;
- end if;
- INSERT INTO curbside_addresses
- (id,customer_id,`location_id`,zip,city,state,address,suite,verified_at)
- SELECT id,null as customer_id,location_id,zip,city,state,address,suite,verified_at
- FROM tload_curbside_addresses ;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'tload_curbside_subscription'
- and index_name = 'ix_tload_curbside_subscription_customer_id') then
- alter table tload_curbside_subscription add index ix_tload_curbside_subscription_customer_id (customer_id);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'tload_curbside_addresses'
- and index_name = 'ix_tload_curbside_addresses_sid') then
- alter table tload_curbside_addresses add index ix_tload_curbside_addresses_sid (old_subscription_id);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'tload_curbside_subscription'
- and index_name = 'ix_tload_curbside_subscription_sid') then
- alter table tload_curbside_subscription add index ix_tload_curbside_subscription_sid (old_subscription_id);
- end if;
- INSERT INTO curbside_subscription
- (subscription_id,earn_id,customer_id,curbside_address_id,activation_code_id,is_self_reporting,created_at,start_date,end_date)
- SELECT distinct subscription_id,earn_id,null as customer_id,tca.id,null as activation_code_id,is_self_reporting,created_at,start_date,end_date
- FROM tload_curbside_subscription tcs
- INNER JOIN tload_curbside_addresses tca on tcs.old_subscription_id = tca.old_subscription_id ;
- UPDATE curbside_subscription cs
- INNER JOIN tload_curbside_subscription tcs on cs.subscription_id=tcs.subscription_id
- INNER JOIN customer_entity ce on ce.account_old_id = tcs.customer_id
- SET cs.customer_id = ce.entity_id;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'tload_curbside_addresses'
- and index_name = 'ix_tload_curbside_addresses_customer_id') then
- alter table tload_curbside_addresses add index ix_tload_curbside_addresses_customer_id (customer_id);
- end if;
- UPDATE curbside_addresses ca
- INNER JOIN tload_curbside_addresses tca on ca.id=tca.id
- INNER JOIN customer_entity ce on ce.account_old_id =tca.customer_id
- SET ca.customer_id = ce.entity_id;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_customer` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_customer`()
- BEGIN
- declare newValue int(10);
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'customer_entity'
- and column_name = 'account_old_id') then
- alter table customer_entity add column (account_old_id int(11) null);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'customer_entity'
- and index_name = 'IDX_catalog_product_entity_account_old_id') then
- alter table customer_entity add KEY IDX_catalog_product_entity_account_old_id (account_old_id);
- end if;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'tload_contact_export'
- and column_name = 'contact_new_id') then
- alter table tload_contact_export add column (contact_new_id int(11) null);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'customer_entity'
- and index_name = 'IDX_tload_contact_export_contact_new_id') then
- alter table tload_contact_export add KEY IDX_tload_contact_export_contact_new_id (contact_new_id);
- end if;
- truncate table online_products_line_items;
- truncate table online_products_codes;
- truncate table online_products_deliveries;
- truncate table pah_coupons_printing_offers;
- truncate table pah_coupons_printings;
- truncate table pah_coupons_ci_analytics;
- truncate table pah_coupons_history;
- truncate table pah_coupons;
- truncate table pah_coupons_offers;
- truncate table customer_mobile;
- truncate table customer_entity_datetime;
- truncate table customer_entity_decimal;
- truncate table customer_entity_int;
- truncate table customer_entity_text;
- truncate table customer_entity_varchar;
- truncate table customer_address_entity_datetime;
- truncate table customer_address_entity_decimal;
- truncate table customer_address_entity_int;
- truncate table customer_address_entity_text;
- truncate table customer_address_entity_varchar;
- truncate table customer_address_entity;
- truncate table enterprise_customerbalance_history;
- truncate table enterprise_customersegment_segment;
- truncate table enterprise_customerbalance;
- truncate table sales_flat_order_item;
- truncate table sales_flat_order;
- truncate table curbside_subscription;
- truncate table earns_users;
- truncate table customer_entity;
- set @entity_type_id = 1;
- INSERT INTO `customer_entity` (`entity_type_id`, `website_id`, `group_id`, `email`, `store_id`, `created_at`, `updated_at`, `account_old_id`,`account_number`)
- SELECT @entity_type_id, website_id, group_id, username, store_id, created_at, updated_at, account_id, account_number
- FROM tload_contact_export;
- UPDATE tload_contact_export tl
- inner join customer_entity e on tl.account_id = e.account_old_id
- SET tl.contact_new_id = e.entity_id;
- UPDATE customer_entity
- SET increment_id = LPAD(entity_id, 9, '0');
- SELECT LPAD(MAX(entity_id), 9, '0') INTO @increment_id
- FROM customer_entity;
- UPDATE `eav_entity_store`
- SET `increment_last_id` = @increment_id
- WHERE (entity_store_id='6');
- set @attribute_name = '';
- WHILE EXISTS (select column_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_contact_export'
- and column_name > @attribute_name
- and column_name not in ('website_id', 'group_id', 'store_id', 'email','account_number', 'contact_new_id')) DO
- select column_name into @attribute_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_contact_export'
- and column_name > @attribute_name
- and column_name not in ('website_id', 'group_id', 'store_id', 'email','account_number', 'contact_new_id')
- order by column_name asc
- limit 1;
- set @attribute_id = 0;
- set @backend_type = '';
- select attribute_id, backend_type into @attribute_id, @backend_type from eav_attribute
- where entity_type_id = @entity_type_id
- and attribute_code = @attribute_name;
- if (@backend_type = 'datetime') then
- set @qwr = concat('insert into customer_entity_datetime
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.contact_new_id,
- tl.',@attribute_name,'
- from tload_contact_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'decimal') then
- set @qwr = concat('insert into customer_entity_decimal
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.contact_new_id,
- tl.',@attribute_name,'
- from tload_contact_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'int') then
- set @qwr = concat('insert into customer_entity_int
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.contact_new_id,
- tl.',@attribute_name,'
- from tload_contact_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'text') then
- set @qwr = concat('insert into customer_entity_text
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.contact_new_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_contact_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'varchar') then
- set @qwr = concat('insert into customer_entity_varchar
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.contact_new_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_contact_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- END WHILE;
- insert into customer_mobile (customer_id, phone_number, is_active)
- select contact_new_id, customer_mobile, 0
- from tload_contact_export
- WHERE customer_mobile IS NOT NULL;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_customer_address` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_customer_address`()
- BEGIN
- declare newValue int(10);
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'customer_address_entity'
- and column_name = 'address_old_id') then
- alter table customer_address_entity add column (address_old_id int(11) null);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'customer_address_entity'
- and index_name = 'IDX_customer_address_entity_address_old_id') then
- alter table customer_address_entity add KEY IDX_customer_address_entity_address_old_id (address_old_id);
- end if;
- IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- AND table_name = 'tload_contact_address_export'
- AND column_name = 'region_id') THEN
- ALTER TABLE tload_contact_address_export ADD COLUMN (region_id INT(11) NULL);
- END IF;
- IF NOT EXISTS(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- AND table_name = 'tload_contact_address_export'
- AND index_name = 'IDX_tload_contact_address_export_region') THEN
- ALTER TABLE tload_contact_address_export ADD KEY IDX_tload_contact_address_export_region (region);
- END IF;
- UPDATE tload_contact_address_export r
- INNER JOIN directory_country_region_name rID ON r.`region` = rID.`name`
- SET r.region_id = rID.region_id;
- truncate table customer_address_entity_varchar;
- truncate table customer_address_entity_text;
- truncate table customer_address_entity_int;
- truncate table customer_address_entity_decimal;
- truncate table customer_address_entity_datetime;
- truncate table customer_address_entity;
- set @entity_type_id = 2;
- INSERT INTO `customer_address_entity` (`entity_type_id`, `parent_id`, `created_at`, `updated_at`, address_old_id)
- SELECT @entity_type_id, ce.entity_id, ta.created_at, ta.updated_at, ta.address_id
- from tload_contact_address_export ta
- INNER JOIN customer_entity ce ON ta.account_id = ce.account_old_id;
- UPDATE tload_contact_address_export ta
- INNER JOIN customer_address_entity ce ON ta.address_id = ce.address_old_id
- set ta.address_new_id = ce.entity_id;
- INSERT INTO `customer_entity_int` (`entity_type_id`, `entity_id`, `attribute_id`, `value`)
- select 1, ce.entity_id, 13, ta.address_new_id from tload_contact_address_export ta
- inner join customer_entity ce on ta.account_id = ce.account_old_id
- where ta.is_billing = 1
- ON DUPLICATE KEY UPDATE `value`=VALUES(`value`);
- INSERT INTO `customer_entity_int` (`entity_type_id`, `entity_id`, `attribute_id`, `value`)
- select 1, ce.entity_id, 14, ta.address_new_id from tload_contact_address_export ta
- inner join customer_entity ce on ta.account_id = ce.account_old_id
- where ta.is_shipping = 1
- ON DUPLICATE KEY UPDATE `value`=VALUES(`value`);
- set @attribute_name = '';
- WHILE EXISTS (select column_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_contact_address_export'
- and column_name > @attribute_name
- and column_name not in ('address_id','address1','address2','contact_new_id', 'created_at', 'updated_at', 'is_billing', 'is_shipping', 'address_new_id','client_address_id','unit_num','building_id','qas_verify_level','qas_disable','route','address3')) DO
- select column_name into @attribute_name from INFORMATION_SCHEMA.COLUMNS
- where table_schema = DATABASE()
- and table_name = 'tload_contact_address_export'
- and column_name > @attribute_name
- and column_name not in ('address_id', 'address1','address2','contact_new_id', 'created_at', 'updated_at', 'is_billing', 'is_shipping', 'address_new_id','client_address_id','unit_num','building_id','qas_verify_level','qas_disable','route','address3')
- order by column_name asc
- limit 1;
- set @attribute_id = 0;
- set @backend_type = '';
- select attribute_id, backend_type into @attribute_id, @backend_type from eav_attribute
- where entity_type_id = @entity_type_id
- and attribute_code = @attribute_name;
- if (@backend_type = 'datetime') then
- set @qwr = concat('insert into customer_address_entity_datetime
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.address_new_id,
- tl.',@attribute_name,'
- from tload_contact_address_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'decimal') then
- set @qwr = concat('insert into customer_address_entity_decimal
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.address_new_id,
- tl.',@attribute_name,'
- from tload_contact_address_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'int') then
- set @qwr = concat('insert into customer_address_entity_int
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.address_new_id,
- tl.',@attribute_name,'
- from tload_contact_address_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'text') then
- set @qwr = concat('insert into customer_address_entity_text
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.address_new_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_contact_address_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- if (@backend_type = 'varchar') then
- set @qwr = concat('insert into customer_address_entity_varchar
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select ', @entity_type_id, ',
- ', @attribute_id,',
- tl.address_new_id,
- ifnull(tl.',@attribute_name,','''')
- from tload_contact_address_export tl
- where tl.',@attribute_name,' is not null and tl.',@attribute_name,' <> ''''
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);');
- PREPARE stmt FROM @qwr;
- EXECUTE stmt;
- end if;
- END WHILE;
- drop table if exists tload_customer_address_empty;
- create table tload_customer_address_empty as
- select c.entity_id as customer_id, cvf.value as firstname, cvl.value as lastname from customer_entity c
- left join customer_address_entity a on c.entity_id = a.parent_id
- left join customer_entity_varchar cvf on c.entity_id = cvf.entity_id and cvf.attribute_id = 5
- left join customer_entity_varchar cvl on c.entity_id = cvl.entity_id and cvl.attribute_id = 7
- where a.entity_id is null;
- alter table tload_customer_address_empty add key ix_tload_customer_address_empty_customer_id (customer_id);
- INSERT INTO `customer_address_entity` (`entity_type_id`, `parent_id`, `created_at`, `updated_at`)
- SELECT 2, customer_id, now(), now()
- from tload_customer_address_empty;
- INSERT INTO `customer_entity_int` (`entity_type_id`, `entity_id`, `attribute_id`, `value`)
- select 1, c.customer_id, 13, ca.entity_id
- from tload_customer_address_empty c
- inner join customer_address_entity ca on c.customer_id = ca.parent_id
- ON DUPLICATE KEY UPDATE `value`=VALUES(`value`);
- INSERT INTO `customer_entity_int` (`entity_type_id`, `entity_id`, `attribute_id`, `value`)
- select 1, c.customer_id, 14, ca.entity_id
- from tload_customer_address_empty c
- inner join customer_address_entity ca on c.customer_id = ca.parent_id
- ON DUPLICATE KEY UPDATE `value`=VALUES(`value`);
- insert into customer_address_entity_varchar
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select @entity_type_id,
- 19,
- ca.entity_id,
- ifnull(c.firstname,'')
- from tload_customer_address_empty c
- inner join customer_address_entity ca on c.customer_id = ca.parent_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);
- insert into customer_address_entity_varchar
- (entity_type_id,
- attribute_id,
- entity_id,
- value
- )
- select @entity_type_id,
- 21,
- ca.entity_id,
- ifnull(c.lastname,'')
- from tload_customer_address_empty c
- inner join customer_address_entity ca on c.customer_id = ca.parent_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);
- INSERT INTO customer_address_entity_varchar
- (entity_type_id,
- attribute_id,
- entity_id,
- VALUE
- )
- SELECT @entity_type_id,
- 26,
- ca.entity_id,
- 'US'
- FROM tload_customer_address_empty c
- INNER JOIN customer_address_entity ca ON c.customer_id = ca.parent_id
- ON DUPLICATE KEY UPDATE
- `value`=VALUES(`value`);
- drop table if exists tload_customer_address_empty;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_earn_users` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_earn_users`()
- BEGIN
- declare rb_UK_partner_id int(10);
- declare rb_US_partner_id int(10);
- TRUNCATE TABLE earns_customers_partners;
- truncate table earns_customers;
- INSERT INTO earns_customers
- (id,customer_id,product_id,success_count,fail_count,extra,start_date,end_date,old_subscription_id)
- SELECT
- teu.id,null as user_id,cpev.entity_id, teu.success_count,0 as fail_count,null as extra
- ,teu.start_date,teu.end_date,old_subscription_id
- FROM tload_earns_customers teu
- INNER JOIN catalog_product_entity_varchar cpev
- on cpev.attribute_id = 60 and cpev.value = teu.product_id_name
- WHERE cpev.value in ('Earn Curbside','Earn Curbside UK','Earn GConomy Card','Earn Other CUB Energy Saver','Earn Other WMECO','Earn Points Codes');
- UPDATE earns_customers eu
- INNER JOIN tload_earns_customers teu on eu.id = teu.id
- INNER JOIN customer_entity ce on ce.account_old_id = teu.customer_id
- SET eu.customer_id = ce.entity_id;
- SELECT id INTO rb_UK_partner_id FROM partners_entity WHERE name ='RecycleBank UK';
- SELECT id INTO rb_US_partner_id FROM partners_entity WHERE name ='RecycleBank US';
- INSERT INTO earns_customers_partners (earns_customers_id,partner_id,partner_member_account_number)
- SELECT eu.id
- , case
- WHEN teu.product_id_name= 'Earn Curbside' THEN rb_UK_partner_id
- WHEN teu.product_id_name = 'Earn Curbside UK' THEN rb_US_partner_id
- ELSE
- cpe.partner_id
- END as partner_id
- , teu.partner_member_account_number
- FROM earns_customers eu
- INNER JOIN tload_earns_customers teu on eu.id= teu.id
- INNER JOIN catalog_product_entity cpe on cpe.entity_id = eu.product_id;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_online_online_code_table` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_online_online_code_table`()
- BEGIN
- truncate table online_products_line_items;
- truncate table online_products_codes;
- truncate table online_products_deliveries;
- INSERT INTO online_products_line_items
- ( `id`,`order_id`,`quantity_ordered`,`quantity_remain`,`line_status`,`promotion_id`,`online_code`,
- `date_used`,`date_shipped`,`price`,`created_at`,`updated_at`,`partner_id`,`product_id`,`quantity_voided`,
- `quantity_returned`,`type`,`source_redemption_line_item_id`,`reward_description`,`original_line_item_id`,
- `order_return_id`,`points_credited`,`source_catalog_number`,`return_reason_code`,`channel`,`old_id`
- )
- SELECT
- `id`,null,`quantity_ordered`,`quantity_remain`,`line_status`,`promotion_id`,`online_code`,
- `date_used`,`date_shipped`,`price`,`created_at`,`updated_at`,null,null,`quantity_voided`,
- `quantity_returned`,`type`,`source_redemption_line_item_id`,`reward_description`,`original_line_item_id`,
- `order_return_id`,`points_credited`,`source_catalog_number`,`return_reason_code`,`channel`,`old_id`
- FROM tload_online_products_line_items ;
- UPDATE online_products_line_items li
- inner join tload_online_products_line_items tli on li.id = tli.id
- inner JOIN tload_partners_entity_map_id p on tli.partner_id = p.old_id
- and p.source_table in (1,3,5)
- SET li.partner_id = p.new_id;
- UPDATE online_products_line_items li
- inner join tload_online_products_line_items tli on li.id = tli.id
- inner join catalog_product_entity pe on tli.product_id = pe.reward_old_id
- SET li.product_id = pe.entity_id;
- UPDATE online_products_line_items li
- inner join tload_online_products_line_items tli on li.id = tli.id
- inner join sales_flat_order o on tli.order_id = o.old_id
- SET li.order_id = o.entity_id;
- INSERT INTO `online_products_deliveries`
- (`id`,`date_delivered`,`quantity`,`added_by_id`,`created_at`,`updated_at`,`supplier_type`,
- `unlimited`,`status`,`product_id`,`total_cost`,`date_expired`,`coupon_codes`,`auto_gen_codes`, `type_id`,`old_id` )
- SELECT
- `id`,`date_delivered`,`quantity`,`added_by_id`,`created_at`,`updated_at`,case when `supplier_type` = 0 then null else `supplier_type` end,
- `unlimited`,`status`,null,`total_cost`,`date_expired`,`coupon_codes`,`auto_gen_codes`, `type_id`,`old_id`
- FROM `tload_online_products_deliveries`;
- UPDATE online_products_deliveries pd
- inner join tload_online_products_deliveries tpd on pd.id = tpd.id
- inner join catalog_product_entity pe on tpd.product_id = pe.reward_old_id
- SET pd.product_id = pe.entity_id;
- INSERT INTO online_products_codes
- (`id`,`code`,`used`,`delivery_id`,`product_id`,`partner_id`,`expired_at`,`used_at`,`used_by`,`created_at`,`updated_at`,`line_item_id`,`old_id` )
- SELECT `id`,`code`,`used`,`delivery_id`,null,null,`expired_at`,`used_at`,`used_by`,`created_at`,`updated_at`,`line_item_id`,`old_id`
- FROM tload_online_products_codes;
- UPDATE online_products_codes pc
- inner join tload_online_products_codes tpc on pc.id = tpc.id
- inner JOIN tload_partners_entity_map_id p on tpc.partner_id = p.old_id
- and p.source_table in (1,3,5)
- SET pc.partner_id = p.new_id;
- UPDATE online_products_codes pc
- inner join tload_online_products_codes tpc on pc.id = tpc.id
- inner join catalog_product_entity pe on tpc.product_id = pe.reward_old_id
- SET pc.product_id = pe.entity_id;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_ORDERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_ORDERS`()
- BEGIN
- truncate table online_products_line_items;
- truncate table online_products_codes;
- truncate table online_products_deliveries;
- truncate table pah_coupons_printing_offers;
- truncate table pah_coupons_printings;
- truncate table pah_coupons_ci_analytics;
- truncate table pah_coupons_history;
- truncate table pah_coupons;
- truncate table pah_coupons_offers;
- truncate table sales_flat_order_item;
- truncate table `sales_flat_order`;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'sales_flat_order'
- and column_name = 'old_id') then
- alter table sales_flat_order add column (old_id int(11) null);
- end if;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'sales_flat_order'
- and index_name = 'IDX_sales_flat_order_old_id') then
- alter table sales_flat_order add KEY IDX_sales_flat_order_old_id (old_id);
- end if;
- alter table `tload_sales_flat_order` add index (customer_id);
- alter table `tload_sales_flat_order_item` add index (product_id);
- INSERT INTO `sales_flat_order` (`entity_id`,`status`,`customer_id`,`subtotal`,`total_qty_ordered`,`created_at`,`updated_at`,`date_ordered`, old_id, increment_id)
- SELECT tor.`entity_id`,`status`,null as customer_id,`subtotal`,`total_qty_ordered`,`created_at`,`updated_at`,`date_ordered`, old_id, old_id
- FROM `tload_sales_flat_order` tor ;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'sales_flat_order_item'
- and column_name = 'old_id') then
- alter table sales_flat_order_item add column (old_id int(11) null);
- end if;
- INSERT INTO sales_flat_order_item (`item_id`,`order_id`,`store_id`,`created_at`,`updated_at`,`product_id`,`sku`,`product_type`,`weight`,`name`
- ,`price`,`qty_backordered`,`qty_canceled`,`qty_invoiced`,`qty_ordered`,`qty_refunded`,`qty_shipped`,`line_status`,`batch_id`,`old_id`, `description`)
- SELECT `item_id`,`order_id`,`store_id`,`created_at`,`updated_at`,null as product_id,`sku`,`product_type`,`weight`,`name`
- ,`price`,`qty_backordered`,`qty_canceled`,`qty_invoiced`,1,`qty_refunded`,`qty_shipped`,tori.`line_status`,tori.`batch_id`, tori.`old_id`, tori.`description`
- FROM tload_sales_flat_order_item tori;
- create temporary table temp_customer_sales_flat_order as
- SELECT ce.account_old_id as customer_id, ce.entity_id
- FROM customer_entity ce ;
- alter table temp_customer_sales_flat_order add index (customer_id);
- update sales_flat_order so
- INNER JOIN tload_sales_flat_order tso on so.entity_id = tso.entity_id
- INNER JOIN temp_customer_sales_flat_order tc on tc.customer_id = tso.customer_id
- SET so.customer_id = tc.entity_id;
- create temporary table temp_product_sales_flat_order_item
- as
- SELECT cpe.entity_id,cpe.reward_old_id as reward_old_id
- FROM catalog_product_entity cpe;
- alter table temp_product_sales_flat_order_item add index (reward_old_id);
- update sales_flat_order_item soi
- INNER JOIN `tload_sales_flat_order_item` tsoi on soi.item_id = tsoi.item_id
- INNER JOIN temp_product_sales_flat_order_item ti on tsoi.product_id = ti.reward_old_id
- SET soi.product_id = ti.entity_id;
- drop table if exists temp_customer_sales_flat_order;
- drop table if exists temp_product_sales_flat_order_item;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_pah_coupons_table` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_pah_coupons_table`()
- BEGIN
- truncate table pah_coupons_printing_offers;
- truncate table pah_coupons_printings;
- truncate table pah_coupons_ci_analytics;
- truncate table pah_coupons_history;
- truncate table pah_coupons;
- truncate table pah_coupons_offers;
- insert into pah_coupons_offers
- (id,
- code,
- created_at,
- updated_at,
- status_code,
- employee_id,
- product_id,
- old_id
- )
- select id,
- code,
- created_at,
- updated_at,
- status_code,
- employee_id,
- null,
- old_id
- from tload_pah_coupons_offers;
- UPDATE pah_coupons_offers co
- inner join tload_pah_coupons_offers tco on co.id = tco.id
- inner join catalog_product_entity pe on tco.product_id = pe.reward_old_id
- SET co.product_id = pe.entity_id;
- insert into pah_coupons
- (id,
- code,
- type_code,
- created_at,
- updated_at,
- status_code,
- employee_id,
- product_id,
- old_id
- )
- select id,
- code,
- type_code,
- created_at,
- updated_at,
- status_code,
- employee_id,
- null,
- old_id
- from tload_pah_coupons;
- UPDATE pah_coupons c
- inner join tload_pah_coupons tc on c.id = tc.id
- inner join catalog_product_entity pe on tc.product_id = pe.reward_old_id
- SET c.product_id = pe.entity_id;
- insert into pah_coupons_history
- (id,
- action,
- offer_id,
- coupon_id,
- employee_id,
- created_at,
- updated_at,
- old_id
- )
- select id,
- action,
- null,
- null,
- employee_id,
- created_at,
- updated_at,
- old_id
- from tload_pah_coupons_history;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'pah_coupons_offers'
- and index_name = 'IDX_pah_coupons_offers_old_id') then
- alter table pah_coupons_offers add KEY `IDX_pah_coupons_offers_old_id` (`old_id`);
- end if;
- UPDATE pah_coupons_history ch
- inner join tload_pah_coupons_history tch on ch.id = tch.id
- inner join pah_coupons_offers co on tch.offer_id = co.old_id
- SET ch.offer_id = co.id;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'pah_coupons'
- and index_name = 'IDX_pah_coupons_old_id') then
- alter table pah_coupons add KEY `IDX_pah_coupons_old_id` (`old_id`);
- end if;
- UPDATE pah_coupons_history ch
- inner join tload_pah_coupons_history tch on ch.id = tch.id
- inner join pah_coupons c on tch.coupon_id = c.old_id
- SET ch.coupon_id = c.id;
- insert into pah_coupons_ci_analytics
- (id,
- offer_code,
- coupon_id,
- attempted,
- prints,
- first_print,
- redeemed,
- deny_dev,
- deny_pin,
- deny_fraud,
- deny_network,
- deny_platform,
- coupon_desc,
- created_at,
- updated_at,
- old_id
- )
- select id,
- offer_code,
- null,
- attempted,
- prints,
- first_print,
- redeemed,
- deny_dev,
- deny_pin,
- deny_fraud,
- deny_network,
- deny_platform,
- coupon_desc,
- created_at,
- updated_at,
- old_id
- from tload_pah_coupons_ci_analytics;
- UPDATE pah_coupons_ci_analytics cca
- inner join tload_pah_coupons_ci_analytics tcca on cca.id = tcca.id
- inner join pah_coupons c on tcca.coupon_id = c.old_id
- SET cca.coupon_id = c.id;
- insert into pah_coupons_printings
- (id,
- pin,
- url_string,
- created_at,
- updated_at,
- status_code,
- product_id,
- ci_analytic_id,
- order_id,
- old_id
- )
- select id,
- pin,
- url_string,
- created_at,
- updated_at,
- status_code,
- null,
- null,
- null,
- old_id
- from tload_pah_coupons_printings;
- UPDATE pah_coupons_printings cp
- inner join tload_pah_coupons_printings tcp on cp.id = tcp.id
- inner join catalog_product_entity pe on tcp.product_id = pe.reward_old_id
- SET cp.product_id = pe.entity_id;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'pah_coupons_ci_analytics'
- and index_name = 'IDX_pah_coupons_ci_analytics_old_id') then
- alter table pah_coupons_ci_analytics add KEY `IDX_pah_coupons_ci_analytics_old_id` (`old_id`);
- end if;
- UPDATE pah_coupons_printings cp
- inner join tload_pah_coupons_printings tcp on cp.id = tcp.id
- inner join pah_coupons_ci_analytics cca on tcp.ci_analitic_id = cca.old_id
- SET cp.ci_analytic_id = cca.id;
- UPDATE pah_coupons_printings cp
- inner join tload_pah_coupons_printings tcp on cp.id = tcp.id
- inner join sales_flat_order o on tcp.order_id = o.old_id
- SET cp.order_id = o.entity_id;
- insert into pah_coupons_printing_offers
- (id,
- created_at,
- updated_at,
- coupons_inc_printing_id,
- coupons_inc_offer_id,
- coupons_inc_coupon_id,
- ci_analytic_id,
- old_id
- )
- select id,
- created_at,
- updated_at,
- coupons_inc_printing_id,
- coupons_inc_offer_id,
- coupons_inc_coupon_id,
- null,
- old_id
- from tload_pah_coupons_printing_offers;
- UPDATE pah_coupons_printing_offers cpo
- inner join tload_pah_coupons_printing_offers tcpo on cpo.id = tcpo.id
- inner join pah_coupons_ci_analytics cca on tcpo.ci_analitic_id = cca.old_id
- SET cpo.ci_analytic_id = cca.id;
- alter table pah_coupons_offers drop KEY `IDX_pah_coupons_offers_old_id`;
- alter table pah_coupons_ci_analytics drop KEY `IDX_pah_coupons_ci_analytics_old_id`;
- alter table pah_coupons drop KEY `IDX_pah_coupons_old_id`;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_PARTNERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_PARTNERS`()
- BEGIN
- truncate table curbside_subscription;
- truncate table curbside_addresses;
- truncate table earns_customers_partners;
- truncate table earns_customers;
- truncate table sales_flat_order_item;
- truncate table enterprise_customerbalance_history_ext_partner;
- truncate table online_products_line_items;
- truncate table online_products_codes;
- truncate table online_products_deliveries;
- truncate table online_products_codes;
- truncate table pah_coupons_printing_offers;
- truncate table pah_coupons_printings;
- truncate table pah_coupons_ci_analytics;
- truncate table pah_coupons_history;
- truncate table pah_coupons;
- truncate table pah_coupons_offers;
- truncate table sales_flat_order;
- TRUNCATE TABLE catalog_product_entity_media_gallery;
- TRUNCATE TABLE partners_local_rewards_stores;
- delete from catalog_product_entity;
- truncate table partners_reward_address_merchant_data;
- truncate table partners_reward_merchant_data;
- truncate table partners_reward_address;
- truncate table partners_reward;
- truncate table partners_earn_transactions;
- truncate table partners_earn;
- truncate table partners_entity;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'partners_entity'
- and column_name = 'old_id') then
- alter table partners_entity add column (old_id int(11) null);
- end if;
- INSERT INTO partners_entity
- (id,`name`,is_national,country,description,logo,url_1,url_text_1,`status`,page_url,old_id)
- SELECT id,trim(`name`),is_national,country,description,logo,url_1,url_text_1,`status`,page_url,tm.old_id
- FROM tload_partners_entity tpe
- INNER JOIN tload_partners_entity_map_id tm on tpe.id = tm.new_id and tm.source_table in (1,2,3,6,7);
- INSERT INTO partners_earn (id,partner_id,type,points,has_strict_zero,allow_autolink,g_partner_id,g_partner_secret_key)
- SELECT id,partner_id,type,points,strict_zero,automatic_link,g_partner_id,g_partner_secret_key
- FROM tload_partners_earn where partner_id <> 0;
- INSERT INTO partners_reward (id,partner_id,irs_tax_id)
- SELECT id,partner_id,irs_tax_id
- FROM tload_partners_reward;
- INSERT INTO partners_reward_address
- (id,partner_id,address_1,address_2,city,state,post_code,country,phone_number,`status`,lat,lng )
- SELECT id,partner_id,address_1,address_2,city,state,post_code,country,phone_number,`status`,lat,lng
- FROM tload_partners_reward_address;
- INSERT INTO partners_reward_merchant_data (id,partner_id,bonus_factor,merchant_id,merchant_dba,merchant_category_id)
- SELECT id,partner_id,bonus_factor,merchant_id,merchant_dba,merchant_category_id
- FROM tload_partners_reward_merchant_data;
- INSERT INTO partners_reward_address_merchant_data (id,partner_reward_address_id,bonus_factor,merchant_id)
- SELECT id,partner_reward_address_id,bonus_factor,merchant_id
- FROM tload_partners_reward_address_merchant_data ;
- INSERT INTO `partners_earn_transactions`
- (id,partner_id,`type`,`time`,points,description,customer_id)
- SELECT id,partner_id,`type`,`time`,points,description,null as customer_id
- FROM `tload_partners_earn_transactions` ;
- if not exists(SELECT *
- FROM information_schema.statistics
- WHERE table_schema = DATABASE()
- and table_name = 'tload_partners_earn_transactions'
- and index_name = 'ix_tload_partners_earn_transactions_customer_id') then
- alter table tload_partners_earn_transactions add KEY ix_tload_partners_earn_transactions_customer_id (customer_id);
- end if;
- UPDATE partners_earn_transactions pet
- INNER JOIN `tload_partners_earn_transactions` tpet on pet.id = tpet.id
- INNER JOIN customer_entity ce on tpet.customer_id = ce.account_old_id
- SET pet.customer_id = ce.entity_id;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_Transaktions` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_Transaktions`()
- BEGIN
- truncate table enterprise_customerbalance_history_ext_partner;
- truncate table `enterprise_customerbalance_history`;
- truncate table `enterprise_customerbalance`;
- INSERT INTO `enterprise_customerbalance` (`balance_id`,customer_id,website_id,amount,base_currency_code)
- SELECT `balance_id` ,ce.entity_id as customer_id,tcb.website_id,tcb.amount,tcb.base_currency_code
- FROM tload_enterprise_customerbalance tcb
- INNER JOIN customer_entity ce on ce.account_old_id = tcb.customer_id;
- if not exists (select * from INFORMATION_SCHEMA.COLUMNS
- WHERE table_schema = DATABASE()
- and table_name = 'enterprise_customerbalance_history'
- and column_name = 'transaktions_old_id') then
- alter table enterprise_customerbalance_history add column (transaktions_old_id int(11) null);
- end if;
- INSERT INTO `enterprise_customerbalance_history`
- (history_id,balance_id,updated_at,`action`,balance_amount,balance_delta,additional_info,is_customer_notified,reason_id, description, transaktions_old_id)
- SELECT tcbh.history_id,tcbh.balance_id,tcbh.updated_at,tcbh.`action`,tcbh.balance_amount,tcbh.balance_delta,tcbh.additional_info,tcbh.is_customer_notified,tcbh.reason_id, tcbh.description, tcbh.old_id
- FROM tload_enterprise_customerbalance_history tcbh ;
- INSERT INTO enterprise_customerbalance_history_ext_partner (history_id, partner_id)
- SELECT h.history_id, l.new_id
- FROM tload_enterprise_customerbalance_history h
- inner join tload_partners_entity_map_id l on h.client_old_id = l.old_id
- and l.source_table in (2,4)
- WHERE h.client_old_id is not null;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_import_truncate_tables` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`front_ecs`@`%`*/ /*!50003 PROCEDURE `MG_import_truncate_tables`()
- BEGIN
- truncate table enterprise_customerbalance_history_ext_partner;
- truncate table enterprise_customerbalance_history_ext_code;
- truncate table enterprise_customerbalance_history;
- truncate table enterprise_customersegment_segment;
- truncate table enterprise_customerbalance;
- truncate table curbside_subscription;
- truncate table curbside_addresses;
- truncate table earns_customers_partners;
- truncate table earns_customers;
- truncate table online_products_line_items;
- truncate table online_products_codes;
- truncate table online_products_deliveries;
- truncate table pah_coupons_printing_offers;
- truncate table pah_coupons_printings;
- truncate table pah_coupons_ci_analytics;
- truncate table pah_coupons_history;
- truncate table pah_coupons;
- truncate table pah_coupons_offers;
- truncate table sales_flat_order_item;
- truncate table sales_flat_order;
- TRUNCATE TABLE partners_local_rewards_stores;
- TRUNCATE TABLE catalog_product_entity_media_gallery;
- truncate table catalog_product_entity_datetime;
- truncate table catalog_product_entity_decimal;
- truncate table catalog_product_entity_int;
- truncate table catalog_product_entity_text;
- truncate table catalog_product_entity_varchar;
- truncate table catalog_product_entity;
- truncate table partners_reward_merchant_data;
- truncate table partners_reward;
- truncate table partners_reward_address_merchant_data;
- truncate table partners_reward_address;
- truncate table partners_earn_transactions;
- truncate table partners_earn;
- truncate table partners_entity;
- truncate table customer_address_entity_datetime;
- truncate table customer_address_entity_decimal;
- truncate table customer_address_entity_int;
- truncate table customer_address_entity_text;
- truncate table customer_address_entity_varchar;
- truncate table customer_address_entity;
- truncate table customer_mobile;
- truncate table customer_entity_datetime;
- truncate table customer_entity_decimal;
- truncate table customer_entity_int;
- truncate table customer_entity_text;
- truncate table customer_entity_varchar;
- truncate table customer_entity;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_SELFREPORTING_REMINDER_USERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_SELFREPORTING_REMINDER_USERS`()
- BEGIN
- SELECT now() INTO @curr_dt;
- SELECT case WHEN DAYOFWEEK(@curr_dt) =1 THEN 7 ELSE DAYOFWEEK(@curr_dt)-1 END INTO @dofw ;
- SELECT
- case
- WHEN mod((WEEK(@curr_dt, 5) -
- WEEK(DATE_SUB(@curr_dt, INTERVAL DAYOFMONTH(@curr_dt) - 1 DAY), 5) + 1) ,2 ) = 0
- THEN 1 ELSE 0 END INTO @d_even_odd;
- SELECT `sr`.*
- , `ce`.`email`
- , `fname_table`.`value` AS `first_name`
- , `lname_table`.`value` AS `la
- st_name`
- FROM `customer_self_reporting` AS `sr`
- LEFT JOIN `customer_entity` ce on `sr`.customer_id = ce.entity_id
- LEFT JOIN `customer_entity_varchar` AS `fname_table`
- ON fname_table.entity_id = sr.customer_id AND fname_table.attribute_id = 5
- LEFT JOIN `customer_entity_varchar` AS `lname_table`
- ON lname_table.entity_id = sr.customer_id AND lname_table.attribute_id = 7
- WHERE
- (sr.is_active = 1
- AND
- (
- (sr.frequency_type = 1 AND sr.day_of_week = @dofw)
- OR (sr.frequency_type = 2 AND sr.num = @d_even_odd AND sr.day_of_week =@dofw)
- OR (sr.frequency_type = 3
- AND
- (sr.day_of_month = DAYOFMONTH(@curr_dt)
- OR case
- WHEN DAYOFMONTH(LAST_DAY(@curr_dt)) > 27 AND DAYOFMONTH(LAST_DAY(@curr_dt))< 31
- THEN sr.day_of_month > date(@curr_dt)
- ELSE 1=0 END
- )
- )
- ));
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_TRANSACTIONS_LAST_WEEK` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_TRANSACTIONS_LAST_WEEK`()
- BEGIN
- drop table if exists ttemp_search_transactions ;
- create TEMPORARY table ttemp_search_transactions
- SELECT
- cbh.history_id,cbh.balance_id,cbh.additional_info,cbh.reason_id,cbh.description,cbh.balance_delta,cbh.balance_amount,cbh.updated_at
- FROM enterprise_customerbalance_history cbh
- WHERE cbh.updated_at
- between DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-%d'), INTERVAL -7 DAY)
- and DATE_FORMAT(NOW(), '%Y-%m-%d') ;
- alter table ttemp_search_transactions add index ix_ttttt_tr_balance (balance_id);
- SELECT
- cb.amount,ce.store_id,ce.email,cbh.additional_info,cbh.reason_id,cbh.description,cbh.balance_delta,cbh.balance_amount,cbh.updated_at,ce.store_id
- FROM ttemp_search_transactions cbh
- INNER JOIN enterprise_customerbalance cb on cb.balance_id = cbh.balance_id
- INNER JOIN customer_entity ce on ce.entity_id = cb.customer_id order by email, cbh.history_id desc;
- drop table ttemp_search_transactions;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_UPDATE_PRODUCT_STATUS_DAILY` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_UPDATE_PRODUCT_STATUS_DAILY`(IN iis_uk int )
- BEGIN
- DECLARE done INT DEFAULT 0;
- DECLARE c_entity_id int(10);
- DECLARE cur1
- CURSOR FOR
- SELECT entity_id FROM ttemp_upd_status_daily_ WHERE upd_status =1 ORDER BY entity_id;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- SELECT now() INTO @curr_date;
- SELECT case
- WHEN iis_uk =1 THEN date(DATE_ADD( @curr_date, INTERVAL 10 HOUR ))
- ELSE date(@curr_date) END INTO @dnow;
- DROP table if exists ttemp_upd_status_daily_;
- CREATE temporary table ttemp_upd_status_daily_
- AS
- SELECT
- cpe_status.entity_id
- ,case WHEN cpe_start.value <= cpe_end.value
- THEN
- case WHEN cpe_start.value > @dnow
- THEN 2
- WHEN cpe_start.value = @dnow AND cpe_end.value > @dnow AND ifnull(csi.is_in_stock,0) = 1
- THEN 1
- WHEN cpe_start.value = @dnow AND cpe_end.value > @dnow AND ifnull(csi.is_in_stock,0) = 0
- THEN cpe_status.value
- WHEN cpe_end.value <= @dnow
- THEN 2
- ELSE
- cpe_status.value
- END
- ELSE
- 2
- END as upd_status
- FROM catalog_product_entity_int cpe_status
- INNER JOIN catalog_product_entity cpe
- on cpe_status.entity_id = cpe.entity_id AND cpe.is_uk = iis_uk
- LEFT JOIN catalog_product_entity_datetime cpe_start
- on cpe_status.entity_id = cpe_start.entity_id
- AND cpe_start.attribute_id = 444
- AND cpe_status.store_id = cpe_start.store_id
- LEFT JOIN catalog_product_entity_datetime cpe_end
- on cpe_status.entity_id = cpe_end.entity_id
- AND cpe_end.attribute_id = 463
- AND cpe_status.store_id = cpe_end.store_id
- LEFT JOIN cataloginventory_stock_item csi
- ON csi.product_id = cpe.entity_id
- WHERE cpe_status.attribute_id = 495
- and cpe_status.store_id =0
- and (cpe_start.value is not null AND cpe_end.value is not null)
- and (cpe_start.value > @dnow or cpe_start.value = @dnow or cpe_end.value <= @dnow or cpe_start.value > cpe_end.value )
- AND
- case WHEN cpe_start.value <= cpe_end.value
- THEN
- case WHEN cpe_start.value > @dnow
- THEN 2
- WHEN cpe_start.value = @dnow AND cpe_end.value > @dnow
- THEN 1
- WHEN cpe_end.value <= @dnow
- THEN 2
- ELSE
- cpe_status.value
- END
- ELSE
- 2
- END <> cpe_status.value;
- UPDATE catalog_product_entity_int cpe_status
- INNER JOIN ttemp_upd_status_daily_ t
- on cpe_status.entity_id = t.entity_id
- SET cpe_status.value = t.upd_status
- WHERE cpe_status.store_id = 0 AND cpe_status.attribute_id = 495;
- OPEN cur1;
- read_loop: LOOP
- FETCH cur1 INTO c_entity_id;
- IF done THEN
- LEAVE read_loop;
- END IF;
- call MG_UPSERT_CATALOG_PRODUCT_FLAT(c_entity_id);
- END LOOP;
- CLOSE cur1;
- DELETE FROM catalog_product_flat_1
- WHERE entity_id in (SELECT entity_id FROM ttemp_upd_status_daily_ WHERE upd_status =2);
- DELETE FROM catalog_product_flat_2
- WHERE entity_id in (SELECT entity_id FROM ttemp_upd_status_daily_ WHERE upd_status =2);
- DROP table if exists ttemp_upd_status_daily_;
- end */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_UPDATE_PRODUCT_STATUS_DAILY_TEST` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_UPDATE_PRODUCT_STATUS_DAILY_TEST`(IN iis_uk int )
- BEGIN
- DECLARE done INT DEFAULT 0;
- DECLARE c_entity_id int(10);
- DECLARE cur1
- CURSOR FOR
- SELECT entity_id FROM ttemp_upd_status_daily_ WHERE upd_status =1 ORDER BY entity_id;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- SELECT now() INTO @curr_date;
- SELECT case
- WHEN iis_uk =1 THEN date(DATE_ADD( @curr_date, INTERVAL 5 HOUR ))
- ELSE date(@curr_date) END INTO @dnow;
- DROP table if exists ttemp_upd_status_daily_;
- CREATE temporary table ttemp_upd_status_daily_
- AS
- SELECT
- cpe_status.entity_id
- ,case WHEN cpe_start.value <= cpe_end.value
- THEN
- case WHEN cpe_start.value > @dnow
- THEN 2
- WHEN cpe_start.value = @dnow AND cpe_end.value > @dnow
- THEN 1
- WHEN cpe_end.value < @dnow
- THEN 2
- ELSE
- cpe_status.value
- END
- ELSE
- 2
- END as upd_status
- FROM catalog_product_entity_int cpe_status
- INNER JOIN catalog_product_entity cpe
- on cpe_status.entity_id = cpe.entity_id AND cpe.is_uk = iis_uk
- LEFT JOIN catalog_product_entity_datetime cpe_start
- on cpe_status.entity_id = cpe_start.entity_id
- AND cpe_start.attribute_id = 444
- AND cpe_status.store_id = cpe_start.store_id
- LEFT JOIN catalog_product_entity_datetime cpe_end
- on cpe_status.entity_id = cpe_end.entity_id
- AND cpe_end.attribute_id = 463
- AND cpe_status.store_id = cpe_end.store_id
- WHERE cpe_status.attribute_id = 495
- and cpe_status.store_id =0
- and (cpe_start.value is not null AND cpe_end.value is not null)
- and (cpe_start.value > @dnow or cpe_start.value = @dnow or cpe_end.value < @dnow or cpe_start.value > cpe_end.value )
- AND
- case WHEN cpe_start.value <= cpe_end.value
- THEN
- case WHEN cpe_start.value > @dnow
- THEN 2
- WHEN cpe_start.value = @dnow AND cpe_end.value > @dnow
- THEN 1
- WHEN cpe_end.value < @dnow
- THEN 2
- ELSE
- cpe_status.value
- END
- ELSE
- 2
- END <> cpe_status.value;
- UPDATE catalog_product_entity_int cpe_status
- INNER JOIN ttemp_upd_status_daily_ t
- on cpe_status.entity_id = t.entity_id
- SET cpe_status.value = t.upd_status
- WHERE cpe_status.store_id = 0 AND cpe_status.attribute_id = 495;
- OPEN cur1;
- read_loop: LOOP
- FETCH cur1 INTO c_entity_id;
- IF done THEN
- LEAVE read_loop;
- END IF;
- call MG_UPSERT_CATALOG_PRODUCT_FLAT(c_entity_id);
- END LOOP;
- CLOSE cur1;
- DELETE FROM catalog_product_flat_1
- WHERE entity_id in (SELECT entity_id FROM ttemp_upd_status_daily_ WHERE upd_status =2);
- DELETE FROM catalog_product_flat_2
- WHERE entity_id in (SELECT entity_id FROM ttemp_upd_status_daily_ WHERE upd_status =2);
- DROP table if exists ttemp_upd_status_daily_;
- end */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MG_UPSERT_CATALOG_PRODUCT_FLAT` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `MG_UPSERT_CATALOG_PRODUCT_FLAT`(IN inp_entity_id int(10))
- BEGIN
- DECLARE str_all_fields VARCHAR(100000) DEFAULT '';
- DECLARE str_ins_fields VARCHAR(10000) DEFAULT '';
- DECLARE str_dupl_upd VARCHAR(10000) DEFAULT '';
- DECLARE fld_name VARCHAR(10000) DEFAULT '';
- DECLARE ins_fld_name VARCHAR(255) DEFAULT '';
- DECLARE fld_dupl_upd VARCHAR(10000) DEFAULT '';
- DECLARE done INT DEFAULT 0;
- DECLARE cur1
- CURSOR FOR select
- concat("max(case When a.attribute_code='", a.attribute_code,"' THEN ",case when a.backend_type='varchar' THEN "cev.value" WHEN a.backend_type='datetime' THEN "ced.value" WHEN a.backend_type='decimal' THEN "cedc.value" WHEN a.backend_type = 'int' THEN "cei.value" WHEN a.backend_type = 'text' THEN "cet.value" WHEN a.backend_type = 'static' THEN concat("ce.",a.attribute_code) END," END ) as ",a.attribute_code) as a1,
- a.attribute_code as a2,
- concat("`",a.attribute_code,"`=VALUES(`",a.attribute_code,"`)") as a3
- FROM `eav_attribute` a
- INNER JOIN information_schema.COLUMNS c on c.TABLE_SCHEMA =DATABASE()
- AND c.TABLE_NAME ='catalog_product_flat_1' AND c.column_name = a.attribute_code
- WHERE a.entity_type_id = 4 and a.attribute_code <>'required_options'
- order BY a.attribute_id;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- OPEN cur1;
- read_loop: LOOP
- FETCH cur1 INTO fld_name,ins_fld_name,fld_dupl_upd;
- IF done THEN
- LEAVE read_loop;
- END IF;
- SET str_all_fields = CONCAT(str_all_fields,fld_name,",");
- SET str_ins_fields = CONCAT(str_ins_fields,ins_fld_name,",");
- SET str_dupl_upd = CONCAT(str_dupl_upd,fld_dupl_upd,",");
- END LOOP;
- CLOSE cur1;
- SET str_all_fields = substring(str_all_fields,1,length(str_all_fields)-1);
- SET str_ins_fields = substring(str_ins_fields,1,length(str_ins_fields)-1);
- SET str_dupl_upd = substring(str_dupl_upd,1,length(str_dupl_upd)-1);
- SET @ins_table = 'catalog_product_flat_2';
- SET @str_sql = concat(" FROM `eav_attribute` a \n
- INNER JOIN `catalog_product_entity` ce on a.entity_type_id = ce.entity_type_id \n
- LEFT JOIN `catalog_product_entity_varchar` cev \n
- on a.attribute_id = cev.attribute_id and ce.entity_id = cev.entity_id and cev.store_id =0 \n
- LEFT JOIN `catalog_product_entity_datetime` ced \n
- on a.attribute_id = ced.attribute_id and ce.entity_id = ced.entity_id and ced.store_id =0 \n
- LEFT JOIN `catalog_product_entity_decimal` cedc \n
- on a.attribute_id = cedc.attribute_id and ce.entity_id = cedc.entity_id and cedc.store_id =0 \n
- LEFT JOIN `catalog_product_entity_int` cei \n
- on a.attribute_id = cei.attribute_id and ce.entity_id = cei.entity_id and cei.store_id =0 \n
- LEFT JOIN `catalog_product_entity_text` cet \n
- on a.attribute_id = cet.attribute_id and ce.entity_id = cet.entity_id and cet.store_id =0 \n
- WHERE ce.entity_id = ",inp_entity_id," AND a.entity_type_id = 4 GROUP BY ce.entity_id order BY a.attribute_id ");
- SET @str_ins_sql = concat("INSERT INTO ",@ins_table,"(entity_id,",str_ins_fields,") SELECT ce.entity_id,",str_all_fields,@str_sql,
- " ON DUPLICATE KEY UPDATE `entity_id`=VALUES(`entity_id`),",str_dupl_upd ) ;
- PREPARE s1 FROM @str_ins_sql;
- EXECUTE s1;
- DEALLOCATE PREPARE s1;
- SET @ins_table = 'catalog_product_flat_1';
- SET @str_ins_sql = concat("INSERT INTO ",@ins_table,"(entity_id,",str_ins_fields,") SELECT ce.entity_id,",str_all_fields,@str_sql,
- " ON DUPLICATE KEY UPDATE `entity_id`=VALUES(`entity_id`),",str_dupl_upd ) ;
- PREPARE s1 FROM @str_ins_sql;
- EXECUTE s1;
- DEALLOCATE PREPARE s1;
- end */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_CREATE_AD_HISTORY` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_CREATE_AD_HISTORY`(in loginId int(11),
- in imageUrl varchar(255),
- in showTime int(11),
- out recordId int(11))
- BEGIN
- INSERT INTO mobile_ad_histories (login_id, image_url, show_time, created_at, updated_at)
- VALUES (loginId, imageUrl, showTime, now(), now());
- SET recordId = LAST_INSERT_ID();
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_CREATE_DEVICE_DETAILS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_CREATE_DEVICE_DETAILS`(in loginId int(11),
- in deviceId varchar(255),
- in deviceName varchar(255),
- in osName varchar(255),
- in osVersion varchar(255),
- in appVersion varchar(100),
- out success int)
- BEGIN
- DECLARE deviceCount INT DEFAULT 0;
- SELECT count(*) FROM mobile_device_details dd
- WHERE dd.login_id = loginId
- and dd.device_id = deviceId
- and dd.device_name = deviceName
- and dd.os_name = osName
- and dd.os_version = osVersion
- and dd.app_version = appVersion
- into deviceCount;
- IF deviceCount = 0 THEN
- INSERT INTO mobile_device_details (login_id, device_id, device_name, os_name, os_version, app_version, created_at)
- VALUES (loginId, deviceId, deviceName, osName, osVersion, appVersion, now());
- SELECT 1 INTO success;
- ELSE
- SELECT 0 INTO success;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_CREATE_REWARD_ORDER` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_CREATE_REWARD_ORDER`(IN icustomer_id int(10),
- IN iproduct_id int(10),
- IN iamount decimal(12,4),
- OUT success tinyint(1),
- OUT reason varchar(255))
- BEGIN
- declare o_id int(10);
- declare reward_description text;
- declare istore_id tinyint(1);
- declare tr_id int(10);
- IF EXISTS (SELECT 1 FROM customer_entity WHERE entity_id = icustomer_id)
- AND EXISTS (SELECT 1 FROM catalog_product_entity WHERE entity_id = iproduct_id)
- AND EXISTS (SELECT 1 FROM enterprise_customerbalance
- WHERE customer_id = icustomer_id )
- THEN
- SET istore_id = 1;
- SELECT ce_dba.value
- ,ce_dsa.value
- ,ce.group_id
- ,ce_dob.value
- ,ce.email
- ,ce_firstname.value
- ,ce_lastname.value
- ,ce.account_number
- ,cae_region.value
- ,cae_postcode.value
- ,ecb.balance_id
- ,ecb.amount
- ,ce.store_id
- INTO @id_default_billing_address
- ,@id_default_shipping_address
- ,@icustomer_group_id
- ,@idob
- ,@iemail
- ,@ifirstname
- ,@ilastname
- ,@iaccount_number
- ,@iregion
- ,@ipostcode
- ,@ibalance_id
- ,@balance_amount
- ,istore_id
- FROM customer_entity ce
- LEFT JOIN customer_entity_int ce_dba
- on ce.entity_id = ce_dba.entity_id AND ce_dba.attribute_id = 13
- LEFT JOIN customer_entity_int ce_dsa
- on ce.entity_id = ce_dsa.entity_id AND ce_dsa.attribute_id = 14
- LEFT JOIN customer_entity_datetime ce_dob
- on ce.entity_id = ce_dob.entity_id AND ce_dob.attribute_id = 11
- LEFT JOIN customer_entity_varchar ce_firstname
- on ce.entity_id = ce_firstname.entity_id AND ce_firstname.attribute_id = 5
- LEFT JOIN customer_entity_varchar ce_lastname
- on ce.entity_id = ce_lastname.entity_id AND ce_lastname.attribute_id = 7
- LEFT JOIN customer_address_entity cae
- on ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_varchar cae_region
- on cae.entity_id = cae_region.entity_id and cae_region.attribute_id = 27
- LEFT JOIN customer_address_entity_varchar cae_postcode
- on cae.entity_id = cae_postcode.entity_id and cae_postcode.attribute_id = 29
- LEFT JOIN enterprise_customerbalance ecb on ecb.customer_id = ce.entity_id
- WHERE ce.entity_id = icustomer_id;
- SELECT cpe_name.value,cpe_price.value,cpe.type_id ,cpe.sku,css.qty
- INTO @reward_name,@reward_price,@reward_type,@reward_sku,@reward_qty
- FROM catalog_product_entity cpe
- INNER JOIN catalog_product_entity_varchar cpe_name
- on cpe_name.entity_id = cpe.entity_id AND cpe_name.attribute_id = 60
- INNER JOIN catalog_product_entity_decimal cpe_price
- on cpe_price.entity_id = cpe.entity_id AND cpe_price.attribute_id = 64
- INNER JOIN cataloginventory_stock_status css
- on cpe.entity_id = css.product_id
- WHERE cpe.entity_id = iproduct_id;
- IF (@balance_amount >= @reward_price*iamount ) AND (iamount <= @reward_qty) THEN
- START TRANSACTION;
- BEGIN
- INSERT INTO `sales_flat_quote`
- (`store_id`
- , `created_at`
- , `updated_at`
- , `is_active`
- , `store_to_base_rate`
- , `store_to_quote_rate`
- , `base_currency_code`
- , `store_currency_code`
- , `quote_currency_code`
- , `customer_id`
- , `customer_tax_class_id`
- , `customer_group_id`
- , `customer_email`
- , `customer_prefix`
- , `customer_firstname`
- , `customer_middlename`
- , `customer_lastname`
- , `customer_suffix`
- , `customer_dob`
- , `global_currency_code`
- , `base_to_global_rate`
- , `base_to_quote_rate`
- , `customer_taxvat`
- , `customer_gender`
- , `is_changed`)
- VALUES (
- '1'
- , now()
- , now()
- ,1
- , '1'
- , '1'
- , 'USD'
- , 'USD'
- , 'USD'
- , icustomer_id
- , '3'
- , @icustomer_group_id
- , @iemail
- , NULL
- , @ifirstname
- , NULL
- , @ilastname
- , NULL
- , @idob
- , 'USD'
- , '1'
- , '1'
- , NULL
- , NULL
- , '1'
- );
- SET @nsales_flat_quote = LAST_INSERT_ID();
- INSERT INTO `enterprise_customer_sales_flat_quote`
- (`entity_id`
- , `customer_language_code`
- , `customer_reset_code`
- , `customer_date_last_login`
- , `customer_subbed_to_recyclebank_news`
- , `customer_subbed_to_partner_offers`
- , `customer_village_green_opt_in`
- , `customer_rewards_email_opt_in`
- , `customer_allow_api_access`
- , `customer_points_alert_opt_in`
- , `customer_whats_new_opt_in`
- , `customer_hot_picks_opt_in`
- , `customer_self_reporting_reminder_code`
- , `customer_self_reporting_reminder_day`
- , `customer_self_reporting_reminder_frequency`
- , `customer_self_reporting_reminder_starts_at`
- , `customer_count_showed_print_at_home_lightbox`
- , `customer_contact_id`
- , `customer_home_phone`
- , `customer_fax_number`
- , `customer_cell_phone`
- , `customer_sequrity_question_id`
- , `customer_sequrity_answer`
- , `customer_hear_about_rb_code`
- , `customer_account_id`
- , `customer_account_number`
- , `customer_balance`
- , `customer_bonus_reward_status_code`
- , `customer_subscription_type_code`
- , `customer_barclays_credit_card`
- , `customer_activated_online`
- , `customer_login_id`
- , `customer_username`
- , `customer_date_username_selected`
- , `customer_survey_answered`
- , `customer_picture_id`
- , `customer_rb_name`
- , `customer_prescreen_opt_out`
- , `customer_greenteam_opt_in`
- , `customer_contact_status`
- , `customer_job_title`
- , `customer_pin_number`
- , `customer_date_agreed_to_tos`
- , `customer_email_hash`
- , `customer_status_code`
- , `customer_lock_version`
- , `customer_parent_account_id`
- , `customer_facebook_permissions`
- , `customer_password_reset_key`
- , `customer_work_phone`
- , `customer_title`
- , `customer_updated_at`
- , `customer_security_answer`
- , `customer_security_question_id`)
- VALUES (
- @nsales_flat_quote
- , 'US'
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , @iaccount_number
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , '0000-00-00 00:00:00'
- , NULL
- , NULL);
- INSERT INTO `sales_flat_quote_address`
- (`quote_id`
- , `created_at`
- , `updated_at`
- , `customer_id`
- , `customer_address_id`
- , `address_type`
- , `email`
- , `prefix`
- , `firstname`
- , `middlename`
- , `lastname`
- , `suffix`
- , `company`
- , `street`
- , `city`
- , `region`
- , `region_id`
- , `postcode`
- , `country_id`
- , `telephone`
- , `fax`
- , `giftregistry_item_id`)
- VALUES (
- @nsales_flat_quote
- , now()
- , now()
- , icustomer_id
- ,@id_default_billing_address
- , 'billing'
- , @iemail
- , NULL
- , @ifirstname
- , NULL
- , @ilastname
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , @ipostcode
- , NULL
- , NULL
- , NULL
- , NULL
- );
- SET @nsales_flat_qoute_address_id = LAST_INSERT_ID();
- INSERT INTO `enterprise_customer_sales_flat_quote_address`
- (`entity_id`
- , `lat`
- , `lng`
- , `address_id`
- , `address2`
- , `building_id`
- , `qas_verify_level`
- , `route`
- , `qas_disable`
- , `address3`
- , `client_address_id`
- , `unit_num`
- , `address1`)
- VALUES
- (@nsales_flat_qoute_address_id
- , NULL
- , NULL
- , @nsales_flat_qoute_address_id
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL);
- INSERT INTO `sales_flat_quote_payment`
- (`quote_id`, `created_at`, `updated_at`, `method`, `additional_information`)
- VALUES (@nsales_flat_quote, now(), now(), 'free', NULL);
- SELECT max(increment_last_id)+1
- INTO @new_order_increment_last_id
- FROM `eav_entity_store` WHERE entity_store_id='1' AND `entity_type_id` = '5';
- UPDATE `eav_entity_store`
- SET
- `increment_last_id` = @new_order_increment_last_id
- WHERE entity_store_id='1' AND `entity_type_id` = '5';
- INSERT INTO `sales_flat_order`
- (`status`
- ,`state`
- ,`coupon_code`
- , `protect_code`
- , `shipping_description`
- , `is_virtual`
- , `store_id`
- , `customer_id`
- , `base_discount_amount`
- , `base_grand_total`
- , `base_shipping_amount`
- , `base_shipping_tax_amount`
- , `base_subtotal`
- , `base_tax_amount`
- , `base_to_global_rate`
- , `base_to_order_rate`
- , `discount_amount`
- , `grand_total`
- , `shipping_amount`
- , `shipping_tax_amount`
- , `store_to_base_rate`
- , `store_to_order_rate`
- , `subtotal`
- , `tax_amount`
- , `total_qty_ordered`
- , `customer_is_guest`
- , `customer_note_notify`
- , `customer_group_id`
- , `gift_message_id`
- , `quote_id`
- , `base_shipping_discount_amount`
- , `base_subtotal_incl_tax`
- , `shipping_discount_amount`
- , `subtotal_incl_tax`
- , `weight`
- , `customer_dob`
- , `increment_id`
- , `applied_rule_ids`
- , `base_currency_code`
- , `customer_email`
- , `customer_firstname`
- , `customer_lastname`
- , `customer_middlename`
- , `customer_prefix`
- , `customer_suffix`
- , `customer_taxvat`
- , `discount_description`
- , `global_currency_code`
- , `order_currency_code`
- , `remote_ip`
- , `shipping_method`
- , `store_currency_code`
- , `store_name`
- , `x_forwarded_for`
- , `customer_note`
- , `created_at`
- , `updated_at`
- , `total_item_count`
- , `customer_gender`
- , `hidden_tax_amount`
- , `base_hidden_tax_amount`
- , `shipping_hidden_tax_amount`
- , `base_shipping_hidden_tax_amount`
- , `shipping_incl_tax`
- , `base_shipping_incl_tax`
- , `base_customer_balance_amount`
- , `customer_balance_amount`
- , `gift_cards`
- , `base_gift_cards_amount`
- , `gift_cards_amount`
- , `reward_points_balance`
- , `base_reward_currency_amount`
- , `reward_currency_amount`)
- VALUES
- ('complete'
- ,'complete'
- ,null
- ,'prot'
- ,''
- ,0
- ,1
- , icustomer_id
- ,0
- ,@reward_price*iamount
- ,0
- ,0
- ,@reward_price*iamount
- ,0
- ,1
- ,1
- ,0
- ,@reward_price*iamount
- ,'0'
- ,'0'
- ,'1'
- ,'1'
- ,@reward_price*iamount
- ,0
- ,iamount
- ,0
- ,0
- , @icustomer_group_id
- ,'1'
- , NULL
- ,@nsales_flat_quote
- ,0
- ,@reward_price*iamount
- ,0
- ,0
- , @idob
- ,@new_order_increment_last_id
- ,''
- , 'USD'
- , @iemail
- , @ifirstname
- , @ilastname
- ,null
- ,null
- ,null
- ,null
- ,null
- ,'USD'
- , 'USD'
- ,null
- ,'freeshipping_freeshipping'
- , 'USD'
- ,'Main Website\nMain Website Store\nUS'
- ,null
- ,''
- ,now()
- ,now()
- ,1
- ,null
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , 'a:0:{}'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- );
- SET o_id = LAST_INSERT_ID();
- INSERT INTO `sales_flat_order_address`
- (`parent_id`
- , `customer_address_id`
- , `region_id`
- , `customer_id`
- , `fax`
- , `region`
- , `postcode`
- , `lastname`
- , `street`
- , `city`
- , `telephone`
- , `country_id`
- , `firstname`
- , `address_type`
- , `prefix`
- , `middlename`
- , `suffix`
- , `company`
- , `giftregistry_item_id`)
- VALUES (
- o_id
- , @id_default_billing_address
- , NULL
- , icustomer_id
- , NULL
- , ''
- , @ipostcode
- , @ilastname
- , ''
- , ''
- , ''
- , ''
- , @ifirstname
- , 'billing'
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL);
- SET @new_billing_sales_flat_order_address_id = LAST_INSERT_ID();
- INSERT INTO `enterprise_customer_sales_flat_order_address`
- (`entity_id`
- , `lat`
- , `lng`
- , `address_id`
- , `address2`
- , `building_id`
- , `qas_verify_level`
- , `route`
- , `qas_disable`
- , `address3`
- , `client_address_id`
- , `unit_num`
- , `address1`)
- VALUES (
- @new_billing_sales_flat_order_address_id
- , NULL
- , NULL
- ,@id_default_billing_address
- , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
- ;
- UPDATE `sales_flat_order`
- SET `billing_address_id` = @new_billing_sales_flat_order_address_id
- WHERE (entity_id=o_id);
- INSERT INTO `sales_flat_order_address`
- (`parent_id`
- , `customer_address_id`
- , `region_id`
- , `customer_id`
- , `fax`
- , `region`
- , `postcode`
- , `lastname`
- , `street`
- , `city`
- , `telephone`
- , `country_id`
- , `firstname`
- , `address_type`
- , `prefix`
- , `middlename`
- , `suffix`
- , `company`
- , `giftregistry_item_id`)
- VALUES (
- o_id
- , @id_default_shipping_address
- , NULL
- , icustomer_id
- , NULL
- , ''
- , @ipostcode
- , @ilastname
- , ''
- , ''
- , ''
- , ''
- , @ifirstname
- , 'shipping'
- , NULL
- , NULL
- , NULL
- , NULL
- , NULL);
- SET @new_shipping_sales_flat_order_address_id = LAST_INSERT_ID();
- INSERT INTO `enterprise_customer_sales_flat_order_address`
- (`entity_id`
- , `lat`
- , `lng`
- , `address_id`
- , `address2`
- , `building_id`
- , `qas_verify_level`
- , `route`
- , `qas_disable`
- , `address3`
- , `client_address_id`
- , `unit_num`
- , `address1`)
- VALUES (
- @new_shipping_sales_flat_order_address_id
- , NULL
- , NULL
- ,@id_default_shipping_address
- , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
- ;
- UPDATE `sales_flat_order`
- SET `shipping_address_id` = @new_shipping_sales_flat_order_address_id
- WHERE (entity_id=o_id);
- INSERT INTO `sales_flat_order_item`
- (`order_id`
- , `quote_item_id`
- , `store_id`
- , `created_at`
- , `updated_at`
- , `product_id`
- , `product_type`
- , `product_options`
- , `weight`
- , `is_virtual`
- , `sku`
- , `name`
- , `description`
- , `applied_rule_ids`
- , `additional_data`
- , `is_qty_decimal`
- , `qty_backordered`
- , `qty_ordered`
- , `base_cost`
- , `price`
- , `base_price`
- , `original_price`
- , `base_original_price`
- , `tax_percent`
- , `tax_amount`
- , `base_tax_amount`
- , `row_total`
- , `base_row_total`
- , `row_weight`
- , `gift_message_id`
- , `gift_message_available`
- , `base_tax_before_discount`
- , `tax_before_discount`
- , `weee_tax_applied`
- , `weee_tax_applied_amount`
- , `weee_tax_applied_row_amount`
- , `base_weee_tax_applied_amount`
- , `base_weee_tax_applied_row_amount`
- , `weee_tax_disposition`
- , `weee_tax_row_disposition`
- , `base_weee_tax_disposition`
- , `base_weee_tax_row_disposition`
- , `price_incl_tax`
- , `base_price_incl_tax`
- , `row_total_incl_tax`
- , `base_row_total_incl_tax`
- , `hidden_tax_amount`
- , `base_hidden_tax_amount`
- , `is_nominal`
- , `event_id`)
- VALUES (o_id
- ,@n_sales_flat_quote_item
- ,istore_id
- , now()
- , now()
- ,iproduct_id
- ,@reward_type
- , 'a:5:{s:15:\"info_buyRequest\";a:2:{s:3:\"qty\";i:1;s:7:\"options\";a:0:{}}s:17:\"giftcard_lifetime\";N;s:22:\"giftcard_is_redeemable\";i:0;s:23:\"giftcard_email_template\";N;s:13:\"giftcard_type\";N;}'
- , NULL
- , 0
- ,@reward_sku
- ,@reward_name
- , NULL
- , ''
- , NULL
- , '0'
- , NULL
- ,iamount
- , NULL
- ,@reward_price
- ,@reward_price
- ,@reward_price
- ,@reward_price
- , '0'
- , '0'
- , '0'
- ,@reward_price*iamount
- ,@reward_price*iamount
- , '0'
- , NULL
- , NULL
- , NULL
- , NULL
- , 'a:0:{}'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- , '0'
- ,@reward_price
- ,@reward_price
- ,@reward_price*iamount
- ,@reward_price*iamount
- , '0'
- , '0'
- , '0'
- , NULL
- );
- SET @new_sales_flat_order_item = LAST_INSERT_ID();
- INSERT INTO `sales_flat_order_payment`
- (`parent_id`
- , `additional_data`
- , `cc_exp_month`
- , `cc_ss_start_year`
- , `method`
- , `cc_last4`
- , `cc_ss_start_month`
- , `cc_owner`
- , `cc_type`
- , `po_number`
- , `cc_exp_year`
- , `cc_ss_issue`
- , `cc_number_enc`
- , `additional_information`)
- VALUES (o_id, NULL, '0', '0', 'free', '', '0', '', '', '', '0', NULL, '', NULL);
- INSERT INTO `sales_flat_order_grid`
- (`entity_id`
- ,`status`
- ,`store_id`
- ,`customer_id`
- ,`base_grand_total`
- ,`base_total_paid`
- ,`grand_total`
- ,`total_paid`
- ,`increment_id`
- ,`base_currency_code`
- ,`order_currency_code`
- ,`store_name`
- ,`created_at`
- ,`updated_at`
- ,`billing_name`
- ,`shipping_name`)
- SELECT
- `main_table`.`entity_id`
- , `main_table`.`status`, `main_table`.`store_id`, `main_table`.`customer_id`, `main_table`.`base_grand_total`, `main_table`.`base_total_paid`, `main_table`.`grand_total`, `main_table`.`total_paid`, `main_table`.`increment_id`, `main_table`.`base_currency_code`, `main_table`.`order_currency_code`, `main_table`.`store_name`, `main_table`.`created_at`, `main_table`.`updated_at`, CONCAT(IFNULL(_table_billing_name.firstname, ""), " ", IFNULL(_table_billing_name.lastname, "")) AS `billing_name`, CONCAT(IFNULL(_table_shipping_name.firstname, ""), " ", IFNULL(_table_shipping_name.lastname, "")) AS `shipping_name`
- FROM `sales_flat_order` AS `main_table`
- LEFT JOIN `sales_flat_order_address` AS `_table_billing_name` ON `main_table`.`billing_address_id`=`_table_billing_name`.`entity_id`
- LEFT JOIN `sales_flat_order_address` AS `_table_shipping_name` ON `main_table`.`shipping_address_id`=`_table_shipping_name`.`entity_id`
- WHERE (main_table.entity_id = o_id ) ;
- INSERT INTO `enterprise_customer_sales_flat_order`
- (`entity_id`
- , `customer_language_code`
- , `customer_reset_code`
- , `customer_date_last_login`
- , `customer_subbed_to_recyclebank_news`
- , `customer_subbed_to_partner_offers`
- , `customer_village_green_opt_in`
- , `customer_rewards_email_opt_in`
- , `customer_allow_api_access`
- , `customer_points_alert_opt_in`
- , `customer_whats_new_opt_in`
- , `customer_hot_picks_opt_in`
- , `customer_self_reporting_reminder_code`
- , `customer_self_reporting_reminder_day`
- , `customer_self_reporting_reminder_frequency`
- , `customer_self_reporting_reminder_starts_at`
- , `customer_count_showed_print_at_home_lightbox`
- , `customer_contact_id`, `customer_home_phone`
- , `customer_fax_number`, `customer_cell_phone`
- , `customer_sequrity_question_id`
- , `customer_sequrity_answer`
- , `customer_hear_about_rb_code`
- , `customer_account_id`
- , `customer_account_number`
- , `customer_balance`
- , `customer_bonus_reward_status_code`
- , `customer_subscription_type_code`
- , `customer_barclays_credit_card`
- , `customer_activated_online`
- , `customer_login_id`, `customer_username`
- , `customer_date_username_selected`
- , `customer_survey_answered`
- , `customer_picture_id`
- , `customer_rb_name`
- , `customer_prescreen_opt_out`
- , `customer_greenteam_opt_in`
- , `customer_contact_status`
- , `customer_job_title`
- , `customer_pin_number`
- , `customer_date_agreed_to_tos`
- , `customer_email_hash`
- , `customer_status_code`
- , `customer_lock_version`
- , `customer_parent_account_id`
- , `customer_facebook_permissions`
- , `customer_password_reset_key`
- , `customer_work_phone`
- , `customer_title`
- , `customer_updated_at`
- , `customer_security_answer`
- , `customer_security_question_id`)
- VALUES (o_id
- , 'US'
- , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @iaccount_number, NULL, 'B3121356', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0000-00-00 00:00:00', NULL, NULL)
- ;
- SELECT max(increment_last_id)+1
- INTO @new_inv_increment_last_id
- FROM `eav_entity_store` WHERE entity_store_id='3' AND `entity_type_id` = '6';
- UPDATE `eav_entity_store`
- SET
- `increment_last_id` = @new_inv_increment_last_id
- WHERE entity_store_id='3' AND `entity_type_id` = '6';
- INSERT INTO `sales_flat_invoice`
- (`store_id`
- , `base_grand_total`
- , `shipping_tax_amount`
- , `tax_amount`
- , `base_tax_amount`
- , `store_to_order_rate`
- , `base_shipping_tax_amount`
- , `base_discount_amount`
- , `base_to_order_rate`
- , `grand_total`
- , `shipping_amount`
- , `subtotal_incl_tax`
- , `base_subtotal_incl_tax`
- , `store_to_base_rate`
- , `base_shipping_amount`
- , `base_to_global_rate`
- , `subtotal`
- , `base_subtotal`
- , `discount_amount`
- , `billing_address_id`
- , `order_id`
- , `state`
- , `shipping_address_id`
- , `store_currency_code`
- , `order_currency_code`
- , `base_currency_code`
- , `global_currency_code`
- , `increment_id`
- , `created_at`
- , `updated_at`
- , `hidden_tax_amount`
- , `base_hidden_tax_amount`
- , `shipping_hidden_tax_amount`
- , `base_shipping_hidden_tax_amount`
- , `base_customer_balance_amount`
- , `customer_balance_amount`)
- VALUES (
- istore_id
- , '0'
- , '0'
- , '0'
- , '0'
- , istore_id
- , '0'
- , '0'
- , '1'
- , '0'
- , '0'
- ,@reward_price*iamount
- ,@reward_price*iamount
- , istore_id
- , '0'
- , '1'
- ,@reward_price*iamount
- ,@reward_price*iamount
- , '0'
- ,@new_billing_sales_flat_order_address_id
- , o_id
- , '1'
- , @new_shipping_sales_flat_order_address_id
- , 'USD'
- , 'USD'
- , 'USD'
- , 'USD'
- , @new_inv_increment_last_id
- , now()
- , now()
- , '0'
- , '0'
- , '0'
- , '0'
- ,@reward_price*iamount
- ,@reward_price*iamount
- );
- SET @new_sales_flat_invoice_id = LAST_INSERT_ID();
- INSERT INTO `sales_flat_invoice_item`
- (`parent_id`
- , `base_price`
- , `base_weee_tax_row_disposition`
- , `weee_tax_applied_row_amount`
- , `base_weee_tax_applied_amount`
- , `base_row_total`
- , `row_total`
- , `weee_tax_row_disposition`
- , `base_weee_tax_disposition`
- , `price_incl_tax`
- , `weee_tax_applied_amount`
- , `base_price_incl_tax`
- , `qty`
- , `weee_tax_disposition`
- , `base_cost`
- , `base_weee_tax_applied_row_amount`
- , `price`
- , `base_row_total_incl_tax`
- , `row_total_incl_tax`
- , `product_id`
- , `order_item_id`
- , `description`
- , `weee_tax_applied`
- , `sku`
- , `name`
- )
- VALUES (
- @new_sales_flat_invoice_id
- , @reward_price
- , '0'
- , '0'
- , '0'
- , @reward_price*iamount
- , @reward_price*iamount
- , '0'
- , '0'
- , '50'
- , '0'
- , @reward_price*iamount
- , iamount
- , '0'
- , NULL
- , '0'
- , @reward_price
- ,@reward_price*iamount
- , @reward_price*iamount
- , iproduct_id
- , o_id
- , NULL
- , 'a:0:{}'
- , @reward_sku
- ,@reward_name
- );
- INSERT INTO `sales_flat_invoice_comment` (`parent_id`, `is_customer_notified`, `comment`, `created_at`)
- VALUES (@new_sales_flat_invoice_id, null, 'Auto invoice', now());
- INSERT INTO `sales_flat_invoice_grid` (`entity_id`,`store_id`,`base_grand_total`,`grand_total`,`order_id`,`state`,`store_currency_code`,`order_currency_code`,`base_currency_code`,`global_currency_code`,`increment_id`,`created_at`,`billing_name`,`order_increment_id`,`order_created_at`) SELECT `main_table`.`entity_id`, `main_table`.`store_id`, `main_table`.`base_grand_total`, `main_table`.`grand_total`, `main_table`.`order_id`, `main_table`.`state`, `main_table`.`store_currency_code`, `main_table`.`order_currency_code`, `main_table`.`base_currency_code`, `main_table`.`global_currency_code`, `main_table`.`increment_id`, `main_table`.`created_at`, CONCAT(IFNULL(_table_billing_name.firstname, ""), " ", IFNULL(_table_billing_name.lastname, "")) AS `billing_name`, `_table_order_increment_id`.`increment_id` AS `order_increment_id`, `_table_order_created_at`.`created_at` AS `order_created_at`
- FROM `sales_flat_invoice` AS `main_table`
- LEFT JOIN `sales_flat_order_address` AS `_table_billing_name`
- ON `main_table`.`billing_address_id`=`_table_billing_name`.`entity_id`
- LEFT JOIN `sales_flat_order` AS `_table_order_increment_id`
- ON `main_table`.`order_id`=`_table_order_increment_id`.`entity_id`
- LEFT JOIN `sales_flat_order` AS `_table_order_created_at`
- ON `main_table`.`order_id`=`_table_order_created_at`.`entity_id`
- WHERE (main_table.entity_id = @new_sales_flat_invoice_id) ;
- INSERT INTO `sales_flat_order_status_history`
- (`parent_id`, `is_customer_notified`, `comment`, `status`, `created_at`)
- VALUES (o_id, '', '', 'pending', now());
- INSERT INTO `sales_flat_order_status_history`
- (`parent_id`, `is_customer_notified`, `comment`, `status`, `created_at`)
- VALUES (o_id, '', '', 'processing', now());
- SELECT max(increment_last_id)+1
- INTO @new_ship_increment_last_id
- FROM `eav_entity_store` WHERE entity_store_id='4' AND `entity_type_id` = '8';
- UPDATE `eav_entity_store`
- SET
- `increment_last_id` = @new_ship_increment_last_id
- WHERE entity_store_id='4' AND `entity_type_id` = '8';
- INSERT INTO `sales_flat_shipment`
- (`store_id`, `total_qty`, `order_id`, `customer_id`, `shipping_address_id`, `billing_address_id`, `increment_id`, `created_at`, `updated_at`)
- VALUES (istore_id, iamount, o_id, icustomer_id, @new_shipping_sales_flat_order_address_id, @new_billing_sales_flat_order_address_id
- , @new_ship_increment_last_id , now(), now() );
- SET @new_sales_flat_shipment = LAST_INSERT_ID();
- INSERT INTO `sales_flat_shipment_item` (`parent_id`, `price`, `weight`, `qty`, `product_id`, `order_item_id`, `description`, `name`, `sku`)
- VALUES (@new_sales_flat_shipment, @reward_price, NULL, iamount, iproduct_id, @new_sales_flat_order_item, NULL, @reward_name, @reward_sku);
- SET @new_sales_flat_shipment_item =LAST_INSERT_ID();
- INSERT INTO `sales_flat_shipment_comment` (`parent_id`, `is_customer_notified`, `comment`, `created_at`)
- VALUES (@new_sales_flat_shipment, '', 'Auto shippment', now());
- INSERT INTO `sales_flat_shipment_grid` (`entity_id`,`store_id`,`total_qty`,`order_id`,`shipment_status`,`increment_id`,`created_at`,`shipping_name`,`order_increment_id`,`order_created_at`) SELECT `main_table`.`entity_id`, `main_table`.`store_id`, `main_table`.`total_qty`, `main_table`.`order_id`, `main_table`.`shipment_status`, `main_table`.`increment_id`, `main_table`.`created_at`, CONCAT(IFNULL(_table_shipping_name.firstname, ""), " ", IFNULL(_table_shipping_name.lastname, "")) AS `shipping_name`, `_table_order_increment_id`.`increment_id` AS `order_increment_id`, `_table_order_created_at`.`created_at` AS `order_created_at`
- FROM `sales_flat_shipment` AS `main_table`
- LEFT JOIN `sales_flat_order_address` AS `_table_shipping_name`
- ON `main_table`.`shipping_address_id`=`_table_shipping_name`.`entity_id`
- LEFT JOIN `sales_flat_order` AS `_table_order_increment_id`
- ON `main_table`.`order_id`=`_table_order_increment_id`.`entity_id`
- LEFT JOIN `sales_flat_order` AS `_table_order_created_at` ON `main_table`.`order_id`=`_table_order_created_at`.`entity_id`
- WHERE (main_table.entity_id = @new_sales_flat_shipment) ;
- INSERT INTO `sales_flat_order_status_history` (`parent_id`, `is_customer_notified`, `comment`, `status`, `created_at`)
- VALUES (o_id, '', '', 'complete', now());
- INSERT INTO `sales_flat_order_grid` (`entity_id`,`status`,`store_id`,`customer_id`,`base_grand_total`,`base_total_paid`,`grand_total`,`total_paid`,`increment_id`,`base_currency_code`,`order_currency_code`,`store_name`,`created_at`,`updated_at`,`billing_name`,`shipping_name`) SELECT `main_table`.`entity_id`, `main_table`.`status`, `main_table`.`store_id`, `main_table`.`customer_id`, `main_table`.`base_grand_total`, `main_table`.`base_total_paid`, `main_table`.`grand_total`, `main_table`.`total_paid`, `main_table`.`increment_id`, `main_table`.`base_currency_code`, `main_table`.`order_currency_code`, `main_table`.`store_name`, `main_table`.`created_at`, `main_table`.`updated_at`, CONCAT(IFNULL(_table_billing_name.firstname, ""), " ", IFNULL(_table_billing_name.lastname, "")) AS `billing_name`, CONCAT(IFNULL(_table_shipping_name.firstname, ""), " ", IFNULL(_table_shipping_name.lastname, "")) AS `shipping_name`
- FROM `sales_flat_order` AS `main_table`
- LEFT JOIN `sales_flat_order_address` AS `_table_billing_name`
- ON `main_table`.`billing_address_id`=`_table_billing_name`.`entity_id`
- LEFT JOIN `sales_flat_order_address` AS `_table_shipping_name`
- ON `main_table`.`shipping_address_id`=`_table_shipping_name`.`entity_id`
- WHERE (main_table.entity_id = o_id ) ON DUPLICATE KEY UPDATE `entity_id`=VALUES(`entity_id`), `status`=VALUES(`status`), `store_id`=VALUES(`store_id`), `customer_id`=VALUES(`customer_id`), `base_grand_total`=VALUES(`base_grand_total`), `base_total_paid`=VALUES(`base_total_paid`), `grand_total`=VALUES(`grand_total`), `total_paid`=VALUES(`total_paid`), `increment_id`=VALUES(`increment_id`), `base_currency_code`=VALUES(`base_currency_code`), `order_currency_code`=VALUES(`order_currency_code`), `store_name`=VALUES(`store_name`), `created_at`=VALUES(`created_at`), `updated_at`=VALUES(`updated_at`), `billing_name`=VALUES(`billing_name`), `shipping_name`=VALUES(`shipping_name`);
- INSERT INTO `enterprise_customerbalance_history`
- (`balance_id`, `updated_at`, `action`, `balance_amount`, `balance_delta`, `additional_info`, `reason_id`)
- VALUES (@ibalance_id, now(), '3', @balance_amount - (@reward_price*iamount), -(@reward_price*iamount), concat('Order ',@new_order_increment_last_id), '12');
- UPDATE enterprise_customerbalance ecb
- SET ecb.amount= ecb.amount - (@reward_price*iamount)
- WHERE ecb.balance_id = @ibalance_id;
- UPDATE `cataloginventory_stock_status` css
- SET css.`qty` = css.`qty` - iamount
- WHERE `product_id` = iproduct_id AND `stock_id` =1 ;
- UPDATE cataloginventory_stock_item csi
- SET csi.`qty` = csi.`qty` - iamount
- WHERE csi.`product_id` = iproduct_id AND csi.`stock_id` =1 ;
- INSERT INTO `sales_flat_quote_item`
- (`quote_id`
- , `created_at`
- , `updated_at`
- , `product_id`
- , `store_id`
- , `is_virtual`
- , `sku`
- , `name`
- , `is_qty_decimal`
- , `weight`
- , `qty`
- , `product_type`
- , `base_cost`
- )
- VALUES (
- @nsales_flat_quote
- , now()
- , now()
- ,iproduct_id
- ,istore_id
- , NULL
- ,@reward_sku
- ,@reward_name
- , '0'
- , NULL
- ,iamount
- ,@reward_type
- , NULL
- );
- END;
- COMMIT;
- SELECT case when o_id is not null THEN 1 ELSE 0 END
- ,case when o_id is not null THEN "order created" ELSE "order not created" END
- INTO success,reason;
- ELSE
- SELECT 0 ,"insufficient customer balance amount or catalog product qty" INTO success,reason;
- END IF;
- ELSE
- SELECT 0 ,"customer entity or product entity does not exists" INTO success,reason;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_CUSTOMER_TRANSACTIONS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_CUSTOMER_TRANSACTIONS`(customerId int(11))
- BEGIN
- SELECT ecbh.balance_delta as 'point_change',
- CASE
- WHEN ecbh.description IS NOT NULL
- THEN ecbh.description
- WHEN ecbh.additional_info IS NOT NULL
- THEN CONCAT('Reward ', ecbh.additional_info)
- ELSE
- ecbr.reason_code
- END as 'reason',
- ecbh.updated_at as 'date'
- FROM enterprise_customerbalance_history ecbh
- INNER JOIN enterprise_customerbalance ecb ON ecbh.balance_id = ecb.balance_id
- LEFT OUTER JOIN enterprise_customerbalance_reasons ecbr ON ecbr.id = ecbh.reason_id
- WHERE ecb.customer_id = customerId AND ecbr.reason_code <> 'Order'
- UNION ALL
- SELECT -o.subtotal AS 'point_change',
- CONCAT('Reward Order #', o.increment_id) AS 'reason',
- o.updated_at AS 'date'
- FROM customer_entity c
- INNER JOIN sales_flat_order o ON c.entity_id = o.customer_id
- WHERE c.entity_id = customerId
- ORDER BY 3 DESC;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_DEALS_REWARDS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_DEALS_REWARDS`(custId int(11), ilt FLOAT, ilg FLOAT)
- BEGIN
- DECLARE zips_seq VARCHAR(8000) DEFAULT '\'X\'';
- DECLARE one_zip VARCHAR(255);
- DECLARE one_distance DOUBLE;
- DECLARE l_last_row_fetched INT;
- DECLARE storeId INT;
- DECLARE near_zip_cur CURSOR FOR
- SELECT zip, distance
- FROM near_zip;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_last_row_fetched=1;
- drop temporary table if exists near_zip;
- create temporary table near_zip(zip varchar(10), distance double);
- insert into near_zip(zip, distance)
- SELECT ra.zip AS zip, (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) AS distance
- FROM zip_geo ra
- WHERE (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) <= 30
- ORDER BY 2
- LIMIT 200;
- SET l_last_row_fetched=0;
- OPEN near_zip_cur;
- zip_loop: LOOP
- FETCH near_zip_cur INTO one_zip, one_distance;
- IF l_last_row_fetched = 1 THEN
- LEAVE zip_loop;
- END IF;
- SET zips_seq = CONCAT(zips_seq, ',\'', one_zip, '\'');
- END LOOP zip_loop;
- SET l_last_row_fetched = 0;
- CLOSE near_zip_cur;
- SELECT store_id
- FROM customer_entity
- WHERE entity_id = custId
- INTO storeId;
- SET @str_sql=concat(
- "SELECT cpe.entity_id as `id`
- ,cpev_name.value as `name`
- ,cpev_image.value as `image`
- ,cped_price.value as `price`
- ,pe.name as `sponsor_name`
- FROM
- catalog_product_entity cpe
- INNER JOIN catalog_category_product ccp on cpe.entity_id = ccp.product_id
- INNER JOIN partners_entity pe on cpe.partner_id = pe.id
- INNER JOIN catalog_category_entity cce on ccp.category_id = cce.entity_id
- INNER JOIN catalog_product_entity_varchar cpev_name
- on cpe.entity_id = cpev_name.entity_id AND cpev_name.attribute_id = 60
- INNER JOIN catalog_category_entity_varchar ccev_name
- on cce.entity_id = ccev_name.entity_id AND ccev_name.attribute_id = 33 AND ccev_name.value = '_Deals'
- INNER JOIN catalog_product_entity_int cpei ON cpe.entity_id = cpei.entity_id AND cpei.attribute_id = 442 AND cpei.store_id = 0 AND
- (EXISTS (SELECT * FROM partners_local_rewards_stores AS plrs INNER JOIN partners_reward_address AS pra ON plrs.store_id = pra.id WHERE cpe.entity_id = plrs.product_id AND pra.post_code IN (", zips_seq, ")) or cpei.value = 1)
- INNER JOIN cataloginventory_stock_item csi ON cpe.entity_id = csi.product_id AND csi.qty > 0
- LEFT JOIN catalog_product_entity_varchar cpev_image
- on cpe.entity_id = cpev_image.entity_id AND cpev_image.attribute_id = 74
- LEFT JOIN catalog_product_entity_decimal cped_price
- on cpe.entity_id = cped_price.entity_id AND cped_price.attribute_id = 64
- WHERE cpe.is_uk = ", case storeId WHEN 2 THEN "1 " ELSE "0 " END,
- "ORDER by cped_price.value ");
- PREPARE stmt FROM @str_sql;
- EXECUTE stmt;
- drop temporary table near_zip;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_FEATURES_REWARDS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_FEATURES_REWARDS`(custId int(11), ilt FLOAT, ilg FLOAT)
- BEGIN
- DECLARE zips_seq VARCHAR(8000) DEFAULT '\'X\'';
- DECLARE one_zip VARCHAR(255);
- DECLARE one_distance DOUBLE;
- DECLARE l_last_row_fetched INT;
- DECLARE storeId INT;
- DECLARE near_zip_cur CURSOR FOR
- SELECT zip, distance
- FROM near_zip;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_last_row_fetched=1;
- drop temporary table if exists near_zip;
- create temporary table near_zip(zip varchar(10), distance double);
- insert into near_zip(zip, distance)
- SELECT ra.zip AS zip, (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) AS distance
- FROM zip_geo ra
- WHERE (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) <= 30
- ORDER BY 2
- LIMIT 200;
- SET l_last_row_fetched=0;
- OPEN near_zip_cur;
- zip_loop: LOOP
- FETCH near_zip_cur INTO one_zip, one_distance;
- IF l_last_row_fetched = 1 THEN
- LEAVE zip_loop;
- END IF;
- SET zips_seq = CONCAT(zips_seq, ',\'', one_zip, '\'');
- END LOOP zip_loop;
- SET l_last_row_fetched = 0;
- CLOSE near_zip_cur;
- SELECT store_id
- FROM customer_entity
- WHERE entity_id = custId
- INTO storeId;
- SET @str_sql=concat(
- "SELECT cpe.entity_id as `id`
- ,cpev_name.value as `name`
- ,cpev_image.value as `image`
- ,cped_price.value as `price`
- ,pe.name as `sponsor_name`
- FROM
- catalog_product_entity cpe
- INNER JOIN catalog_category_product ccp on cpe.entity_id = ccp.product_id
- INNER JOIN partners_entity pe on cpe.partner_id = pe.id
- INNER JOIN catalog_category_entity cce on ccp.category_id = cce.entity_id
- INNER JOIN catalog_product_entity_varchar cpev_name
- on cpe.entity_id = cpev_name.entity_id AND cpev_name.attribute_id = 60
- INNER JOIN catalog_category_entity_varchar ccev_name
- on cce.entity_id = ccev_name.entity_id AND ccev_name.attribute_id = 33 AND ccev_name.value = '_Featured'
- INNER JOIN catalog_product_entity_int cpei ON cpe.entity_id = cpei.entity_id AND cpei.attribute_id = 442 AND cpei.store_id = 0 AND
- (EXISTS (SELECT * FROM partners_local_rewards_stores AS plrs INNER JOIN partners_reward_address AS pra ON plrs.store_id = pra.id WHERE cpe.entity_id = plrs.product_id AND pra.post_code IN (", zips_seq, ")) or cpei.value = 1)
- INNER JOIN cataloginventory_stock_item csi ON cpe.entity_id = csi.product_id AND csi.qty > 0
- LEFT JOIN catalog_product_entity_varchar cpev_image
- on cpe.entity_id = cpev_image.entity_id AND cpev_image.attribute_id = 74
- LEFT JOIN catalog_product_entity_decimal cped_price
- on cpe.entity_id = cped_price.entity_id AND cped_price.attribute_id = 64
- WHERE cpe.is_uk = ", case storeId WHEN 2 THEN "1 " ELSE "0 " END,
- "ORDER by cped_price.value ");
- PREPARE stmt FROM @str_sql;
- EXECUTE stmt;
- drop temporary table near_zip;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_LAST_REWARD` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_LAST_REWARD`(custId int(11))
- BEGIN
- SELECT sfo.date_ordered AS 'date_ordered', pe.name AS 'vendor_name'
- FROM customer_entity ce
- INNER JOIN sales_flat_order sfo ON ce.entity_id = sfo.customer_id
- INNER JOIN sales_flat_order_item sfoi ON sfo.entity_id = sfoi.order_id
- LEFT OUTER JOIN catalog_product_entity cpe ON sfoi.product_id = cpe.entity_id
- LEFT OUTER JOIN partners_entity pe ON cpe.partner_id = pe.id
- WHERE ce.entity_id = custId
- ORDER BY sfo.date_ordered DESC, sfoi.created_at DESC
- LIMIT 0, 1;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_POINTSCODES_PARTNERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_POINTSCODES_PARTNERS`(custId int(11))
- BEGIN
- DECLARE earn_pointcodes_type VARCHAR(32) DEFAULT 'earn_pointscodes';
- DECLARE country_us VARCHAR(255) DEFAULT 'USA';
- DECLARE country_uk VARCHAR(255) DEFAULT 'GBR';
- SELECT
- pe.id as 'id',
- pe.name as 'name',
- pe.country as 'country',
- cpe.is_uk as 'is_uk'
- FROM partners_entity pe
- INNER JOIN partners_earn per
- ON pe.id = per.partner_id
- INNER JOIN catalog_product_entity cpe
- ON pe.id = cpe.partner_id
- INNER JOIN catalog_product_entity_varchar cpe_name
- ON cpe.entity_id = cpe_name.entity_id AND cpe_name.attribute_id = 60
- INNER JOIN customer_entity ce
- ON ce.entity_id = custId
- WHERE
- cpe.type_id = earn_pointcodes_type
- AND
- CASE
- WHEN ce.store_id = 1
- THEN pe.country = country_us
- WHEN ce.store_id = 2
- THEN pe.country = country_uk
- ELSE 1=1
- END
- GROUP BY pe.id;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_REWARDS_BY_CATEGORY` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_REWARDS_BY_CATEGORY`(custId int(11), categoryId int(11), getNum int(11), skipNum int(11), priceOrder bool, ilt FLOAT, ilg FLOAT)
- BEGIN
- DECLARE zips_seq VARCHAR(8000) DEFAULT '\'X\'';
- DECLARE one_zip VARCHAR(255);
- DECLARE one_distance DOUBLE;
- DECLARE l_last_row_fetched INT;
- DECLARE storeId INT;
- DECLARE near_zip_cur CURSOR FOR
- SELECT zip, distance
- FROM near_zip;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_last_row_fetched=1;
- drop temporary table if exists near_zip;
- create temporary table near_zip(zip varchar(10), distance double);
- insert into near_zip(zip, distance)
- SELECT ra.zip AS zip, (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) AS distance
- FROM zip_geo ra
- WHERE (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) <= 30
- ORDER BY 2
- LIMIT 200;
- SET l_last_row_fetched=0;
- OPEN near_zip_cur;
- zip_loop: LOOP
- FETCH near_zip_cur INTO one_zip, one_distance;
- IF l_last_row_fetched = 1 THEN
- LEAVE zip_loop;
- END IF;
- SET zips_seq = CONCAT(zips_seq, ',\'', one_zip, '\'');
- END LOOP zip_loop;
- SET l_last_row_fetched = 0;
- CLOSE near_zip_cur;
- SELECT store_id
- FROM customer_entity
- WHERE entity_id = custId
- INTO storeId;
- SET @str_sql=concat(
- "SELECT cpe.entity_id as `id`
- ,cpev_name.value as `name`
- ,cpev_image.value as `image`
- ,cped_price.value as `price`
- ,pe.name as `sponsor_name`
- FROM
- catalog_product_entity cpe
- INNER JOIN catalog_category_product ccp on cpe.entity_id = ccp.product_id
- INNER JOIN partners_entity pe on cpe.partner_id = pe.id
- INNER JOIN catalog_category_entity cce on ccp.category_id = cce.entity_id AND cce.entity_id=",categoryId,"
- INNER JOIN catalog_product_entity_varchar cpev_name
- on cpe.entity_id = cpev_name.entity_id AND cpev_name.attribute_id = 60
- INNER JOIN catalog_product_entity_int cpei ON cpe.entity_id = cpei.entity_id AND cpei.attribute_id = 442 AND cpei.store_id = 0 AND
- (EXISTS (SELECT * FROM partners_local_rewards_stores AS plrs INNER JOIN partners_reward_address AS pra ON plrs.store_id = pra.id WHERE cpe.entity_id = plrs.product_id AND pra.post_code IN (", zips_seq, ")) or cpei.value = 1)
- INNER JOIN cataloginventory_stock_item csi ON cpe.entity_id = csi.product_id AND csi.qty > 0
- LEFT JOIN catalog_product_entity_varchar cpev_image
- on cpe.entity_id = cpev_image.entity_id AND cpev_image.attribute_id = 74
- LEFT JOIN catalog_product_entity_decimal cped_price
- on cpe.entity_id = cped_price.entity_id AND cped_price.attribute_id = 64
- WHERE cpe.is_uk = ", case storeId WHEN 2 THEN "1 " ELSE "0 " END,
- "ORDER by cped_price.value ",case priceOrder WHEN 0 THEN "asc " ELSE "desc " END,
- "LIMIT ",skipNum,",",getNum);
- PREPARE stmt FROM @str_sql;
- EXECUTE stmt;
- drop temporary table near_zip;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_REWARDS_BY_KEYWORD` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_REWARDS_BY_KEYWORD`(custId int(11), keyword varchar(255), getNum int(11), skipNum int(11), priceOrder bool, ilt FLOAT, ilg FLOAT)
- BEGIN
- DECLARE zips_seq VARCHAR(8000) DEFAULT '\'X\'';
- DECLARE one_zip VARCHAR(255);
- DECLARE one_distance DOUBLE;
- DECLARE l_last_row_fetched INT;
- DECLARE storeId INT;
- DECLARE near_zip_cur CURSOR FOR
- SELECT zip, distance
- FROM near_zip;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_last_row_fetched=1;
- drop temporary table if exists near_zip;
- create temporary table near_zip(zip varchar(10), distance double);
- insert into near_zip(zip, distance)
- SELECT ra.zip AS zip, (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) AS distance
- FROM zip_geo ra
- WHERE (((acos(sin((ilt*pi()/180)) * sin((latitude*pi()/180)) + cos((ilt*pi()/180)) * cos((latitude*pi()/180)) * cos(((ilg-longitude)*pi()/180))))*180/pi())*60*1.1515) <= 30
- ORDER BY 2
- LIMIT 200;
- SET l_last_row_fetched=0;
- OPEN near_zip_cur;
- zip_loop: LOOP
- FETCH near_zip_cur INTO one_zip, one_distance;
- IF l_last_row_fetched = 1 THEN
- LEAVE zip_loop;
- END IF;
- SET zips_seq = CONCAT(zips_seq, ',\'', one_zip, '\'');
- END LOOP zip_loop;
- SET l_last_row_fetched = 0;
- CLOSE near_zip_cur;
- SELECT store_id
- FROM customer_entity
- WHERE entity_id = custId
- INTO storeId;
- SET @str_sql=concat(
- "SELECT cpe.entity_id as `id`
- ,cpev_name.value as `name`
- ,cpev_image.value as `image`
- ,cped_price.value as `price`
- ,pe.name as `sponsor_name`
- FROM
- catalog_product_entity cpe
- INNER JOIN partners_entity pe on cpe.partner_id = pe.id
- INNER JOIN catalog_product_entity_varchar cpev_name
- on cpe.entity_id = cpev_name.entity_id AND cpev_name.attribute_id = 60 AND cpev_name.value like '%",keyword,"%'
- INNER JOIN catalog_product_entity_int cpei ON cpe.entity_id = cpei.entity_id AND cpei.attribute_id = 442 AND cpei.store_id = 0 AND
- (EXISTS (SELECT * FROM partners_local_rewards_stores AS plrs INNER JOIN partners_reward_address AS pra ON plrs.store_id = pra.id WHERE cpe.entity_id = plrs.product_id AND pra.post_code IN (", zips_seq, ")) or cpei.value = 1)
- INNER JOIN cataloginventory_stock_item csi ON cpe.entity_id = csi.product_id AND csi.qty > 0
- LEFT JOIN catalog_product_entity_varchar cpev_image
- on cpe.entity_id = cpev_image.entity_id AND cpev_image.attribute_id = 74
- LEFT JOIN catalog_product_entity_decimal cped_price
- on cpe.entity_id = cped_price.entity_id AND cped_price.attribute_id = 64
- WHERE cpe.is_uk = ", case storeId WHEN 2 THEN "1 " ELSE "0 " END,
- "ORDER by cped_price.value ",case priceOrder WHEN 0 THEN "asc " ELSE "desc " END,
- "LIMIT ",skipNum,",",getNum);
- PREPARE stmt FROM @str_sql;
- EXECUTE stmt;
- drop temporary table near_zip;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_REWARDS_CATEGORIES` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_REWARDS_CATEGORIES`()
- BEGIN
- DECLARE storeId smallint(5) DEFAULT 0;
- DECLARE category_name_attribute_id int DEFAULT 33;
- DECLARE category_image_attribute_id int DEFAULT 37;
- SELECT cce.entity_id AS 'category_id',
- ccev_name.value AS 'category_name',
- ccev_image.value AS 'category_image'
- FROM catalog_category_entity cce
- INNER JOIN catalog_category_entity_varchar ccev_name
- ON cce.entity_id = ccev_name.entity_id
- AND ccev_name.attribute_id = category_name_attribute_id
- AND ccev_name.store_id = storeId
- LEFT OUTER JOIN catalog_category_entity_varchar ccev_image
- ON cce.entity_id = ccev_image.entity_id
- AND ccev_image.attribute_id = category_image_attribute_id
- AND ccev_image.store_id = storeId
- WHERE cce.parent_id = 11 and ccev_name.value NOT RLIKE '^_';
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_REWARDS_CATEGORIES_TEST` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_REWARDS_CATEGORIES_TEST`(custId int(11))
- BEGIN
- DECLARE defStoreId SMALLINT(6) DEFAULT 0;
- DECLARE custStoreId SMALLINT(6) DEFAULT 0;
- DECLARE category_name_attribute_id int DEFAULT 33;
- DECLARE category_image_attribute_id int DEFAULT 37;
- SELECT ce.store_id
- INTO custStoreId
- FROM customer_entity ce
- WHERE entity_id = custId;
- SELECT cce.entity_id AS 'category_id',
- COALESCE(ccev_name_cust_store.value, ccev_name_def_store.value) AS 'category_name',
- COALESCE(ccev_image_cust_store.value, ccev_image_def_store.value) AS 'category_image'
- FROM catalog_category_entity cce
- LEFT OUTER JOIN catalog_category_entity_varchar ccev_name_def_store
- ON cce.entity_id = ccev_name_def_store.entity_id
- AND ccev_name_def_store.attribute_id = category_name_attribute_id
- AND ccev_name_def_store.store_id = defStoreId
- LEFT OUTER JOIN catalog_category_entity_varchar ccev_name_cust_store
- ON cce.entity_id = ccev_name_cust_store.entity_id
- AND ccev_name_cust_store.attribute_id = category_name_attribute_id
- AND ccev_name_def_store.store_id = custStoreId
- LEFT OUTER JOIN catalog_category_entity_varchar ccev_image_def_store
- ON cce.entity_id = ccev_image_def_store.entity_id
- AND ccev_image_def_store.attribute_id = category_image_attribute_id
- AND ccev_image_def_store.store_id = defStoreId
- LEFT OUTER JOIN catalog_category_entity_varchar ccev_image_cust_store
- ON cce.entity_id = ccev_image_cust_store.entity_id
- AND ccev_image_cust_store.attribute_id = category_image_attribute_id
- AND ccev_image_cust_store.store_id = custStoreId
- WHERE cce.parent_id = 11
- AND COALESCE(ccev_name_cust_store.value, ccev_name_def_store.value) NOT RLIKE '^_'
- AND EXISTS (SELECT 1
- FROM catalog_product_entity cpe
- INNER JOIN catalog_category_product ccp on cpe.entity_id = ccp.product_id
- WHERE ccp.category_id = cce.entity_id)
- ;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_REWARDS_THEMES` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_REWARDS_THEMES`()
- BEGIN
- DECLARE storeId smallint(5) DEFAULT 0;
- DECLARE name_attribute_id int DEFAULT 33;
- DECLARE image_attribute_id int DEFAULT 37;
- SELECT cce_child.entity_id AS 'theme_id',
- ccev_child_name.value AS 'theme_name',
- ccev_child_image.value AS 'theme_image'
- FROM catalog_category_entity cce_parent
- INNER JOIN catalog_category_entity_varchar ccev_parent_name
- ON cce_parent.entity_id = ccev_parent_name.entity_id
- AND ccev_parent_name.attribute_id = name_attribute_id
- AND ccev_parent_name.store_id = storeId
- INNER JOIN catalog_category_entity cce_child
- ON cce_parent.entity_id = cce_child.parent_id
- INNER JOIN catalog_category_entity_varchar ccev_child_name
- ON cce_child.entity_id = ccev_child_name.entity_id
- AND ccev_child_name.attribute_id = name_attribute_id
- AND ccev_child_name.store_id = storeId
- LEFT OUTER JOIN catalog_category_entity_varchar ccev_child_image
- ON cce_child.entity_id = ccev_child_image.entity_id
- AND ccev_child_image.attribute_id = image_attribute_id
- AND ccev_child_image.store_id = storeId
- WHERE cce_parent.parent_id = 11 and ccev_parent_name.value = '_Themes';
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_REWARD_DETAILS_BY_ID` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_REWARD_DETAILS_BY_ID`(rewardId int(11))
- BEGIN
- DECLARE today DATE DEFAULT DATE(NOW());
- SELECT cpe.entity_id AS `id`,
- CASE cpe.type_id
- WHEN 'reward_printathome' THEN 'Print At Home'
- WHEN 'reward_rewardmailer' THEN 'Reward Mailer'
- WHEN 'reward_online' THEN 'Online'
- WHEN 'reward_partnerfulfilled' THEN 'Donations'
- ELSE cpe.type_id
- END AS `type`,
- cpev_name.value AS `name`,
- cpev_image.value AS `image`,
- CASE
- WHEN
- cped_sp.value IS NOT NULL
- AND (cped_sp_sd.value IS NULL OR cped_sp_sd.value <= today)
- AND (cped_sp_ed.value IS NULL OR cped_sp_ed.value >= today)
- THEN cped_sp.value
- ELSE cped_p.value
- END AS `price`,
- pe.name AS `sponsor_name`,
- cpev_shdesc.value AS `short_description`,
- cpev_desc.value AS `description`,
- cpev_term.value AS `terms`
- FROM
- catalog_product_entity cpe
- INNER JOIN partners_entity pe ON cpe.partner_id = pe.id
- INNER JOIN catalog_product_entity_varchar cpev_name
- ON cpe.entity_id = cpev_name.entity_id AND cpev_name.attribute_id = 60
- LEFT JOIN catalog_product_entity_varchar cpev_image
- ON cpe.entity_id = cpev_image.entity_id AND cpev_image.attribute_id = 74
- LEFT JOIN catalog_product_entity_text cpev_desc
- ON cpe.entity_id = cpev_desc.entity_id AND cpev_desc.attribute_id = 61
- LEFT JOIN catalog_product_entity_text cpev_shdesc
- ON cpe.entity_id = cpev_shdesc.entity_id AND cpev_shdesc.attribute_id = 62
- LEFT JOIN catalog_product_entity_text cpev_term
- ON cpe.entity_id = cpev_term.entity_id AND cpev_term.attribute_id = 498
- LEFT JOIN catalog_product_entity_decimal cped_p
- ON cpe.entity_id = cped_p.entity_id AND cped_p.attribute_id = 64
- LEFT JOIN catalog_product_entity_decimal cped_sp
- ON cpe.entity_id = cped_sp.entity_id AND cped_sp.attribute_id = 468
- LEFT JOIN catalog_product_entity_datetime cped_sp_sd
- ON cpe.entity_id = cped_sp_sd.entity_id AND cped_sp_sd.attribute_id = 466
- LEFT JOIN catalog_product_entity_datetime cped_sp_ed
- ON cpe.entity_id = cped_sp_ed.entity_id AND cped_sp_ed.attribute_id = 467
- WHERE cpe.entity_id = rewardId;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_STATES` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_STATES`(custId int(11))
- BEGIN
- DECLARE default_store_id INT(11) DEFAULT 0;
- DECLARE country_config_path VARCHAR(255) DEFAULT 'general/country/default';
- DECLARE country_stores_scope VARCHAR(255) DEFAULT 'stores';
- DECLARE country_default_scope VARCHAR(255) DEFAULT 'default';
- DECLARE cust_country_id VARCHAR(4) DEFAULT '';
- DECLARE cust_store_id INT(6);
- DECLARE country_scope VARCHAR(255) DEFAULT country_stores_scope;
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET cust_country_id = '';
- SELECT cae_country.value
- INTO cust_country_id
- FROM customer_entity ce
- INNER JOIN customer_address_entity cae
- ON ce.entity_id = cae.parent_id
- INNER JOIN customer_address_entity_varchar cae_country
- ON cae.entity_id = cae_country.entity_id AND cae_country.attribute_id = 26
- WHERE ce.entity_id = custId;
- END;
- IF (cust_country_id IS NULL OR TRIM(cust_country_id) = '') THEN
- SELECT ce.store_id
- INTO cust_store_id
- FROM customer_entity ce
- WHERE ce.entity_id = custId;
- IF NOT EXISTS
- (
- SELECT 1
- FROM core_config_data ccd
- WHERE
- ccd.path = country_config_path
- AND ccd.scope = country_scope
- AND ccd.scope_id = cust_store_id
- )
- THEN
- SET cust_store_id = default_store_id;
- SET country_scope = country_default_scope;
- END IF;
- SELECT ccd.value
- INTO cust_country_id
- FROM core_config_data ccd
- WHERE ccd.path = country_config_path AND ccd.scope_id = cust_store_id AND ccd.scope = country_scope;
- END IF;
- SELECT
- dcr.region_id AS 'state_id',
- dcr.default_name AS 'state_name'
- FROM directory_country_region dcr
- WHERE dcr.country_id = cust_country_id
- ORDER BY dcr.default_name ASC;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_BY_FACEBOOK_ID` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_BY_FACEBOOK_ID`(fbId varchar(255))
- BEGIN
- SELECT ce.entity_id AS 'id',
- ce.email AS 'username',
- ce.account_number AS 'account_number',
- NOT EXISTS (SELECT 1 FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 16) AS 'is_confirmed',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 12) AS 'password_hash',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 5) AS 'first_name',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 7) AS 'last_name',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 217) AS 'contact_id',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 224) AS 'account_id',
- (SELECT cb.amount FROM enterprise_customerbalance cb WHERE cb.customer_id = ce.entity_id) AS 'points',
- cae_country.value AS 'country',
- ce.is_active AS 'account_status',
- 19.47 AS 'saved_trees',
- 24.93 AS 'saved_oil'
- FROM customer_entity ce
- INNER JOIN customer_entity_varchar cev_fb ON ce.entity_id = cev_fb.entity_id AND cev_fb.attribute_id = 303
- LEFT JOIN customer_address_entity cae ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_varchar cae_country ON cae.entity_id = cae_country.entity_id AND cae_country.attribute_id = 26
- WHERE cev_fb.value = fbId AND ce.is_active = 1;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_BY_ID` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_BY_ID`(userId int(11))
- BEGIN
- SELECT ce.entity_id AS 'id',
- ce.email AS 'username',
- ce.account_number AS 'account_number',
- NOT EXISTS (SELECT 1 FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 16) AS 'is_confirmed',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 12) AS 'password_hash',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 5) AS 'first_name',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 7) AS 'last_name',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 217) AS 'contact_id',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 224) AS 'account_id',
- (SELECT cb.amount FROM enterprise_customerbalance cb WHERE cb.customer_id = ce.entity_id) AS 'points',
- cae_country.value AS 'country',
- ce.is_active AS 'account_status',
- 19.47 AS 'saved_trees',
- 24.93 AS 'saved_oil'
- FROM customer_entity ce
- LEFT JOIN customer_address_entity cae ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_varchar cae_country ON cae.entity_id = cae_country.entity_id AND cae_country.attribute_id = 26
- WHERE ce.entity_id = userId AND ce.is_active = 1;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_BY_LOGIN` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_BY_LOGIN`(login VARCHAR(255))
- BEGIN
- SELECT ce.entity_id AS 'id',
- ce.email AS 'username',
- ce.account_number AS 'account_number',
- NOT EXISTS (SELECT 1 FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 16) AS 'is_confirmed',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 12) AS 'password_hash',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 5) AS 'first_name',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 7) AS 'last_name',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 217) AS 'contact_id',
- (SELECT cev.value FROM customer_entity_varchar cev WHERE cev.entity_id = ce.entity_id AND cev.attribute_id = 224) AS 'account_id',
- (SELECT cb.amount FROM enterprise_customerbalance cb WHERE cb.customer_id = ce.entity_id) AS 'points',
- cae_country.value AS 'country',
- ce.is_active AS 'account_status',
- 19.47 AS 'saved_trees',
- 24.93 AS 'saved_oil'
- FROM customer_entity ce
- LEFT JOIN customer_address_entity cae ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_varchar cae_country ON cae.entity_id = cae_country.entity_id AND cae_country.attribute_id = 26
- WHERE ce.email = login AND ce.is_active = 1;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_COORD` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_COORD`(izip VARCHAR(10), OUT lt FLOAT, OUT lg FLOAT)
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- BEGIN
- SET lt = 0;
- SET lg = 0;
- END;
- SELECT zg.latitude, zg.longitude
- FROM zip_geo zg
- WHERE zg.zip = izip
- INTO lt, lg;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_DETAILS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_DETAILS`(userId int(11))
- BEGIN
- SELECT
- ce.entity_id AS 'id',
- ce.email AS 'username',
- ce.store_id AS 'store_id',
- cae_country.value AS 'country',
- cae_region.value AS 'state',
- cae_city.value AS 'city',
- cae_postcode.value AS 'postal_code',
- YEAR(CURDATE()) - YEAR(cp.customer_age_range) -
- CASE
- WHEN MONTH(CURDATE()) > MONTH(cp.customer_age_range) THEN 0
- WHEN MONTH(CURDATE()) < MONTH(cp.customer_age_range) THEN 1
- WHEN DAYOFMONTH(CURDATE()) >= DAYOFMONTH(cp.customer_age_range) THEN 0
- ELSE 1
- END AS 'age',
- CASE
- WHEN ca.customer_children > 0 THEN true
- WHEN ca.customer_children = 0 THEN false
- ELSE null
- END AS 'is_parent',
- CASE
- WHEN ca.customer_homeowner = 0 THEN false
- WHEN ca.customer_homeowner = 1 THEN true
- ELSE null
- END AS 'is_home_owner',
- CASE
- WHEN cp.customer_gender = 0 THEN 'female'
- WHEN cp.customer_gender = 1 THEN 'male'
- ELSE null
- END AS 'gender'
- FROM customer_entity ce
- LEFT JOIN customer_address_entity cae
- ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_varchar cae_city
- ON cae.entity_id = cae_city.entity_id AND cae_city.attribute_id = 25
- LEFT JOIN customer_address_entity_varchar cae_region
- ON cae.entity_id = cae_region.entity_id AND cae_region.attribute_id = 27
- LEFT JOIN customer_address_entity_varchar cae_postcode
- ON cae.entity_id = cae_postcode.entity_id AND cae_postcode.attribute_id = 29
- LEFT JOIN customer_address_entity_varchar cae_country
- ON cae.entity_id = cae_country.entity_id AND cae_country.attribute_id = 26
- LEFT JOIN customer_additional ca ON ce.entity_id = ca.customer_id
- LEFT JOIN customer_personal cp ON ce.entity_id = cp.customer_id
- WHERE ce.entity_id = userId;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_MAILING_ADDRESS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_MAILING_ADDRESS`(accNumber varchar(255))
- BEGIN
- DECLARE delim CHAR(1) DEFAULT '\n';
- SELECT
- SUBSTRING_INDEX(cae_street.value, delim, 1) AS 'street',
- SUBSTRING_INDEX(SUBSTRING(cae_street.value, LENGTH(SUBSTRING_INDEX(cae_street.value, delim, 1)) + LENGTH(delim) + 1), delim, 1) AS 'unit',
- cae_city.value AS 'city',
- cae_region.value AS 'state',
- cae_postcode.value AS 'postal_code',
- cae_country.value AS 'country'
- FROM customer_entity ce
- LEFT JOIN customer_address_entity cae
- ON ce.entity_id = cae.parent_id
- LEFT JOIN customer_address_entity_text cae_street
- ON cae.entity_id = cae_street.entity_id AND cae_street.attribute_id = 24
- LEFT JOIN customer_address_entity_varchar cae_city
- ON cae.entity_id = cae_city.entity_id AND cae_city.attribute_id = 25
- LEFT JOIN customer_address_entity_varchar cae_region
- ON cae.entity_id = cae_region.entity_id AND cae_region.attribute_id = 27
- LEFT JOIN customer_address_entity_varchar cae_postcode
- ON cae.entity_id = cae_postcode.entity_id AND cae_postcode.attribute_id = 29
- LEFT JOIN customer_address_entity_varchar cae_country
- ON cae.entity_id = cae_country.entity_id AND cae_country.attribute_id = 26
- WHERE ce.account_number = accNumber;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_GET_USER_ZIP_CODE` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_GET_USER_ZIP_CODE`(custId INT(11), OUT ozip VARCHAR(255))
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET ozip = "";
- SELECT cae_postcode.value
- FROM customer_entity ce
- INNER JOIN customer_address_entity cae
- ON ce.entity_id = cae.parent_id
- INNER JOIN customer_address_entity_varchar cae_postcode
- ON cae.entity_id = cae_postcode.entity_id AND cae_postcode.attribute_id = 29
- WHERE ce.entity_id = custId
- INTO ozip;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_SET_ZIP_COORD` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_SET_ZIP_COORD`(izip varchar(10), ilt FLOAT, ilg FLOAT)
- BEGIN
- INSERT INTO zip_geo (`zip`, `latitude`, `longitude`) VALUES (izip, ilt, ilg);
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_UPDATE_AD_SHOWN_TIME` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_UPDATE_AD_SHOWN_TIME`(in recordId int(11), in showTime int(11))
- BEGIN
- UPDATE mobile_ad_histories
- SET show_time = showTime,
- updated_at = now()
- WHERE record_id = recordId;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MOBILE_UPDATE_USER_MAILING_ADDRESS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MOBILE_UPDATE_USER_MAILING_ADDRESS`(
- iacc_num varchar(255),
- icountry varchar(255),
- istate varchar(255),
- icity varchar(255),
- istreet varchar(255),
- iunit varchar(255),
- ipostal_code varchar(255),
- out success boolean)
- BEGIN
- DECLARE delim CHAR(1) DEFAULT '\n';
- DECLARE custId INT(11);
- DECLARE addrId INT(11);
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET custId = -1;
- SET success = 0;
- SELECT ce.entity_id
- FROM customer_entity ce
- WHERE ce.account_number = iacc_num
- INTO custId;
- IF custId <> -1
- THEN
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET addrId = -1;
- SELECT cae.entity_id
- FROM customer_entity ce
- INNER JOIN customer_address_entity cae ON ce.entity_id = cae.parent_id
- WHERE ce.entity_id = custId
- INTO addrId;
- IF addrId = -1
- THEN
- INSERT INTO customer_address_entity(entity_type_id, attribute_set_id, increment_id, parent_id, is_active)
- VALUES(2, 0, '', custId, 1);
- SELECT LAST_INSERT_ID() INTO addrId;
- INSERT INTO customer_entity_int(entity_type_id, attribute_id, entity_id, value)
- VALUES (1, 13, custId, addrId),(1, 14, custId, addrId);
- END IF;
- END;
- IF icountry IS NOT NULL
- THEN
- BEGIN
- DECLARE countryId INT(11);
- DECLARE countryAttrId SMALLINT(6) DEFAULT 26;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET countryId = -1;
- SELECT value_id
- FROM customer_address_entity_varchar
- WHERE entity_id = addrId AND attribute_id = countryAttrId
- INTO countryId;
- IF countryId <> - 1
- THEN
- UPDATE customer_address_entity_varchar
- SET value = icountry
- WHERE value_id = countryId;
- ELSE
- INSERT INTO customer_address_entity_varchar(entity_type_id, attribute_id, entity_id, value)
- VALUES(2, countryAttrId, addrId, icountry);
- END IF;
- END;
- END IF;
- IF istate IS NOT NULL
- THEN
- BEGIN
- DECLARE stateId INT(11);
- DECLARE stateAttrId SMALLINT(6) DEFAULT 27;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET stateId = -1;
- SELECT value_id
- FROM customer_address_entity_varchar
- WHERE entity_id = addrId AND attribute_id = stateAttrId
- INTO stateId;
- IF stateId <> - 1
- THEN
- UPDATE customer_address_entity_varchar
- SET value = istate
- WHERE value_id = stateId;
- ELSE
- INSERT INTO customer_address_entity_varchar(entity_type_id, attribute_id, entity_id, value)
- VALUES(2, stateAttrId, addrId, istate);
- END IF;
- END;
- END IF;
- IF icity IS NOT NULL
- THEN
- BEGIN
- DECLARE cityId INT(11);
- DECLARE cityAttrId SMALLINT(6) DEFAULT 25;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET cityId = -1;
- SELECT value_id
- FROM customer_address_entity_varchar
- WHERE entity_id = addrId AND attribute_id = cityAttrId
- INTO cityId;
- IF cityId <> - 1
- THEN
- UPDATE customer_address_entity_varchar
- SET value = icity
- WHERE value_id = cityId;
- ELSE
- INSERT INTO customer_address_entity_varchar(entity_type_id, attribute_id, entity_id, value)
- VALUES(2, cityAttrId, addrId, icity);
- END IF;
- END;
- END IF;
- IF istreet IS NOT NULL OR iunit IS NOT NULL
- THEN
- BEGIN
- DECLARE streetId INT(11);
- DECLARE streetAttrId SMALLINT(6) DEFAULT 24;
- DECLARE streetUnit VARCHAR(255) DEFAULT '';
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET streetId = -1;
- SELECT value_id
- FROM customer_address_entity_text
- WHERE entity_id = addrId AND attribute_id = streetAttrId
- INTO streetId;
- IF streetId <> - 1
- THEN
- IF istreet IS NOT NULL AND iunit IS NOT NULL
- THEN
- UPDATE customer_address_entity_text
- SET value = CONCAT(istreet, delim, iunit, SUBSTRING(value, LENGTH(SUBSTRING_INDEX(value, delim, 2)) + 1))
- WHERE value_id = streetId;
- ELSE
- IF istreet IS NOT NULL
- THEN
- UPDATE customer_address_entity_text
- SET value = CONCAT(istreet, SUBSTRING(value, LENGTH(SUBSTRING_INDEX(value, delim, 1)) + 1))
- WHERE value_id = streetId;
- ELSE
- IF iunit IS NOT NULL
- THEN
- UPDATE customer_address_entity_text
- SET value = CONCAT(SUBSTRING_INDEX(value, delim, 1), delim, iunit, SUBSTRING(value, LENGTH(SUBSTRING_INDEX(value, delim, 2)) + 1))
- WHERE value_id = streetId;
- END IF;
- END IF;
- END IF;
- ELSE
- IF istreet IS NOT NULL
- THEN
- SET streetUnit = CONCAT(streetUnit, istreet);
- END IF;
- SET streetUnit = CONCAT(streetUnit, delim);
- IF iunit IS NOT NULL
- THEN
- SET streetUnit = CONCAT(streetUnit, iunit);
- END IF;
- INSERT INTO customer_address_entity_text(entity_type_id, attribute_id, entity_id, value)
- VALUES(2, streetAttrId, addrId, streetUnit);
- END IF;
- END;
- END IF;
- IF ipostal_code IS NOT NULL
- THEN
- BEGIN
- DECLARE postalCodeId INT(11);
- DECLARE postalCodeAttrId SMALLINT(6) DEFAULT 29;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET postalCodeId = -1;
- SELECT value_id
- FROM customer_address_entity_varchar
- WHERE entity_id = addrId AND attribute_id = postalCodeAttrId
- INTO postalCodeId;
- IF postalCodeId <> - 1
- THEN
- UPDATE customer_address_entity_varchar
- SET value = ipostal_code
- WHERE value_id = postalCodeId;
- ELSE
- INSERT INTO customer_address_entity_varchar(entity_type_id, attribute_id, entity_id, value)
- VALUES(2, postalCodeAttrId, addrId, ipostal_code);
- END IF;
- END;
- END IF;
- SET success = 1;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MS_CREATE_CUST_ERROR` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MS_CREATE_CUST_ERROR`(i_cust_id INT(11), i_error_id VARCHAR(255), i_message VARCHAR(255), i_description VARCHAR(255))
- BEGIN
- INSERT INTO ms_errors(cust_id, error_id, message, description)
- VALUES (i_cust_id, i_error_id, i_message, i_description);
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MS_GET_REMINDER_USERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MS_GET_REMINDER_USERS`(IN `custId` int(11))
- BEGIN
- SELECT now() INTO @curr_dt;
- SELECT case WHEN DAYOFWEEK(@curr_dt) = 1 THEN 7 ELSE DAYOFWEEK(@curr_dt)-1 END INTO @dofw;
- SELECT
- case
- WHEN mod((WEEK(@curr_dt, 5) -
- WEEK(DATE_SUB(@curr_dt, INTERVAL DAYOFMONTH(@curr_dt) - 1 DAY), 5) + 1) ,2 ) = 0
- THEN 1
- ELSE 0
- END
- INTO @d_even_odd;
- SELECT `sr`.`frequency_type` AS `frequency_type`,
- `sr`.`day_of_week` AS `day_of_week`,
- `sr`.`day_of_month` AS `day_of_month`,
- `ce`.`entity_id` AS `id`,
- `ce`.`email`,
- `ce`.`store_id`,
- `fname_table`.`value` AS `first_name`,
- `lname_table`.`value` AS `last_name`
- FROM `customer_self_reporting` AS `sr`
- LEFT JOIN `customer_entity` ce ON `sr`.customer_id = ce.entity_id
- LEFT JOIN `customer_entity_varchar` AS `fname_table` ON fname_table.entity_id = sr.customer_id AND fname_table.attribute_id = 5
- LEFT JOIN `customer_entity_varchar` AS `lname_table` ON lname_table.entity_id = sr.customer_id AND lname_table.attribute_id = 7
- LEFT JOIN customer_entity_varchar cev_confirm ON cev_confirm.entity_id = ce.entity_id AND cev_confirm.attribute_id = 16
- WHERE
- coalesce(sr.start_date,date('0000-00-00'))<> date('0000-00-00') AND sr.start_date<=now()
- AND
- CASE
- WHEN custId IS NOT null
- THEN ce.entity_id > custId
- ELSE 1=1
- END
- AND cev_confirm.value_id IS NULL
- AND (sr.is_active = 1
- AND
- (
- (sr.frequency_type = 1 AND sr.day_of_week = @dofw)
- OR (sr.frequency_type = 2 AND
- case
- WHEN
- MOD( DATEDIFF(@curr_dt ,sr.start_date ) ,14) =0
- THEN 1
- ELSE 0
- END = 1
- )
- OR (sr.frequency_type = 3
- AND
- (sr.day_of_month = DAYOFMONTH(@curr_dt)
- OR case
- WHEN DAYOFMONTH(LAST_DAY(@curr_dt)) > 27 AND DAYOFMONTH(LAST_DAY(@curr_dt)) < 31
- THEN sr.day_of_month > date(@curr_dt)
- ELSE 1=0 END
- )
- )
- ))
- ORDER BY ce.entity_id ASC;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MT_CREATE_CUST_ERROR` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MT_CREATE_CUST_ERROR`(i_cust_id INT(11), i_error_id VARCHAR(255), i_message VARCHAR(255), i_description VARCHAR(255))
- BEGIN
- INSERT INTO mt_errors(cust_id, error_id, message, description)
- VALUES (i_cust_id, i_error_id, i_message, i_description);
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `MT_GET_LAST_WEEK_TRANSACTIONS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `MT_GET_LAST_WEEK_TRANSACTIONS`(IN `custId` INT(11))
- BEGIN
- DECLARE start_date_criteria DATETIME DEFAULT DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-%d'), INTERVAL -7 DAY);
- DECLARE end_date_criteria DATETIME DEFAULT DATE_FORMAT(NOW(), '%Y-%m-%d');
- DROP TABLE IF EXISTS ttemp_all_transactions;
- CREATE TEMPORARY TABLE ttemp_all_transactions
- SELECT
- cbh.history_id,
- cbh.balance_id,
- cbh.additional_info,
- REPLACE(cbh.additional_info, 'Order #', '') AS increment_id,
- cbh.reason_id,
- cbh.description,
- cbh.balance_delta,
- cbh.balance_amount,
- cbh.updated_at
- FROM enterprise_customerbalance_history cbh
- WHERE cbh.updated_at BETWEEN start_date_criteria AND end_date_criteria;
- DROP TABLE IF EXISTS ttemp_search_transactions;
- CREATE TEMPORARY TABLE ttemp_search_transactions AS
- SELECT * FROM ttemp_all_transactions tst
- WHERE
- CASE WHEN reason_id = 12
- THEN
- NOT EXISTS (
- SELECT 1
- FROM sales_flat_order sfo
- WHERE sfo.increment_id = tst.increment_id
- AND EXISTS (
- SELECT 1
- FROM sales_flat_quote sfq
- WHERE sfq.entity_id = sfo.quote_id AND sfq.is_reordered = 1)
- )
- ELSE 1= 1
- END
- ;
- ALTER TABLE ttemp_search_transactions ADD INDEX ix_ttttt_tr_balance(balance_id);
- SELECT ce.entity_id AS 'cust_id',
- ce.store_id AS 'store_id',
- ce.email AS 'email',
- cb.amount AS 'balance',
- cbh.history_id AS 'trans_id',
- cbh.balance_delta AS 'points',
- CASE
- WHEN cbh.description IS NOT NULL
- THEN cbh.description
- WHEN cbh.additional_info IS NOT NULL
- THEN CONCAT('Reward ', cbh.additional_info)
- ELSE
- cbr.reason_code
- END AS 'reason',
- cbh.updated_at AS 'date'
- FROM ttemp_search_transactions cbh
- INNER JOIN enterprise_customerbalance cb ON cb.balance_id = cbh.balance_id
- INNER JOIN customer_entity ce ON ce.entity_id = cb.customer_id
- LEFT OUTER JOIN enterprise_customerbalance_reasons cbr ON cbr.id = cbh.reason_id
- LEFT OUTER JOIN customer_entity_varchar cev_confirm ON cev_confirm.entity_id = ce.entity_id AND cev_confirm.attribute_id = 16
- WHERE
- CASE
- WHEN custId IS NOT NULL
- THEN ce.entity_id > custId
- ELSE 1=1
- END
- AND cev_confirm.value_id IS NULL
- AND TRIM(ce.email) <> ''
- ORDER BY ce.entity_id, cbh.updated_at DESC;
- DROP TABLE IF EXISTS ttemp_search_transactions;
- DROP TABLE IF EXISTS ttemp_all_transactions;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `rsp_delete_transactions` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `rsp_delete_transactions`(
- IN ihistory_id int(10)
- )
- BEGIN
- SELECT ecb.balance_id,ecb.balance_delta
- INTO @sbalance_id,@sbalance_delta
- FROM enterprise_customerbalance_history ecb
- WHERE ecb.history_id = ihistory_id;
- START TRANSACTION;
- BEGIN
- declare exit handler for sqlexception rollback;
- UPDATE enterprise_customerbalance ec
- SET ec.amount = ec.amount - @sbalance_delta
- WHERE ec.balance_id = @sbalance_id;
- DELETE FROM enterprise_customerbalance_history
- WHERE history_id = ihistory_id;
- UPDATE enterprise_customerbalance_history ecb
- SET ecb.balance_amount = ecb.balance_amount - @sbalance_delta
- WHERE ecb.balance_id = @sbalance_id AND ecb.history_id > ihistory_id;
- END;
- COMMIT;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `rsp_del_transactions_cursor` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `rsp_del_transactions_cursor`()
- BEGIN
- declare done smallint;
- declare chistory_id int(10);
- DECLARE cursTR CURSOR FOR
- SELECT t.history_id FROM enterprise_customerbalance_history t
- WHERE history_id > 29695827
- AND (t.reason_id BETWEEN 7 AND 11 OR t.reason_id BETWEEN 25 AND 39)
- AND t.additional_info = 'ongoing migration'
- AND t.balance_id = 714220
- ORDER BY t.balance_id;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- OPEN cursTR;
- read_loop: LOOP
- FETCH cursTR INTO chistory_id;
- IF done THEN
- LEAVE read_loop;
- END IF;
- call rsp_delete_transactions(chistory_id);
- END LOOP;
- CLOSE cursTR;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `rsp_earn_partner_points_allocation` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`rb`@`%`*/ /*!50003 PROCEDURE `rsp_earn_partner_points_allocation`(IN inp_earn_partner TEXT, IN inp_start_date DATE, IN inp_end_date DATE)
- BEGIN
- DROP TABLE IF EXISTS temp_earn_partner;
- CREATE TEMPORARY TABLE temp_earn_partner(partner_id INT(10));
- CALL rsp_split_string(inp_earn_partner, ',');
- INSERT INTO temp_earn_partner
- SELECT * FROM temp_values;
- DROP TABLE temp_values;
- SELECT
- pe.NAME AS `earn_partner`
- ,pett.type_name AS `transaction_type`
- ,eph.transaction_description AS `earn_opportunity`
- ,ce.account_number
- ,ce.email
- ,cae_city.`value` AS `city`
- ,cae_region.`value` AS `state`
- ,pet.points AS `rb_points_allocated`
- ,DATE(pet.`time`) AS `transaction_date`
- ,TIME(pet.`time`) AS `transaction_time`
- ,DATE(inp_start_date) AS inp_start_date
- ,DATE(inp_end_date) AS inp_end_date
- FROM partners_earn_transactions pet
- INNER JOIN partners_earn_trans_type pett
- ON pett.`type` = pet.`type`
- INNER JOIN enterprise_customerbalance_history ecbh
- ON ecbh.history_id = pet.customer_balance_history_id
- INNER JOIN partners_entity pe
- ON pe.id = pet.partner_id
- AND pe.id IN (SELECT partner_id FROM temp_earn_partner )
- INNER JOIN partners_earn per
- ON per.partner_id = pe.id
- INNER JOIN customer_entity ce
- ON ce.entity_id = pet.customer_id
- INNER JOIN customer_address_entity cae
- ON cae.parent_id =ce.entity_id
- LEFT JOIN customer_address_entity_varchar cae_city
- ON cae_city.entity_id = cae.entity_id
- AND cae_city.attribute_id = 25
- LEFT JOIN customer_address_entity_varchar cae_region
- ON cae_region.entity_id = cae.entity_id
- AND cae_region.attribute_id = 28
- LEFT JOIN earn_plugin_hashes eph
- ON eph.transaction_description = pet.description
- WHERE
- DATE(pet.`time`) BETWEEN inp_start_date AND inp_end_date
- /*AND EXISTS ( SELECT 1 FROM enterprise_customerbalance_history ecbh
- WHERE ecbh.history_id = pet.customer_balance_history_id )
- */
- GROUP BY pet.id
- ;
- DROP TABLE IF EXISTS temp_earn_partner;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `SBB_GET_EMAIL_BY_NUMBER` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `SBB_GET_EMAIL_BY_NUMBER`(accNumber varchar(255), out iemail varchar(255))
- BEGIN
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET iemail = '';
- SELECT email
- FROM customer_entity
- WHERE account_number = accNumber
- INTO iemail;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `SBB_LOOKUP_GNOMY_MEMBER` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `SBB_LOOKUP_GNOMY_MEMBER`(IN iaccount_number varchar(255)
- ,IN ibaccount_number varchar(255)
- ,IN iemail varchar(255)
- ,IN iaddress1 varchar(255)
- ,IN iaddress2 varchar(255)
- ,IN icity varchar(255)
- ,IN istate_province varchar(255)
- ,IN ilocality varchar(255)
- )
- BEGIN
- DECLARE rrowcount int(10);
- declare oaccount_number varchar(255);
- declare opartner_member_account_number varchar(255);
- SET rrowcount =0;
- IF isnull(iaccount_number)=0 THEN
- SELECT SQL_CALC_FOUND_ROWS
- ce.account_number
- ,case WHEN cpe_name.value = 'Earn GConomy Card' THEN ecp.partner_member_account_number END
- INTO oaccount_number,opartner_member_account_number
- FROM
- customer_entity ce
- LEFT JOIN earns_customers ec
- on ce.entity_id = ec.customer_id
- LEFT JOIN catalog_product_entity cpe on cpe.entity_id = ec.product_id
- LEFT JOIN catalog_product_entity_varchar cpe_name
- on cpe.entity_id = cpe_name.entity_id AND cpe_name.attribute_id =60
- LEFT JOIN earns_customers_partners ecp
- on ec.id = ecp.earns_customers_id AND ecp.partner_id = cpe.partner_id
- WHERE ce.account_number = iaccount_number
- GROUP BY ce.account_number ;
- SET rrowcount = FOUND_ROWS();
- END IF;
- IF rrowcount > 0 THEN
- SELECT oaccount_number,opartner_member_account_number;
- ELSE
- IF isnull(ibaccount_number)=0 THEN
- SELECT SQL_CALC_FOUND_ROWS
- ce.account_number
- ,case WHEN cpe_name.value = 'Earn GConomy Card' THEN ecp.partner_member_account_number END
- INTO oaccount_number,opartner_member_account_number
- FROM
- customer_entity ce
- LEFT JOIN earns_customers ec
- on ce.entity_id = ec.customer_id
- LEFT JOIN catalog_product_entity cpe on cpe.entity_id = ec.product_id
- LEFT JOIN catalog_product_entity_varchar cpe_name
- on cpe.entity_id = cpe_name.entity_id AND cpe_name.attribute_id =60
- LEFT JOIN earns_customers_partners ecp
- on ec.id = ecp.earns_customers_id AND ecp.partner_id = cpe.partner_id
- WHERE ecp.partner_member_account_number = ibaccount_number
- GROUP BY ce.account_number
- ;
- SET rrowcount = FOUND_ROWS();
- END IF;
- IF rrowcount > 0 THEN
- SELECT oaccount_number,opartner_member_account_number;
- ELSE
- IF isnull(iemail)=0 THEN
- SELECT SQL_CALC_FOUND_ROWS distinct
- ce.account_number
- ,case WHEN cpe_name.value = 'Earn GConomy Card' THEN ecp.partner_member_account_number END
- INTO oaccount_number,opartner_member_account_number
- FROM
- customer_entity ce
- LEFT JOIN earns_customers ec
- on ce.entity_id = ec.customer_id
- LEFT JOIN catalog_product_entity cpe on cpe.entity_id = ec.product_id
- LEFT JOIN catalog_product_entity_varchar cpe_name
- on cpe.entity_id = cpe_name.entity_id AND cpe_name.attribute_id =60
- LEFT JOIN earns_customers_partners ecp
- on ec.id = ecp.earns_customers_id AND ecp.partner_id = cpe.partner_id
- WHERE ce.email = iemail
- GROUP BY ce.account_number;
- SET rrowcount = FOUND_ROWS();
- END IF;
- IF rrowcount > 0 THEN
- SELECT oaccount_number,opartner_member_account_number;
- ELSE
- IF iaddress1 is not null or iaddress2 is not null or icity is not null or istate_province is not null or ilocality is not null THEN
- SELECT
- ce.account_number as oaccount_number
- ,case WHEN cpe_name.value = 'Earn GConomy Card' THEN ecp.partner_member_account_number END
- as opartner_member_account_number
- FROM
- customer_entity ce
- LEFT JOIN earns_customers ec
- on ce.entity_id = ec.customer_id
- LEFT JOIN catalog_product_entity cpe on cpe.entity_id = ec.product_id
- LEFT JOIN catalog_product_entity_varchar cpe_name
- on cpe.entity_id = cpe_name.entity_id AND cpe_name.attribute_id =60
- LEFT JOIN earns_customers_partners ecp
- on ec.id = ecp.earns_customers_id AND ecp.partner_id = cpe.partner_id
- INNER JOIN customer_address_entity cae on ce.entity_id = cae.parent_id
- INNER JOIN magento_dev.customer_address_entity_text cae_street
- on cae.entity_id = cae_street.entity_id and cae_street.attribute_id = 24
- INNER JOIN customer_address_entity_varchar cae_city
- on cae.entity_id = cae_city.entity_id AND cae_city.attribute_id = 25
- INNER JOIN customer_address_entity_varchar cae_region
- on cae.entity_id = cae_region.entity_id AND cae_region.attribute_id = 27
- INNER JOIN customer_address_entity_varchar cae_postcode
- on cae.entity_id = cae_postcode.entity_id AND cae_postcode.attribute_id = 29
- WHERE
- ( case WHEN iaddress1 is not null and iaddress2 is not null
- THEN cae_street.value like concat('%',iaddress1,'%') and cae_street.value like concat('%',iaddress2,'%')
- WHEN iaddress1 is not null and iaddress2 is null
- THEN cae_street.value like concat('%',iaddress1,'%')
- WHEN iaddress1 is null and iaddress2 is not null
- THEN cae_street.value like concat('%',iaddress2,'%') ELSE 1=1 END
- )
- and case WHEN icity is not null THEN cae_city.value = icity ELSE 1=1 END
- and case WHEN istate_province is not null THEN cae_region.value = istate_province ELSE 1=1 END
- and case WHEN ilocality is not null THEN cae_postcode.value = ilocality ELSE 1=1 END
- GROUP BY ce.account_number;
- ELSE
- SELECT oaccount_number,opartner_member_account_number from dual where 1=0;
- END IF;
- END IF;
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `SBB_LOOKUP_MERCHANT` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `SBB_LOOKUP_MERCHANT`(
- IN igpartner_id int(11),
- IN istore_account_number VARCHAR(255),
- IN iname VARCHAR(255),
- IN isic INT(11)
- )
- BEGIN
- DECLARE rrowcount int(10);
- SET rrowcount =0;
- IF isnull(istore_account_number)=0 THEN
- SELECT SQL_CALC_FOUND_ROWS
- pramd_bonus.bonus_factor INTO @o_bonus_factor
- FROM partners_reward_address pra
- INNER JOIN partners_reward_address_merchant_data pramd
- on pramd.partner_reward_address_id = pra.id and pramd.merchant_id is not null
- INNER JOIN partners_reward_address_merchant_data pramd_bonus
- on pramd_bonus.partner_reward_address_id = pra.id and pramd_bonus.bonus_factor is not null
- WHERE pra.status =1
- AND pramd.merchant_id = istore_account_number
- AND pramd_bonus.bonus_factor <>0
- limit 1
- ;
- SET rrowcount = FOUND_ROWS();
- END IF;
- IF rrowcount =0 THEN
- IF (isnull(iname)=0 AND ISNULL(isic)=0 ) THEN
- SELECT SQL_CALC_FOUND_ROWS
- prmd_bonus.bonus_factor INTO @o_bonus_factor
- FROM partners_reward_merchant_data prmd_name
- INNER JOIN partners_reward_merchant_data prmd_category
- on prmd_category.partner_id = prmd_name.partner_id AND prmd_category.merchant_category_id is not null
- INNER JOIN partners_reward_merchant_data prmd_bonus
- on prmd_bonus.partner_id = prmd_name.partner_id AND prmd_bonus.bonus_factor is not null
- WHERE prmd_name.merchant_dba is not null
- AND
- prmd_category.merchant_category_id = isic
- AND locate(iname,prmd_name.merchant_dba)>0
- AND prmd_bonus.bonus_factor <> 0
- ORDER BY locate(iname,prmd_name.merchant_dba) asc
- limit 1
- ;
- SET rrowcount = FOUND_ROWS();
- END IF;
- END IF;
- IF rrowcount <>0 THEN
- SELECT @o_bonus_factor as bonus_factor;
- ELSE
- SELECT '' as bonus_factor FROM dual WHERE 1=0;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `SBB_SUBSCRIBE` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `SBB_SUBSCRIBE`(IN ipartner_id int(10),
- IN iaccount_number varchar(255),
- IN iemail varchar(255),
- IN ipartner_member_account_number varchar(255),
- IN irb_member_pwd varchar(255),
- OUT subs_id int(11),
- OUT reason varchar(255))
- BEGIN
- declare ipartner_name varchar(255);
- declare icustomer_id int(10);
- declare spartner_id int(10);
- declare sproduct_id int(10);
- declare searn_id int(10);
- SET searn_id =0;
- IF iaccount_number is not NULL THEN
- SELECT entity_id INTO icustomer_id
- FROM customer_entity ce WHERE account_number = iaccount_number;
- ELSE
- IF iemail is not NULL THEN
- SELECT entity_id INTO icustomer_id FROM customer_entity ce WHERE email = iemail;
- ELSE
- SET searn_id =0;
- SELECT 'please put account_number or email' INTO reason;
- SELECT searn_id INTO subs_id;
- END IF;
- END IF;
- IF isnull(icustomer_id) THEN
- SELECT searn_id INTO subs_id;
- SET searn_id =0;
- SELECT 'customer does not exists' INTO reason;
- SELECT searn_id INTO subs_id;
- ELSE
- SELECT pe.id INTO spartner_id FROM partners_entity pe
- INNER JOIN partners_earn per on pe.id = per.partner_id WHERE per.g_partner_id = ipartner_id ;
- IF isnull(spartner_id) THEN
- SET searn_id =0;
- SELECT 'partner does not exists' INTO reason;
- SELECT searn_id INTO subs_id;
- ELSE
- SELECT case spartner_id
- WHEN 2910 THEN 2954
- WHEN 2911 THEN 2955 END INTO sproduct_id ;
- IF isnull(sproduct_id) THEN
- SET searn_id =0;
- SELECT 'product for g_partner does not exists' INTO reason;
- SELECT searn_id INTO subs_id;
- ELSE
- IF not EXISTS (SELECT 1 FROM earns_customers ec
- INNER JOIN earns_customers_partners ecp ON ec.id = ecp.earns_customers_id
- WHERE ec.customer_id = icustomer_id AND ecp.partner_id = spartner_id
- AND case when ipartner_member_account_number is not null THEN
- ecp.partner_member_account_number = ipartner_member_account_number ELSE 1=1 END
- AND ec.end_date is null)
- THEN
- START TRANSACTION;
- BEGIN
- declare exit handler for sqlexception rollback;
- INSERT INTO earns_customers (customer_id,product_id,start_date)
- VALUES (icustomer_id,sproduct_id,now());
- SET searn_id = LAST_INSERT_ID();
- INSERT INTO earns_customers_partners
- (earns_customers_id,partner_id,partner_member_account_number)
- VALUES (searn_id,spartner_id,ipartner_member_account_number);
- SET searn_id = LAST_INSERT_ID();
- END;
- COMMIT;
- SELECT searn_id INTO subs_id;
- ELSE
- SET searn_id =0;
- SELECT 'customer alredy subscribed' INTO reason;
- SELECT searn_id INTO subs_id;
- END IF;
- END IF;
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `SBB_UNSUBSCRIBE` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `SBB_UNSUBSCRIBE`( IN ipartner_id int(10),
- IN iaccount_number varchar(255),
- IN ipartner_member_account_number varchar(255),
- OUT success tinyint(1),
- OUT reason varchar(255))
- BEGIN
- declare ipartner_name varchar(255);
- declare icustomer_id int(10);
- declare spartner_id int(10);
- IF iaccount_number is not NULL THEN
- SELECT entity_id INTO icustomer_id
- FROM customer_entity ce WHERE account_number = iaccount_number;
- ELSE
- SELECT 0,'please put account_number' INTO success,reason;
- END IF;
- IF isnull(icustomer_id) THEN
- SELECT 0,'customer does not exists' INTO success,reason;
- ELSE
- SELECT pe.id INTO spartner_id FROM partners_entity pe
- INNER JOIN partners_earn per on pe.id = per.partner_id WHERE per.g_partner_id = ipartner_id ;
- IF isnull(spartner_id) THEN
- SELECT 0,'partner does not exists' INTO success,reason;
- ELSE
- IF EXISTS (SELECT 1 FROM earns_customers ec
- INNER JOIN earns_customers_partners ecp
- ON ec.id = ecp.earns_customers_id
- WHERE ec.customer_id = icustomer_id AND ecp.partner_id = spartner_id
- AND case when ipartner_member_account_number is not null THEN
- ecp.partner_member_account_number = ipartner_member_account_number ELSE 1=1 END
- AND ec.end_date is null)
- THEN
- UPDATE
- earns_customers ec
- INNER JOIN earns_customers_partners ecp ON ec.id = ecp.earns_customers_id
- SET ec.end_date = now()
- WHERE ec.customer_id = icustomer_id AND ecp.partner_id = spartner_id
- AND case when ipartner_member_account_number is not null THEN
- ecp.partner_member_account_number = ipartner_member_account_number ELSE 1=1 END
- AND ec.end_date is null;
- SELECT ROW_COUNT() into @upd_rows;
- IF @upd_rows>0 THEN
- SELECT 1,'customer unsubscribed' INTO success,reason;
- ELSE
- SELECT 0,'unsucsess' INTO success,reason;
- END IF;
- ELSE
- SELECT 0,'can not find customer for unsubscribe' INTO success,reason;
- END IF;
- END IF;
- END IF;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `scramble_fields` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `scramble_fields`()
- BEGIN
- DECLARE letterBig nvarchar(100);
- DECLARE letterSmall nvarchar(100);
- drop table if exists temp_email_not_modified;
- create temporary table temp_email_not_modified(email nvarchar(255));
- insert into temp_email_not_modified(email)
- values(
- 'rb2.moc@gmail.com'),
- ('rb4.moc@gmail.com'),
- ('rbtest59@val.co.ua'),
- ('rbtest60@val.co.ua'),
- ('testovy.email@gmail.com'),
- ('v.yarmolatiy@gmail.com'),
- ('rbtest28@val.co.ua'),
- ('rbtest37@val.co.ua'),
- ('rbtest46@val.co.ua'),
- ('irynchatko@ukr.net'),
- ('irynchatko@gmail.com'),
- ('irynchatko123@gmail.com'),
- ('irynchatko1234@gmail.com'),
- ('somyk83@mail.ru'),
- ('mrs.hrystyna1@gmail.com'),
- ('hrystyna@gmail.com'),
- ('mrs.hrystyna@gmail.com'),
- ('heleneperekopskaya-uk@gmail.com'),
- ('heleneperekopskaya-us@gmail.com'),
- ('heleneperekopskaya+us@gmail.com'),
- ('heleneperekopskaya+uk@gmail.com'),
- ('petvova@yahoo.com'),
- ('petvova1@yahoo.com'),
- ('petrushkevych@yahoo.com');
- UPDATE contacts c
- INNER JOIN `contactings` l ON c.id = l.contact_id
- INNER JOIN `accounts` a ON l.contactable_id = a.id
- SET c.first_name = CONCAT('fname',a.account_number)
- WHERE l.contactable_type = 'Account' and l.contact_type_id = 1
- AND c.first_name IS NOT NULL AND c.first_name != ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com' ;
- UPDATE contacts c
- INNER JOIN `contactings` l ON c.id = l.contact_id
- INNER JOIN `accounts` a ON l.contactable_id = a.id
- SET c.last_name = CONCAT('lname',a.account_number)
- WHERE l.contactable_type = 'Account' and l.contact_type_id = 1
- AND c.last_name IS NOT NULL AND c.last_name != ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com' ;
- UPDATE customer_entity_varchar ce_fname
- INNER JOIN customer_entity ce
- ON ce_fname.entity_id = ce.entity_id
- SET ce_fname.value = CONCAT('fname',ce.account_number)
- WHERE ce_fname.attribute_id = 5 AND ce_fname.value<>'' AND ce.email not in (SELECT email from temp_email_not_modified) AND ce.email not like '%@recyclebank.com' ;
- UPDATE customer_entity_varchar ce_lname
- INNER JOIN customer_entity ce
- ON ce_lname.entity_id = ce.entity_id
- SET ce_lname.value = CONCAT('lname',ce.account_number)
- WHERE ce_lname.attribute_id = 7 AND ce_lname.value<>'' AND ce.email not in (SELECT email from temp_email_not_modified) AND ce.email not like '%@recyclebank.com';
- SET letterBig = 'QWERTYUIOPLKJHGFDSAZXCVBNMKLPOIJNBHUYGVCFTRDXZSEWQASDEWQZXCVBNMKLOPIUYTREWQASDFGHJKLMNBVCXZASDFGHJKL';
- SET letterSmall = 'qwertyuioplkjhgfdsazxcvbnmlpokijuhygtfrdeswqazxcvbnmklpoijbhuygvcftrdxzsewqasdrftgcvbnjuikolpmjhytrf';
- UPDATE addresses a
- INNER JOIN addressings adr ON adr.address_id = a.id and adr.addressable_type = 'Contact' and adr.is_mailing_addr = 1
- INNER JOIN contacts c ON c.id = adr.addressable_id
- INNER JOIN contactings co ON co.contact_id = c.id
- INNER JOIN accounts aa ON co.contactable_id = aa.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- SET a.street_name = CONCAT(LEFT(SUBSTRING(letterBig, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- LEFT(SUBSTRING(letterSmall, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- LEFT(SUBSTRING(letterSmall, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- SUBSTRING(street_name, 4, length( street_name))
- )
- where a.street_name is not null and a.street_name <> ''
- and length(a.street_name) > 3
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com' ;
- UPDATE addresses a
- INNER JOIN addressings adr ON adr.address_id = a.id and adr.addressable_type = 'Contact' and adr.is_mailing_addr = 1
- INNER JOIN contacts c ON c.id = adr.addressable_id
- INNER JOIN contactings co ON co.contact_id = c.id
- INNER JOIN accounts aa ON co.contactable_id = aa.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- SET a.street_num = left(TRUNCATE((rand()* 1000000), 0), length(a.street_num))
- where a.street_num is not null and a.street_num <> ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com' ;
- UPDATE addresses a
- INNER JOIN addressings adr ON adr.address_id = a.id and adr.addressable_type = 'Contact' and adr.is_mailing_addr = 1
- INNER JOIN contacts c ON c.id = adr.addressable_id
- INNER JOIN contactings co ON co.contact_id = c.id
- INNER JOIN accounts aa ON co.contactable_id = aa.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- SET a.address1 = CONCAT(ifnull(a.street_num,''), ' ', ifnull(a.street_name,''))
- where ((a.street_num is not null) or (a.street_name is not null) )
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com' ;
- UPDATE addresses a
- INNER JOIN addressings adr ON adr.address_id = a.id and adr.addressable_type = 'Contact' and adr.is_mailing_addr = 1
- INNER JOIN contacts c ON c.id = adr.addressable_id
- INNER JOIN contactings co ON co.contact_id = c.id
- INNER JOIN accounts aa ON co.contactable_id = aa.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- SET a.address1 = CONCAT(
- TRUNCATE((rand()* 1000), 0),
- ' ',
- LEFT(SUBSTRING(letterBig, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- LEFT(SUBSTRING(letterSmall, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- LEFT(SUBSTRING(letterSmall, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- SUBSTRING(a.address1, 4, length(a.address1))
- )
- where a.street_num is null and a.street_name is null
- and a.address1 is not null and a.address1 <> ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com' ;
- UPDATE customer_address_entity_text cae_street
- INNER JOIN customer_address_entity cae ON cae_street.entity_id = cae.entity_id
- INNER JOIN customer_entity ce ON cae.parent_id = ce.entity_id
- INNER JOIN accounts aa ON aa.account_number = ce.account_number
- INNER JOIN contactings co ON co.contactable_id = aa.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- INNER JOIN contacts c ON c.id = co.contact_id
- INNER JOIN addressings adr ON adr.addressable_id = c.id AND adr.addressable_type = 'Contact' AND adr.is_mailing_addr = 1
- INNER JOIN addresses a ON a.id = adr.address_id
- SET
- cae_street.value = CONCAT(REPLACE(REPLACE(coalesce(a.address1,''), CHAR(10), ' '), CHAR(13), ' '), CHAR(13), CHAR(10), REPLACE(REPLACE(a.address2, CHAR(10), ' '), CHAR(13), ' '))
- WHERE cae_street.attribute_id = 24 AND cae_street.value <>''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com';
- UPDATE customer_address_entity_text cae_street
- INNER JOIN customer_address_entity cae ON cae_street.entity_id = cae.entity_id
- INNER JOIN customer_entity ce ON cae.parent_id = ce.entity_id
- LEFT JOIN accounts aa ON aa.account_number = ce.account_number
- LEFT JOIN contactings co ON co.contactable_id = aa.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- LEFT JOIN contacts c ON c.id = co.contact_id
- LEFT JOIN addressings adr ON adr.addressable_id = c.id AND adr.addressable_type = 'Contact' AND adr.is_mailing_addr = 1
- LEFT JOIN addresses a ON a.id = adr.address_id
- SET
- cae_street.value = CONCAT(
- TRUNCATE((rand()* 1000), 0),
- ' ',
- LEFT(SUBSTRING(letterBig, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- LEFT(SUBSTRING(letterSmall, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- LEFT(SUBSTRING(letterSmall, TRUNCATE((rand()* 100), 0)+1, 1) , 10),
- SUBSTRING(cae_street.value, 4, length(cae_street.value))
- )
- WHERE cae_street.attribute_id = 24 AND cae_street.value <>''
- AND a.id is null
- AND ce.email not in (SELECT email from temp_email_not_modified) AND ce.email not like '%@recyclebank.com';
- update contacts c
- set c.home_phone =
- CONCAT(
- left(TRUNCATE((rand()* 100000), 0), 3),
- '-',
- left(TRUNCATE((rand()* 100000), 0), 3),
- '-',
- left(TRUNCATE((rand()* 100000), 0), 4)
- )
- where c.home_phone is not null and c.home_phone <> ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com';
- UPDATE customer_mobile ce_m
- INNER JOIN customer_entity ce ON ce.entity_id = ce_m.customer_id
- INNER JOIN accounts a ON a.account_number = ce.account_number
- INNER JOIN contactings co ON co.contactable_id = a.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- INNER JOIN contacts c ON c.id = co.contact_id
- SET
- ce_m.phone_number = case WHEN c.home_phone is not null THEN replace(c.home_phone,'-','') ELSE TRUNCATE( ( rand()* 10000000000), 0) END
- WHERE
- ce_m.phone_number <> '' AND ce.email not in (SELECT email from temp_email_not_modified) AND ce.email not like '%@recyclebank.com';
- UPDATE customer_mobile ce_m
- INNER JOIN customer_entity ce ON ce.entity_id = ce_m.customer_id
- LEFT JOIN accounts a ON a.account_number = ce.account_number
- LEFT JOIN contactings co ON co.contactable_id = a.id AND co.contactable_type = 'Account' AND co.contact_type_id = 1
- LEFT JOIN contacts c ON c.id = co.contact_id
- SET
- ce_m.phone_number = TRUNCATE( ( rand()* 10000000000), 0)
- WHERE
- c.id is null AND ce_m.phone_number <> '' AND ce.email not in (SELECT email from temp_email_not_modified) AND ce.email not like '%@recyclebank.com';
- update contacts c
- set c.work_phone =
- CONCAT(
- left(TRUNCATE((rand()* 100000), 0), 3),
- '-',
- left(TRUNCATE((rand()* 100000), 0), 3),
- '-',
- left(TRUNCATE((rand()* 100000), 0), 4)
- )
- where c.work_phone is not null and c.work_phone <> ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com';
- update contacts c
- set c.cell_phone =
- CONCAT(
- left(TRUNCATE((rand()* 100000), 0), 3),
- '-',
- left(TRUNCATE((rand()* 100000), 0), 3),
- '-',
- left(TRUNCATE((rand()* 100000), 0), 4)
- )
- where c.cell_phone is not null and c.cell_phone <> ''
- AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com';
- UPDATE contacts c
- INNER JOIN `contactings` l ON c.id = l.contact_id
- INNER JOIN `accounts` a ON l.contactable_id = a.id
- SET c.email = CONCAT('qa',a.account_number,'@recyclebank.com')
- WHERE l.contactable_type = 'Account' and l.contact_type_id = 1
- AND c.email IS NOT NULL AND c.email != '' AND c.email not in (SELECT email from temp_email_not_modified) AND c.email not like '%@recyclebank.com';
- UPDATE customer_entity ce
- SET ce.email = CONCAT('qa',ce.account_number,'@recyclebank.com')
- WHERE ce.email is not null and ce.email !=''
- AND ce.email not in (SELECT email from temp_email_not_modified) AND ce.email not like '%@recyclebank.com' ;
- drop table temp_email_not_modified;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `sel_all_attribute` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = '' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 PROCEDURE `sel_all_attribute`(IN inp_entity_id int(10))
- BEGIN
- DECLARE str_all_fields VARCHAR(100000) DEFAULT '';
- DECLARE str_ins_fields VARCHAR(10000) DEFAULT '';
- DECLARE fld_name VARCHAR(10000) DEFAULT '';
- DECLARE ins_fld_name VARCHAR(255) DEFAULT '';
- DECLARE done INT DEFAULT 0;
- DECLARE cur1
- CURSOR FOR select
- concat("max(case When a.attribute_code='", a.attribute_code,"' THEN case when a.backend_type='varchar' THEN cev.value WHEN a.backend_type='datetime' THEN ced.value WHEN a.backend_type='decimal' THEN cedc.value WHEN a.backend_type = 'int' THEN cei.value WHEN a.backend_type = 'text' THEN cet.value END END ) as ",a.attribute_code) as a1,
- a.attribute_code as a2
- FROM `eav_attribute` a
- INNER JOIN information_schema.COLUMNS c on c.TABLE_SCHEMA =DATABASE()
- AND c.TABLE_NAME ='catalog_product_flat_1' AND c.column_name = a.attribute_code
- WHERE a.entity_type_id = 4
- order BY a.attribute_id;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- OPEN cur1;
- read_loop: LOOP
- FETCH cur1 INTO fld_name,ins_fld_name;
- IF done THEN
- LEAVE read_loop;
- END IF;
- SET str_all_fields = CONCAT(str_all_fields,fld_name,",");
- SET str_ins_fields = CONCAT(str_ins_fields,ins_fld_name,",");
- END LOOP;
- CLOSE cur1;
- SET str_all_fields = substring(str_all_fields,1,length(str_all_fields)-1);
- SET str_ins_fields = substring(str_ins_fields,1,length(str_ins_fields)-1);
- SET @str_sql = concat(" FROM `eav_attribute` a \n
- INNER JOIN `catalog_product_entity` ce on a.entity_type_id = ce.entity_type_id \n
- LEFT JOIN `catalog_product_entity_varchar` cev \n
- on a.attribute_id = cev.attribute_id and ce.entity_id = cev.entity_id \n
- LEFT JOIN `catalog_product_entity_datetime` ced \n
- on a.attribute_id = ced.attribute_id and ce.entity_id = ced.entity_id \n
- LEFT JOIN `catalog_product_entity_decimal` cedc \n
- on a.attribute_id = cedc.attribute_id and ce.entity_id = cedc.entity_id \n
- LEFT JOIN `catalog_product_entity_int` cei \n
- on a.attribute_id = cei.attribute_id and ce.entity_id = cei.entity_id \n
- LEFT JOIN `catalog_product_entity_text` cet \n
- on a.attribute_id = cet.attribute_id and ce.entity_id = cet.entity_id \n
- WHERE ce.entity_id = ",inp_entity_id," AND a.entity_type_id = 4 GROUP BY ce.entity_id order BY a.attribute_id ");
- SET @str_sql = concat("INSERT INTO catalog_product_flat_2(entity_id,",str_ins_fields,") SELECT ce.entity_id,",str_all_fields,@str_sql ) ;
- SELECT @str_sql;
- end */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!50003 DROP PROCEDURE IF EXISTS `SOLR_INDEX_CUSTOMERS` */;
- /*!50003 SET @saved_cs_client = @@character_set_client */ ;
- /*!50003 SET @saved_cs_results = @@character_set_results */ ;
- /*!50003 SET @saved_col_connection = @@collation_connection */ ;
- /*!50003 SET character_set_client = utf8 */ ;
- /*!50003 SET character_set_results = utf8 */ ;
- /*!50003 SET collation_connection = utf8_general_ci */ ;
- /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
- /*!50003 SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO' */ ;
- DELIMITER ;;
- /*!50003 CREATE*/ /*!50020 DEFINER=`RB_qa`@`%`*/ /*!50003 PROCEDURE `SOLR_INDEX_CUSTOMERS`()
- BEGIN
- SELECT `e`.`entity_id`, `e`.`email`, `e`.`account_number`, `_table_firstname`.`value` AS `firstname`, `_table_lastname`.`value` AS `lastname`, `_table_billing_postcode`.`value` AS `zipcode`, `_table_billing_city`.`value` AS `city`, `_table_billing_street`.`value` AS `street`, `cmb`.`phone_number` AS `phone`, `cmb`.`is_active` AS `is_phone_active`, `_table_billing_region`.`value` AS `region_state`, `_table_billing_country_id`.`value` AS `country` FROM `customer_entity` AS `e`
- LEFT JOIN `customer_mobile` as `cmb` ON `e`.`entity_id` = `cmb`.`customer_id`
- LEFT JOIN `customer_entity_varchar` AS `_table_prefix` ON (_table_prefix.entity_id = e.entity_id) AND (_table_prefix.attribute_id='4')
- LEFT JOIN `customer_entity_varchar` AS `_table_firstname` ON (_table_firstname.entity_id = e.entity_id) AND (_table_firstname.attribute_id='5')
- LEFT JOIN `customer_entity_varchar` AS `_table_middlename` ON (_table_middlename.entity_id = e.entity_id) AND (_table_middlename.attribute_id='6')
- LEFT JOIN `customer_entity_varchar` AS `_table_lastname` ON (_table_lastname.entity_id = e.entity_id) AND (_table_lastname.attribute_id='7')
- LEFT JOIN `customer_entity_varchar` AS `_table_suffix` ON (_table_suffix.entity_id = e.entity_id) AND (_table_suffix.attribute_id='8')
- LEFT JOIN `customer_entity_int` AS `_table_default_billing` ON (_table_default_billing.entity_id = e.entity_id) AND (_table_default_billing.attribute_id='13')
- LEFT JOIN `customer_address_entity_varchar` AS `_table_billing_postcode` ON (_table_billing_postcode.entity_id = _table_default_billing.value) AND (_table_billing_postcode.attribute_id='29')
- LEFT JOIN `customer_address_entity_varchar` AS `_table_billing_city` ON (_table_billing_city.entity_id = _table_default_billing.value) AND (_table_billing_city.attribute_id='25')
- LEFT JOIN `customer_address_entity_text` AS `_table_billing_street` ON (_table_billing_street.entity_id = _table_default_billing.value) AND (_table_billing_street.attribute_id='24')
- LEFT JOIN `customer_address_entity_varchar` AS `_table_billing_telephone` ON (_table_billing_telephone.entity_id = _table_default_billing.value) AND (_table_billing_telephone.attribute_id='30')
- LEFT JOIN `customer_address_entity_varchar` AS `_table_billing_region` ON (_table_billing_region.entity_id = _table_default_billing.value) AND (_table_billing_region.attribute_id='27')
- LEFT JOIN `customer_address_entity_varchar` AS `_table_billing_country_id` ON (_table_billing_country_id.entity_id = _table_default_billing.value) AND (_table_billing_country_id.attribute_id='26') WHERE (e.entity_type_id = '1') ORDER BY `e`.`entity_id` desc, `e`.`entity_id`;
- END */;;
- DELIMITER ;
- /*!50003 SET sql_mode = @saved_sql_mode */ ;
- /*!50003 SET character_set_client = @saved_cs_client */ ;
- /*!50003 SET character_set_results = @saved_cs_results */ ;
- /*!50003 SET collation_connection = @saved_col_connection */ ;
- /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
- /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
- /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
- /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
- /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
- -- Dump completed on 2011-10-26 18:43:39
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement