RSS

Monthly Archives: October 2015

Export Magento Product Categories to custom table

<?php

ini_set('max_execution_time', 1500);
error_reporting(-1);
ini_set('display_errors', 1);

require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);


$categories = Mage::getModel('catalog/category')->getCollection()
        ->addAttributeToSelect('id')
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('url_key')
        ->addAttributeToSelect('url')
        ->addAttributeToSelect('is_active');

foreach ($categories as $category) {

    $entity_id = $category->getId();
    $name = mysql_real_escape_string($category->getName());
    $url_key = $category->getUrlKey();
    $url_path = $category->getUrl();
    $is_active = $category->getIsActive();
    $now = time();

    $catids = array();
    foreach ($category->getParentCategories() as $parent) {
        $catids[] = $parent->getId();
    }
    unset($catids[count($catids) - 1]);

    $parent = NULL;
    if (empty($catids)) {
        $parent = NULL;
    } else {
        $parent = array_pop($catids);
    }

$con = mysql_connect("HOST", "USER", "PASSWORD");
mysql_select_db("DB", $con) or die("");

mysql_query("INSERT INTO `categories`(`id`, `name`, `slug`, `parent_id`, `enabled`, `modified_at`, `modified_by`) VALUES ('$entity_id', '$name', '$url_key', '$parent' ,'$is_active', '$now', 1)")  or die(mysql_error());
}

 
Leave a comment

Posted by on October 27, 2015 in ECommerce, Magento

 
Link

Survey of the Best Online Mapping Tools for Web Developers: The Roadmap to Roadmaps

 
Leave a comment

Posted by on October 20, 2015 in Uncategorized

 

Change Database Collation with PHP

This little sql statement can change the collation in your database including tables, columns and everywhere. This is something phpMyAdmin can not handle completely.

Credits goes to original poster.


$conn1=new MySQLi("localhost","root","","exam_db");
if($conn1->connect_errno){
    echo mysqli_connect_error();
    exit;
}
$res=$conn1->query("show tables") or die($conn1->error);
while($tables=$res->fetch_array()){
    $conn1->query("ALTER TABLE $tables[0] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") or die($conn1->error);
}
echo "The collation of your database has been successfully changed!";

$res->free();
$conn1->close();


 
Leave a comment

Posted by on October 2, 2015 in PHP

 

Tags: