Default Attribute Fields Products Manager

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Default Attribute Fields Products Manager

Post by personIsHere »

Greetings,

I am using Product manager to display information on the usual type of things, i.e., name img desc etc...
I have made a custom field for a stock table.

My question is as follows:

- In the same way that a default attribute can be added to a content block, i.e, {content assign='newName' default='<p>Default</p>'} etc

Is there any kind of equivalent to this from the way custom fields are generated in the template?

Something like this:

Code: Select all

    {foreach from=$entry->fields key='stockTable' item='field'}
        {if $field->stockTable == 'detail'}
            {$field->value default='<p>default text here</p>'}
        {/if}
        {if $field->name == 'stockTable'}
            {$field->value default='<p>default text here</p>'}
        {/if}
    {/foreach}
obviously that is not the correct solutiuon but is what I am trying to achieve doable? It's just so the client does not have to manually enter table every single time...

Hope this is all clear enough and makes sense in way question is written... first post on this forum. ;D

Thank you!
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: Default Attribute Fields Products Manager

Post by PinkElephant »

Hi,

There's a smarty modifier for that: "default" so something like...

Code: Select all

<p>{$field->value|default:'You said nothing so I say "Table"'}</p>

{$field->value|trim|default:'Table'}
... which is like...

Code: Select all

{if !empty($field->value)}
    {$field->value}
{else}
    Table
{/if}
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Re: Default Attribute Fields Products Manager

Post by personIsHere »

Hi Pink Elephant, thanks for responding - I see what you mean, and that does produce a default piece of content -

however what I really need to know if it's possible to do, is have the table with the table headings colour small medium etc actually appear in the content block in the back office so the content is editable by the user, so when they go to fill in their stock levels it is already created and they can just drop numbers in...

So just to re-iterate - WYSWYG should already have a table inside it generated ready to be filled.

Is that possible?

Or is that what you were getting at in the first place and I have misunderstood and done it wrong ...?

Thanks!
User avatar
PinkElephant
Forum Members
Forum Members
Posts: 169
Joined: Fri Feb 06, 2009 2:08 pm

Re: Default Attribute Fields Products Manager

Post by PinkElephant »

Ah, sorry -- I didn't realise you were talking about the admin view. Yes, templates can determine what's seen under admin but behaviour will vary by module but I've not tried the Products module so I better back off. I'm sure there will be a way of getting what you want...
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Re: Default Attribute Fields Products Manager

Post by personIsHere »

OK no worries thanks anyway hopefully someone else will know - ive tried various things and cannot seem to solve at the moment.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Default Attribute Fields Products Manager

Post by velden »

I doubt filling up a wysiwyg field this way is a good idea.
If you need data, better ask for this data and create the table in the template.

Some day you will need the data to create another layout. Consider to let the user/editor enter the data in another way.
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Re: Default Attribute Fields Products Manager

Post by personIsHere »

Ordinarily I would create some kind of a drop down field or other entry for data - here is the deal -

It is a cheap job.
They have products which are not being purchased online, simply information displayed and then price upon asking contact form kind of setup.

The table heaidngs will be (example HTML to demonstrate the nature of the table content)

Code: Select all

<table>
<tr>
<th>Colour</th>
<th>Small (stock quantity)</th>
<th>Medium (stock quantity)</th>
</tr>
<tr>
<td>Blue</td>
<td>12</td>
<td>98</td>
</tr>
<tr>
<td>Orange</td>
<td>13</td>
<td>0</td>
</tr>
</table>
Because I have been given absolutley no information about how many colours their range of 60 odd t shirts vary in, I feel the best way is, rather than creating a fixed amount of fields to be completed, that some kind of as-and-when repeater field is the best way so that they can add a new row of colours whenever they like.
Due to the scope of how little they are actually willing to pay for this I feel that maybe the best option is just let them make a table in WYSWYG since its not really that much skin of their nose to do that, however I would be interested what the best way of handling this for future reference would be?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Default Attribute Fields Products Manager

Post by velden »

I once wrote a guest article on https://www.cmscanbesimple.org/blog/simple-list

Perhaps this is something you can use. Just insert a NON wysiwyg text area and teach your client how to fill the information line by line

Code: Select all

Blue|12|98
Orange|13|0
For the client it might be an easy way to quickly fill in the information. You will have freedom of how to use the data.

Obviously you can change the separator | to another symbol.

Perfect for a cheap job ;-)
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Re: Default Attribute Fields Products Manager

Post by personIsHere »

Great solution! Am trying to make work but something has not quite worked...
Because I am using the Products Manager module I am under the impression that

Code: Select all

{content block=cnt_example assign=cnt_example label='Example' wysiwyg=false}
is not going to do anything...

I have created a custom field in the Field Definitions section of the module and called it cnt_example to remain consistant in the naming...
Presumibly this would not have a bearing on anything? Since the only real function that that content block was doing was assigning a name?...

Not sure why is not working to be honest... not displaying table but just UDT "content_to_array" requires parameters "content" and "assign" to be set

UDT

Code: Select all

if (!isset($params['assign']) || !isset($params['content'])) {
 echo 'UDT "content_to_array" requires parameters "content" and "assign" to be set';
 return;
}

$assign_var = $params['assign'];
$content = $params['content'];

$lines = array_filter(
  explode("\n",$content),
  function($a) {
    $b = trim($a);
    return ($b != '' && substr($a,0,1) != '#');
  }
);

$smarty->assign($assign_var, array_map(function($a){return trim($a);},$lines));

Product Detail Template

Code: Select all

{content_to_array assign=lines content=$cnt_example}
{if $lines|count > 0}
    <table>
        <tr>
            <th>Colour</th>
            <th>Small</th>
            <th>Medium</th>
            <th>Large</th>
        </tr>
        {foreach from=$lines item=line}
            {$items='|'|explode:$line}
            <tr>
                <td>{$items.0|default:'&nbsp;'}</td>
                <td>{$items.1|default:'&nbsp;'}</td>
                <td>{$items.2|default:'&nbsp;'}</td>
                <td>{$items.3|default:'&nbsp;'}</td>
            </tr>
        {/foreach}
    </table>
{/if}
Many thanks for all of your help so far - it is definitly a better solution than I would have come up with for sure!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Default Attribute Fields Products Manager

Post by velden »

Yeah, within the detail template you need to read the value of the specific field definition.

For Products module I think it will be something like:

Code: Select all

{content_to_array assign=lines content=$entry->fields.cnt_example->value}
Locked

Return to “Modules/Add-Ons”