magento后台无法删除订单(似乎不是magento团队不添加这个功能,因为似乎商家删订单涉及法律问题),所以就在数据库删吧。

在数据库运行如下命令,若可以,请备份数据库后再做此操作。 以下命令将订单和用户都清空了,我试过只删除订单不删用户是不行的,因为用户的数据和订单总是关联的,不一起删除删不干净。记得清空magento的var文件

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;

TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;

ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;

TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

如果你通过后台去删除,你会发现magento后台提供的产品批量删除功能几乎不能用.为什么,因为magento采用EAV的数据库设计模式,一个产品的数据记录会保存在大概10个以上,甚至20个表中,那么删除时肯定会使用事务,在批量删除时我想是没处理好,导到mysql在执行时非常缓慢.很多想,既然magento不行,我们就直接从数据库操作,但是到底和哪些表相关呢,要如何才能完整干净的清除所有的产品呢?

TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
insert into `catalog_product_link_type`(`link_type_id`,`code`) values (1,’relation’),(2,’bundle’),(3,’super’),(4,’up_sell’),(5,’cross_sell’);
insert into `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) values (1,2,’qty’,'decimal’),(2,1,’position’,'int’),(3,4,’position’,'int’),(4,5,’position’,'int’),(6,1,’qty’,'decimal’),(7,3,’position’,'int’),(8,3,’qty’,'decimal’);
insert into `cataloginventory_stock`(`stock_id`,`stock_name`) values (1,’Default’);

1.进入原来的phymyadmin,选择magento的那个数据库,在右边的标签上点击导出。

2.全选所有的表,结构那儿都勾上:添加 DROP TABLE,如果不存在就增加,添加 AUTO_INCREMENT 值,请在表名及字段名使用引号;数据那儿选择完整插入;勾上另存为文件,点击执行,保存当前数据库 。

3.打开保存的数据库导出的文件

在头上添加

SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;
SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;
SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;
SET NAMES utf8;
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;
SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;

在结尾添加

SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT;
SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS;
SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;
SET SQL_NOTES=@OLD_SQL_NOTES;

然后查找并且替换所有的 原来的主路径 到 现在的主路径(比如原来是www.amagento.com,现在是www.bmagento.com,必须要全部替换掉),不然数据转移后的Magento将仍然不能使用。

4.在新的地方重新安装MAGENTO,再将app和skin文件全部覆盖去,访问新的地方的phpmyadmin,点击导入,将上面的那个文件选择进去,如果太大,压缩为ZIP格式,点击执行。

5.修改配置文件

/app/etc/local.xml


< ![CDATA[localhost]]>
< ![CDATA[database_username]]>

< ![CDATA[database_password]]> < ![CDATA[database_name]]>
1

6.完成之后将新的magento文件夹下面var/session,和var/cache下面的缓存文件全部清空。

到此,Magento数据转移全部完成。

显示父分类的分类名
$currentCat = Mage::registry(‘current_category’);
//如果是根目录,则显示当前目录
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
//显示当前目录名
echo $this->getCurrentCategory()->getName() ;
else
{
//显示当前目录的父分类名
echo $this->getCurrentCategory()->getParentCategory()->getName() ;
}
显示子分类的分类名
显示的子分类是建立在当前的父分类的基础上
$currentCat = Mage::registry(‘current_category’);

if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// 当前分类是顶级分类
$loadCategory = $currentCat;
}
else
{
// 当前分类是顶级分类的的一个子分类,载入当前分类的父分类
$loadCategory = Mage::getModel(‘catalog/category’)->load($currentCat->getParentId());
}
$subCategories = explode(‘,’, $loadCategory->getChildren());

foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel(‘catalog/category’)->load($subCategoryId);

if($cat->getIsActive())
{

}
}

magento系统开发的商城中,子目录的url地址默认会带上一级目录的url key,如果要去掉子目录中带的父目录的url key,例如:

多级分类URL:http://www.xxx.com/catagory1/catagory2/catagory3

简化后的URL:分类3的路径为:http://www.xxx.com/catagory3

打开app/code/core/Mage/Catalog/Model/Url.php这个php文件,找到

if (null === $parentPath) {

$parentPath = $this->getResource()->getCategoryParentPath($category);

}

elseif ($parentPath == ‘/’) {

$parentPath = ”;

}

把上面的代码修改为:

//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == ’/') {
$parentPath = ”;
//}