/ Published in: PHP
This will only run in the admin
There are 2 booleans to implement the script:
$run_script = true;
$delete = false;
If delete is true then products that are not within a category will be removed.
There are 2 booleans to implement the script:
$run_script = true;
$delete = false;
If delete is true then products that are not within a category will be removed.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$run_script = true; $delete = false; $admin_logged_in = (stristr(Mage::helper('core/url')->getCurrentUrl(), 'storeadmin') !== FALSE) ? $admin_logged_in : FALSE; // ..get back to the original. if($run_script && $admin_logged_in) { $wr = Mage::getSingleton('core/resource')->getConnection('core_write');; echo '<hr />Starting products script<hr />'; $ps = Mage::getModel('catalog/product')->getCollection()->load(); $count = 0; foreach ($ps as $p) { $ti = $p->getTypeID(); $ci = $p->getCategoryIds(); if($p->getTypeID() == 'configurable') { $a = Mage::getModel('eav/entity_attribute_set')->load($p->getAttributeSetId()); $attributeSetName = $a->getAttributeSetName(); Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter('configurable')->addFilter('attribute_set_name', $attributeSetName); $attributes = $p->getTypeInstance(true)->getSetAttributes($p);; foreach($attributes as $attribute) { if ($p->getTypeInstance(true)->canUseAttribute($attribute, $p)) { try { $s = "INSERT INTO wf_catalog_product_super_attribute (`product_id`, `attribute_id`) VALUES ('".$p->getId()."', '".$attribute['attribute_id']."')"; $wr->query($s); $lastInsertId = $wr->lastInsertId(); $s = "INSERT INTO wf_catalog_product_super_attribute_label (`product__super_attribute_id`, `value`) VALUES ('".$lastInsertId."', '".$attribute->getStoreLabel()."')"; $wr->query($s); echo $attribute->getStoreLabel().'associated to product '.$p->getName().'<br />' ; } catch (Exception $e) { } } } // Check all products for the name of the item $cfg_prs = Mage::getModel('catalog/product')->getCollection() ->addAttributeToFilter('type_id', 'simple') foreach ($cfg_prs as $_cp) { try { $s = "INSERT INTO wf_catalog_product_super_link (`parent_id`, `product_id`) VALUES ('".$p->getId()."', '".$_cp->getId()."')"; $wr->query($s); echo $_cp->getSku().' associated correctly<br />'; } catch (Exception $e) { } } } // Delete { $cps = $p->getUsedProducts(null, $product); foreach ($cps as $cp) { echo $cp->getName().' deleted<br />'; $cp->delete(); $count++; } echo $p->getName().' deleted<br />'; $p->delete(); $count++; } } echo '<hr />Finishing products script. '.$count.' product(s) deleted<hr />'; }