How to configure and adapt Aimeos based shops as developer
Forum rules: Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#3584 by Innonic
02 Nov 2016, 11:51
Hello everyone,

I've been struggling with the shipping costs for some time now. There are products that have different size and weight.
But I can only tell: Shipping costs: DHL: xx.xx€, UPS yy.yy€, etc.
Of course I can add costs for shipping to each product itself which is shown in the shopping basket. But on the delivery/shipping page there is "0.00€" next to each shipping provider and that's inconsistent and ugly.
I read about decorators and so forth but is there a simple way to do that in the backend?
I haven't found a good tutorial for the creation of decorators and how to use (size) attributes I created myself and I don't have time to learn this from scratch.
Does anyone have a clue on what to do?

Thank you very much!
#3586 by aimeos
02 Nov 2016, 13:42
If the shipping costs of your products is mainly based on their weight, you can use the Weight decorator which is available out of the box:
https://github.com/aimeos/aimeos-core/blob/master/lib/mshoplib/src/MShop/Service/Provider/Decorator/Weight.php

Most of the documentation about services (and decorators) is available here:
https://aimeos.org/docs/Developers/Library/Service
#3598 by Innonic
07 Nov 2016, 10:36
Thank you for your answer.

I don't get along with this decorator thing. I searched for quite a long time now, but I don't find information on how to configure the decorators (for non-specialists). Is there somewhere a list of key-value-pairs to use? I guess I need a tutorial for dummies.

I see the reduction example with key 'reduction.basket-value-min' and value '{"EUR":"20"}'
That is pretty clear so far.

But how to trigger the weight decorator? Specifying the price of a product, you have to define a currency. That's where "EUR" comes from. 'Weight' is just a property with a value, no unit.
So what key and value do I have to use for the weight decorator? Is it like:

weight.max:{"kg":"10.0"}?

My decorator configuration does exactly... nothing!

I'm an absolute beginner so I hope you don't mind these questions. What should I see, if it was working?

Thank you very much
#3600 by aimeos
07 Nov 2016, 11:12
To use the "Weight" decorator in combination with e.g. the "Manual" delivery service provider, you have to enter
Code: Select allManual,Weight

into the "Provider" input field in the service item detail view (expert mode, "Service" tab).

The weight decorator has two configuration options you can add on the right side of the service item detail view:
- weight.min
- weight.max
Both require almost a number without measure, e.g.
Code: Select allweight.min 10.0
weight.max 15.75

As you've already noted, there's no measure included. It's assumed that you always use the same measure for all package weights, e.g. kg, g, lbs, etc. that you enter in the "Physical values" tab of the product detail view in the simple mode admin interface. The example above would show the delivery service item using the "Manual" provider only if the sum of the weight of all products is between 10 and 15.75 (whatever measure you use).
#3601 by Innonic
07 Nov 2016, 11:52
Thank you very much for that quick answer.

I configured everything exactly as you described it. I defined a product weight of 0.6 (kg).
I have defined a weight range from (weight.min) 0.6 to (weight.max) 10.0 (see image1).

Now I add the article 20 times to my shopping basket. But the behavior didn't change at all...

I get to the details of my shopping basket and it still calculates 20 times the shipping costs, etc.

I would be grateful if you could give me another hint on what I'm doing wrong.
Attachments
image1.png
image1.png (4.36 KiB) Viewed 989 times
#3602 by aimeos
07 Nov 2016, 12:43
There's still an error in reasoning. You've configured shippings costs in your product (costs per item) and if you add that product 20 times, you will get 20 times the shipping cost added (because it's per single item) in the basket.

The Weight decorator applies to the delivery option in the delivery page of the checkout process. It can show or hide delivery options depending if the weight of all products is in the configured range of the Weight decorator added to the delivery option or not. It doesn't change the shipping costs attached to a delivery option or the shipping costs per item!

Hence, remove the costs per item in your product and add three delivery options, each with its own price:
- Up to 0.6
- From 0.6 to 10.0
- Over 10.0
If you add the product (0.6kg) 20 times, only the delivery option for over 10kg will be shown.
#3603 by Innonic
07 Nov 2016, 13:31
Thank you very much, that did it! :D

I really appreciate your help and I'm very grateful!

I hope you grant me one last question:
If I use decorators in the future, where can I look up how the configuration (parameters) must look?
e.g.
JSON for Reduction -> reduction.basket-value-min:{"EUR":"200.00"}
Float values for Weight -> weight.max: 10.0, weight.min: 0.6
...

Thank you again for the great support!!!
#3604 by aimeos
07 Nov 2016, 13:42
Innonic wrote:If I use decorators in the future, where can I look up how the configuration (parameters) must look?
e.g.
JSON for Reduction -> reduction.basket-value-min:{"EUR":"200.00"}
Float values for Weight -> weight.max: 10.0, weight.min: 0.6


We've added the missing documentation for the Weight and Currency decorator in the meantime:
https://aimeos.org/docs/User_Manual/Administration_Interface/Service_decorators

Everything related to service decorators should be documented there.
If there's something missing or hard to understand (or examples missing), please drop us a note.

Innonic wrote:Thank you again for the great support!!!


Thank you very much!
We hope that you enjoy working with Aimeos in your project besides such issues.
If you have any suggestions what we can make better to simplify your life, please don't hesitate and tell us. This feedback is what an Open Source project needs :-)
#3663 by Innonic
22 Nov 2016, 14:03
Hello again 8-)

I encountered another little issue.
I wrote my own decorators and would like to be able to debug them a little. To achieve this I added a method to my decorators to write some things into a log file (which I added to the same directory).
But whatever I do, it seems that "fopen" is not able to access the file.
I created another file that contains nothing except the code to write "Hello" to the log file. That works perfectly. Therefore I don't think it's a rights or permission problem.
Can you tell me, why the same code doesn't work within the decorator?

The code simply is:
Code: Select all$data = "Hello";
$filehandle = fopen("debug.txt","w");
fwrite($filehandle, $data);
fclose($filehandle);


Thanks in advance!
#3665 by aimeos
22 Nov 2016, 14:59
Better use
Code: Select all$this->getContext()->getLogger()->log( 'your message' );

The output will be written to the madmin_log table.

Alternatively, you can use the error_log() method, which write the messages to the error.log of the web server.