1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

V4.1.x Displaying variables and extra fields NOT already shown on the page

Discussion in 'Modules / Plugins / Modifications' started by seymourjames, Jul 4, 2009.

  1. seymourjames All Hands On Deck

    Google has nothing to do with anything here :confused:


    One of the issues to appreciate is that extrafields are not independent entities that you can manipulate easily. They are tied to categories and managed in a group for want of a better word. It has never been easy to deal with extrafields in the way you want to do at the template level. They have not been designed to accomplish what now appears to be your goal. One which has taken a few thousand lines of text to get to.

    What is becoming clearer however is why don't you be practical and use $price == 0 to mean Free to Good Home? This variable can be used and manipulated easily at the template level.

    In other words in your checkout you just present a suitable message saying please leave the price field blank if the item is Give Away or Free to Good Home. Just make your message clear. In your viewlisting template you then just test if it is an item for sale or FREE by testing the $price

    {if $price == '0.00'} Free to Good Home {else} For Sale: {$price|format_money}{/if}

    Just after the {$price|format_money} you can also return the value of your extrafield (ONO, OVNO, NO OFFERS) using the normal plugin. However, before you ask, don't expect your checkout to be completely consistent if you have this other extrafield ONO, OVNO, NO OFFERS. It will still display in the checkout even if someone does not enter a price. You will not be able to say if $price == 0 don't display the input request for this extrafield. Search however will be slightly more consistent. People know 0 means free. It is intuitive. What will be silly though is if they put in price 0 and then select ONO in the advanced search. I see no easy or practical way round that unless you make this field non-searchable which is what I would do.

    Likewise you can do something very similar in your showlistings template file too by testing for a zero price.

    In truth I do not understand why are you trying to use extrafields to accomplish your goal and making it complicated? It seems to me that you are trying to make different types of price and attempting to use an extrafield to do it. 68C was not designed to accommodate what you are trying to achieve - multiple states in the price variable. In others words a mixed system of items with prices with different qualities and items without prices. What I have done for property sites is say if price is zero (not given or entered as zero) then it actually always gets displayed everywhere as Price On Application. I do not bother with ONO, OVNO or NO OFFERS - its just overkill and not a real requirement as everything is negotiable in the real world. I really don't think the lack of even having this will make the slightest difference to your site.

    As for other extrafields and displaying them where you want then you can use my prior advice. Set them to not display in the admin control panel and then use the normal extrafield plugin to display them where you wish on your view listing template. The only complication you will have with this approach is if you have different sets of extrafields applying to different categories. It may get messy testing for different categories to know what to specifically display.
  2. T0m1 Customer

    This statement was merely trying to say that if the best way to achieve my goal was to hide data on the actual page unless required to be displayed. Im not a fan of hiding white text on white backgrounds etc, but anyway this is another discussion completely.

    I know and understand that extra fields may not have been designed for this. But I believe that being able to do this opens the script up to more functionality. With regards to your point on $price ==0 I did mention this here http://www.68classifieds.com/forums...ields-not-already-shown-page-3.html#post51248
    Although this is the easiest thing I could do, thinking from the point of the user, this is the most complex thing I could expect them to do. My explanation a couple of posts back, dulled everything down to (as requested by Larry) to just a single extrafield. If I use your idea (which i currently am and find it annoying myself) I would end up with the following;

    0.00 = Free to good home
    0.01 = Wanted
    0.02 = Sold
    0.03 => actual asking price

    (This incidentally is another reason I stated using elseif instead of just else)

    Asking a user to choose if the item is to: Sell, Give Away, Wanted, Sold by means of a drop down box is far easier than asking them to input certain prices to achieve the same goal.

    Indeed I am trying to use an extrafield to accomodate additional "Price States" as it were. I am aware that 68c was not 'innitially' designed to do this and instead offer 2 choices ask for money or not, which personally after having seen a great deal (and I mean researching into hundreds) of different classified websites seems extremely limiting. with the exception of a few every classifieds site (live ones not systems sold) I visited offered the ability to choose ONO, OVNO, No Offers etc as well as asking if it was free, wanted charged. The few that didnt surprisingly had very few advertisements?

    But again don't take me as being rude or sarcastic in my explanations, im not copying them to be like them, heck if that were true id be asking for some very elaborate stuff. Instead I am listening to my users, who have specifically requested the ability to do just this hence I am trying to find a solution to the riddle. Ultimately every site has different sets of users and different requirements, hence there are so many sites out there, if this wasnt true I dare say we would have a handful of sites in the big bad world and nothing more.

    Indeed and I thank you kindly for suggesting this and pointing it out to me (as I was unaware this could be used in this way).
    I do not plan on hundreds of extra fields all over the place, it was mostly just the few above it were to relate to which would be global.

    Kindest regards,
  3. Lhotch curmudgeon

    put {debug} in your layout to make the console pop up.

    Set your extra fields so they are seen in the ad.

    Look at the debug console and see all of the extra fields in an array.

    edit your viewlisting template, you will notice at the template level the array is looped over and the contents displayed. coment out or remove this section and then handle the extra fields manually.

    This will give you the power to manually evaluate and show, if desired, the exta fields or some text based on the contents of a given array element.
  4. seymourjames All Hands On Deck

  5. T0m1 Customer

    Ahh,

    I think on this note I completely agree with David in that it would become overly complex not to mention the hard coding of each and every extra field for the entire site.

    ** PLEASE DONT JUMP ON ME HERE or at least take it in turns**
    But what is the purpose of the "Short Description" field? Obviously this would make upgrading harder, but would it not be possible to change the db field type and then change the form field type in step3.php ensuring that the relevant line in step3submit.php
    Code:
    $data['shortDescription'] = isset($_POST['shortDescription']) ? String::stringHTML($_POST['shortDescription'], 'stringHTML') : '';
    is altered to match?
    I only say this as I cannot imagine the use for a short description field as well as a description field? Unless off course searches are conducted on what content is in the short description field instead of the description field?

    Many thanks
  6. Lhotch curmudgeon

    We are all just throwing darts blindfolded here. The advice you have been given has been half assed because we dont know anything about your site. For every suggestion there are ramifications which may or may not affect you. We cant warn you of them because we dont have a complete detailed idea of what your site consists of.

    There is a loop that loops over the extra field array and displays the results in the template. You can totally remove it and handle it manually which isnt a big deal if you just have a couple extra fields and they are consistent across all cats. Definitely not as practical is you have 100 cats and each cat has 5 unique extra fields, but we dont have the specifics so cant accurately guide you as to a solution.

    If you dont want to do away with the default loop over extra field array at the template you can add in a logical check within the loop and selectively hide/evaluate values within at and act accordingly.

    At the end of the day I personally think the countless hours wasted on bells and whistles should be spent marketing your site. Once you have a solid user base find out whats important to them and THEN work on that. Day in and day out we have people come here and tell us what THEY think is important to their clients and more often than not they are very wrong.
  7. seymourjames All Hands On Deck

    The bottom line is this. 68C was not designed and nor can it be easily modified to manage a site where you have multiple price states: sell, sold, wanted, free and there are conditions on some of those states too like ONO, OVNO, etc. Even if you manage to display things as you wish by hook or by crook, you will be faced with inconsistent data entry in the checkout process (lots of special cases to consider where things will not make sense otherwise). How about asking your advertiser to enter a FREE item and then ask him is it OVNO. These are mutually exclusive aren't they. How about ordering a list of items even. What is the criteria to rank them? Is it price only. Does a FREE item get listed before or after a Wanted item. Does a Wanted item even have a price? Then you also face the problem of making a consistent search. How would it make sense to search FREE items which are ONO etc.

    What I am trying to say is not only is this technically challenging because of the 68C design but your specification is likely to create ambiguities and the market reasons for all of this are doubtful.

    Sure you can find sites that do some of these things but they were almost certainly custom developed and cost a lot of money to develop. All of it was worked out on paper first. In 68C you can even using a few bits of code manage to use the price field creatively when it is left blank.
  8. T0m1 Customer

    Hi Larry and David,

    Again many thanks for responding. I agree that you dont know anything about my site :), but in fairness if I told you it used 68c thats it you know everything there is to know. Other than a custom template nothing has been altered, changed modified etc.

    David, you raise many valid points, and indeed a custom design would have been fantastic, however I am a realistic person. As such, items listed with values of Free, Wanted etc get listed as normal and mixed in with the rest, Unless of course a person selected featured in which case the normal rules still apply. This is mostly because im compromising and know that sorting of this kind would take some serious undertaking.

    As you mentioned, there may be slight odd instances with data and seeing free ono would be strange. This is why I tried to use a conditional statement,
    if field says free show words free else if field says sell show price and flexibility(ono).

    Ok so the input would look strange, but again this is something I am compromising in. In that im happy to display a paragraph saying they are only needed if selling for a price.

    My statement about finding other sites offering this functionality was only in response to yours about it not making a difference, when to my belief it would.

    Larry, At present im still receiving feedback on how the categories wold best be structured so no specifics as yet. However I think it is safe to say that some categories will have unique extra fields (such as cars, make, year, milage), or houses (bedrooms, house type, etc).
    With this in mind I dont think its going to be valid in removing the loop, this would need to remain in place for such fields.

    Right I need to go and complete some tasks, but again many thanks to both of you for your input, it is highly valued and appreciated.

    Kindest regards,
  9. Lhotch curmudgeon

    Thats a totally incorrect assumption and the fact that so many ideas have been produced in this thread about how to solve your problem prove that even working withing the confines of an unmodified site, when you want to accomplish something, how you have your site set up makes all the difference in the world as to the best approach to take. Once you start adding extra fields and categories your site IS different and thinking otherwise will just ad to confusion between you and those trying to help which over time will greatly reduce your chances of getting help.
  10. T0m1 Customer

    Hi Larry,

    Apologise if you took offence to my reply as this truly was not my intention. I am greatlful for any and all help given.

    I agree that I may look at things at times with a narrow mind. I have been as truthful in the setup and info of my site as anyone could be, and in what exactly I had hoped to achieve.

    I agree that there are many things which may affect the way in which a modification may work, which is why I was looking at performing the mod before anything else was done. In fairness if I take your membership module as an example, you designed it and thought it up to work a particular way. Now it works exactly as you thought it up for many that buy it and use it other than those with who's install of 68c it is not compatible, the core has been altered or those of which do not read the write up.
    Having additional groups doesn't prevent or alter the workings of your mod in any way, nor does having more packages. This is exactly what I was looking for, a method by which it didn't make the slightest difference if I had 2 extra fields or 99 (as the ones needed for the plugin/condition to work would have been specified).

    Obviously my interpretation of a different system in comparison to your is different.
    I would think that my install of 68c with lets say 8 categories and 10 sub cats and 6 extra fields is no different than yours as an example with 2 categories, no sub cats and 1 extra field. Only because they are both being used within the confines of the original design of the system. For this I apologise clearly I need to be much more specific at times in the details I give, but on the same token if these were very relevant you only had to ask :).

    Again, as mentioned above I ment no offence in my response and if any were caused I apologise.

    Kindest regards,
  11. Lhotch curmudgeon

    Tom,

    in short the best way to accomplish something is based on many factors beyond just your desired result.

    As someone new to 68C I can understand why you dont see the bigger picture but you also need to understand that many of the things you think dont matter are actually key issues in the decision process of how best to proceed.

    As a developer we are constantly faced with these challenges, people think Oh he can write code this will be easy. Sometimes it is, sometimes is deceptivly complex but for those not in our shoes they take it for granted.

    Now back to your 'problem', now that I know what we are dealing with the solution is not that difficult. As I have already stated, the extra fields are presented to the template as an array of data, the array is looped over and each item is checked to se if it has a value and if it does its displayed.

    so, look a the debug console to see your extra fields.....

    look at the viewlistoing.tpl template to see the section that loops over

    PHP:

    {* Extra Fields *}
                {foreach 
    from=$extrafields item=extras}
                <
    tr>
                    <
    td><strong>{$extras.title}:</strong></td>
                    <
    td>
                        {if isset(
    $extras.value)}
                          {foreach 
    key=key item=item from=$extras.value}
                            {
    $item|nl2br}<br />
                            {
    foreachelse}
                            {
    $extras.value}
                          {/foreach}
                         {/if}
                    </
    td>
                </
    tr>
                {/foreach}
                {* 
    End Extra Fields *}
    Okay, so now you have an extra field called "List Type" or what ever you named it, its a dropdown list with fixed choices.

    The template variable $extrafields is actually a multidimentional array or group of arrays within an array. The smarty foreach loop says that its going to break dow the $extrafields multidimensional array into single arrays and for each array its going to display values.

    The first thing in the loop an table row is created, then a data cell to hold the title of the exta field. If you want to have your extra field called "list type" not to be displayed in the ad for the client to see then what would you do? You have 2 options, set the extra field to not be seen in the ad OR use logic to check for the extra field in the foreach and dont display it if its encountered. If you set the field to not be displayed then the data wont be there to evaluate against so I would probably opt for the later.

    So now, if we are only concerned with the output and value of that one extra field and they are all being looped over, then all we have to do is ad a logic check in the existing loop to see if the current loop iteration is the extra field in question. Its important to note that the table row is created first after the foreach loop starts so if we dont want a row added if our "list type" extra field is encountered we would want to put the logic before the opening TR tag.....something like this...

    PHP:

    {* Extra Fields *}
                {foreach 
    from=$extrafields item=extras}
    {if 
    $extras.title != "List Type"}
                <
    tr>
                    <
    td><strong>{$extras.title}:</strong></td>
                    <
    td>
                        {if isset(
    $extras.value)}
                          {foreach 
    key=key item=item from=$extras.value}
                            {
    $item|nl2br}<br />
                            {
    foreachelse}
                            {
    $extras.value}
                          {/foreach}
                         {/if}
                    </
    td>
                </
    tr>
    {/if}
                {/foreach}
                {* 
    End Extra Fields *}
    So above3 all I did was say if the title of the current extra field being looped over IS NOT "List Type" then proceed, create the table row and data cells etc. That will allow all of your extra fields, regardless of how unique or many to be displayed by the list type field will not be.

    Ok, but maybe you dont actually want to hide the field, just change the vale of the extra field depending on its current setting, thats simple enough to do by simply replacing the bottom {/if} I added with an else and then adding in your needed logic to look at the value of the drop down and output what is desired.


    PHP:

    {* Extra Fields *}
                {foreach 
    from=$extrafields item=extras}
    {if 
    $extras.title != "List Type"}
                <
    tr>
                    <
    td><strong>{$extras.title}:</strong></td>
                    <
    td>
                        {if isset(
    $extras.value)}
                          {foreach 
    key=key item=item from=$extras.value}
                            {
    $item|nl2br}<br />
                            {
    foreachelse}
                            {
    $extras.value}
                          {/foreach}
                         {/if}
                    </
    td>
                </
    tr>
    {else}
    <
    tr>
                    <
    td><strong>{$extras.title}:</strong></td>
                    <
    td>
                        {if isset(
    $extras.value)}
                          {foreach 
    key=key item=item from=$extras.value}
                            {
    $item|nl2br}<br />
                            {
    foreachelse}

    {if 
    $extras.value == "Give Away"}
    Free to Good Home.
    {elseif 
    $extras.value =="Sell"}
    {
    $price|format_money}
    {/if}                        

                          {/foreach}
                         {/if}
                    </
    td>
                </
    tr>
    {/if]
                {/foreach}
                {* 
    End Extra Fields *}
  12. T0m1 Customer

    Hi Larry,

    What can I say other than my sincerest thanks. I will give this a test today :)

    Just to double check, where you have put "List Type" I need to insert the name of the field I gave it? Not the backend name but the regular name ?

    I will let you know how everything goes and how I fair :)

    Again very many thanks,

    Tom.
  13. T0m1 Customer

    Hi Larry,

    I have given the above code a try. Unfortunately I am still only seeing the out as per the inbuilt list extra fields function...

    It would seem it doesnt even get to your modified code before terminating as complete...

    However, upon having reordered the foreacha dn if statements a little I have got it to display as expected.

    I am unsure of the effects of doing so but, ive been able to "Split" your example into 2 seperate bits of code which allow me to place the price side of things with the price instead of bringing the price aspects down tot he extra fields are.

    So I now have the following, for the price controlled areas;
    PHP:
    {* Custom Extra Field *}
                {foreach 
    from=$extrafields item=extras}
                    {if 
    $extras.title == "Sale Type"}
                        <
    tr>
                            <
    td><strong>{$smarty.const.LANG_PRICE}:</strong></td>
                            <
    td>
                                {if isset(
    $extras.value)}
                                {foreach 
    key=key item=item from=$extras.value}
                                {if 
    $extras.value == "To Give Away"}
                                
    Free to good home.
                                {elseif 
    $extras.value == "Sell"}
                                {
    $price|format_money} {get_extra_field id=$view fid=7}
                                {/if}
                                {/foreach}
                                {/if}
                                </
    td>
                                </
    tr>
                     {/if}
                {/foreach}
                {* 
    End Custom Extra Field *}
    And then for the extra fields (have we had to set the "Sell, Give Away" one to show
    PHP:
    {* Extra Fields *}
                {foreach 
    from=$extrafields item=extras}
    {if 
    $extras.title != "Sale Type"}
                <
    tr>
                    <
    td><strong>{$extras.title}:</strong></td>
                    <
    td>
                        {if isset(
    $extras.value)}
                          {foreach 
    key=key item=item from=$extras.value}
                            {
    $item|nl2br}<br />
                            {
    foreachelse}
                            {
    $extras.value}
                          {/foreach}
                         {/if}
                    </
    td>
                </
    tr>
    {/if}
                {/foreach}
                {* 
    End Extra Fields *}
    This now (from first outlook) appears to be working like an absolute charm.

    Many many many thanks for all your help. I definately wouldnt have been able to do this without you, thats for sure

    Kindest regards,
  14. Lhotch curmudgeon

    I figured you would probably end up with another loop over the extra fields up at the price but wasnt going to get that involved until you had a basic understanding of how to evaluate the current loop over extra fields.

    Glad ya got it working.

Share This Page