I'm using the Joomla's extension Virtuemart 1.1.9 with joomla 1.5 to create my shopping cart. With the help of another component, I can upload a plain text file to the server with the Product Id and the quantity. With the following routine I can conolidate the load into the cart.
The problem with this method is that when I proceed to place the order, the products prices don't multiply with the quantity ordered to obtain the total of the order.
Any ideas?
here is the code
DECLARE done INT DEFAULT 0;
declare producto, cantidad, cliente, carga, categoria int;
declare cantidadreg, cuenta, i int default 0;
declare cadena text default "";
declare varcarga int default 0;
declare cur1 cursor for select jos_vm_product.product_id, cant_producto, id_cliente, datos_cargas_vm.id_carga, category_id
from datos_cargas_vm inner join cargas_vm on datos_cargas_vm.id_carga=cargas_vm.id_carga
inner join jos_vm_product on datos_cargas_vm.id_producto=jos_vm_product.product_sku
inner join jos_vm_product_category_xref on jos_vm_product.product_id = jos_vm_product_category_xref.product_id
where estado_carga='P'
order by datos_cargas_vm.id_carga, jos_vm_product.product_id;
declare continue handler for not found set done = true;
open cur1;
read_loop: LOOP
fetch cur1 into producto, cantidad, cliente, carga, categoria;
if done then
leave read_loop;
end if;
if varcarga!=carga then
select count(*) into cantidadreg from datos_cargas_vm inner join cargas_vm on datos_cargas_vm.id_carga=cargas_vm.id_carga
inner join jos_vm_product on datos_cargas_vm.id_producto=jos_vm_product.product_sku
inner join jos_vm_product_category_xref on jos_vm_product.product_id = jos_vm_product_category_xref.product_id
where estado_carga='P' and datos_cargas_vm.id_carga=carga;
set varcarga:=carga;
set cadena:=concat("a:",cast(cantidadreg+1 as char),":{s:3:\"idx\";i:",cast(cantidadreg as char),";");
set i:=0;
end if;
set cadena:=concat(cadena,"i:",cast(i as char),";a:5:{s:8:\"quantity\";i:",cast(cantidad as char),
";s:10:\"product_id\";s:5:\"",cast(producto as char),"\";s:9:\"parent_id\";i:",cast(producto as char),
";s:11:\"category_id\";i:",cast(categoria as char),";s:11:\"description\";s:0:\"\";}");
set i:=i+1;
if i=cantidadreg then
set cadena:=concat(cadena,"}");
-- select cantidadreg,cadena;
select count(*) into cantidadreg from jos_vm_cart where user_id = cliente;
if cantidadreg=0 then
insert into jos_vm_cart(user_id,cart_content) values(cliente,cadena);
else
update jos_vm_cart set cart_content=cadena where user_id=cliente;
end if;
update cargas_vm set estado_carga='C' where id_carga=carga;
end if;
END LOOP;
close cur1;