owebia / magento2-module-advanced-shipping

Other
90 stars 28 forks source link

Configurable products being counted twice #61

Closed bexdoggett closed 4 years ago

bexdoggett commented 5 years ago

Hello,

This may be more of a question then issue, I've gone through the docs and I'm not sure what else to use. I've been using array_sum and array_map to go through all products in the cart, then find a custom product attribute value and assign a shipping cost for each product, which are all then added up to a total shipping cost.

It is working, however the total amount was more then the calculation, so I stripped it back to just be equal to how many items were in the cart i.e. 5 items shipping cost is £5. It looks like configurable products are being counted twice, so if I have a simple product and a configurable product in my cart, rather than the expected £2 I have a shipping cost of £3. Below is the code I'm using:

addMethod('id_002', [
        'title'      => "Owebia Delivery",
        'price'      => array_sum(
                            array_map(
                                function ($item) {
                                        return $item->qty;
                                },
                                $request->all_items
                            )
                        ) ,
    ]);

I'm on Magento 2.3.2 using luma demo data and 2.6.3 of your module.

owebia commented 5 years ago

Hi, you can use $item->product_type to check if product is "configurable" or "simple"