查找同一可配置关联的存在不用属性组名的简单商品的SKU

<?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();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值