【发布时间】:2012-12-02 17:02:59
【问题描述】:
我尝试在以下文章的帮助下按地理位置数据对 magento 中的产品列表进行排序:https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=hu-HU。
我在我的模块中覆盖了 Mage_Catalog_Block_Product_List 以便我可以访问这行代码:
$this->_productCollection = $layer->getProductCollection();
拥有 _productCollection 对象后,我想将公式添加为“虚拟”属性“距离”,以便可以使用它对查询进行排序。这是我的想法:
$this->_productCollection = $layer->getProductCollection()
->addAttributeToSelect('distance','I insert my custom formula here')
->addAttributeToSort('distance','DESC');
我知道 API 不是为处理这种语法而设计的,但我认为它可以帮助人们理解这个想法。
这是我要添加的公式:
SELECT ( 3959 * acos( cos( 弧度(37) ) * cos( 弧度( lat ) ) * cos(弧度(lng)-弧度(-122))+ sin(弧度(37))* sin( 弧度( lat ) ) ) ) AS 距离
知道怎么做吗?
【问题讨论】:
标签: magento geolocation