Jump to content

Update


Jluis

Recommended Posts

In order to update  ps_feature_value  , ps_feature_product  database  for existing products with valaues from a csv file  as shown in the picture below , i made the function below  , an error appears :

CREATE PROCEDURE processorders()

BEGIN

 DECLARE done INT DEFAULT FALSE 

  DECLARE b , c , d int(10) 
 
   DECLARE ordernumbers CURSOR FOR SELECT  id_feature,id_product,id_feature_value  FROM psdms_feature_product
    
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE

   
    OPEN ordernumbers

    read_loop:LOOP

    FETCH ordernumbers INTO b,c,d

  IF done THEN
      LEAVE read_loop
    END IF 
   
    IF (c) THEN
    IF (b == 510) THEN
   
					update psdms_feature_value_lang t1

				    LEFT JOIN
							psdms_feature_product t2
					ON      t1.id_feature_value = t2.id_feature_value
				    SET value ='95090€'
					WHERE   t2.id_product = 1 AND  t2.id_feature = 510

    ELSE

    
insert into  psdms_feature_value ( id_feature ) values (510)
insert into  psdms_feature_product ( id_feature, id_product , id_feature_value) values (b , c , d )

END IF
    
END IF
   
END LOOP
 
 CLOSE ordernumber 

END 

 

the error is : 

 

Quote

Erreur dans la requête (1064): Syntax error near 'DECLARE b int(10) DECLARE c int(10) DECLARE d int(10) DECLARE orde' at line 7

Any suggestion please ??

aide.PNG

Link to comment
Share on other sites

Seems you are using a third partie module. For to update prices you need also to update some other tables. If you are not the developer of the module, than please contact developer. To make manual updates in database without knowing the dependencies Prestashop is writing is a high risk. If you are the developer of the module, than you should take a look into database schema.

ps_product and ps_product_shop is also a required table which handles prices.

Link to comment
Share on other sites

i'm the owner , i would like to modify " caractéristique->prix HT  " as mentionned in the image .  If the product has that old value just we update it , if not we create a new feature and associate to the situable product as mentionned in code , this does not work? 

Link to comment
Share on other sites

I am not an expert on Mysql procedures. But it seems to me that this error says that there is something wrong with your syntax. If that is indeed the case you would find more help on a mysql forum as your problem has nothing to do with Prestashop. 

If I had to make one guess it would be to put a semicolon after "DECLARE b , c , d int(10)".

Link to comment
Share on other sites

@PrestaShop Superstar , Actuallay there is no error :) , when i run only that part of the code  , it works well and the attribute value chnages 

update psdms_feature_value_lang t1

				    LEFT JOIN
							psdms_feature_product t2
					ON      t1.id_feature_value = t2.id_feature_value
				    SET value =666
					WHERE   t2.id_product = 1 AND  t2.id_feature = 362;

but integrated in the function nothing is done 

Link to comment
Share on other sites

@PrestaShop Superstar , I have tried that relationship join between tables but nothing is done , is tha the way ?

 DECLARE ordernumbers CURSOR FOR SELECT id_feature,id_product,id_feature_value  FROM psdms_feature_product  z1,  psdms_product_shop z2 , psdms_product z3 WHERE z1.id_product=z2.id_product AND z1.id_product=z3.id_product ;

 

Edited by Jluis (see edit history)
Link to comment
Share on other sites

@PrestaShop Superstar , it is the whole code 

DELIMITER $$
CREATE PROCEDURE testt61()

BEGIN


 DECLARE done INT DEFAULT FALSE;

  DECLARE b , c , d INT(10) unsigned;
 
   DECLARE ordernumbers CURSOR FOR SELECT id_feature,id_product,id_feature_value  FROM psdms_feature_product  z1,  psdms_product_shop z2 , psdms_product z3 WHERE z1.id_product = z2.id_product AND z1.id_product = z3.id_product ;
    
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

   
    OPEN ordernumbers ;

    read_loop:LOOP FETCH ordernumbers INTO  b , c , d ;

    IF done  THEN
      LEAVE read_loop ;
    END IF ; 
   
    IF c = 1  THEN
    IF b = 362 THEN
   
					update psdms_feature_value_lang t1

				    LEFT JOIN
						psdms_feature_product t2
					ON      t1.id_feature_value = t2.id_feature_value
				    SET value ='888€'
					WHERE   t2.id_product = 1 AND  t2.id_feature = 362;

    ELSE

    
insert into  psdms_feature_value ( id_feature ) values (510);
insert into  psdms_feature_product  values (b , c , d );

END IF;
   
END IF;
   
END LOOP;
 
 CLOSE ordernumbers;

END ;
DELIMITER ;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...