Created
June 2, 2014 13:21
-
-
Save mklooss/bea85aa34aeb4b098023 to your computer and use it in GitHub Desktop.
copy Parent/Simple Category to each other
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'app/Mage.php'; | |
Mage::app('admin'); | |
$resource = Mage::getSingleton('core/resource'); | |
/* @var $resource Mage_Core_Model_Resource */ | |
$conn = $resource->getConnection('core_write'); | |
/* @var $conn Varien_Db_Adapter_Interface */ | |
$sql = $conn->select() | |
->from($resource->getTableName('catalog_product_super_link')); | |
$links = $conn->fetchAll($sql); | |
foreach($links as $_cid) | |
{ | |
$productid = $_cid['parent_id']; | |
$sql = $conn->select() | |
->from($resource->getTableName('catalog_category_product'), 'category_id') | |
->where('product_id = ?', $_cid['product_id']); | |
$categoryids = $conn->fetchCol($sql); | |
foreach($categoryids as $categoryid) | |
{ | |
echo $productid. '-'.$categoryid."\n"; | |
$update = array( | |
'product_id' => $productid, | |
'category_id' => $categoryid | |
); | |
$conn->insertOnDuplicate($resource->getTableName('catalog_category_product'), $update, array('category_id', 'product_id')); | |
} | |
} | |
$sql = $conn->select() | |
->from($resource->getTableName('catalog_product_super_link')); | |
$links = $conn->fetchAll($sql); | |
foreach($links as $_cid) | |
{ | |
$productid = $_cid['parent_id']; | |
$sql = $conn->select() | |
->from($resource->getTableName('catalog_category_product'), 'category_id') | |
->where('product_id = ?', $productid); | |
$categoryids = $conn->fetchCol($sql); | |
foreach($categoryids as $categoryid) | |
{ | |
echo $_cid['product_id']. '-'.$categoryid."\n"; | |
$update = array( | |
'product_id' => $_cid['product_id'], | |
'category_id' => $categoryid | |
); | |
$conn->insertOnDuplicate($resource->getTableName('catalog_category_product'), $update, array('category_id', 'product_id')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment