Forum Activity for @ken-rich

Ken Rich
@ken-rich
04/03/16 06:43:45PM
926 posts

How to limit the number of items a user can create?


Jamroom Developers

This seems like it should be a very simple thing to accomplish, but I have made dozens of attempts and wasted many hours.

On the item_index.tpl of a module, once a profile owner has created an item in that module, I want the create button to disappear in that profile.

This is in order to limit them to the creation of one item, unless they delete it, in which case the button should reappear.

I am thinking an IF statement should work but I am doing something wrong. The button code is the same for all modules, in this case sales so:

{jrCore_item_index_buttons module="xxSales" profile_id=$_profile_id}

I am adding to it variations of code like:

 
  {if isset($_item_id.item_id) && strlen($_item.item_id) > 0}
{else}
{jrCore_item_index_buttons module="xxSales" profile_id=$_profile_id}        
      {/if}

In some variations, I try using values creates by the form like sales_editor or sales_title. I've tried empty and is null instead of isset.

In every case that didn't "break the page", the buttons were hidden on two test accounts or not hidden on the two accounts. It treats them the same but one has an item created and one doesn't.

I'm expecting the IF statement to hide the buttons on the account with the item created but not the other. That never happens in any of my coding attempts.

What am I doing wrong?
updated by @ken-rich: 07/29/16 04:28:38AM
Ken Rich
@ken-rich
03/30/16 09:22:29AM
926 posts

One Editable Space - Not Unlimited


Design and Skin Customization

Ah... I see... I didn't know that stuff was available to all parts of the profile - cool.

I think I can get that to work, the only downside is another potentially confusing editor on the main profile form (my free members don't even have Foxycart sales).

I think I've stumbled across another possible solution. I've discovered (by trial and error) that the create button is on the item_index.tpl page as:

{jrCore_item_index_buttons module="xxSales" profile_id=$_profile_id}

So I'm thinking if I can simply come up with an IF statement to show the button ONLY when there is no item already created in the datastore, then only one can be created. Unless the current one is deleted then the button should show again - allowing a new one to be created.

So I've done HOURS AND HOURS of experiments with statements like:

{if empty($_items)}
{jrCore_item_index_buttons module="xxSales" profile_id=$_profile_id}
{/if}

Some of my experimental statements break the page, some remove the create button on profiles that have an item created (but also on those which do not). Some don't remove it on either.

After literally dozens of attempts, I have been unable to find one that will only show the create button if the datastore is empty. I don't know if I should be trying ID, post, item or what - nothing seems to work.

What would you suggest? Can such a statement be crafted or am I "barking up the wrong tree"?
updated by @ken-rich: 03/30/16 09:23:12AM
Ken Rich
@ken-rich
03/30/16 08:43:56AM
926 posts

User Tip - "Embed Saleable Files"


Design and Skin Customization

The current default for the File Module creates "dead links" and no buy button when a file that is for sale is embedded. Personally, I think that is a bad user experience and not useful at all.

So I have made my saleable files embed with the Buy button, and instead of "dead links", the file title and image link back to the file's detail page. So a saleable file then embeds like any other product for sale.

Jamroom isn't planning on changing the default by giving this to everyone as an update, so here is how it's done for those who are interested.

In your Admin Panel go to Profiles and then Files. Then in the templates folder modify item_embed.tpl to the code below

{jrCore_module_url module="jrFile" assign="murl"}

 {if empty($item.file_file_item_price) && empty($item.file_file_item_bundle)}
<div>
    <table class="item" style="width:80%;margin-left:0">
        <tr>
            <td rowspan="2" style="width:5%;padding-right:12px">
               <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.file_title_url}">{jrCore_image module="jrFile" image="`$item.file_file_extension`.png" width="42" height="42" alt=$item.file_file_extension}</a>
            </td>
            <td>
                <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.file_title_url}"><h3>{$item.file_title}</h3></a>
                  <td rowspan="2" style="width:5%;padding-right:12px"> <a href="{$jamroom_url}/{$murl}/download/file_file/{$item._item_id}">{jrCore_image module="jrFoxyCartBundle" image="IELTS-writing-task-2-free-download.png" width="140" alt="Free Download"}</a>
            </td>
        </tr>
        <tr>
            <td class="sublabel" style="width:95%">{$item.file_file_name}, {$item.file_file_size|jrCore_format_size}
               
 <br>{if strlen($item.file_description) > 0}
     {$item.file_description|truncate:90}
{/if}
</td>

        </tr>
    </table>
</div>
{else}
<div>
    <table class="item" style="width:80%;margin-left:0">
        <tr>
            <td rowspan="2" style="width:5%;padding-right:12px">
                <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.file_title_url}">{jrCore_image module="jrFile" image="`$item.file_file_extension`.png" width="42" height="42" alt=$item.file_file_extension}</a>
            </td> 
            <td>
                <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.file_title_url}"><h3>{$item.file_title}</h3></a>
           </td>
                      
  <td rowspan="2" style="width:20%;white-space:nowrap;padding-right:12px">
 {jrCore_module_function function="jrFoxyCart_add_to_cart" module='jrFile' field='file_file' item=$item}
 </td>          
        </tr>
        
        <tr>
            <td class="sublabel" style="width:95%">{$item.file_file_name}, {$item.file_file_size|jrCore_format_size}
 <br>{if strlen($item.file_description) > 0}
     {$item.file_description|truncate:90}
{/if}
         </td>            
        </tr>
      
    </table>
</div>
{/if} 
       

Note: The description section is optional and just for those who want a short description of their file to also embed (helpful). You must add a description section to your create/update forms as a text area for this to work. Then this section of code will be relevant.

 <br>{if strlen($item.file_description) > 0}
     {$item.file_description|truncate:90}


To see how this works, I embedded a saleable PDF book here - http://kenrich.me/page/227/in-defense-of-contemporary-christian-music

So now the file is saleable wherever it is embedded on my network, and the PDF icon and title link back to the files detail page. The detail page is also enhanced by adding a full editor to the form but that's a separate issue.

This could potentially be good for downloadable ticket sales too - let me know if you implement a system where the ticket codes automatically increment - thanks.
updated by @ken-rich: 07/15/16 09:51:21PM
Ken Rich
@ken-rich
03/29/16 08:27:33PM
926 posts

One Editable Space - Not Unlimited


Design and Skin Customization

michael:
Ah, this is the part I was not understanding 'to have an editable space on top just like the profile_index on the Ningja'
You're wanting to have only a single item be able to be created.
There are a couple of ways to do it, I would probably go with adding that editor to add the top of the sales page content to the profile update screen rather than the module itself.

Can you please tell me where to find the profile update screen as I don't know what you are referring to.
Ken Rich
@ken-rich
03/27/16 07:56:36PM
926 posts

Wrong Metadata on New Module


Design and Skin Customization

I just did a test and I believe this is a cross domain issue. My profile is "mapped" with the domain mapping module.

There is another profile in the same quota (has the new Sales module) that is not mapped and it's proper metadata is showing.

Brian fixed this issue in other modules but I don't know how.
updated by @ken-rich: 03/27/16 07:57:16PM
Ken Rich
@ken-rich
03/27/16 07:43:28PM
926 posts

One Editable Space - Not Unlimited


Design and Skin Customization

OK - I tried that above again and still couldn't get it to work (nothing showed). Then I tried this in the item_index.tpl and it didn't work either.

{if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
           {/if}

I also tried deactivating the create function but as I suspected I was then not able to make an initial entry.
updated by @ken-rich: 03/27/16 07:45:29PM
Ken Rich
@ken-rich
03/27/16 07:03:10PM
926 posts

One Editable Space - Not Unlimited


Design and Skin Customization

michael:
I would probably go with adding that editor to add the top of the sales page content to the profile update screen rather than the module itself.

Can you elaborate on that statement as I am not understanding.

1) I don't know what you mean by the "profile update screen". Do you mean in the form designer?

2) The editor is currently added to the form as sales_editor and active for both create and update. I'm thinking it should perhaps be active for update only.

3) I don't know where you are getting "$profile_sales_header". I gave the editor I added to the form designer the name "sales_editor", so shouldn't that be used? Is that what you are referring to by a different name?

3) I initially tried copying the Ningja profile_index in a similar manner as what you are suggesting but couldn't get it to work, probably because I was missing something. I think I tried it like this in item_index.tpl

{* If the member edits the page it will show here *}
        {if strlen($sales_editor) > 1}
               <div class="row" style="margin-top:0;important!">
            <div class="col12 last" style="margin-top:0;important!">
                <div class="block" style="margin-top:0;important!">
                    <div class="block_content" style="margin-top:0;important!">
                        <div class="item" style="margin-top:0;important!">
                            {$sales_editor|jrCore_format_string:$profile_quota_id}
              
                </div>
            </div>
        </div>
        {/if}
                </div>
            </div>
Ken Rich
@ken-rich
03/27/16 04:34:35PM
926 posts

One Editable Space - Not Unlimited


Design and Skin Customization

Ah - I changed the inner part of that
{if strlen($item.sales_editor) > 0}     
{$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
           {/if} 

The rest was already there and I don't know enough about code to change it. If that is causing my unwanted loop perhaps that is what needs to be changed.

What I am trying to accomplish is simple. I want the sales page to have an editable space on top just like the profile_index on the Ningja skin does.

I'm going to do an experiment with deactivating sales_editor for create and just have it for modify. Perhaps that's the problem.

I just checked and that seems to be how it is being done for the profile_index editor though I can't understand how the initial space is created.
updated by @ken-rich: 03/27/16 04:35:57PM
Ken Rich
@ken-rich
03/27/16 04:17:05PM
926 posts

Wrong Metadata on New Module


Design and Skin Customization

No, it wasn't there. So I copied the one from blogs and modified by replacing blog with sales wherever I found it. Then reset cache.

{jrCore_module_url module="xxSales" assign="murl"}
<meta property="og:url" content="{$og_item_url|replace:"http:":"`$method`:"}" />
<meta property="og:see_also" content="{$og_item_url|replace:"http:":"`$method`:"}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="{$sales_title|jrCore_entity_string}" />
{if isset($sales_image_size) && $sales_image_size > 100}
<meta property="og:image" content="{$jamroom_url|replace:"http:":"`$method`:"}/{$murl}/image/sales_image/{$_item_id}/xxlarge/_v={$sales_image_time}" />
<meta property="og:image:width" content="512" />
<meta property="og:image:height" content="385" />
{/if}
<meta property="og:description" content="{$sales_text|jrCore_format_string:$profile_quota_id|jrCore_strip_html|jrCore_entity_string|truncate:200}" />
<meta property="og:site_name" content="{$_conf.jrCore_system_name}" />
<meta property="og:updated_time" content="{$_updated}" />

However, as you can see in the attached screenshot, the metadata is still wrong in the Facebook debugger.
metadata.JPG.jpg metadata.JPG.jpg - 110KB
Ken Rich
@ken-rich
03/27/16 12:41:19PM
926 posts

One Editable Space - Not Unlimited


Design and Skin Customization

Hmmm... This is new to me - will have to study and experiment - thanks.

However, I am not exactly interested in DISPLAYING only one editor output (if multiple ones can be created , stored, or are available on detail pages).

I'm really interested in limiting the CREATION to just one, not in allowing the creation of many but the DISPLAY of just one.

I'm not sure if your loop solution addresses that.
updated by @ken-rich: 03/27/16 12:57:01PM
  15