<?php
require_once 'abstract.php';
class Mage_Shell_DifferentSizeSearch extends Mage_Shell_Abstract
{
/**
* Run script
*
*/
public function run()
{
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$file_path = BP . DS . 'var'. DS . 'export_csv'. DS . 'size_different_' . date('Y-m-d') . '.csv';
$fp = fopen($file_path,'w+');
chmod($file_path,0777);
$list = array("sku");
//get all config product
$storeId = Mage::app()->getStore()->getStoreId();
$config_product =
Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', 'configurable')
->addStoreFilter($storeId);
foreach ($config_product as $cp) {
$parent_sku = $cp->getSku();
$aps = $cp->getTypeInstance()->getUsedProducts();
$attNames = array();
foreach ($aps as $ap) {
//var_dump($ap->getAdditionalData());
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($ap->getAttributeSetId());
$attributeSetName = $attributeSetModel->getAttributeSetName();
//var_dump($attributeSetName);
if(count($attNames) == 0) {
$attNames[] = $attributeSetName;
} else if (!in_array($attributeSetName,$attNames)) {
var_dump($cp->getSku() . ' has different attribute group name.');
$list[] = $cp->getSku();
$cSku = trim($cp->getSku());
//delete all the simple product and congfig product and rewrite url
foreach ($aps as $tp) {
$tp->delete();
}
$cp->delete();
$sql = "DELETE FROM `core_url_rewrite`
WHERE `request_path` LIKE '%{$cSku}%'";
$write->query($sql);
break;
}
}
if (count($attNames) == 1) {
var_dump($cp->getSku() . ' is ok.');
}
}
foreach ($list as $line) {
fputcsv($fp, explode(',', $line));
}
fclose($fp);
}
}
$shell = new Mage_Shell_DifferentSizeSearch();
$shell->run();