Search

HI everyone, please need some help is this.

Here’s the problem: I have a section of “orders”, and this has a link field to another section of “items”. In the “items” have 2 main fields: quantity and unit value, and a third field that is a “Reflection Field” called “total value” with the expression: {number(entry/quantity) * number(entry/unit-value)}

So far all is well. the problem is that the Orders section has a field with the sum of all fields “total value” of the Items related.

Is there a way for that “Total” field of Orders section is calculated automatically by changing the data of Items section? If anyone has any better ideas…

Thank you very much for your attention and sorry for google translated english LOL =}

Is there a reason you need to actually store the total value in Orders, rather than generating it dynamically when you render your data on the front end?

My guess is that users are entering orders into the backend directly, without submitting them via events from a web frontend.

This could be done with a custom field type. You’d create an extension that provides a field, perhaps named “Order Details”. This field doesn’t do anything in Data Sources or Events, but its purpose is purely to render a panel in the backend using its displayPublishPanel method to return HTML. You would need to write some SQL lookups to find the related Item entries, but you could show a mini order summary, perhaps in a table:

Item    Quantity    Unit    Total
Item 1  1           1.99    1.99
Item 2  2           1.99    2.98
Item 3  8           1       8
                    TOTAL   12.97

But that depends on how complex you want it to go. You could simply sum the values of your Reflection field and do it in a single SQL query.

We did this recently on a site that had a section Bands (to store information about uploaded musician information), and to show a panel with an overview of the author entry (from a Users section):

Band info

The order is saved from frontend, but isn’t edited in. So far so good. But if client desire to change values, then the need to recalculate.

The Total value is stored more for practical purposes. Like avoid the need of client make the calcs in your own calculator… This isn’t a e-commerce system, just store orders.

So if is not possible to do de sum in parent section, i’ll need to do a frontend editing page. But this would be an extra work.

Thanks Czheng

Nickdunn, nice idea. There is a way to get via SQL the Total-value fields of the related Items section? No need to save in DB, like you say, just a little panel with this information. This would be an extension field?

Excuse my limited knowledge. Im newbie in Symphony :]

This would be an extension field?

Yes, it would require a few SQL JOINs I’m afraid. If this is your first jump into writing an extension it might be a leap too far. But in essence you’d want to:

  • obtain the current entry ID (which the field will know)
  • look at the database table for the Select Box Link (which is conducting the relationship between the two sections) for entries that use this ID as the link
  • sum the value of the Reflection field value for these linked entries

Yeah, my first jump. I’ll try, and make some reading in others similar extensions. I’m anxious waiting for more documentation about the development of extensions. Many ideas and desire to contribute.

Thanks a lot for help, I may come back with some new questions.

What do you think of a merger of the extensions: Reflection Field and Selectbox Link Field, using similar format to the publication of Entry URL Field? Like a “Reflection Link”. (I’m doing a Frankenstein extension here… lol)

I’ve been playing with an alternative idea tonight. I’ll hopefully be releasing something shortly which should help you out with this :-)

Nickdunn, after 12 hours trying, I got something that works. It isn’t cute but works fine in my case. Unfortunately I could not do with configurations.

By the way, I can’t get entry_id in function prepareTableValue(). Has some way to do this?

I’m still interested in knowing about your alternative idea! Thanks. =]

germchaos, HTML Panel might be of use to you. The README shows an example that fits your use-case quite well.

Woa! Awesome! Very useful extension! =D

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details