ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Expire a category on a related entry

April 27, 2012 5:01am

Subscribe [2]
  • #1 / Apr 27, 2012 5:01am

    WhiteConcierge

    11 posts

    I have a conundrum that has me flummoxed!! I’m guessing there could be a couple of potential solutions but as yet I keep hitting brick walls.

    I have a restaurants channel with a batch of entries, I also have a special offers channel with an offer added as an entry.  Back in the restaurants entry I have set up a related_entry to call in the offer and set an expiry date on the offer as directed in this thread.  Now I’m using MX Google maps and everything works well, I can find restaurants in a given radius and if one of those restaurants has an offer within the valid period it will show the offer and after the period the offer is removed.  What I need to do next is search for restaurants within the radius WITH special offers, to do this I need create a category for special offers and assign the category to the restaurant, here lies the issue.  The restaurant(s) with a special offer is/are being returned but they are continually being returned after the special offer has expired.  How can I expire the category so restaurants with expired offers are not returned, is there a way of dynamically setting/removing a category or is there another way around this.  Any help on this is very much appreciated.

    Cheers
    Jon

  • #2 / Apr 27, 2012 12:19pm

    Neil Evans

    1403 posts

    So as far as i can tell…
    you have related offers to restaurants. And then in your search your query for restaurants with offers (but the system does not then check if those offers are expired, just if there is an offer)

    The only way i can see to do this is with a custom query of your own which returns the restaurants and then checks if offer has expired or not.

    You would want to do this early on, otherwise returning the first 10 restaurants might then be filtered down to just 2 with active offers - so really it needs to be a custom db query.

    However, if you are returning all within that selected area - could you use a filter that “hides” non active restaurants, allowing the user to turn them back on again if and as they need?

  • #3 / Apr 30, 2012 4:15am

    WhiteConcierge

    11 posts

    Thanks for your response Nevsie,
    You are correct in your understanding of what I’m trying to achieve.  Returning all within a selected area is not a problem as the restaurants with special offers will show an icon depicting this and if expired the icons and offer details on subsequent pages will be removed.

    So it’s just with a dedicated search for “Special offers” which is the issue.  I guess what you’re saying is I need a custom db query that when returning restaurants categorised as “special offers” is checked against expiry date and results returned that are valid.  That sounds like a perfect solution, the only question now is “how do I do that?”, I’m not versed in mySql or PHP for that matter so any help from anyone within that arena would be very much appreciated.

    Cheers
    Jon

  • #4 / Apr 30, 2012 10:46am

    Dan Decker

    7338 posts

    Hi Jon,

    You might want to think along the lines of adding the new category to your offers channel. That way you can denote an offer as “special” and relate it to the correct restaurant. Then those special offers would expire just like any other offer.

    If you wanted to go a bit further, you could create a new channel solely for special offers, and add an additional relationship field to your restaurants channel.

    However, there is no way to “expire” a category, or change it automatically.

    Cheers!

  • #5 / May 01, 2012 4:24am

    WhiteConcierge

    11 posts

    Hi Dan,
    Thanks for your response.
    I have done exactly that in both instances and tried all options.
    I have a special offers Channel and a special offers category, I then assigned the category to the channel and added a related_entries channel field.  When the special offer is used in a restaurant entry and is within its validity period I assumed it would show but it’s not showing at all, it only shows when the special offers category is assigned to the restaurants channel and selected in the restaurant entry.
    Is that right that categories assigned and set in a related_entries entry do not get carried through to the main entry it’s related to??

    Cheers
    Jon

  • #6 / May 02, 2012 11:12am

    Dan Decker

    7338 posts

    Hey Jon,

    I would expect categories to not factor in. Related entries should pull in regardless.

    Can I get you to post all the relevant template code? I’d love to have a look at how it all ties together.

    Cheers,

  • #7 / May 08, 2012 4:52am

    WhiteConcierge

    11 posts

    Hi Dan,
    apologies for delayed response, been suffering with man flu.
    Here’s my template code.

    <strong>Search</strong>
    
    {exp:mx_google_map:form result_page="results_panels/restaurantResults" log="" lat="" unit="m" backspace="1" id="restForm" show_expired="no"} 
      <fieldset class="locations">
       <label class="label_select" for="locationSelectR"> Location</label>
       <input id="locationSelectR" class="of locSelect" type="text" name="address"> 
      </fieldset>   
         
      <fieldset class="cuisine">
       <label class="label_select" for="cuisine"> Cuisine</label>
       <select class="select regularSelect2 catSel1" id="cuisine" name="categories[]"> 
        <option>--</option>
       {exp:channel:categories channel="restaurants" category_group="8" style="linear"}
        <option id="{category_id}" value="{category_id}">{category_name}</option>
       {/exp:channel:categories}
       </select>
      </fieldset>
    
      <fieldset class="bestFor">
       <label class="label_select" for="bestFor"> Best for</label>
       <select class="select regularSelect2 catSel2" id="bestFor" name="categories[]"> 
        <option>--</option>
       {exp:channel:categories channel="restaurants" category_group="7" style="linear"}
        <option id="{category_id}" value="{category_id}">{category_name}</option>
       {/exp:channel:categories}
       </select>
      </fieldset>
    
      <fieldset class="price">
       <label class="label_select" for="restPrice"> Price range</label>
       <select class="select regularSelect2 catSel5" id="restPrice" name="categories[]">
        <option>--</option>
       {exp:channel:categories channel="restaurants" category_group="9" style="linear"}
        <option id="{category_id}" value="{category_id}">{category_name}</option>
       {/exp:channel:categories}               
       </select>      
      </fieldset>
            
      <fieldset class="distRadius">     
       <label class="label_select" for="radiusR">Radius of</label>
       <input class="" name="radius" id="radiusR" value="" readonly="readonly" /> <span class="miles">Miles</span>
       <input class="radiusKmH" id="kiloRadiusR" value="" readonly="readonly" /> <span class="miles">Kilometres</span>      
      </fieldset>
        
      {exp:channel:categories channel="restaurant_special_offers" category_group="11" style="linear" limit="1" show_expired="no"}    
       <fieldset class="radios">
        <label class="label_select">Special Offers</label>
        <label class="label_check" for="{category_id}">
        <input name="categories[]" id="{category_id}" value="{category_id}" type="checkbox" {checked} />
        {category_description} </label>
       </fieldset>
      {/exp:channel:categories} 
            
      <button class="go goRest green button" id="locate" type="submit">Go</button> 
    
    {/exp:mx_google_map:form}

    The special offers is in the last fieldset.
    And here’s the results code.

    <strong>Results</strong>
    
    {exp:mx_google_map:search channel="restaurants" reverse_geocoding="true" address="" log="" lat="" unit="m" prec="2" radius="" limit="2000" orderby=“distance” show_expired="no"}
     You searched for <span class="priceType"></span> <strong class="cuisineType"></strong> restaurants<span class="bestType"></span> within a <strong>{radius}</strong> Mile radius <span class="of">{address}</span>.
      <table cellspacing="0" cellpadding="0" width="100%" class="resTable">
       <thead>
        <tr>
         <th>No.</th>
         <th width="100">Restaurant</th>
         <th class="resRight">Dist.</th>
         <th>Info</th>
         <th>Price</th>
         <th> </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <td> </td><td> </td><td> </td>
         <td> </td><td> </td><td> </td>
        </tr>
        {entries}{restAddress}
        <tr>   
         <td valign="top"><a href="http://{url_title_path=%22name=%22num{count}%22&gt&lt/a&gt{site_url}/images/numb/{count}.png&lt/td&gt" class="resRight">/images/info.png</a></td>
        </tr>
        {if no_results}
         <tr>
          <td colspan="6">
    
            No Restaurants were found for your search.
    
          </td>
         </tr>
        {/if}
        {restAddress}{/entries}
       </tbody>
      </table>
    {/exp:mx_google_map:search}

    The

    {if special_offers}

    conditional works perfectly in that it shows a special offer icon if the special offer is within its valid period and this functionality provides an indication of offers available when doing a wider search but when a specific search is made for special offers all expired offers are shown too (without icon).  (sorry if I’m repeating the issue, I’m sure you understand by now).

    Cheers
    Jon

  • #8 / May 11, 2012 4:20am

    WhiteConcierge

    11 posts

  • #9 / May 11, 2012 11:39am

    Dan Decker

    7338 posts

    Hi John!

    Oh man, that was funny. Sorry to leave you hanging. We had a release this week and things tend to get backed up with that.

    Oh… oh. This is built using MX Google Maps? That kinda takes me out of the running for providing support. The way that add-on behaves is outside the purview of ExpressionEngine. You’ll have to file your ticket with Max.

    I’m sorry it took us till now to get to that.

    Cheers,

  • #10 / May 14, 2012 4:12am

    WhiteConcierge

    11 posts

    Hi Dan,
    No problem. Thanks for pointing me in the right direction.

    Cheers
    Jon

  • #11 / May 16, 2012 4:47pm

    Dan Decker

    7338 posts

    Hi Jon,

    Thank you for using ExpressionEngine!

    If you have other questions in the future, just let us know.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases