Skip to content

Instantly share code, notes, and snippets.

@steverobbins
Last active July 12, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverobbins/75108976cd9f1c1e3ebff1e2f4401dc4 to your computer and use it in GitHub Desktop.
Save steverobbins/75108976cd9f1c1e3ebff1e2f4401dc4 to your computer and use it in GitHub Desktop.
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
if (version_compare(phpversion(), '5.3.0', '<')===true) {
echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.3.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
Magento using PHP-CGI as a work-around.</p></div>';
exit;
}
/**
* Compilation includes configuration file
*/
define('MAGENTO_ROOT', getcwd());
$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
include $compilerConfig;
}
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';
if (!file_exists($mageFilename)) {
if (is_dir('downloader')) {
header("Location: downloader");
} else {
echo $mageFilename." was not found";
}
exit;
}
if (file_exists($maintenanceFile)) {
include_once dirname(__FILE__) . '/errors/503.php';
exit;
}
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
#Varien_Profiler::enable();
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
umask(0);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::app($mageRunCode, $mageRunType);
$map = array(693 => 701,
694 => 703,
695 => 731,
696 => 712,
697 => 704,
698 => 706,
699 => 707,
700 => 708,
701 => 709,
702 => 710,
703 => 714,
704 => 715,
705 => 716,
706 => 717,
707 => 718,
708 => 719,
709 => 723,
710 => 724,
711 => 725,
712 => 726,
713 => 727,
714 => 728,
715 => 729,
716 => 734,
717 => 735,
718 => 736,
720 => 737,
721 => 747,
722 => 748,
723 => 749,
724 => 750,
725 => 733,
726 => 732,
727 => 763,
728 => 764,
729 => 766,
730 => 767,
731 => 769,
732 => 770,
733 => 771,
734 => 772,
735 => 751,
736 => 752,
737 => 753,
738 => 754,
739 => 755,
740 => 757,
741 => 758,
742 => 760,
743 => 759,
745 => 761,
746 => 738,
747 => 739,
748 => 740,
749 => 741,
750 => 742,
751 => 743,
752 => 744,
753 => 745,
754 => 746,
755 => 721,
756 => 720,
757 => 730,
758 => 711,
759 => 713,
760 => 762,
761 => 705,
762 => 722,
763 => 756,
764 => 702,
765 => 768,
766 => 765,);
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku');
foreach ($products as $product) {
$categories = $product->getCategoryCollection()->getAllIds();
echo '"' . $product->getSku() . '",';
$cats = array();
foreach ($categories as $cat) {
if (isset($map[$cat])) {
$cats[] = $map[$cat];
}
}
echo '"' . implode(",", $cats) . '"' . PHP_EOL;
}
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage
* @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
if (version_compare(phpversion(), '5.3.0', '<')===true) {
echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.3.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
Magento using PHP-CGI as a work-around.</p></div>';
exit;
}
/**
* Compilation includes configuration file
*/
define('MAGENTO_ROOT', getcwd());
$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
include $compilerConfig;
}
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';
if (!file_exists($mageFilename)) {
if (is_dir('downloader')) {
header("Location: downloader");
} else {
echo $mageFilename." was not found";
}
exit;
}
if (file_exists($maintenanceFile)) {
include_once dirname(__FILE__) . '/errors/503.php';
exit;
}
require MAGENTO_ROOT . '/app/bootstrap.php';
require_once $mageFilename;
#Varien_Profiler::enable();
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
umask(0);
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::app($mageRunCode, $mageRunType);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$file = fopen('cp.csv', 'r');
while (($row = fgetcsv($file)) !== false) {
$sku = $row[0];
$cats = explode(',', $row[1]);
if (count($cats) == 0) {
continue;
}
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
if (!$product || !$product->getId()) {
echo 'No product ' . $sku . PHP_EOL;
continue;
}
echo $sku . PHP_EOL;
$current = $product->getCategoryCollection()->getAllIds();
$save = false;
foreach ($cats as $cat) {
if (!in_array($cat, $current)) {
$save = true;
$current[] = $cat;
}
}
if ($save) {
$product->setCategoryIds($current)->save();
}
}
insert into mage_catalog_category_product (category_id, product_id, position)
select mc.prod_id, mp.prod_id, mcp.position
from migrate_category_product mcp
inner join migrate_category mc on mc.stage_id = mcp.category_id
inner join migrate_product mp on mp.stage_id = mcp.product_id
where mcp.category_id in (697,698,699,700,701,758,703,704,706,766,765)
on duplicate key update position = mcp.position;
insert into mage_catalog_category_product_index (category_id, product_id, position, is_parent, store_id, visibility)
select mc.prod_id, mp.prod_id, mcp.position, mcp.is_parent, mcp.store_id, mcp.visibility
from migrate_category_product_index mcp
inner join migrate_category mc on mc.stage_id = mcp.category_id
inner join migrate_product mp on mp.stage_id = mcp.product_id
where mcp.category_id in (697,698,699,700,701,758,703,704,706,766,765)
on duplicate key update position = mcp.position, is_parent = mcp.is_parent, store_id = mcp.store_id, visibility = mcp.visibility;
select c_name.value, c_url.value, c_display.value, c_metatitle.value, c.position
from mage_catalog_category_entity c
inner join mage_catalog_category_entity_varchar c_name on c_name.entity_id = c.entity_id and c_name.store_id = 0 and c_name.attribute_id = 33
inner join mage_catalog_category_entity_varchar c_url on c_url.entity_id = c.entity_id and c_url.store_id = 0 and c_url.attribute_id = 35
inner join mage_catalog_category_entity_varchar c_display on c_display.entity_id = c.entity_id and c_display.store_id = 0 and c_display.attribute_id = 41
inner join mage_catalog_category_entity_varchar c_metatitle on c_metatitle.entity_id = c.entity_id and c_metatitle.store_id = 0 and c_metatitle.attribute_id = 38
-- where c.path like "1/693/%"
where c.parent_id = 720 or c.parent_id = 724
order by c.parent_id, round(length(c.path) - length(replace(c.path, "/", "")) - length("c.path")), c.position;
insert into migrate_category_id (stage_id, prod_id)
select mc.entity_id, c.entity_id
from migrate_category mc
inner join mage_catalog_category_entity_varchar c on c.value = mc.value and c.attribute_id = 33 and c.store_id = 0
where mc.entity_id > 692
and c.entity_id > 700
and mc.attribute_id = 33
and mc.store_id = 0;
update mage_nwdthemes_revslider_slides set
params = replace(params, 'staging.flashingblinkylights.com', 'new.alightpromos.com'),
layers = replace(layers, 'staging.flashingblinkylights.com', 'new.alightpromos.com');
insert into mage_price_matrix (product_id, ap_net_price, marktype1, marktype2, marktype3, marktype4, markamount1, markamount2, markamount3, ap_net_day1, ap_list_day1, ap_net_day2, ap_list_day2, fbl_day1, fbl_day2, multiplier, notes, old_id)
select p.entity_id, mm.ap_net_price, mm.marktype1, mm.marktype2, mm.marktype3, mm.marktype4, mm.markamount1, mm.markamount2, mm.markamount3, mm.ap_net_day1, mm.ap_list_day1, mm.ap_net_day2, mm.ap_list_day2, mm.fbl_day1, mm.fbl_day2, mm.multiplier, mm.notes, mm.old_id
from migrate_matrix mm
left join mage_price_matrix m on m.old_sku = mm.old_sku
inner join mage_catalog_product_entity p on p.sku = mm.old_sku
where m.old_sku is null;
insert into mage_price_matrix_price (matrix_id, qty, fbl_price, markdown, ap_net, ap_list, markup, custom_show, stock_show, is_custom, show_5day, show_60day, fbl_real, markup_5day)
select m.id, mmp.qty, mmp.fbl_price, mmp.markdown, mmp.ap_net, mmp.ap_list, mmp.markup, mmp.custom_show, mmp.stock_show, mmp.is_custom, mmp.show_5day, mmp.show_60day, mmp.fbl_real, mmp.markup_5day
from migrate_matrix_price mmp
inner join migrate_matrix mm on mm.id = mmp.matrix_id
inner join mage_price_matrix m on m.old_sku = mm.old_sku
where m.id > 1455;
;
update mage_price_matrix m
inner join mage_catalog_product_entity p on m.product_id = p.entity_id
set m.old_sku = p.sku;
update migrate_category mc
inner join mage_catalog_category_entity_varchar cv
on cv.attribute_id = 35
and cv.store_id = 0
and cv.entity_id > 700
and mc.slug = cv.value
set prod_id = cv.entity_id
where mc.stage_id > 692;
delete from migrate_category where prod_id = 0;
update migrate_product mp
inner join mage_catalog_product_entity p
on p.sku = mp.sku
set mp.prod_id = p.entity_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment