Created
April 15, 2013 05:59
-
-
Save jaseclamp/5385991 to your computer and use it in GitHub Desktop.
This script migrates data from pinnacle cart to magento. Put this file in Magento root and edit db connection details. This script migrates categories. It's script one of three.
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 | |
//this script migrates categories from pinnacle cart to magento | |
//it's part one of three | |
require_once 'app/Mage.php'; | |
Mage::app('default'); // Default or your store view name. | |
mysql_connect("host", "user", "pass") or die(mysql_error()); | |
mysql_select_db("db") or die(mysql_error()); | |
$result = mysql_query("Select * from `catalog` where `parent` = 0") or die(mysql_error()); | |
//The root category in Magento, the one you get by default install, usually has the id 2 | |
$_rootParentCat = 2; | |
while($_rootCat = mysql_fetch_assoc( $result ) ) | |
{ | |
//print_r( $_rootCat ); die; | |
$rootCat = new Mage_Catalog_Model_Category(); | |
$rootCat->setName($_rootCat['name']); | |
$rootCat->setUrlKey($_rootCat['key_name']); | |
$rootCat->setDescription($_rootCat['description']); | |
$rootCat->setMetaTitle($_rootCat['meta_title']); | |
$rootCat->setMetaDescription($_rootCat['meta_description']); | |
$rootCat->setMetaKeywords($_rootCat['meta_keywords']); | |
$rootCat->setIsActive(1); | |
$parentCategory = Mage::getModel('catalog/category')->load($_rootParentCat); | |
$rootCat->setPath($parentCategory->getPath()); | |
$rootCat->save(); | |
//Zend_Debug::dump($_c); | |
/* START Create second level categories */ | |
echo $_rootCat['cid'].":".$rootCat->getId()."<br>"; | |
$result2 = mysql_query("Select * from `catalog` where `parent` = ".$_rootCat['cid']) or die(mysql_error()); | |
while($_childCat = mysql_fetch_assoc( $result2 ) ) | |
{ | |
$childCat = new Mage_Catalog_Model_Category(); | |
$childCat->setName($_childCat['name']); | |
$childCat->setUrlKey($_childCat['key_name']); | |
$childCat->setDescription($_childCat['description']); | |
$childCat->setMetaTitle($_childCat['meta_title']); | |
$childCat->setMetaDescription($_childCat['meta_description']); | |
$childCat->setMetaKeywords($_childCat['meta_keywords']); | |
$childCat->setIsActive(1); | |
$parentCategory = Mage::getModel('catalog/category')->load($rootCat->getId()); | |
$childCat->setPath($parentCategory->getPath()); | |
$childCat->save(); | |
//Zend_Debug::dump($_cc); | |
echo $_childCat['cid'].":".$childCat->getId()."<br>"; | |
$result3 = mysql_query("Select * from `catalog` where `parent` = ".$_childCat['cid']) or die(mysql_error()); | |
while($_subCat = mysql_fetch_assoc( $result3 ) ) | |
{ | |
$subCat = new Mage_Catalog_Model_Category(); | |
$subCat->setName($_subCat['name']); | |
$subCat->setUrlKey($_subCat['key_name']); | |
$subCat->setDescription($_subCat['description']); | |
$subCat->setMetaTitle($_subCat['meta_title']); | |
$subCat->setMetaDescription($_subCat['meta_description']); | |
$subCat->setMetaKeywords($_subCat['meta_keywords']); | |
$subCat->setIsActive(1); | |
$parentCategory = Mage::getModel('catalog/category')->load($childCat->getId()); | |
$subCat->setPath($parentCategory->getPath()); | |
$subCat->save(); | |
//Zend_Debug::dump($_cc); | |
//echo "<pre>"; print_r($_rootCat); print_r($_childCat); print_r($_subCat); die; | |
echo $_subCat['cid'].":".$subCat->getId()."<br>"; | |
unset($subCat); | |
} | |
unset($childCat); | |
} | |
/* END Create second level categories */ | |
unset($rootCat); | |
} | |
/* END Create first level categories */ | |
/** Zend_Debug::dump($c->debug()); | |
array(25) { | |
["entity_id"] => string(1) "3" | |
["entity_type_id"] => string(1) "3" | |
["attribute_set_id"] => string(1) "3" | |
["parent_id"] => string(1) "2" | |
["created_at"] => string(19) "2010-05-24 12:14:56" | |
["updated_at"] => string(19) "2010-05-24 17:02:17" | |
["path"] => string(5) "1/2/3" | |
["position"] => string(1) "1" | |
["level"] => string(1) "2" | |
["children_count"] => string(1) "0" | |
["name"] => string(6) "Sample" | |
["url_key"] => string(6) "sample" | |
["meta_title"] => string(0) "" | |
["display_mode"] => string(8) "PRODUCTS" | |
["custom_design"] => string(0) "" | |
["page_layout"] => string(0) "" | |
["url_path"] => string(6) "sample" | |
["is_active"] => string(1) "1" | |
["is_anchor"] => string(1) "0" | |
["custom_design_apply"] => string(1) "1" | |
["description"] => string(21) "Sample category here." | |
["meta_keywords"] => string(0) "" | |
["meta_description"] => string(38) "Meta Sample category description here." | |
["custom_layout_update"] => string(0) "" | |
["available_sort_by"] => string(0) "" | |
} | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment