Skip to content

Instantly share code, notes, and snippets.

@megabayt
Created October 22, 2017 12:25
Show Gist options
  • Save megabayt/4df4492d4a138f5aa6d76951d51bbe40 to your computer and use it in GitHub Desktop.
Save megabayt/4df4492d4a138f5aa6d76951d51bbe40 to your computer and use it in GitHub Desktop.
remove doubles opencart
public function clear_doubles(){
$query = $this->db->query("SELECT * FROM `oc_product` WHERE xml_id IN ( SELECT xml_id FROM `oc_product` GROUP BY `xml_id` HAVING COUNT( `xml_id` ) > 1 ) ORDER BY `oc_product`.`xml_id` ASC");
$doubles = $query->num_rows != 0 ? $query->rows : [];
$original = array_shift($doubles);
foreach($doubles as $double){
var_dump($original['xml_id'], $double['xml_id']); echo "<br>";
$this->load->model('catalog/product');
if($original['xml_id'] == $double['xml_id']){
echo "delete ".$double['product_id']." double of ".$original['product_id']."<br>";
$this->model_catalog_product->deleteProduct($double['product_id']);
}else{
$original['xml_id'] = $double['xml_id']; continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment