[Magento代码] 关联SKU到指定的分类下面
来源:互联网 发布:云计算部署模式哪三种 编辑:程序博客网 时间:2024/05/22 15:24
<?phperror_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);/** * 添加产品所属分类 * * @param $skustr 产品SKU拼接的字符串 * @param $$categoryId 分类ID */function add_category_product($skustr,$categoryId){ $skuArray = explode('|',$skustr); foreach($skuArray as $sku){ if(trim($sku)){ $_product = Mage::getModel('catalog/product')->loadByAttribute('sku',trim($sku)); if($_product){ $productId = $_product->getId(); //给该产品添加分类 //先查询是否已经存在,存在就不新增 $read= Mage::getSingleton('core/resource')->getConnection('core_read'); $sql = "SELECT * from catalog_category_product WHERE category_id=$categoryId AND product_id=$productId"; $results = $read->fetchAll($sql); if(!$results){ $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $sql = "insert into catalog_category_product values($categoryId,$productId,1)"; $write->query($sql); } } } }}$skustr = "TL30079 | EP20870 | EP21581 | EP20868 | EP18965 |EP19235 | EP19236 | HB83558 | HB83559 | EP20587 | TL30081 | TL28825 | TL28827 |AT3638RE+ | AT4158+ | AT4284 | AT4085 | ET1126 | AT4079|HW49745NA | TL30122|TL28555 | TL28554 | TL27435 | AT4305 | AT4309 | TL31060 | TL31061 | TL31071 | TL31134 | TL25975-10 | TL11552|AT3957 | AT3956 | AT3715 | AT3372 | AT3373 | TL28534 | AP2032 | HW51122 | HW51121 | HW51120 | HW51119 | HW50080GR | EP20447 | EP19995 | EP20570-110V | EP20571-110V | EP19568-110V | EP20485 | EP21052 | EP20572-110V | TL28822 ";$categoryId = 89;add_category_product($skustr,$categoryId);
0 0
- [Magento代码] 关联SKU到指定的分类下面
- [Magento SQL] 查询分类名称,和该分类下关联的所有sku
- [Magento SQL] 查询指定SKU一段时间范围内的浏览量
- [Magento代码]-导入excel添加分类,并关联产品到该分类下
- [Magento SQL] 更加分类名称,查询该分类下所有的sku
- Magento获取指定分类下的产品
- Magento通过分类id获取该分类下的产品(entity_id、type_id、sku、created_at、updated_at、status、visibility)
- magento获取指定目录分类的子分类
- magento获取指定目录分类的子分类
- magento获取指定目录分类的子分类
- Magento里显示指定分类的所有子分类
- magento -- 根据产品的sku获得产品
- Magento 用代码批量 添加产品的评论review(通过SKU)
- Magento获取指定分类下的产品销量排行
- Magento跟获取分类遍历分类相关的代码段
- 如何将twitter关联到你的magento站点 oauth1
- IPHONE 模板块、Magento 使用Api将Sku添加到Url中 /Magento Free template iphone
- Magento 根据SKU查询订单信息的SQL语句
- 【c/c++】STL标准入门汇总
- hashcode方法浅析
- volley post请求 gzip压缩 json 传输
- 设计模式-工厂方法模式
- Spring事务配置的五种方式
- [Magento代码] 关联SKU到指定的分类下面
- linux环境变量
- 3.HUD 定时任务 常见问题 模型 一个控件看不到有哪些可能
- ListView与GridView的属性讲解
- js this指针绑定问题 及闭包小析
- js 选项卡
- Android设备 xp sp dp dip px 的换算和理解
- 设计模式-抽象工厂模式
- Golang初级系列教程-手把手编写 Hello World