从excel导入sku,然后修改产品的状态Status
2016-01-04 14:56
453 查看
<?php error_reporting(E_ALL); set_time_limit(0); define('MAGENTO', realpath(dirname(__FILE__))); require_once MAGENTO . '/app/Mage.php'; umask(0); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); function changeStatus($sku){ /* * #根据产品SKU修改产品状态 #enabled = 1,disabled = 2 #我这里catalog_product_entity_int表attribute_id=96表示产品的Status值 * */ // For Write $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $sql = "UPDATE catalog_product_entity_int t1, catalog_product_entity t2 SET t1.`value` = 1 WHERE t2.entity_id = t1.entity_id AND t1.attribute_id = 96 AND t2.sku = '{$sku}'"; $write->query($sql); } //============================导入excel start====================================== require_once MAGENTO . '/lib/PHPExcel/PHPExcel.php';//引入PHPExcel类文件 $PHPExcel = new PHPExcel();// 实例化PHPExcel工具类 //excel文件的地址 $excel_fiel_path = MAGENTO.'/var/importexport/2016-01-12.xlsx'; //分析文件获取后缀判断是2007版本还是2003 $extend = pathinfo("./" . $excel_fiel_path); $extend = strtolower($extend["extension"]); // 判断xlsx版本,如果是xlsx的就是2007版本的,否则就是2003 if ($extend=="xlsx") { $PHPReader = new PHPExcel_Reader_Excel2007(); $PHPExcel = $PHPReader->load($excel_fiel_path); }else{ $PHPReader = new PHPExcel_Reader_Excel5(); $PHPExcel = $PHPReader->load($excel_fiel_path); } /* 第二种方法*/ $objWorksheet = $PHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); //echo 'highestRow='.$highestRow; //echo "<br>"; $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数 //echo 'highestColumnIndex='.$highestColumnIndex; //echo "<br>"; $headtitle=array(); for ($row = 2;$row <= $highestRow;$row++) { $strs=array(); //注意highestColumnIndex的列数索引从0开始 for ($col = 0;$col < $highestColumnIndex;$col++) { $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); } ///调用函数 echo $strs[0].'<br>'; changeStatus(trim($strs[0])); } //============================导入excel end======================================
相关文章推荐
- SAP SLT (Landscape Transformation) 企业定制培训
- Shiro web 和spring
- MFC基础类及其层次结构
- Xcode插件管理工具Alcatraz
- Angularjs1.x 项目结构
- [Android]使用Dagger 2依赖注入 - 图表创建的性能(翻译)
- storm提交任务
- 遗留问题
- 在同服务器下,安装多个不同jetty容器
- HAProxy和负载均衡概念介绍
- javaweb 服务器 提供SOAP协议接口,android客户端调用代码实现过程
- 关于CodeFile和CodeBehind
- ubuntn 12.04源
- 随笔 2016-1-4
- android 4.4打开MTP模式以及USB CD Rom模式打开方法
- Oracle的rollup、cube、grouping sets函数
- swing 之FlowLayout 实现自动换行和滚动条添加
- 浅析JVM及其调优(一)
- QT运行时加载UI文件
- IIS将应用程序池配置为在计划时间执行回收 (IIS 7)