magento获取商品信息
来源:互联网 发布:全国房地产数据公司 编辑:程序博客网 时间:2024/05/01 21:28
I was recently working on a site where a “featured” product was required on the homepage. Rather than just making this a category, or a specific product, I wanted to give as much flexibilty as possible, and also allow them some extra functionality.
So, I created a new attribute, “homepage_product” – a boolean. This attribute can be assigned to any product. So, what if there are 10 products selected? I only have room for one. I needed to get a random product from the list of products that had this attribute selected.
I guess I could have read all the products into an array, and then used rand() to grab a random product from that array, but that seemed to provide an over-head, and seemed too complicated for something that should surely be able to be done in Magento.
So, I came up with this:
// get products tagged with homepage_product$collection = Mage::getModel('catalog/product')->getCollection() ->addFieldToFilter(array( array('attribute'=>'homepage_product','eq'=>'1'), )) ->addStoreFilter();$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));$numProducts = 1;$collection->setPage(1, $numProducts)->load(); foreach($collection as $homepageProduct) { $homepageProductInformation = Mage::getModel('catalog/product')->load($homepageProduct->getEntityId());}?>
- magento获取商品信息
- 二种方法从Magento获取商品ID和商品信息
- 二种方法从Magento获取商品ID和商品信息
- taobao topsdk获取商品信息
- PHP获取淘宝单个商品信息
- 商品信息
- 淘宝开放平台 获取商品信息api权限获取
- magento 获取所有分类
- magento 获取路径
- magento获取当前路径
- magento获取 category
- magento 获取产品分类
- magento getBaseUrl()获取地址
- magento获取当前路径
- magento 获取产品库存
- magento 获取表名
- Magento获取product image
- Magento获取商品CategoryIds
- zoj-1093-Monkey and Banana
- 谷歌地图api v3学习之:起步
- hdu 1305 字典树 模板
- C#在WinFrom程序实现Get和Post请求及QQ农场的Cookie保存
- 配置EIGRP身份认证的步骤为
- magento获取商品信息
- vs2008做的项目转换成vs2005
- 重走Java路
- java项目中遇到的问题及解决办法002
- asterisk常用调试监测命令
- 一款经典简洁的CSS滑动门代码
- 关于 struts2 单例 实例的思考
- 调用startActivityForResult,onActivityResult无响应的问题
- 2013年9月4日、内部类访问特点|思维方法