Fórum OpenCart Brasil

Por um e-commerce livre, confiável e profissional

Suporte geral sobre problemas técnicos para OpenCart v2.x.
#77904
Só postando uma solução que funcionou pra mim... tive um problema que duplicou vários produtos meus.

Como eram muitos, usei o código abaixo direto no banco de dados para remover os produtos duplicados (com base no nome igual)

Funcionou bem no opencart 2.3.0.2

Primeiro rodei o seguinte select para verificar os produtos duplicados com mesmo nome:
Código: Selecionar todos
select p1.product_id
from oc_product p1
join oc_product_description d1 on d1.product_id = p1.product_id
join oc_product_description d2 
on d2.product_id <> d1.product_id
and d2.name = d1.name;
Depois usei o select mais implementado pra filtrar somente os que seriam deletados
Código: Selecionar todos
select p1.product_id
from oc_product p1
join oc_product_description d1 on d1.product_id = p1.product_id
join oc_product_description d2 
on d2.product_id <> d1.product_id
and d2.name = d1.name
join oc_product p2 on p2.product_id = d2.product_id
and p2.product_id < p1.product_id;
Após confirmar que esses eram os dados a apagar, usei os seguinte script
Código: Selecionar todos
create temporary table tmptable (id int);

INSERT tmptable (id)
select p1.product_id
from oc_product p1
join oc_product_description d1 on d1.product_id = p1.product_id
join oc_product_description d2 
on d2.product_id <> d1.product_id
and d2.name = d1.name
join oc_product p2 on p2.product_id = d2.product_id
and p2.product_id < p1.product_id;

delete 
from oc_product
where product_id in (select id from tmptable);

delete
from oc_product_description
where product_id in (select id from tmptable);

delete from oc_product where product_id in (select id from tmptable);
DELETE FROM oc_product WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_attribute WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_description WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_discount WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_image WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_option WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_option_value WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_related WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_related WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_reward WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_special WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_to_category WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_to_download WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_to_layout WHERE product_id in (select id from tmptable);
DELETE FROM oc_product_to_store WHERE product_id in (select id from tmptable);
DELETE FROM oc_review WHERE product_id in (select id from tmptable);

Looking for a partner for an unforgettable night? […]

Olá! Tudo bem? Verifique as configura&cced[…]

Olá! Tudo bem? Trabalho com Opencart h&aac[…]

Imagem do Carrinho de Compras

Olá! Tudo bem? São vários lo[…]