shadimanna / dhl-logistic-services-for-woocommerce

6 stars 8 forks source link

CN22 generation should use prices from order not from product #205

Open thefool opened 1 year ago

thefool commented 1 year ago

Hi, we use your plugin, and the CN22 shows the wrong values. It always shows the base price of the product in our shop, rather than the one from the current order. This means that when the price is dropped using

the CN22 always shows the original price of the product, not the one that would be on the accompanying invoice.

Could you change your plugin so that it reflects the prices of the items in the order, as they are set in the order?

Abdalsalaam commented 1 year ago

Hello @thefool Let me check this, thank you!

thefool commented 12 months ago

Hi, just checking - is there any progress on this?

alexan059 commented 11 months ago

Hi, according to lines 820-824 in abstract-pr-dhl-wc-order.php it was never meant to exclude the discount price:

https://github.com/shadimanna/dhl-logistic-services-for-woocommerce/blob/a1f938f729cf97d082b330a6b75a7bbe6ec629b5/pr-dhl-woocommerce/includes/abstract-pr-dhl-wc-order.php#L820-L824

Later in line 862 and 879 the original product price gets set if the previous value was 0:

https://github.com/shadimanna/dhl-logistic-services-for-woocommerce/blob/a1f938f729cf97d082b330a6b75a7bbe6ec629b5/pr-dhl-woocommerce/includes/abstract-pr-dhl-wc-order.php#L860-L863

I would suggest to use (line_subtotal + line_subtotal_tax) / qty instead of line_total / qty to solve this problem. But we want the discounted price, if the value is bigger than 0. Changing this line would remove this szenario.

Our problem is that we have a discount of 100% on a product that has a different price than the original one, e. g.

Original Product: 99€ Adjusted Price in Order: 59€ (line_subtotal is 59) Order Discount: 100% (so line_total is 0)

We get 99€ instead of 59€ on the CN22.

So maybe we can add another fallback after line 822 like

if ( empty( $new_item['item_value'] ) ) {
    $new_item['item_value'] = ( ( $item['line_subtotal'] + $item['line_subtotal_tax'] ) / $item['qty'] );
}

and $product_variation->get_price() is called as a last resort.