Prestashop:存储搜索结果返回缺失的结果

时间:2016-10-20 14:51:13

标签: google-maps prestashop prestashop-1.6

在商店页面中,我们可以通过提供城市或地址来搜索商店,当我检查结果时,他们会错过一些商店。 我试着检查stores.js文件,我发现存储是由Store控制器的ajax返回的,displayAjax函数正在调用getStores函数。

displaAjax函数

protected function displayAjax()
{
    $stores = $this->getStores();
    $parnode = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><markers></markers>');

    foreach ($stores as $store) {
        $other = '';
        $newnode = $parnode->addChild('marker');
        $newnode->addAttribute('name', $store['name']);
        $address = $this->processStoreAddress($store);

        $other .= $this->renderStoreWorkingHours($store);
        $newnode->addAttribute('addressNoHtml', strip_tags(str_replace('<br />', ' ', $address)));
        $newnode->addAttribute('address', $address);
        $newnode->addAttribute('other', $other);
        $newnode->addAttribute('phone', $store['phone']);
        $newnode->addAttribute('id_store', (int)$store['id_store']);
        $newnode->addAttribute('has_store_picture', file_exists(_PS_STORE_IMG_DIR_.(int)$store['id_store'].'.jpg'));
        $newnode->addAttribute('lat', (float)$store['latitude']);
        $newnode->addAttribute('lng', (float)$store['longitude']);
        if (isset($store['distance'])) {
            $newnode->addAttribute('distance', (int)$store['distance']);
        }
    }

    header('Content-type: text/xml');
    die($parnode->asXML());
}

getStores函数

 public function getStores()
{
    $distance_unit = Configuration::get('PS_DISTANCE_UNIT');
    if (!in_array($distance_unit, array('km', 'mi'))) {
        $distance_unit = 'km';
    }

    if (Tools::getValue('all') == 1) {
        $stores = Db::getInstance()->executeS('
        SELECT s.*, cl.name country, st.iso_code state
        FROM '._DB_PREFIX_.'store s
        '.Shop::addSqlAssociation('store', 's').'
        LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
        LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
        WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id);
    } else {
        $distance = 1000;//(int)Tools::getValue('radius', 100);
        $multiplicator = ($distance_unit == 'km' ? 6371 : 3959);

        $stores = Db::getInstance()->executeS('
        SELECT s.*, cl.name country, st.iso_code state,
        ('.(int)$multiplicator.'
            * acos(
                cos(radians('.(float)Tools::getValue('latitude').'))
                * cos(radians(latitude))
                * cos(radians(longitude) - radians('.(float)Tools::getValue('longitude').'))
                + sin(radians('.(float)Tools::getValue('latitude').'))
                * sin(radians(latitude))
            )
        ) distance,
        cl.id_country id_country
        FROM '._DB_PREFIX_.'store s
        '.Shop::addSqlAssociation('store', 's').'
        LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country)
        LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state)
        WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id.'
        HAVING distance < '.(int)$distance.'
        ORDER BY distance ASC
        LIMIT 0,20');
    }

    return $stores;
}

我试图将半径增加到1000公里但总是得到相同的结果。

2 个答案:

答案 0 :(得分:0)

$distance = 1000;//(int)Tools::getValue('radius', 100);

通过名为“radius”的URL参数获取radius的值(根据上面的代码行)。你有没有尝试增加它的价值?

答案 1 :(得分:0)

我删除了结果限制

 LIMIT 0,20

我得到了所有结果