Computed Field - Shipping Method

Hello,
I have been trying to generate a Complimentary attribute in Sales Orders module to ‘compute’ the Shipping Method…to no avail!
This is what I’ve tried so far:
(($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->shipping_method: ‘not found’)

This produces nothing.
Can someone clue me in? What am I doing wrong?

Also tried this:
(($reloadedobj = new llx_c_shipment_mode($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->libelle: ‘-1’)

I did discover that the following:
$objectoffield->shipping_method_id

at least results in the index of the shipping method correctly.

But how to get the label?

Hi,

Is this for adding to each orderline?

and did you add this in the product?
so an extrafield shipment_mode?

or what is it that you would like to produce

Hello @PimDolie,
I’m trying to make a Complimentary attribute in Sales Orders module to ‘compute’ the Shipping Method.

I selected a Shipping Method when creating a Sales Order. However, I think this information is actually stored in the Shipment module, correct?

Thanks

As of right now, {object_shipping_method} tag does not produce anything in my Sales Order ODT template file.
v19.02

@PimDolie
So, as a workaround, I’m trying to make an extra field (Complimentary attribute) to compute or link to the Shipping Method specified and stored in the Shipment module.
(For some reason {object_shipping_method} works just fine with Shipment ODTs.)

Then all I need to do is add the new {…options…} tag to my Sales Order ODT.

Maybe there is another way?
Thanks

Hello :slight_smile:

can you try
(($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->shipping_method: ‘not found’))
or
(($reloadedobj = new llx_c_shipment_mode($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->libelle: ‘-1’))

Good continuation

Hello @pcbleu

I tried your suggestions with the following results:

Bad string syntax to evaluate (found chars that are not chars for simplestring): (($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->shipping_method: ‘not found’))

and

Bad string syntax to evaluate (found chars that are not chars for simplestring): (($reloadedobj = new llx_c_shipment_mode($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->libelle: ‘-1’))

Maybe I did something wrong?

Thanks

please see here:

Hello @DG-Rilling

Thank you for the input.

Is there any more information on this error? Is this because of the formula or the result?

Is there anything I can do to work around this? All I want is to load the Shipping Method for use on Sales Order documents.

Hello :slight_smile:

The problem is due to the text in the first post - quoted string ‘-1’ were tranformed with ‘-1’
can you try
(($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->shipping_method: 'not found'))
or
(($reloadedobj = new llx_c_shipment_mode($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->libelle: '-1'))

Good continuation

—Any other ideas?—

Hello :slight_smile:

The problem is due to the text in the first post - quoted string ‘-1’ were tranformed with ‘-1’
can you try
(($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->shipping_method: 0))

Good continuation

OK

I tried that as well as:
(($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0 ? $reloadedobj->shipping_method: 1))

I did not get the “Bad string syntax to evaluate (found chars that are not chars for simplestring):” error.

In fact, I got nothing at all. (blank)

Any other ideas?

Hello

It is probably because the ($objectoffield->id) does not represent an expedition record

Make sure that you use this formula with an expedition extrafields

Good continuation

I believe the closing brackets are wrong…

Please try this:

(($reloadedobj = new Expedition($db)) && ($reloadedobj->fetchNoCompute($objectoffield->id) > 0)) ? $reloadedobj->shipping_method: 'not found'

@DG-Rilling
Thanks

I just tried that. The result was blank.

Are we looking in the correct place? Where is the Sales Order “Shipping method” saved?

I think this solution is very close:

$objectoffield->shipping_method_id

Result:
image

This appears to result with an Index # (5) for the selected “Shipping Method”.

Does anyone know how to change the result from the shipment ID to the shipment Label?

?I’m confused?
The label is shown above in the “Shipping method”.
Why did you need this again in a computed field?

Anyway you can use:

(($result = $db->query('select description from llx_c_shipment_mode where rowid = " '.$objectoffield->shipping_method_id.'" ')) && $row = $db->fetch_object($result)) ? $row->description : 'not found'

@DG-Rilling
Thanks

I just tried that with the following result:

Any more ideas?