magento custom product api (2) --- getskubyurl
来源:互联网 发布:福彩双色球软件靠谱吗 编辑:程序博客网 时间:2024/05/17 07:36
注意:首先要保证url key 唯一
至于api配置部分就不再重复,想看配置custom api请点击:magento custom api configuration
/* * Get product sku by url_key * @param string $urlKey * @param null $store * * @return array */ public function getskubyurl($urlKey,$store=null){ error_log("\n----urlKey param------".var_export($urlKey,true),3,Mage::getBaseDir().'/var/log/getSkuByUrl.log'); $baseUrl = Mage::getBaseUrl(); $baseUrl = str_ireplace('index.php/', '', $baseUrl); //not used //$urlKey = str_replace($baseUrl, '', $urlKey); $urlKey = str_ireplace('http://www.homes-up.com/', '', $urlKey); $urlKey = str_ireplace('.html', '', $urlKey); error_log("\n----urlKey ------".var_export($urlKey,true),3,Mage::getBaseDir().'/var/log/getSkuByUrl.log'); $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToSelect('sku'); $collection->addAttributeToSelect('updated_at'); $collection->addAttributeToFilter("url_key", trim($urlKey)); $collection = $collection->getData(); $result = array(); if(count($collection) && isset($collection[0]['sku'])){ $result['sku'] = $collection[0]['sku']; $result['updated_at'] = $collection[0]['updated_at']; } return $result; }
That's all ,thank you!
希望能给刚刚开始接触magento的朋友一点帮助,同时欢迎大家指正我代码的错误之处,非常感谢!
- magento custom product api (2) --- getskubyurl
- magento custom product api (1)--- infomobile
- magento custom product api (3) --- getupdatedproducts
- magento custom product api(4) --- getallproducts
- magento custom category api (2) --- collectioninfo
- create magento custom api
- magento custom api configuration
- Writing Magento Custom API
- Magento How To Display Product Custom Option On list.phtml
- 获得magento simple product的custom option信息
- magento custom category api (1) --- collectiontree
- magento获得产品的custom option信息 Getting all custom options of a product
- Magento - get custom attributes
- [Magento] Get Product Attributes
- [Magento] Product Import Scripts
- magento missing product img
- magento product import
- Magento获取product image
- 每次都查fopen模式,烦人
- C# 上传文件到指定目录,单击下载文件,删除指定目录文件,打开文件列表
- linux下递归删除目录下所有文件
- php函数-- array_pop() 和array_splice()
- XML介绍之XML使用CSS与XSL修饰
- magento custom product api (2) --- getskubyurl
- 游戏数据分析-基本指标
- AVR MCU 选型指南
- java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/Str
- 基于Ubuntu 11.10/12.04编译OpenCV 2.3.x和2.4.x(适用于Fedora和红帽子rhel 6.2)
- 面试1
- 诡异的楼梯(2)
- Cxf webservice Can't find the request for **'s Observer
- 工作流简介