Jump to content

Automatic Locations based on Category Selection


Josh Journey

Recommended Posts

You'll need to create filter_functions.php and will need to modify the switch statement for your categories/related listings.

Clickfwd\Hook\Filter::add('listing_save_pre', function($data, $params) 
{

    if (! $params['is_new']) {
            return $data;
    }
    else {

        // Get the category
        $category = $data["Listing"]["catid"];

        switch ($category) {

            case "18": // Alaska
                $data["Field"]["Listing"]["jr_location"][0] = "172"; // North America
                $data["Field"]["Listing"]["jr_location"][1] = "171"; // United States
                $data["Field"]["Listing"]["jr_location"][2] = "47"; // Alaska

            break;
            case "21": // Alberta
                $data["Field"]["Listing"]["jr_location"][0] = "172"; // North America
                $data["Field"]["Listing"]["jr_location"][1] = "1086"; // Canada
                $data["Field"]["Listing"]["jr_location"][2] = "50"; // Alberta
            break;
	//case "":
	//break;
            default:
                      return $data;
                  }
        return $data;
    }
});

Change out each case with the category id you'd like to assign related listing data to. It was helpful to create a master index list so I could quickly copy each id and would write as much code as possible without data such as $data["Field"]["Listing"]["jr_location"][] = "" so that I only had to place in the listing id's and index arrays. Alternatively could keep each full index for each listing followed by leaving the index blank for a quick copy and paste fest. You can do this for other custom fields, default locations such as coordinates. Can easily be done for multi-select variations too.

Link to comment
×
×
  • Create New...