예제 #1
0
 public function searchArea()
 {
     $resto_cuisine = '';
     $rating = '';
     $minimum = '';
     $pay_by = '';
     $minus_has_delivery_rates = 0;
     $cuisine_list = Yii::app()->functions->Cuisine(true);
     $country_list = Yii::app()->functions->CountryList();
     $this->data['s'] = isset($this->data['s']) ? $this->data['s'] : "";
     $search_str = explode(",", $this->data['s']);
     if (is_array($search_str) && count($search_str) >= 2) {
         $city = isset($search_str[1]) ? trim($search_str[1]) : '';
         $state = isset($search_str[2]) ? trim($search_str[2]) : '';
     } else {
         $city = trim($this->data['s']);
         $state = trim($this->data['s']);
     }
     $from_address = $this->data['s'];
     if (empty($from_address)) {
         $from_address = isset($this->data['st']) ? $this->data['st'] : '';
         if (!empty($this->data['st'])) {
             $_SESSION['kr_search_address'] = $this->data['st'];
         }
     }
     if ($res = Yii::app()->functions->searchByArea($city, $state)) {
         if (is_array($res) && count($res) >= 1) {
             $total = Yii::app()->functions->search_result_total;
             $feed_datas['sEcho'] = $this->data['sEcho'];
             $feed_datas['iTotalRecords'] = $total;
             $feed_datas['iTotalDisplayRecords'] = $total;
             /*dump($feed_datas);
               die();*/
             foreach ($res as $val) {
                 $merchant_address = $val['street'] . " " . $val['city'] . " " . $val['post_code'];
                 $miles = 0;
                 $kms = 0;
                 $ft = false;
                 $new_distance_raw = 0;
                 if ($distance = getDistance($from_address, $merchant_address, $val['country_code'], false)) {
                     $miles = $distance->rows[0]->elements[0]->distance->text;
                     //dump($miles);
                     if (preg_match("/ft/i", $miles)) {
                         $ft = true;
                         $miles_raw = $miles;
                         $new_distance_raw = str_replace("ft", '', $miles);
                         $new_distance_raw = ft2kms(trim($new_distance_raw));
                     } else {
                         $miles_raw = str_replace(array(" ", "mi"), "", $miles);
                         $kms = miles2kms(unPrettyPrice($miles_raw));
                         $new_distance_raw = $kms;
                         $kms = standardPrettyFormat($kms);
                     }
                 }
                 /*get merchant distance */
                 $mt_delivery_miles = Yii::app()->functions->getOption("merchant_delivery_miles", $val['merchant_id']);
                 $merchant_distance_type = Yii::app()->functions->getOption("merchant_distance_type", $val['merchant_id']);
                 /*dump($mt_delivery_miles);
                 		dump($miles_raw);*/
                 $resto_cuisine = '';
                 $cuisine = !empty($val['cuisine']) ? (array) json_decode($val['cuisine']) : false;
                 if ($cuisine != false) {
                     foreach ($cuisine as $valc) {
                         if (array_key_exists($valc, (array) $cuisine_list)) {
                             $resto_cuisine .= $cuisine_list[$valc] . ", ";
                         }
                     }
                     $resto_cuisine = !empty($resto_cuisine) ? substr($resto_cuisine, 0, -2) : '';
                 }
                 $resto_info = "<h5><a href=\"" . baseUrl() . "/store/menu/merchant/" . $val['restaurant_slug'] . "\">" . $val['restaurant_name'] . "</a></h5>";
                 //$resto_cuisine="<span class=\"cuisine-list\">".$resto_cuisine."</span>";
                 $resto_cuisine = wordwrap($resto_cuisine, 50, "<br />\n");
                 $resto_info .= "<p class=\"uk-text-muted\">" . $val['street'] . " " . $val['city'] . " " . $val['post_code'] . "</p>";
                 if (array_key_exists($val['country_code'], (array) $country_list)) {
                     $resto_info .= "<p class=\"uk-text-bold\">" . $country_list[$val['country_code']] . "</p>";
                 }
                 $resto_info .= "<p class=\"uk-text-bold\">" . Yii::t('default', "Cuisine") . " - " . $resto_cuisine . "</p>";
                 $delivery_est = Yii::app()->functions->getOption("merchant_delivery_estimation", $val['merchant_id']);
                 $distancesya = $miles_raw;
                 $unit_distance = $merchant_distance_type;
                 if (!empty($from_address)) {
                     if ($ft == TRUE) {
                         $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Distance") . ": </span> {$miles_raw} </p>";
                         if ($merchant_distance_type == "km") {
                             $distance_type = Yii::t("default", "km");
                         } else {
                             $distance_type = Yii::t("default", "miles");
                         }
                     } else {
                         if ($merchant_distance_type == "km") {
                             $distance_type = Yii::t("default", "km");
                             $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Distance") . ": </span> {$kms} " . Yii::t("default", "km") . "</p>";
                             $distancesya = $kms;
                         } else {
                             $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Distance") . ": </span> {$miles_raw} " . Yii::t("default", "miles") . "</p>";
                             $distance_type = Yii::t("default", "miles");
                         }
                     }
                 }
                 $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Delivery Est") . ": </span> " . $delivery_est . "</p>";
                 if (is_numeric($mt_delivery_miles)) {
                     $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Delivery Distance") . ": </span> " . $mt_delivery_miles . " " . $distance_type . "</p>";
                 }
                 $shipping_enabled = Yii::app()->functions->getOption("shipping_enabled", $val['merchant_id']);
                 //delivery rates table
                 $delivery_fee = $val['delivery_charges'];
                 if ($shipping_enabled == 2) {
                     $FunctionsK = new FunctionsK();
                     //$distancesya=round($distancesya);
                     //dump($distancesya);
                     $delivery_fee = $FunctionsK->getDeliveryChargesByDistance($val['merchant_id'], $distancesya, $unit_distance, $delivery_fee);
                     if ($delivery_fee >= 0.01) {
                         if (isset($_GET['filter_promo'])) {
                             if (preg_match("/free-delivery/i", $_GET['filter_promo'])) {
                                 $minus_has_delivery_rates++;
                                 continue;
                             }
                         }
                     }
                 }
                 if (is_numeric($delivery_fee) && $delivery_fee >= 1) {
                     $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Delivery Fee") . ":</span> " . displayPrice(getCurrencyCode(), prettyFormat($delivery_fee)) . "</p>";
                 } else {
                     $resto_info .= "<p><span class=\"uk-text-bold\">" . Yii::t("default", "Delivery Fee") . ":</span> " . "<span class=\"uk-text-success\">" . Yii::t("default", "Free Delivery") . "</span>" . "</p>";
                 }
                 $image = '';
                 $merchant_photo = Yii::app()->functions->getOption("merchant_photo", $val['merchant_id']);
                 if (!empty($merchant_photo)) {
                     $image .= "<a href=\"" . baseUrl() . "/store/menu/merchant/" . $val['restaurant_slug'] . "\">";
                     $image .= "<img class=\"uk-thumbnail uk-thumbnail-mini\" src=\"" . baseUrl() . "/upload/" . $merchant_photo . "\" alt=\"\" title=\"\">";
                     $image .= "</a>";
                 }
                 if (empty($image)) {
                     $image .= "<a href=\"" . baseUrl() . "/store/menu/merchant/" . $val['restaurant_slug'] . "\">";
                     $image .= "<img class=\"uk-thumbnail uk-thumbnail-mini\" src=\"" . baseUrl() . "/assets/images/thumbnail-medium.png\" alt=\"\" title=\"\">";
                     $image .= "</a>";
                 }
                 $ratings = Yii::app()->functions->getRatings($val['merchant_id']);
                 $rating_meanings = '';
                 if ($ratings['ratings'] >= 1) {
                     $rating_meaning = Yii::app()->functions->getRatingsMeaning($ratings['ratings']);
                     $rating_meanings = ucwords($rating_meaning['meaning']);
                 }
                 $rating = "<div class=\"rate-wrap\">\r\n\t    \t\t\t\t<h6 class=\"rounded2\" data-uk-tooltip=\"{pos:'bottom-left'}\" title=\"{$rating_meanings}\" >" . number_format($ratings['ratings'], 1) . "</h6>\r\n\t    \t\t\t\t<span>" . $ratings['votes'] . " " . Yii::t("default", "Votes") . "</span>\r\n\t    \t\t\t\t</div>";
                 $stores_open_day = Yii::app()->functions->getOption("stores_open_day", $val['merchant_id']);
                 $stores_open_starts = Yii::app()->functions->getOption("stores_open_starts", $val['merchant_id']);
                 $stores_open_ends = Yii::app()->functions->getOption("stores_open_ends", $val['merchant_id']);
                 $stores_open_custom_text = Yii::app()->functions->getOption("stores_open_custom_text", $val['merchant_id']);
                 $stores_open_day = !empty($stores_open_day) ? (array) json_decode($stores_open_day) : false;
                 $stores_open_starts = !empty($stores_open_starts) ? (array) json_decode($stores_open_starts) : false;
                 $stores_open_ends = !empty($stores_open_ends) ? (array) json_decode($stores_open_ends) : false;
                 $stores_open_custom_text = !empty($stores_open_custom_text) ? (array) json_decode($stores_open_custom_text) : false;
                 $tip = '';
                 $open_starts = '';
                 $open_ends = '';
                 $open_text = '';
                 $tip .= "<ul class=\"hr_op rounded2\"><i class=\"fa fa-caret-up\"></i>";
                 if (is_array($stores_open_day) && count($stores_open_day) >= 1) {
                     foreach ($stores_open_day as $val_open) {
                         if (array_key_exists($val_open, (array) $stores_open_starts)) {
                             $open_starts = timeFormat($stores_open_starts[$val_open], true);
                         }
                         if (array_key_exists($val_open, (array) $stores_open_ends)) {
                             $open_ends = timeFormat($stores_open_ends[$val_open], true);
                         }
                         if (array_key_exists($val_open, (array) $stores_open_custom_text)) {
                             $open_text = $stores_open_custom_text[$val_open];
                         }
                         $tip .= '<li><span>' . ucwords(Yii::t("default", $val_open)) . '</span><value>' . $open_starts . " - " . $open_ends . "&nbsp;&nbsp;&nbsp;" . ucfirst($open_text) . '</value></li>';
                         $open_starts = '';
                         $open_ends = '';
                         $open_text = '';
                     }
                 } else {
                     $tip .= '<li>' . Yii::t("default", "Not available.") . '</li>';
                 }
                 $tip .= "<div class=\"clear\"></div>";
                 $tip .= "</ul>";
                 $tips = "<a class=\"opening-hours-wrap\" href=\"javascript:;\">" . Yii::t("default", "Hours of Operation") . "{$tip}</a>";
                 $resto_info .= $tips;
                 $resto_info .= "<div class=\"spacer\"></div>";
                 $resto_info .= "<div>\r\n\t\t\t\t\t\t<a class=\"uk-button uk-button-success uk-width-1-2\" href=\"" . baseUrl() . "/store/menu/merchant/" . $val['restaurant_slug'] . "\">";
                 $resto_info .= Yii::t("default", "Order Now");
                 $resto_info .= "</a></div>";
                 $resto_info .= "<div class=\"spacer\"></div>";
                 $table_book = Yii::app()->functions->getOption("merchant_table_booking", $val['merchant_id']);
                 if ($table_book == "") {
                     $resto_info .= "<div>\r\n\t\t\t\t\t\t<a class=\"uk-button uk-button-success uk-width-1-2\" href=\"" . baseUrl() . "/store/menu/merchant/" . $val['restaurant_slug'] . "/?tab=booking" . "\">";
                     $resto_info .= Yii::t("default", "Book a Table");
                     $resto_info .= "</a></div>";
                 }
                 $is_sponsored = '';
                 if ($val['is_sponsored'] == 2) {
                     $is_sponsored = "<br/><div class=\"uk-badge uk-badge-warning\">" . Yii::t("default", "sponsored") . "</div>";
                 }
                 $is_merchant_open = Yii::app()->functions->isMerchantOpen($val['merchant_id']);
                 $merchant_preorder = Yii::app()->functions->getOption("merchant_preorder", $val['merchant_id']);
                 $now = date('Y-m-d');
                 $is_holiday = false;
                 if ($m_holiday = Yii::app()->functions->getMerchantHoliday($val['merchant_id'])) {
                     if (in_array($now, (array) $m_holiday)) {
                         $is_merchant_open = false;
                     }
                 }
                 $tag_open = '';
                 if ($is_merchant_open == TRUE) {
                     $tag_open = '<div class="uk-badge uk-badge-success">' . t("Open") . '</div>';
                 } else {
                     if ($merchant_preorder) {
                         $tag_open = '<div class="uk-badge uk-badge-warning">' . t("Pre-Order") . '</div>';
                     } else {
                         $tag_open = '<div class="uk-badge uk-badge-danger">' . t("Closed") . '</div>';
                     }
                 }
                 $is_sponsored .= $tag_open;
                 $offers = Widgets::offers($val['merchant_id'], 2);
                 $is_sponsored .= $offers;
                 $merchant_latitude = Yii::app()->functions->getOption("merchant_latitude", $val['merchant_id']);
                 $merchant_longtitude = Yii::app()->functions->getOption("merchant_longtitude", $val['merchant_id']);
                 $merchant_latitude = !empty($merchant_latitude) ? $merchant_latitude : '0';
                 $merchant_longtitude = !empty($merchant_longtitude) ? $merchant_longtitude : '0';
                 $feed_data[] = array($image, $resto_info, $rating, !empty($val['minimum_order']) ? displayPrice(getCurrencyCode(), prettyFormat($val['minimum_order'])) . "<br/>" . $is_sponsored : "{$is_sponsored}", $miles_raw, $merchant_latitude, $merchant_longtitude, addslashes($val['restaurant_name']), $merchant_address, $val['restaurant_slug'], $image, $new_distance_raw);
             }
             $this->data['sort_filter'] = isset($this->data['sort_filter']) ? $this->data['sort_filter'] : '';
             //dump($feed_data);
             if ($this->data['sort_filter'] == "distance") {
                 Yii::app()->functions->arraySortByColumn($feed_data, 11);
                 $feed_datas['aaData'] = $feed_data;
             } else {
                 /** sort by distance */
                 if (Yii::app()->functions->getOptionAdmin('search_result_bydistance') == 2) {
                     Yii::app()->functions->arraySortByColumn($feed_data, 11);
                     $feed_datas['aaData'] = $feed_data;
                 } else {
                     $feed_datas['aaData'] = $feed_data;
                 }
             }
             //dump("minus_has_delivery_rates->".$minus_has_delivery_rates);
             if ($minus_has_delivery_rates >= 1) {
                 $feed_datas['iTotalRecords'] = $feed_datas['iTotalRecords'] - $minus_has_delivery_rates;
                 $feed_datas['iTotalDisplayRecords'] = $feed_datas['iTotalDisplayRecords'] - $minus_has_delivery_rates;
                 if ($feed_datas['iTotalRecords'] <= 0) {
                     $this->otableNodata();
                 }
             }
             $this->otableOutput($feed_datas);
         }
     }
     $this->otableNodata();
 }
예제 #2
0
function getDeliveryDistance2($from_address = '', $merchant_address = '', $country_code = '')
{
    $miles = 0;
    $miles_raw = 0;
    $kms = 0;
    if ($distance = getDistance($from_address, $merchant_address, $country_code, true)) {
        $miles = $distance->rows[0]->elements[0]->distance->text;
        $miles_raw = str_replace(array(" ", "mi"), "", $miles);
        $km = $distance->rows[0]->elements[0]->distance->value;
        //$kms=($km * 0.621371 / 1000);
        $kms = miles2kms(unPrettyPrice($miles_raw));
        $kms = standardPrettyFormat($kms);
    }
    return array('mi' => $miles_raw, 'km' => $kms);
}