Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/12/2012, 13:06
jnavarrete2311
 
Fecha de Ingreso: noviembre-2012
Mensajes: 30
Antigüedad: 12 años
Puntos: 0
Respuesta: Asignar valor a variable en un SP

Mira te lo mando mejor sin codigo comentado:

Código MySQL:
Ver original
  1. -- --------------------------------------------------------------------------------
  2. -- Routine DDL
  3. -- Note: comments before and after the routine body will not be stored by the server
  4. -- --------------------------------------------------------------------------------
  5. DELIMITER $$
  6.  
  7. CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertOrder`(
  8. IN Nombre VARCHAR(100),
  9. IN Apellido VARCHAR(100),
  10. IN TotalPaidNoTax float,
  11. IN TotalConTax float,
  12. IN ShippingNoTax float,
  13. IN ReferenceCode VARCHAR(100),
  14. IN CurrentState INT,
  15. IN Payment VARCHAR(100),
  16. IN Module VARCHAR(100),
  17. IN Tax float
  18. )
  19.  
  20. DECLARE customer_id INT;
  21. SET customer_id = 0;
  22. SELECT id_customer
  23. FROM `ps_customer`
  24. WHERE firstname = Nombre AND lastname= Apellido
  25. INTO customer_id;
  26. SELECT customer_id;
  27.  
  28.     set @id_cart = (select MAX(id_cart) from `ps_cart`);
  29.     set @id_address = (select id_address from `ps_address` where firstname = Nombre and lastname= Apellido);
  30.     set @id_guest = (select id_guest from `ps_guest` where id_customer = @customer_id);
  31.  
  32.             insert into  `ps_cart`(id_shop_group,id_shop,id_carrier,delivery_option,id_lang,
  33.                                    id_address_delivery,id_address_invoice,id_currency,id_customer,
  34.                                    id_guest,secure_key,recyclable,gift,gift_message,allow_seperated_package,
  35.                                    date_add,date_upd
  36.                                    )
  37.             select
  38.                   id_shop_group,id_shop,id_carrier,delivery_option,id_lang,id_address_delivery,
  39.                   id_address_invoice,id_currency,id_customer,id_guest,secure_key,recyclable,gift,
  40.                   gift_message,allow_seperated_package,date_add = CURRENT_TIMESTAMP(),
  41.                   date_upd = CURRENT_TIMESTAMP()
  42.             from
  43.                 ps_cart where id_cart = @id_cart;
  44.                        
  45.             set @id_cart = (select MAX(id_cart) from ps_cart);
  46.  
  47.             update `ps_cart` set id_guest=@id_guest, id_address_delivery = @id_address,
  48.                                  id_address_invoice = @id_address, id_customer = @customer_id,
  49.                                  date_add=CURRENT_TIMESTAMP(),date_upd=CURRENT_TIMESTAMP()
  50.             where id_cart=@id_cart;
  51.  
  52.             set @id_cart = (select MAX(id_cart) from ps_cart);
  53.             set @id_order_max = (select MAX(id_order) from `ps_orders`);
  54.             set @invoice_number = (select invoice_number from `ps_orders` where id_order = @id_order_max);
  55.             set @TotalMenosShippingIncl = (TotalPaidNoTax - 2.32);
  56.             set @TotalProductMenosShipping = (TotalConTax  - 2.32);
  57.             set @shippingTax = ShippingNoTax + ((ShippingNoTax * Tax)/100);
  58.            
  59.             insert into `ps_orders`(reference,id_carrier,id_lang,id_customer,id_cart,id_currency,
  60.                                     id_address_delivery,id_address_invoice,current_state,secure_key,
  61.                                     payment,conversion_rate,module,gift_message,shipping_number,
  62.                                     total_paid,total_paid_tax_incl,total_paid_tax_excl,total_paid_real,
  63.                                     total_products,total_products_wt,total_shipping,total_shipping_tax_incl,
  64.                                     total_shipping_tax_excl,carrier_tax_rate,date_add,date_upd
  65.                                     )
  66.                               values(
  67.                                     ReferenceCode,2,4,@customer_id,@id_cart,1,@id_address,@id_address,
  68.                                     CurrentState,'91b5b10c93a6f626f8e6154b32279510',Payment,
  69.                                     1.000000,Module,'','',TotalConTax,TotalConTax,TotalPaidNoTax,
  70.                                     0.00,@TotalMenosShippingIncl,@TotalProductMenosShipping,@shippingTax,
  71.                                     @shippingTax,ShippingNoTax,Tax,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()
  72.                                     );